From 801e7da5ee07521b81f405dae1af5097be45fccf Mon Sep 17 00:00:00 2001 From: flow Date: Tue, 18 Oct 2022 11:00:28 -0300 Subject: [PATCH 1/2] feat: allow specifying fallbacks to INI files Signed-off-by: flow --- launcher/settings/INISettingsObject.cpp | 23 ++++++++++++++++++++++- launcher/settings/INISettingsObject.h | 5 ++++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/launcher/settings/INISettingsObject.cpp b/launcher/settings/INISettingsObject.cpp index 12513403..3677e238 100644 --- a/launcher/settings/INISettingsObject.cpp +++ b/launcher/settings/INISettingsObject.cpp @@ -16,7 +16,28 @@ #include "INISettingsObject.h" #include "Setting.h" -INISettingsObject::INISettingsObject(const QString &path, QObject *parent) +#include +#include + +INISettingsObject::INISettingsObject(QStringList paths, QObject *parent) + : SettingsObject(parent) +{ + auto first_path = paths.constFirst(); + auto path = paths.takeFirst(); + while (!QFile::exists(path)) + path = paths.takeFirst(); + + if (path != first_path && QFile::exists(path)) { + // Copy the fallback to the preferred path. + QFile::copy(path, first_path); + qDebug() << "Copied settings from" << path << "to" << first_path; + } + + m_filePath = first_path; + m_ini.loadFile(first_path); +} + +INISettingsObject::INISettingsObject(QString path, QObject* parent) : SettingsObject(parent) { m_filePath = path; diff --git a/launcher/settings/INISettingsObject.h b/launcher/settings/INISettingsObject.h index 26cc32e5..d2f448a9 100644 --- a/launcher/settings/INISettingsObject.h +++ b/launcher/settings/INISettingsObject.h @@ -28,7 +28,10 @@ class INISettingsObject : public SettingsObject { Q_OBJECT public: - explicit INISettingsObject(const QString &path, QObject *parent = 0); + /** 'paths' is a list of INI files to try, in order, for fallback support. */ + explicit INISettingsObject(QStringList paths, QObject* parent = nullptr); + + explicit INISettingsObject(QString path, QObject* parent = nullptr); /*! * \brief Gets the path to the INI file. From 32cdfb871c5cb0008cd34b5d5c1ff133920382d9 Mon Sep 17 00:00:00 2001 From: flow Date: Tue, 18 Oct 2022 12:00:47 -0300 Subject: [PATCH 2/2] fix: add fallback for polymc.cfg Signed-off-by: flow --- launcher/Application.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/launcher/Application.cpp b/launcher/Application.cpp index e94e96a9..b85729f0 100644 --- a/launcher/Application.cpp +++ b/launcher/Application.cpp @@ -488,7 +488,8 @@ Application::Application(int &argc, char **argv) : QApplication(argc, argv) // Initialize application settings { - m_settings.reset(new INISettingsObject(BuildConfig.LAUNCHER_CONFIGFILE, this)); + // Provide a fallback for migration from PolyMC + m_settings.reset(new INISettingsObject({ BuildConfig.LAUNCHER_CONFIGFILE, "polymc.cfg" }, this)); // Updates // Multiple channels are separated by spaces m_settings->registerSetting("UpdateChannel", BuildConfig.VERSION_CHANNEL);