refactor: remove auto fallback paths for server binary

they are not correct in the help and its dynamic based on the first found Deskflow.conf file. The gui sets this manually and users running the cli should too
This commit is contained in:
sithlord48 2025-04-23 10:03:37 -04:00 committed by Chris Rizzitello
parent 48f824ca31
commit ebc6186fe7

View file

@ -114,15 +114,11 @@ void ServerApp::parseArgs(int argc, const char *const *argv)
void ServerApp::help() void ServerApp::help()
{ {
const auto userConfig = QString(Settings::UserSettingFile).toStdString();
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
<< " --config <pathname>"
<< " [--address <address>]" << " [--address <address>]"
<< " [--config <pathname>]"
#if WINAPI_XWINDOWS #if WINAPI_XWINDOWS
<< " [--display <display>] [--no-xinitthreads]" << " [--display <display>] [--no-xinitthreads]"
@ -136,8 +132,8 @@ void ServerApp::help()
<< "Start the " << kAppName << " mouse/keyboard sharing server.\n" << "Start the " << kAppName << " mouse/keyboard sharing server.\n"
<< "\n" << "\n"
<< " -a, --address <address> listen for clients on the given address.\n" << " -a, --address <address> listen for clients on the given address.\n"
<< " -c, --config <pathname> use the named configuration file " << " -c, --config <pathname> path of the configuration file\n"
<< "instead.\n" HELP_COMMON_INFO_1 << HELP_COMMON_INFO_1
<< " --disable-client-cert-check disable client SSL certificate \n" << " --disable-client-cert-check disable client SSL certificate \n"
" checking (deprecated)\n" " checking (deprecated)\n"
<< HELP_SYS_INFO HELP_COMMON_INFO_2 << "\n" << HELP_SYS_INFO HELP_COMMON_INFO_2 << "\n"
@ -158,15 +154,7 @@ void ServerApp::help()
<< "hostname must be the address or hostname of an interface on the " << "hostname must be the address or hostname of an interface on the "
<< "system.\n" << "system.\n"
<< "The default is to listen on all interfaces. The port overrides the\n" << "The default is to listen on all interfaces. The port overrides the\n"
<< "default port, " << kDefaultPort << ".\n" << "default port, " << kDefaultPort << ".\n";
<< "\n"
<< "If no configuration file pathname is provided then the first of the\n"
<< "following to load successfully sets the configuration:\n"
<< " " << orConfig << "\n"
#ifndef Q_OS_WIN
<< " " << userConfig << "\n"
#endif
<< " " << sysConfig << "\n";
LOG((CLOG_PRINT "%s", help.str().c_str())); LOG((CLOG_PRINT "%s", help.str().c_str()));
} }
@ -190,43 +178,13 @@ void ServerApp::reloadConfig(const Event &, void *)
void ServerApp::loadConfig() void ServerApp::loadConfig()
{ {
bool loaded = false; const auto path = args().m_configFile;
std::string path; if (path.empty()) {
LOG((CLOG_CRIT "no configuration path provided"));
// load the config file, if specified m_bye(kExitConfig);
if (!args().m_configFile.empty()) {
path = args().m_configFile;
loaded = loadConfig(path);
} }
// load the default configuration if no explicit file given if (!loadConfig(path)) {
else {
path = QString("settings/%2").arg(kAppName).toStdString();
if (loadConfig(path)) {
loaded = true;
args().m_configFile = path;
}
#ifndef Q_OS_WIN
if (!loaded) {
path = QString(Settings::UserSettingFile).toStdString();
if (loadConfig(path)) {
loaded = true;
args().m_configFile = path;
}
}
#endif
if (!loaded) {
path = QString(Settings::SystemSettingFile).toStdString();
if (loadConfig(path)) {
loaded = true;
args().m_configFile = path;
}
}
}
if (!loaded) {
LOG((CLOG_CRIT "%s: failed to load config: %s", args().m_pname, path.c_str())); LOG((CLOG_CRIT "%s: failed to load config: %s", args().m_pname, path.c_str()));
m_bye(kExitConfig); m_bye(kExitConfig);
} }
@ -239,10 +197,7 @@ bool ServerApp::loadConfig(const std::string &pathname)
LOG((CLOG_DEBUG "opening configuration \"%s\"", pathname.c_str())); LOG((CLOG_DEBUG "opening configuration \"%s\"", pathname.c_str()));
std::ifstream configStream(deskflow::filesystem::path(pathname)); std::ifstream configStream(deskflow::filesystem::path(pathname));
if (!configStream.is_open()) { if (!configStream.is_open()) {
// report failure to open configuration as a debug message LOG((CLOG_ERR "cannot open configuration \"%s\"", pathname.c_str()));
// since we try several paths and we expect some to be
// missing.
LOG((CLOG_DEBUG "cannot open configuration \"%s\"", pathname.c_str()));
return false; return false;
} }
configStream >> *args().m_config; configStream >> *args().m_config;