From 40ad807d1372163efa68d13f182a294eb1819c74 Mon Sep 17 00:00:00 2001 From: slipher Date: Sat, 13 Jul 2024 00:43:16 -0500 Subject: [PATCH] Linux: store QSettings in a single location Fixes the Linux part of #121. Choose the location of our settings by changing the default location for settings, rather than customizing the parameter of our settings object. This makes it so the settings added by a component we depend on end up in the same place. Some more explanation quoted from the Github thread: > I still don't understand the reasoning? Is it that the name "Unvanquished Development" is better on Windows? > With the organization name, actually Mac and Windows are the same and Linux will now be different. Previously, we chose the unvanquished/updater path to store the main settings of the updater. Some stuff was stored in an Unvanquished Development/Unvanquished Updater path by accident; I want to stop that. We need to go with the lowercase one to maintain compatibility with the previous version of the updater. But yes, the lowercase ones seem more in line with Linux stylistic conventions. --- linux.cpp | 8 +++++++- main.cpp | 3 +-- osx.cpp | 6 ++++++ system.h | 1 + win.cpp | 9 +++++++++ 5 files changed, 24 insertions(+), 3 deletions(-) diff --git a/linux.cpp b/linux.cpp index 733ae0e..a365c69 100644 --- a/linux.cpp +++ b/linux.cpp @@ -270,10 +270,16 @@ std::string getCertStore() return ""; } +void initApplicationName() +{ + QCoreApplication::setOrganizationName("unvanquished"); + QCoreApplication::setApplicationName("updater"); +} + // Settings are stored in ~/.config/unvanquished/updater.conf QSettings* makePersistentSettings(QObject* parent) { - return new QSettings("unvanquished", "updater", parent); + return new QSettings(parent); } QString getGameCommand(const QString& installPath) diff --git a/main.cpp b/main.cpp index c4970df..7048d2f 100644 --- a/main.cpp +++ b/main.cpp @@ -158,9 +158,8 @@ CommandLineOptions getCommandLineOptions(const QApplication& app) { int main(int argc, char *argv[]) { - QCoreApplication::setApplicationName("Unvanquished Updater"); + Sys::initApplicationName(); QCoreApplication::setApplicationVersion(GIT_VERSION); - QCoreApplication::setOrganizationName("Unvanquished Development"); QCoreApplication::setOrganizationDomain("unvanquished.net"); QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); QApplication app(argc, argv); diff --git a/osx.cpp b/osx.cpp index 5895778..a532444 100644 --- a/osx.cpp +++ b/osx.cpp @@ -173,6 +173,12 @@ std::string getCertStore() return ""; // Not used on OSX. } +void initApplicationName() +{ + QCoreApplication::setOrganizationName("Unvanquished Development"); + QCoreApplication::setApplicationName("Unvanquished Updater"); +} + // Settings are stored in "~/Library/Preferences/net.unvanquished.Unvanquished Updater.plist" // After deleting/changing the file, you must run `sudo killall cfprefsd` for it to take effect QSettings* makePersistentSettings(QObject* parent) diff --git a/system.h b/system.h index 53b34f8..195c654 100644 --- a/system.h +++ b/system.h @@ -26,6 +26,7 @@ namespace Sys { QString archiveName(); QString defaultInstallPath(); +void initApplicationName(); // influences default storage location for QSettings bool validateInstallPath(const QString& installPath); // Checks installing as root in homepath on Linux bool installShortcuts(); // Install launch menu entries and protocol handlers bool installUpdater(const QString& installPath); // Copies current application to /updater[.exe|.app] diff --git a/win.cpp b/win.cpp index 4fe8e92..c8dc933 100644 --- a/win.cpp +++ b/win.cpp @@ -295,11 +295,20 @@ std::string getCertStore() return ""; // Not used on Windows. } +void initApplicationName() +{ + QCoreApplication::setOrganizationName("Unvanquished Development"); + QCoreApplication::setApplicationName("Unvanquished Updater"); +} + // Settings are stored in the registry at (on 64-bit Windows) // HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Unvanquished Development\Unvanquished Updater // ≤v0.0.5 used HKEY_CURRENT_USER\Software\Unvanquished Development\Unvanquished Updater +// Note: a class that we use, QQControlsFileDialog, creates some of its own registry entries +// at HKEY_CURRENT_USER\SOFTWARE\Unvanquished Development\Unvanquished Updater QSettings* makePersistentSettings(QObject* parent) { + // We install to Program Files by default, so use global rather than per-user settings. return new QSettings(QSettings::SystemScope, parent); }