refactor: settings for windows try to use registry unless portable install

new Settings::isUsingRegistry() true when using the registry
          move daemon log back to config dir
This commit is contained in:
sithlord48 2025-03-31 13:38:36 -04:00 committed by Nick Bolton
parent cf4fe32aab
commit 1b8067797e
3 changed files with 41 additions and 16 deletions

View file

@ -1,7 +1,10 @@
# GUI Config # GUI Config
Deskflow will automaticlly figure out where to save settings and other files.
## Unix Systems
The search order for a setting file is: The search order for a setting file is:
1. `<install-path>/settings/Deskflow.conf`
1. `<XDG_CONFIG_HOME>/Deskflow/Deskflow.conf` 1. `<XDG_CONFIG_HOME>/Deskflow/Deskflow.conf`
1. A user settings file 1. A user settings file
1. A system settings file 1. A system settings file
@ -9,10 +12,6 @@
A new settings file will be created in the user path if no settings file is found. A new settings file will be created in the user path if no settings file is found.
The path of the settings file will be used as the base for all other config files. The path of the settings file will be used as the base for all other config files.
### Windows
- System: `C:\ProgramData\Deskflow\Deskflow.conf`
- User: `C:\Users\userName\AppData\Local\Deskflow\Deskflow.conf`
### Linux ### Linux
- System: `/etc/Deskflow/Deskflow.conf` - System: `/etc/Deskflow/Deskflow.conf`
- User: `~/.config/Deskflow/Deskflow.conf` - User: `~/.config/Deskflow/Deskflow.conf`
@ -21,6 +20,17 @@
- System: `/Library/Deskflow/Deskflow.conf` - System: `/Library/Deskflow/Deskflow.conf`
- User: `~/Library/Deskflow/Deskflow.conf` - User: `~/Library/Deskflow/Deskflow.conf`
## Windows
The search order for a setting file is:
1. `<install-path>/settings/Deskflow.conf`
1. Windows Registry `HKCU\Software\Deskflow\Deskflow`
Windows will save to the install dir if settings are loaded from there. If not, it saves any other config files in: `C:\ProgramData\Deskflow\`
When using settings from the install dir its not recommend to have elevation enabled.
# Server Config Examples # Server Config Examples
The `deskflow-server` command accepts the `-c` or `--config` option, which takes one argument, The `deskflow-server` command accepts the `-c` or `--config` option, which takes one argument,

View file

@ -35,22 +35,27 @@ void Settings::setSettingFile(const QString &settingsFile)
Settings::Settings(QObject *parent) : QObject(parent) Settings::Settings(QObject *parent) : QObject(parent)
{ {
m_portableSettingsFile = m_portableSettingsFile.arg(QCoreApplication::applicationDirPath(), kAppName);
QString fileToLoad; QString fileToLoad;
#ifdef Q_OS_WIN
m_portableSettingsFile = m_portableSettingsFile.arg(QCoreApplication::applicationDirPath(), kAppName);
if (QFile(m_portableSettingsFile).exists()) { if (QFile(m_portableSettingsFile).exists()) {
fileToLoad = m_portableSettingsFile; fileToLoad = m_portableSettingsFile;
m_settings = new QSettings(fileToLoad, QSettings::IniFormat);
} else { } else {
if (!qEnvironmentVariable("XDG_CONFIG_HOME").isEmpty()) m_settings = new QSettings(QSettings::NativeFormat, QSettings::UserScope, kAppName, kAppName);
fileToLoad = QStringLiteral("%1/%2/%2.conf").arg(qEnvironmentVariable("XDG_CONFIG_HOME"), kAppName);
else if (QFile(UserSettingFile).exists())
fileToLoad = UserSettingFile;
else if (QFile(SystemSettingFile).exists())
fileToLoad = SystemSettingFile;
else
fileToLoad = UserSettingFile;
} }
#else
if (!qEnvironmentVariable("XDG_CONFIG_HOME").isEmpty())
fileToLoad = QStringLiteral("%1/%2/%2.conf").arg(qEnvironmentVariable("XDG_CONFIG_HOME"), kAppName);
else if (QFile(UserSettingFile).exists())
fileToLoad = UserSettingFile;
else if (QFile(SystemSettingFile).exists())
fileToLoad = SystemSettingFile;
else
fileToLoad = UserSettingFile;
m_settings = new QSettings(fileToLoad, QSettings::IniFormat); m_settings = new QSettings(fileToLoad, QSettings::IniFormat);
#endif
m_settingsProxy = std::make_shared<QSettingsProxy>(); m_settingsProxy = std::make_shared<QSettingsProxy>();
m_settingsProxy->load(fileToLoad); m_settingsProxy->load(fileToLoad);
qInfo().noquote() << "settings file:" << m_settings->fileName(); qInfo().noquote() << "settings file:" << m_settings->fileName();
@ -157,9 +162,16 @@ const QStringList Settings::validKeys()
bool Settings::isWritable() bool Settings::isWritable()
{ {
if (instance()->isNativeMode())
return true;
return instance()->m_settings->isWritable(); return instance()->m_settings->isWritable();
} }
bool Settings::isNativeMode()
{
return instance()->m_settings->format() == QSettings::NativeFormat;
}
const QString Settings::settingsFile() const QString Settings::settingsFile()
{ {
return instance()->m_settings->fileName(); return instance()->m_settings->fileName();
@ -167,6 +179,8 @@ const QString Settings::settingsFile()
const QString Settings::settingsPath() const QString Settings::settingsPath()
{ {
if (instance()->isNativeMode())
return SystemDir;
return QFileInfo(instance()->m_settings->fileName()).absolutePath(); return QFileInfo(instance()->m_settings->fileName()).absolutePath();
} }

View file

@ -140,6 +140,7 @@ public:
static void restoreDefaultSettings(); static void restoreDefaultSettings();
static QVariant defaultValue(const QString &key); static QVariant defaultValue(const QString &key);
static bool isWritable(); static bool isWritable();
static bool isNativeMode();
static const QString settingsFile(); static const QString settingsFile();
static const QString settingsPath(); static const QString settingsPath();
static const QString tlsDir(); static const QString tlsDir();