From 630b4ed3b9bf7f358909fd7261ec33b9e2e6168c Mon Sep 17 00:00:00 2001 From: sledgehammer999 Date: Sun, 22 Jan 2023 17:47:32 +0200 Subject: [PATCH] Migrate settings much earlier --- src/app/application.cpp | 13 +++++++++++++ src/app/main.cpp | 25 +++++-------------------- src/app/upgrade.cpp | 2 +- src/app/upgrade.h | 2 +- 4 files changed, 20 insertions(+), 22 deletions(-) diff --git a/src/app/application.cpp b/src/app/application.cpp index ab595cdfb..1ab192784 100644 --- a/src/app/application.cpp +++ b/src/app/application.cpp @@ -88,6 +88,7 @@ #include "base/version.h" #include "applicationinstancemanager.h" #include "filelogger.h" +#include "upgrade.h" #ifndef DISABLE_GUI #include "gui/addnewtorrentdialog.h" @@ -173,6 +174,18 @@ Application::Application(int &argc, char **argv) SettingsStorage::initInstance(); Preferences::initInstance(); + const bool firstTimeUser = !Preferences::instance()->getAcceptedLegal(); + if (!firstTimeUser) + { + if (!upgrade()) + throw RuntimeError(u"Failed migration of old settings"_qs); // Not translatable. Translation isn't configured yet. + handleChangedDefaults(DefaultPreferencesMode::Legacy); + } + else + { + handleChangedDefaults(DefaultPreferencesMode::Current); + } + initializeTranslation(); connect(this, &QCoreApplication::aboutToQuit, this, &Application::cleanup); diff --git a/src/app/main.cpp b/src/app/main.cpp index 97e6869a1..69d91f739 100644 --- a/src/app/main.cpp +++ b/src/app/main.cpp @@ -221,26 +221,6 @@ int main(int argc, char *argv[]) app->setAttribute(Qt::AA_DontShowIconsInMenus); #endif - if (!firstTimeUser) - { - handleChangedDefaults(DefaultPreferencesMode::Legacy); - -#ifndef DISABLE_GUI - if (!upgrade()) return EXIT_FAILURE; -#elif defined(Q_OS_WIN) - if (!upgrade(_isatty(_fileno(stdin)) - && _isatty(_fileno(stdout)))) return EXIT_FAILURE; -#else - if (!upgrade(!params.shouldDaemonize - && isatty(fileno(stdin)) - && isatty(fileno(stdout)))) return EXIT_FAILURE; -#endif - } - else - { - handleChangedDefaults(DefaultPreferencesMode::Current); - } - #if defined(DISABLE_GUI) && !defined(Q_OS_WIN) if (params.shouldDaemonize) { @@ -274,6 +254,11 @@ int main(int argc, char *argv[]) displayBadArgMessage(er.message()); return EXIT_FAILURE; } + catch (const RuntimeError &er) + { + qDebug() << er.message(); + return EXIT_FAILURE; + } } #if !defined(DISABLE_GUI) diff --git a/src/app/upgrade.cpp b/src/app/upgrade.cpp index 2eb7f7f50..01d3ddef8 100644 --- a/src/app/upgrade.cpp +++ b/src/app/upgrade.cpp @@ -409,7 +409,7 @@ namespace } } -bool upgrade(const bool /*ask*/) +bool upgrade() { CachedSettingValue version {MIGRATION_VERSION_KEY, 0}; diff --git a/src/app/upgrade.h b/src/app/upgrade.h index 4271f5a19..0ef24fae8 100644 --- a/src/app/upgrade.h +++ b/src/app/upgrade.h @@ -35,5 +35,5 @@ enum class DefaultPreferencesMode }; void handleChangedDefaults(DefaultPreferencesMode mode); -bool upgrade(bool ask = true); +bool upgrade(); void setCurrentMigrationVersion();