From 8a82da95bd0f8f49b6ff844d12bd6de1076b11f7 Mon Sep 17 00:00:00 2001 From: Albert S Date: Mon, 13 Jun 2022 20:13:14 +0200 Subject: [PATCH] shared: common: Retire 'firstrun' settings logic --- shared/common.cpp | 52 ++++++++++++++++++++++------------------------- shared/common.h | 1 - 2 files changed, 24 insertions(+), 29 deletions(-) diff --git a/shared/common.cpp b/shared/common.cpp index 78f6d89..4a27daa 100644 --- a/shared/common.cpp +++ b/shared/common.cpp @@ -84,10 +84,10 @@ void Common::setPdfViewer() void Common::ensureConfigured() { QSettings settings; - QVariant firstRun = settings.value(SETTINGS_KEY_FIRSTRUN); - if(!firstRun.isValid()) + QString dbpath = databasePath(); + if(dbpath == "") { - QString dbpath = QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation); + dbpath = QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation); QDir dir; if(!dir.exists(dbpath)) { @@ -97,38 +97,34 @@ void Common::ensureConfigured() } } dbpath += "/looqs.sqlite"; + } + if(!QFile::exists(dbpath)) + { if(!initSqliteDatabase(dbpath)) { throw LooqsGeneralException("Failed to initialize sqlite database"); } - - settings.setValue(SETTINGS_KEY_FIRSTRUN, false); settings.setValue(SETTINGS_KEY_DBPATH, dbpath); - setPdfViewer(); } - else + DatabaseFactory factory{dbpath}; + auto db = factory.forCurrentThread(); + DBMigrator migrator{db}; + if(migrator.migrationNeeded()) { - - QString dbpath = databasePath(); - if(!QFile::exists(dbpath)) - { - throw LooqsGeneralException("Database " + dbpath + " was not found"); - } - DatabaseFactory factory{dbpath}; - auto db = factory.forCurrentThread(); - DBMigrator migrator{db}; - if(migrator.migrationNeeded()) - { - QFile out; - out.open(stderr, QIODevice::WriteOnly); - Logger migrationLogger{&out}; - migrationLogger << "Database is being upgraded, please be patient..." << Qt::endl; - QObject::connect(&migrator, &DBMigrator::migrationDone, - [&migrationLogger](uint32_t migration) - { migrationLogger << "Progress: Successfully migrated to: " << migration << Qt::endl; }); - migrator.performMigrations(); - migrationLogger << "Database upgraded successfully" << Qt::endl; - } + QFile out; + out.open(stderr, QIODevice::WriteOnly); + Logger migrationLogger{&out}; + migrationLogger << "Database is being upgraded, please be patient..." << Qt::endl; + QObject::connect(&migrator, &DBMigrator::migrationDone, + [&migrationLogger](uint32_t migration) + { migrationLogger << "Progress: Successfully migrated to: " << migration << Qt::endl; }); + migrator.performMigrations(); + migrationLogger << "Database upgraded successfully" << Qt::endl; + } + QVariant pdfViewer = settings.value(SETTINGS_KEY_PDFVIEWER); + if(!pdfViewer.isValid()) + { + setPdfViewer(); } } diff --git a/shared/common.h b/shared/common.h index 68ebe4b..bbc04be 100644 --- a/shared/common.h +++ b/shared/common.h @@ -4,7 +4,6 @@ #include #define SETTINGS_KEY_DBPATH "dbpath" -#define SETTINGS_KEY_FIRSTRUN "firstrun" #define SETTINGS_KEY_IPCSOCKETPATH "ipcsocketpath" #define SETTINGS_KEY_PDFVIEWER "pdfviewer" #define SETTINGS_KEY_EXCLUDEDPATHS "excludedpaths"