Browse Source

Migrate settings much earlier

adaptive-webui-19844
sledgehammer999 2 years ago
parent
commit
630b4ed3b9
No known key found for this signature in database
GPG Key ID: 6E4A2D025B7CC9A2
  1. 13
      src/app/application.cpp
  2. 25
      src/app/main.cpp
  3. 2
      src/app/upgrade.cpp
  4. 2
      src/app/upgrade.h

13
src/app/application.cpp

@ -88,6 +88,7 @@
#include "base/version.h" #include "base/version.h"
#include "applicationinstancemanager.h" #include "applicationinstancemanager.h"
#include "filelogger.h" #include "filelogger.h"
#include "upgrade.h"
#ifndef DISABLE_GUI #ifndef DISABLE_GUI
#include "gui/addnewtorrentdialog.h" #include "gui/addnewtorrentdialog.h"
@ -173,6 +174,18 @@ Application::Application(int &argc, char **argv)
SettingsStorage::initInstance(); SettingsStorage::initInstance();
Preferences::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(); initializeTranslation();
connect(this, &QCoreApplication::aboutToQuit, this, &Application::cleanup); connect(this, &QCoreApplication::aboutToQuit, this, &Application::cleanup);

25
src/app/main.cpp

@ -221,26 +221,6 @@ int main(int argc, char *argv[])
app->setAttribute(Qt::AA_DontShowIconsInMenus); app->setAttribute(Qt::AA_DontShowIconsInMenus);
#endif #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 defined(DISABLE_GUI) && !defined(Q_OS_WIN)
if (params.shouldDaemonize) if (params.shouldDaemonize)
{ {
@ -274,6 +254,11 @@ int main(int argc, char *argv[])
displayBadArgMessage(er.message()); displayBadArgMessage(er.message());
return EXIT_FAILURE; return EXIT_FAILURE;
} }
catch (const RuntimeError &er)
{
qDebug() << er.message();
return EXIT_FAILURE;
}
} }
#if !defined(DISABLE_GUI) #if !defined(DISABLE_GUI)

2
src/app/upgrade.cpp

@ -409,7 +409,7 @@ namespace
} }
} }
bool upgrade(const bool /*ask*/) bool upgrade()
{ {
CachedSettingValue<int> version {MIGRATION_VERSION_KEY, 0}; CachedSettingValue<int> version {MIGRATION_VERSION_KEY, 0};

2
src/app/upgrade.h

@ -35,5 +35,5 @@ enum class DefaultPreferencesMode
}; };
void handleChangedDefaults(DefaultPreferencesMode mode); void handleChangedDefaults(DefaultPreferencesMode mode);
bool upgrade(bool ask = true); bool upgrade();
void setCurrentMigrationVersion(); void setCurrentMigrationVersion();

Loading…
Cancel
Save