refactor: ServerApp begin to use Settings

This commit is contained in:
sithlord48 2025-03-17 20:56:46 -04:00 committed by Nick Bolton
parent 6444e2c208
commit 6c8eca6c41

View file

@ -13,7 +13,7 @@
#include "base/Log.h" #include "base/Log.h"
#include "base/Path.h" #include "base/Path.h"
#include "base/TMethodEventJob.h" #include "base/TMethodEventJob.h"
#include "common/constants.h" #include "common/Settings.h"
#include "deskflow/App.h" #include "deskflow/App.h"
#include "deskflow/ArgParser.h" #include "deskflow/ArgParser.h"
#include "deskflow/Screen.h" #include "deskflow/Screen.h"
@ -112,8 +112,9 @@ void ServerApp::parseArgs(int argc, const char *const *argv)
void ServerApp::help() void ServerApp::help()
{ {
const auto userConfig = ARCH->concatPath(ARCH->getUserDirectory(), CONFIG_NAME); const auto userConfig = QString(Settings::UserSettingFile).toStdString();
const auto sysConfig = ARCH->concatPath(ARCH->getSystemDirectory(), CONFIG_NAME); const auto sysConfig = QString(Settings::SystemSettingFile).toStdString();
const auto orConfig = QStringLiteral("settings/%2").arg(kAppName).toStdString();
std::stringstream help; std::stringstream help;
help << "Usage: " << args().m_pname help << "Usage: " << args().m_pname
@ -160,7 +161,10 @@ void ServerApp::help()
<< "\n" << "\n"
<< "If no configuration file pathname is provided then the first of the\n" << "If no configuration file pathname is provided then the first of the\n"
<< "following to load successfully sets the configuration:\n" << "following to load successfully sets the configuration:\n"
<< " " << orConfig << "\n"
#ifndef Q_OS_WIN
<< " " << userConfig << "\n" << " " << userConfig << "\n"
#endif
<< " " << sysConfig << "\n"; << " " << sysConfig << "\n";
LOG((CLOG_PRINT "%s", help.str().c_str())); LOG((CLOG_PRINT "%s", help.str().c_str()));
@ -196,27 +200,27 @@ void ServerApp::loadConfig()
// load the default configuration if no explicit file given // load the default configuration if no explicit file given
else { else {
// get the user's home directory path = QString("settings/%2").arg(kAppName).toStdString();
path = ARCH->getUserDirectory(); if (loadConfig(path)) {
if (!path.empty()) { loaded = true;
// complete path args().m_configFile = path;
path = ARCH->concatPath(path, CONFIG_NAME); }
// now try loading the user's configuration #ifndef Q_OS_WIN
if (!loaded) {
path = QString(Settings::UserSettingFile).toStdString();
if (loadConfig(path)) { if (loadConfig(path)) {
loaded = true; loaded = true;
args().m_configFile = path; args().m_configFile = path;
} }
} }
#endif
if (!loaded) { if (!loaded) {
// try the system-wide config file path = QString(Settings::SystemSettingFile).toStdString();
path = ARCH->getSystemDirectory(); if (loadConfig(path)) {
if (!path.empty()) { loaded = true;
path = ARCH->concatPath(path, CONFIG_NAME); args().m_configFile = path;
if (loadConfig(path)) {
loaded = true;
args().m_configFile = path;
}
} }
} }
} }