aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--backends/networking/sdl_net/localwebserver.h5
-rw-r--r--gui/storagewizarddialog.cpp50
-rw-r--r--gui/storagewizarddialog.h3
3 files changed, 34 insertions, 24 deletions
diff --git a/backends/networking/sdl_net/localwebserver.h b/backends/networking/sdl_net/localwebserver.h
index 3512583605..107c21e341 100644
--- a/backends/networking/sdl_net/localwebserver.h
+++ b/backends/networking/sdl_net/localwebserver.h
@@ -47,10 +47,11 @@ typedef struct _TCPsocket *TCPsocket;
namespace Networking {
+#define NETWORKING_LOCALWEBSERVER_ENABLE_PORT_OVERRIDE
+
class LocalWebserver : public Common::Singleton<LocalWebserver> {
static const uint32 FRAMES_PER_SECOND = 20;
static const uint32 TIMER_INTERVAL = 1000000 / FRAMES_PER_SECOND;
- static const uint32 DEFAULT_SERVER_PORT = 12345;
static const uint32 MAX_CONNECTIONS = 10;
friend void localWebserverTimer(void *); //calls handle()
@@ -84,6 +85,8 @@ class LocalWebserver : public Common::Singleton<LocalWebserver> {
void resolveAddress(void *ipAddress);
public:
+ static const uint32 DEFAULT_SERVER_PORT = 12345;
+
LocalWebserver();
virtual ~LocalWebserver();
diff --git a/gui/storagewizarddialog.cpp b/gui/storagewizarddialog.cpp
index a8574ab7d2..299da11812 100644
--- a/gui/storagewizarddialog.cpp
+++ b/gui/storagewizarddialog.cpp
@@ -61,15 +61,15 @@ StorageWizardDialog::StorageWizardDialog(uint32 storageId):
new ButtonWidget(this, "GlobalOptions_Cloud_ConnectionWizard.OpenUrlButton", _("Open URL"), 0, kOpenUrlCmd);
_connectWidget = new ButtonWidget(this, "GlobalOptions_Cloud_ConnectionWizard.ConnectButton", _("Connect"), 0, kConnectCmd);
-#ifdef USE_SDL_NET
- // hide fields and even the button if local webserver is on
- returnLine1->setLabel(_s("You would be navigated to ScummVM's page"));
- returnLine2->setLabel(_s("when you'd allow it to use your storage."));
- for (uint32 i = 0; i < CODE_FIELDS; ++i)
- _codeWidget[i]->setVisible(false);
- _messageWidget->setVisible(false);
- _connectWidget->setVisible(false);
-#endif
+ if (couldUseLocalServer()) {
+ // hide fields and even the button if local webserver is on
+ returnLine1->setLabel(_s("You would be navigated to ScummVM's page"));
+ returnLine2->setLabel(_s("when you'd allow it to use your storage."));
+ for (uint32 i = 0; i < CODE_FIELDS; ++i)
+ _codeWidget[i]->setVisible(false);
+ _messageWidget->setVisible(false);
+ _connectWidget->setVisible(false);
+ }
}
void StorageWizardDialog::open() {
@@ -97,18 +97,18 @@ void StorageWizardDialog::open() {
}
}
-#ifdef USE_SDL_NET
- _stopServerOnClose = !LocalServer.isRunning();
- LocalServer.start();
- LocalServer.indexPageHandler().setTarget(this);
-#endif
+ if (couldUseLocalServer()) {
+ _stopServerOnClose = !LocalServer.isRunning();
+ LocalServer.start();
+ LocalServer.indexPageHandler().setTarget(this);
+ }
}
void StorageWizardDialog::close() {
-#ifdef USE_SDL_NET
- if (_stopServerOnClose) LocalServer.stopOnIdle();
- LocalServer.indexPageHandler().setTarget(nullptr);
-#endif
+ if (couldUseLocalServer()) {
+ if (_stopServerOnClose) LocalServer.stopOnIdle();
+ LocalServer.indexPageHandler().setTarget(nullptr);
+ }
Dialog::close();
}
@@ -182,12 +182,10 @@ void StorageWizardDialog::handleCommand(CommandSender *sender, uint32 cmd, uint3
close();
break;
}
-#ifdef USE_SDL_NET
case kStorageCodePassedCmd:
CloudMan.connectStorage(_storageId, LocalServer.indexPageHandler().code());
_close = true;
break;
-#endif
default:
Dialog::handleCommand(sender, cmd, data);
}
@@ -210,12 +208,18 @@ Common::String StorageWizardDialog::getUrl() const {
case Cloud::kStorageGoogleDriveId: url += "gd"; break;
case Cloud::kStorageBoxId: url += "bx"; break;
}
-#ifdef USE_SDL_NET
- url += "s";
-#endif
+
+ if (couldUseLocalServer()) url += "s";
return url;
}
+bool StorageWizardDialog::couldUseLocalServer() const {
+#ifdef USE_SDL_NET
+ return Networking::LocalWebserver::getPort() == Networking::LocalWebserver::DEFAULT_SERVER_PORT;
+#else
+ return false;
+#endif
+}
int StorageWizardDialog::decodeHashchar(char c) {
const char HASHCHARS[65] = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ?!";
diff --git a/gui/storagewizarddialog.h b/gui/storagewizarddialog.h
index 6b00d60915..26e8cd42ab 100644
--- a/gui/storagewizarddialog.h
+++ b/gui/storagewizarddialog.h
@@ -51,6 +51,9 @@ class StorageWizardDialog : public Dialog {
/** Return short scummvm.org URL for user to navigate to. */
Common::String getUrl() const;
+ /** Return whether fields should be used or not. */
+ bool couldUseLocalServer() const;
+
/**
* Return the value corresponding to the given character.
*