Skip to content

Commit

Permalink
Linux: store QSettings in a single location
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
slipher committed Jul 16, 2024
1 parent 242b423 commit 40ad807
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 3 deletions.
8 changes: 7 additions & 1 deletion linux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 1 addition & 2 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 6 additions & 0 deletions osx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions system.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <install path>/updater[.exe|.app]
Expand Down
9 changes: 9 additions & 0 deletions win.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down

0 comments on commit 40ad807

Please sign in to comment.