From ea0222b1e6268eb7153e637aa473f8bbad43be3d Mon Sep 17 00:00:00 2001 From: sithlord48 Date: Mon, 1 Dec 2025 21:39:58 -0500 Subject: [PATCH] refactor: App::loadConfig(const std::string&) => App::loadConfig(const QString &) --- src/lib/deskflow/App.h | 2 +- src/lib/deskflow/ClientApp.h | 2 +- src/lib/deskflow/ServerApp.cpp | 26 +++++++++++++++----------- src/lib/deskflow/ServerApp.h | 4 ++-- 4 files changed, 19 insertions(+), 15 deletions(-) diff --git a/src/lib/deskflow/App.h b/src/lib/deskflow/App.h index 94d4384bf..9fbee9afd 100644 --- a/src/lib/deskflow/App.h +++ b/src/lib/deskflow/App.h @@ -51,7 +51,7 @@ public: virtual void parseArgs() = 0; virtual void loadConfig() = 0; - virtual bool loadConfig(const std::string &pathname) = 0; + virtual bool loadConfig(const QString &filename) = 0; virtual const char *daemonInfo() const = 0; void setByeFunc(void (*bye)(int)) override diff --git a/src/lib/deskflow/ClientApp.h b/src/lib/deskflow/ClientApp.h index 286e5dc62..7dca2146d 100644 --- a/src/lib/deskflow/ClientApp.h +++ b/src/lib/deskflow/ClientApp.h @@ -38,7 +38,7 @@ public: { // do nothing } - bool loadConfig(const std::string &) override + bool loadConfig(const QString &) override { return false; } diff --git a/src/lib/deskflow/ServerApp.cpp b/src/lib/deskflow/ServerApp.cpp index b788f1243..405da2482 100644 --- a/src/lib/deskflow/ServerApp.cpp +++ b/src/lib/deskflow/ServerApp.cpp @@ -11,7 +11,6 @@ #include "arch/Arch.h" #include "base/IEventQueue.h" #include "base/Log.h" -#include "base/Path.h" #include "common/ExitCodes.h" #include "common/PlatformInfo.h" #include "common/Settings.h" @@ -90,11 +89,11 @@ void ServerApp::reloadSignalHandler(Arch::ThreadSignal, void *) events->addEvent(Event(EventTypes::ServerAppReloadConfig, events->getSystemTarget())); } -std::string ServerApp::currentConfig() const +QString ServerApp::currentConfig() const { bool useExt = Settings::value(Settings::Server::ExternalConfig).toBool(); - return useExt ? Settings::value(Settings::Server::ExternalConfigFile).toString().toStdString() - : Settings::defaultValue(Settings::Server::ExternalConfigFile).toString().toStdString(); + return useExt ? Settings::value(Settings::Server::ExternalConfigFile).toString() + : Settings::defaultValue(Settings::Server::ExternalConfigFile).toString(); } void ServerApp::reloadConfig() @@ -111,25 +110,30 @@ void ServerApp::reloadConfig() void ServerApp::loadConfig() { const auto path = currentConfig(); - if (path.empty()) { + if (path.isEmpty()) { LOG_CRIT("no configuration path provided"); bye(s_exitConfig); } if (!loadConfig(path)) { - LOG_CRIT("%s: failed to load config: %s", qPrintable(processName()), path.c_str()); + LOG_CRIT("%s: failed to load config: %s", qPrintable(processName()), path.toStdString().c_str()); bye(s_exitConfig); } } -bool ServerApp::loadConfig(const std::string &pathname) +bool ServerApp::loadConfig(const QString &filename) { + const auto path = filename.toStdString(); try { // load configuration - LOG_DEBUG("opening configuration \"%s\"", pathname.c_str()); - std::ifstream configStream(deskflow::filesystem::path(pathname)); + LOG_DEBUG("opening configuration \"%s\"", path.c_str()); +#ifdef SYSAPI_WIN32 + std::ifstream configStream(filename.toStdWString()); +#else + std::ifstream configStream(path); +#endif if (!configStream.is_open()) { - LOG_ERR("cannot open configuration \"%s\"", pathname.c_str()); + LOG_ERR("cannot open configuration \"%s\"", path.c_str()); return false; } configStream >> *m_config; @@ -137,7 +141,7 @@ bool ServerApp::loadConfig(const std::string &pathname) return true; } catch (ServerConfigReadException &e) { // report error in configuration file - LOG_ERR("cannot read configuration \"%s\": %s", pathname.c_str(), e.what()); + LOG_ERR("cannot read configuration \"%s\": %s", path.c_str(), e.what()); } return false; } diff --git a/src/lib/deskflow/ServerApp.h b/src/lib/deskflow/ServerApp.h index 31d7d0620..ba5e4dd0f 100644 --- a/src/lib/deskflow/ServerApp.h +++ b/src/lib/deskflow/ServerApp.h @@ -56,7 +56,7 @@ public: const char *daemonName() const override; const char *daemonInfo() const override; void loadConfig() override; - bool loadConfig(const std::string &pathname) override; + bool loadConfig(const QString &filename) override; deskflow::Screen *createScreen() override; int mainLoop() override; int runInner(StartupFunc startup) override; @@ -107,7 +107,7 @@ private: std::unique_ptr getSocketFactory() const; NetworkAddress getAddress(const NetworkAddress &address) const; - std::string currentConfig() const; + QString currentConfig() const; bool m_suspended = false; Server *m_server = nullptr; ServerState m_serverState = ServerState::Uninitialized;