Windows: Warn if Windows Firewall blocks PPSSPP.

This should alert people who are using Public firewall profiles or
similar, and have their sharing blocked.
This commit is contained in:
Unknown W. Brackets 2020-03-09 23:01:55 -07:00
parent 3a40a39a63
commit 4914c04989
2 changed files with 65 additions and 3 deletions

View File

@ -15,10 +15,16 @@
// Official git repository and contact information can be found at // Official git repository and contact information can be found at
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/. // https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
#include "ppsspp_config.h"
#include <algorithm> #include <algorithm>
#include <thread> #include <thread>
#include <mutex> #include <mutex>
#if PPSSPP_PLATFORM(WINDOWS) && !PPSSPP_PLATFORM(UWP)
#include "Common/CommonWindows.h"
#include <netfw.h>
#endif
#include "base/timeutil.h" #include "base/timeutil.h"
#include "file/path.h" #include "file/path.h"
// TODO: For text align flags, probably shouldn't be in gfx_es2/... // TODO: For text align flags, probably shouldn't be in gfx_es2/...
@ -41,6 +47,49 @@ static const int REPORT_PORT = 80;
static bool scanCancelled = false; static bool scanCancelled = false;
static bool scanAborted = false; static bool scanAborted = false;
enum class ServerAllowStatus {
NO,
YES,
UNKNOWN,
};
static ServerAllowStatus IsServerAllowed(int port) {
#if PPSSPP_PLATFORM(WINDOWS) && !PPSSPP_PLATFORM(UWP)
INetFwMgr *fwMgr = nullptr;
HRESULT hr = CoCreateInstance(__uuidof(NetFwMgr), nullptr, CLSCTX_INPROC_SERVER, __uuidof(INetFwMgr), (void **)&fwMgr);
if (FAILED(hr)) {
return ServerAllowStatus::UNKNOWN;
}
std::wstring app;
size_t sz;
do {
app.resize(app.size() + MAX_PATH);
// On failure, this will return the same value as passed in, but success will always be one lower.
sz = GetModuleFileName(nullptr, &app[0], (DWORD)app.size());
} while (sz >= app.size());
VARIANT allowedV, restrictedV;
VariantInit(&allowedV);
VariantInit(&restrictedV);
hr = fwMgr->IsPortAllowed(&app[0], NET_FW_IP_VERSION_ANY, port, nullptr, NET_FW_IP_PROTOCOL_TCP, &allowedV, &restrictedV);
fwMgr->Release();
if (FAILED(hr)) {
return ServerAllowStatus::UNKNOWN;
}
bool allowed = allowedV.vt == VT_BOOL && allowedV.boolVal != VARIANT_FALSE;
bool restricted = restrictedV.vt == VT_BOOL && restrictedV.boolVal != VARIANT_FALSE;
if (!allowed || restricted) {
return ServerAllowStatus::NO;
}
return ServerAllowStatus::YES;
#else
return ServerAllowStatus::UNKNOWN;
#endif
}
static std::string RemoteSubdir() { static std::string RemoteSubdir() {
if (g_Config.bRemoteISOManual) { if (g_Config.bRemoteISOManual) {
return g_Config.sRemoteISOSubdir; return g_Config.sRemoteISOSubdir;
@ -203,12 +252,21 @@ static bool LoadGameList(const std::string &url, std::vector<std::string> &games
return !games.empty(); return !games.empty();
} }
RemoteISOScreen::RemoteISOScreen() : serverRunning_(false), serverStopping_(false) { RemoteISOScreen::RemoteISOScreen() {
} }
void RemoteISOScreen::update() { void RemoteISOScreen::update() {
UIScreenWithBackground::update(); UIScreenWithBackground::update();
if (!WebServerStopped(WebServerFlags::DISCS)) {
auto result = IsServerAllowed(g_Config.iRemoteISOPort);
if (result == ServerAllowStatus::NO) {
firewallWarning_->SetVisibility(V_VISIBLE);
} else if (result == ServerAllowStatus::YES) {
firewallWarning_->SetVisibility(V_GONE);
}
}
bool nowRunning = !WebServerStopped(WebServerFlags::DISCS); bool nowRunning = !WebServerStopped(WebServerFlags::DISCS);
if (serverStopping_ && !nowRunning) { if (serverStopping_ && !nowRunning) {
serverStopping_ = false; serverStopping_ = false;
@ -233,6 +291,9 @@ void RemoteISOScreen::CreateViews() {
leftColumnItems->Add(new TextView(ri->T("RemoteISODesc", "Games in your recent list will be shared"), new LinearLayoutParams(Margins(12, 5, 0, 5)))); leftColumnItems->Add(new TextView(ri->T("RemoteISODesc", "Games in your recent list will be shared"), new LinearLayoutParams(Margins(12, 5, 0, 5))));
leftColumnItems->Add(new TextView(ri->T("RemoteISOWifi", "Note: Connect both devices to the same wifi"), new LinearLayoutParams(Margins(12, 5, 0, 5)))); leftColumnItems->Add(new TextView(ri->T("RemoteISOWifi", "Note: Connect both devices to the same wifi"), new LinearLayoutParams(Margins(12, 5, 0, 5))));
firewallWarning_ = leftColumnItems->Add(new TextView(ri->T("RemoteISOWinFirewall", "WARNING: Windows Firewall is blocking sharing"), new LinearLayoutParams(Margins(12, 5, 0, 5))));
firewallWarning_->SetTextColor(0xFF0000FF);
firewallWarning_->SetVisibility(V_GONE);
rightColumnItems->SetSpacing(0.0f); rightColumnItems->SetSpacing(0.0f);
Choice *browseChoice = new Choice(ri->T("Browse Games")); Choice *browseChoice = new Choice(ri->T("Browse Games"));

View File

@ -38,8 +38,9 @@ protected:
UI::EventReturn HandleBrowse(UI::EventParams &e); UI::EventReturn HandleBrowse(UI::EventParams &e);
UI::EventReturn HandleSettings(UI::EventParams &e); UI::EventReturn HandleSettings(UI::EventParams &e);
bool serverRunning_; UI::TextView *firewallWarning_ = nullptr;
bool serverStopping_; bool serverRunning_ = false;
bool serverStopping_ = false;
}; };
enum class ScanStatus { enum class ScanStatus {