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,18 +1,17 @@
# GUI Config
Deskflow will automaticlly figure out where to save settings and other files.
## Unix Systems
The search order for a setting file is:
1. `<install-path>/settings/Deskflow.conf`
1. `<XDG_CONFIG_HOME>/Deskflow/Deskflow.conf`
1. A user settings file
1. A system settings file
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.
### Windows
- System: `C:\ProgramData\Deskflow\Deskflow.conf`
- User: `C:\Users\userName\AppData\Local\Deskflow\Deskflow.conf`
### Linux
- System: `/etc/Deskflow/Deskflow.conf`
- User: `~/.config/Deskflow/Deskflow.conf`
@ -20,6 +19,17 @@
### macOS
- System: `/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

View File

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

View File

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