From cbc2de6b851e959c14c27c4fef3c8c682e80498d Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Sun, 5 Dec 2021 03:11:51 +0800 Subject: [PATCH 1/5] Use proper method for checking value existence --- src/app/upgrade.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/upgrade.cpp b/src/app/upgrade.cpp index 5cf8dbec8..79455b53d 100644 --- a/src/app/upgrade.cpp +++ b/src/app/upgrade.cpp @@ -255,7 +255,7 @@ void handleChangedDefaults(const DefaultPreferencesMode mode) SettingsStorage *settingsStorage {SettingsStorage::instance()}; for (auto it = changedDefaults.cbegin(); it != changedDefaults.cend(); ++it) { - if (settingsStorage->loadValue(it->name).isNull()) + if (!settingsStorage->hasKey(it->name)) settingsStorage->storeValue(it->name, (mode == DefaultPreferencesMode::Legacy ? it->legacy : it->current)); } } From b8a7ecfe692bb62018cf619762cc6604d4007c3f Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Sun, 5 Dec 2021 12:43:42 +0800 Subject: [PATCH 2/5] Introduce versioning on main configuration file --- src/app/upgrade.cpp | 26 ++++++++++++++++++++------ src/base/utils/version.h | 4 ++-- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/src/app/upgrade.cpp b/src/app/upgrade.cpp index 79455b53d..3c46cb324 100644 --- a/src/app/upgrade.cpp +++ b/src/app/upgrade.cpp @@ -36,12 +36,15 @@ #include "base/preferences.h" #include "base/profile.h" #include "base/settingsstorage.h" +#include "base/settingvalue.h" #include "base/utils/fs.h" #include "base/utils/io.h" #include "base/utils/string.h" namespace { + const int MIGRATION_VERSION = 1; + void exportWebUIHttpsFiles() { const auto migrate = [](const QString &oldKey, const QString &newKey, const QString &savePath) @@ -229,12 +232,23 @@ namespace bool upgrade(const bool /*ask*/) { - exportWebUIHttpsFiles(); - upgradeTorrentContentLayout(); - upgradeListenPortSettings(); - upgradeSchedulerDaysSettings(); - upgradeDNSServiceSettings(); - upgradeTrayIconStyleSettings(); + CachedSettingValue version {"Meta/MigrationVersion", 0}; + + if (version != MIGRATION_VERSION) + { + if (version < 1) + { + exportWebUIHttpsFiles(); + upgradeTorrentContentLayout(); + upgradeListenPortSettings(); + upgradeSchedulerDaysSettings(); + upgradeDNSServiceSettings(); + upgradeTrayIconStyleSettings(); + } + + version = MIGRATION_VERSION; + } + return true; } diff --git a/src/base/utils/version.h b/src/base/utils/version.h index 12c7f75d1..8357313b3 100644 --- a/src/base/utils/version.h +++ b/src/base/utils/version.h @@ -146,9 +146,9 @@ namespace Utils { return Version(s); } - catch (const RuntimeError &er) + catch (const RuntimeError &error) { - qDebug() << "Error parsing version:" << er.message(); + qDebug() << "Error parsing version:" << error.message(); return defaultVersion; } } From 2d4858157004eccae4e86d3a3959476e9e8f428c Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Thu, 9 Dec 2021 15:53:42 +0800 Subject: [PATCH 3/5] Move main window setting to its own section --- src/base/preferences.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/base/preferences.cpp b/src/base/preferences.cpp index 91a7275c7..d7248e7d3 100644 --- a/src/base/preferences.cpp +++ b/src/base/preferences.cpp @@ -1296,12 +1296,12 @@ void Preferences::setMainVSplitterState(const QByteArray &state) QString Preferences::getMainLastDir() const { - return value("MainWindowLastDir", QDir::homePath()); + return value("MainWindow/LastDir", QDir::homePath()); } void Preferences::setMainLastDir(const QString &path) { - setValue("MainWindowLastDir", path); + setValue("MainWindow/LastDir", path); } QByteArray Preferences::getPeerListState() const From 261f08b90e43c76be8aee46e75c4372d7afbf91e Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Wed, 1 Dec 2021 16:15:34 +0800 Subject: [PATCH 4/5] Sort WebUI language selection values --- src/webui/www/private/views/preferences.html | 62 ++++++++++---------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/src/webui/www/private/views/preferences.html b/src/webui/www/private/views/preferences.html index cc47719ca..acd3c36c8 100644 --- a/src/webui/www/private/views/preferences.html +++ b/src/webui/www/private/views/preferences.html @@ -634,62 +634,62 @@ QBT_TR(Language)QBT_TR[CONTEXT=OptionsDialog] From 1c52fff1cc7669b254784e98c6c6ce4d65c248db Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Tue, 7 Dec 2021 14:11:53 +0800 Subject: [PATCH 5/5] Unify value loading paths The idea is to try load every intermediate value from the base case and then convert them to their respective type. --- src/base/settingsstorage.h | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/base/settingsstorage.h b/src/base/settingsstorage.h index 500398a2a..524f87170 100644 --- a/src/base/settingsstorage.h +++ b/src/base/settingsstorage.h @@ -60,17 +60,18 @@ public: { if constexpr (std::is_enum_v) { - const auto value = loadValueImpl(key).toString(); + const auto value = loadValue(key); return Utils::String::toEnum(value, defaultValue); } - else if constexpr (std::is_same_v) + else if constexpr (IsQFlags::value) { - return loadValueImpl(key, defaultValue); + const typename T::Int value = loadValue(key, static_cast(defaultValue)); + return T {value}; } - else if constexpr (IsQFlags::value) + else if constexpr (std::is_same_v) { - const QVariant value = loadValueImpl(key, static_cast(defaultValue)); - return T {value.template value()}; + // fast path for loading QVariant + return loadValueImpl(key, defaultValue); } else {