Merge pull request #55 from flowln/config_add_fallback

This commit is contained in:
DioEgizio 2022-10-18 19:50:34 +02:00 committed by GitHub
commit fb4cf0b75d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 3 deletions

View File

@ -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);

View File

@ -16,7 +16,28 @@
#include "INISettingsObject.h"
#include "Setting.h"
INISettingsObject::INISettingsObject(const QString &path, QObject *parent)
#include <QDebug>
#include <QFile>
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;

View File

@ -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.