diff options
Diffstat (limited to 'SQLiteStudio3/coreSQLiteStudio/services')
6 files changed, 45 insertions, 75 deletions
diff --git a/SQLiteStudio3/coreSQLiteStudio/services/impl/configimpl.cpp b/SQLiteStudio3/coreSQLiteStudio/services/impl/configimpl.cpp index 046993f..5aed863 100644 --- a/SQLiteStudio3/coreSQLiteStudio/services/impl/configimpl.cpp +++ b/SQLiteStudio3/coreSQLiteStudio/services/impl/configimpl.cpp @@ -560,47 +560,38 @@ void ConfigImpl::initDbFile() QString globalPath = getConfigPath(); QString portablePath = getPortableConfigPath(); - QStringList paths; + QList<QPair<QString,bool>> paths; if (!globalPath.isNull() && !portablePath.isNull()) { if (QFileInfo(portablePath).exists()) { - paths << portablePath+"/"+DB_FILE_NAME; - paths << globalPath+"/"+DB_FILE_NAME; + paths << QPair<QString,bool>(portablePath+"/"+DB_FILE_NAME, false); + paths << QPair<QString,bool>(globalPath+"/"+DB_FILE_NAME, true); } else { - paths << globalPath+"/"+DB_FILE_NAME; - paths << portablePath+"/"+DB_FILE_NAME; + paths << QPair<QString,bool>(globalPath+"/"+DB_FILE_NAME, true); + paths << QPair<QString,bool>(portablePath+"/"+DB_FILE_NAME, false); } } else if (!globalPath.isNull()) { - paths << globalPath+"/"+DB_FILE_NAME; + paths << QPair<QString,bool>(globalPath+"/"+DB_FILE_NAME, true); } else if (!portablePath.isNull()) { - paths << portablePath+"/"+DB_FILE_NAME; - } - - // Create global config directory if not existing - QDir dir; - if (!globalPath.isNull()) - { - dir = QDir(globalPath); - if (!dir.exists()) - QDir::root().mkpath(globalPath); + paths << QPair<QString,bool>(portablePath+"/"+DB_FILE_NAME, false); } // A fallback to in-memory db - paths << ":memory:"; + paths << QPair<QString,bool>(":memory:", false); // Go through all candidates and pick one - QString path; - foreach (path, paths) + QDir dir; + for (const QPair<QString,bool>& path : paths) { - dir = QDir(path); - if (path != ":memory:") + dir = QDir(path.first); + if (path.first != ":memory:") dir.cdUp(); if (tryInitDbFile(path)) @@ -614,17 +605,29 @@ void ConfigImpl::initDbFile() if (configDir == ":memory:") { paths.removeLast(); + QStringList pathStrings; + for (const QPair<QString,bool>& path : paths) + pathStrings << path.first; + notifyError(QObject::tr("Could not initialize configuration file. Any configuration changes and queries history will be lost after application restart." - " Tried to initialize the file at following localizations: %1.").arg(paths.join(", "))); + " Tried to initialize the file at following localizations: %1.").arg(pathStrings.join(", "))); } qDebug() << "Using configuration directory:" << configDir; db->exec("PRAGMA foreign_keys = 1;"); } -bool ConfigImpl::tryInitDbFile(const QString &dbPath) +bool ConfigImpl::tryInitDbFile(const QPair<QString, bool> &dbPath) { - db = new DbSqlite3("SQLiteStudio settings", dbPath, {{DB_PURE_INIT, true}}); + // Create global config directory if not existing + if (dbPath.second && !dbPath.first.isNull()) + { + QDir dir(dbPath.first.mid(0, dbPath.first.length() - DB_FILE_NAME.length() - 1)); + if (!dir.exists()) + QDir::root().mkpath(dir.absolutePath()); + } + + db = new DbSqlite3("SQLiteStudio settings", dbPath.first, {{DB_PURE_INIT, true}}); if (!db->open()) { safe_delete(db); diff --git a/SQLiteStudio3/coreSQLiteStudio/services/impl/configimpl.h b/SQLiteStudio3/coreSQLiteStudio/services/impl/configimpl.h index 3bdb7a5..bd31f0b 100644 --- a/SQLiteStudio3/coreSQLiteStudio/services/impl/configimpl.h +++ b/SQLiteStudio3/coreSQLiteStudio/services/impl/configimpl.h @@ -93,7 +93,7 @@ class API_EXPORT ConfigImpl : public Config QString getPortableConfigPath(); void initTables(); void initDbFile(); - bool tryInitDbFile(const QString& dbPath); + bool tryInitDbFile(const QPair<QString, bool>& dbPath); QVariant deserializeValue(const QVariant& value); void asyncAddSqlHistory(qint64 id, const QString& sql, const QString& dbName, int timeSpentMillis, int rowsAffected); diff --git a/SQLiteStudio3/coreSQLiteStudio/services/impl/dbmanagerimpl.cpp b/SQLiteStudio3/coreSQLiteStudio/services/impl/dbmanagerimpl.cpp index a7bff0d..cbdc921 100644 --- a/SQLiteStudio3/coreSQLiteStudio/services/impl/dbmanagerimpl.cpp +++ b/SQLiteStudio3/coreSQLiteStudio/services/impl/dbmanagerimpl.cpp @@ -578,46 +578,4 @@ void DbManagerImpl::loaded(Plugin* plugin, PluginType* type) DbPlugin* dbPlugin = dynamic_cast<DbPlugin*>(plugin); rescanInvalidDatabasesForPlugin(dbPlugin); -// Db* db = nullptr; - -// QUrl url; -// for (Db* invalidDb : getInvalidDatabases()) -// { -// if (invalidDb->getConnectionOptions().contains(DB_PLUGIN) && invalidDb->getConnectionOptions()[DB_PLUGIN].toString() != dbPlugin->getName()) -// continue; - -// url = QUrl::fromUserInput(invalidDb->getPath()); -// if (url.isLocalFile() && !QFile::exists(invalidDb->getPath())) -// continue; - -// db = createDb(invalidDb->getName(), invalidDb->getPath(), invalidDb->getConnectionOptions()); -// if (!db) -// continue; // For this db driver was not loaded yet. - -// if (!dbPlugin->checkIfDbServedByPlugin(db)) -// { -// qDebug() << "Managed to load database" << db->getPath() << " (" << db->getName() << ")" -// << "but it doesn't use DbPlugin that was just loaded, so it will not be loaded to the db manager"; - -// delete db; -// continue; -// } - -// removeDbInternal(invalidDb, false); -// delete invalidDb; - -// addDbInternal(db, false); - -// if (!db->getConnectionOptions().contains(DB_PLUGIN)) -// { -// db->getConnectionOptions()[DB_PLUGIN] = dbPlugin->getName(); -// if (!CFG->updateDb(db->getName(), db->getName(), db->getPath(), db->getConnectionOptions())) -// qWarning() << "Could not store handling plugin in options for database" << db->getName(); -// } - -// if (CFG->getDbGroup(db->getName())->open) -// db->open(); - -// emit dbLoaded(db); -// } } diff --git a/SQLiteStudio3/coreSQLiteStudio/services/impl/pluginmanagerimpl.cpp b/SQLiteStudio3/coreSQLiteStudio/services/impl/pluginmanagerimpl.cpp index c3bc581..017d260 100644 --- a/SQLiteStudio3/coreSQLiteStudio/services/impl/pluginmanagerimpl.cpp +++ b/SQLiteStudio3/coreSQLiteStudio/services/impl/pluginmanagerimpl.cpp @@ -20,7 +20,9 @@ PluginManagerImpl::~PluginManagerImpl() void PluginManagerImpl::init() { - pluginDirs += qApp->applicationDirPath() + "/plugins"; + if (getDistributionType() != DistributionType::OS_MANAGED) + pluginDirs += qApp->applicationDirPath() + "/plugins"; + pluginDirs += QDir(CFG->getConfigDir()).absoluteFilePath("plugins"); QString envDirs = SQLITESTUDIO->getEnv("SQLITESTUDIO_PLUGINS"); diff --git a/SQLiteStudio3/coreSQLiteStudio/services/updatemanager.cpp b/SQLiteStudio3/coreSQLiteStudio/services/updatemanager.cpp index 66620f3..3663a1b 100644 --- a/SQLiteStudio3/coreSQLiteStudio/services/updatemanager.cpp +++ b/SQLiteStudio3/coreSQLiteStudio/services/updatemanager.cpp @@ -1,3 +1,5 @@ +#ifdef PORTABLE_CONFIG + #include "updatemanager.h" #include "services/pluginmanager.h" #include "services/notifymanager.h" @@ -44,9 +46,9 @@ UpdateManager::~UpdateManager() cleanup(); } -void UpdateManager::checkForUpdates() +void UpdateManager::checkForUpdates(bool force) { - getUpdatesMetadata(updatesCheckReply); + getUpdatesMetadata(updatesCheckReply, force); } void UpdateManager::update() @@ -150,10 +152,10 @@ void UpdateManager::handleAvailableUpdatesReply(QNetworkReply* reply) emit noUpdatesAvailable(); } -void UpdateManager::getUpdatesMetadata(QNetworkReply*& replyStoragePointer) +void UpdateManager::getUpdatesMetadata(QNetworkReply*& replyStoragePointer, bool force) { -#ifndef NO_AUTO_UPDATES - if (!CFG_CORE.General.CheckUpdatesOnStartup.get() || !isPlatformEligibleForUpdate() || replyStoragePointer) +#ifdef PORTABLE_CONFIG + if ((!CFG_CORE.General.CheckUpdatesOnStartup.get() && !force) || !isPlatformEligibleForUpdate() || replyStoragePointer) return; QUrlQuery query; @@ -1056,3 +1058,5 @@ void UpdateManager::readDownload() { currentDownloadFile->write(updatesGetReply->readAll()); } + +#endif // PORTABLE_CONFIG diff --git a/SQLiteStudio3/coreSQLiteStudio/services/updatemanager.h b/SQLiteStudio3/coreSQLiteStudio/services/updatemanager.h index b8e6006..bb33487 100644 --- a/SQLiteStudio3/coreSQLiteStudio/services/updatemanager.h +++ b/SQLiteStudio3/coreSQLiteStudio/services/updatemanager.h @@ -1,6 +1,8 @@ #ifndef UPDATEMANAGER_H #define UPDATEMANAGER_H +#ifdef PORTABLE_CONFIG + #include "common/global.h" #include "sqlitestudio.h" #include <QObject> @@ -28,7 +30,7 @@ class API_EXPORT UpdateManager : public QObject explicit UpdateManager(QObject *parent = 0); ~UpdateManager(); - void checkForUpdates(); + void checkForUpdates(bool force = false); void update(); bool isPlatformEligibleForUpdate() const; static bool executeFinalStep(const QString& tempDir, const QString& backupDir, const QString& appDir); @@ -54,7 +56,7 @@ class API_EXPORT UpdateManager : public QObject QString getCurrentVersions() const; void handleAvailableUpdatesReply(QNetworkReply* reply); void handleDownloadReply(QNetworkReply* reply); - void getUpdatesMetadata(QNetworkReply*& replyStoragePointer); + void getUpdatesMetadata(QNetworkReply*& replyStoragePointer, bool force = false); void handleUpdatesMetadata(QNetworkReply* reply); QList<UpdateEntry> readMetadata(const QJsonDocument& doc); void downloadUpdates(); @@ -134,4 +136,5 @@ class API_EXPORT UpdateManager : public QObject #define UPDATES SQLITESTUDIO->getUpdateManager() +#endif // PORTABLE_CONFIG #endif // UPDATEMANAGER_H |
