shared: common: Retire 'firstrun' settings logic
This commit is contained in:
parent
a408173064
commit
8a82da95bd
@ -84,10 +84,10 @@ void Common::setPdfViewer()
|
|||||||
void Common::ensureConfigured()
|
void Common::ensureConfigured()
|
||||||
{
|
{
|
||||||
QSettings settings;
|
QSettings settings;
|
||||||
QVariant firstRun = settings.value(SETTINGS_KEY_FIRSTRUN);
|
QString dbpath = databasePath();
|
||||||
if(!firstRun.isValid())
|
if(dbpath == "")
|
||||||
{
|
{
|
||||||
QString dbpath = QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation);
|
dbpath = QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation);
|
||||||
QDir dir;
|
QDir dir;
|
||||||
if(!dir.exists(dbpath))
|
if(!dir.exists(dbpath))
|
||||||
{
|
{
|
||||||
@ -97,38 +97,34 @@ void Common::ensureConfigured()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
dbpath += "/looqs.sqlite";
|
dbpath += "/looqs.sqlite";
|
||||||
|
}
|
||||||
|
if(!QFile::exists(dbpath))
|
||||||
|
{
|
||||||
if(!initSqliteDatabase(dbpath))
|
if(!initSqliteDatabase(dbpath))
|
||||||
{
|
{
|
||||||
throw LooqsGeneralException("Failed to initialize sqlite database");
|
throw LooqsGeneralException("Failed to initialize sqlite database");
|
||||||
}
|
}
|
||||||
|
|
||||||
settings.setValue(SETTINGS_KEY_FIRSTRUN, false);
|
|
||||||
settings.setValue(SETTINGS_KEY_DBPATH, dbpath);
|
settings.setValue(SETTINGS_KEY_DBPATH, dbpath);
|
||||||
setPdfViewer();
|
|
||||||
}
|
}
|
||||||
else
|
DatabaseFactory factory{dbpath};
|
||||||
|
auto db = factory.forCurrentThread();
|
||||||
|
DBMigrator migrator{db};
|
||||||
|
if(migrator.migrationNeeded())
|
||||||
{
|
{
|
||||||
|
QFile out;
|
||||||
QString dbpath = databasePath();
|
out.open(stderr, QIODevice::WriteOnly);
|
||||||
if(!QFile::exists(dbpath))
|
Logger migrationLogger{&out};
|
||||||
{
|
migrationLogger << "Database is being upgraded, please be patient..." << Qt::endl;
|
||||||
throw LooqsGeneralException("Database " + dbpath + " was not found");
|
QObject::connect(&migrator, &DBMigrator::migrationDone,
|
||||||
}
|
[&migrationLogger](uint32_t migration)
|
||||||
DatabaseFactory factory{dbpath};
|
{ migrationLogger << "Progress: Successfully migrated to: " << migration << Qt::endl; });
|
||||||
auto db = factory.forCurrentThread();
|
migrator.performMigrations();
|
||||||
DBMigrator migrator{db};
|
migrationLogger << "Database upgraded successfully" << Qt::endl;
|
||||||
if(migrator.migrationNeeded())
|
}
|
||||||
{
|
QVariant pdfViewer = settings.value(SETTINGS_KEY_PDFVIEWER);
|
||||||
QFile out;
|
if(!pdfViewer.isValid())
|
||||||
out.open(stderr, QIODevice::WriteOnly);
|
{
|
||||||
Logger migrationLogger{&out};
|
setPdfViewer();
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,7 +4,6 @@
|
|||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
|
|
||||||
#define SETTINGS_KEY_DBPATH "dbpath"
|
#define SETTINGS_KEY_DBPATH "dbpath"
|
||||||
#define SETTINGS_KEY_FIRSTRUN "firstrun"
|
|
||||||
#define SETTINGS_KEY_IPCSOCKETPATH "ipcsocketpath"
|
#define SETTINGS_KEY_IPCSOCKETPATH "ipcsocketpath"
|
||||||
#define SETTINGS_KEY_PDFVIEWER "pdfviewer"
|
#define SETTINGS_KEY_PDFVIEWER "pdfviewer"
|
||||||
#define SETTINGS_KEY_EXCLUDEDPATHS "excludedpaths"
|
#define SETTINGS_KEY_EXCLUDEDPATHS "excludedpaths"
|
||||||
|
Loading…
Reference in New Issue
Block a user