From 9618f0ebbf4b88045247c01ce8c8f58203508ebf Mon Sep 17 00:00:00 2001 From: Unit 193 Date: Tue, 12 May 2015 16:19:40 -0400 Subject: Imported Upstream version 3.0.6 --- .../coreSQLiteStudio/services/impl/configimpl.cpp | 51 ++++++++++++---------- .../coreSQLiteStudio/services/impl/configimpl.h | 2 +- .../services/impl/dbmanagerimpl.cpp | 42 ------------------ .../services/impl/pluginmanagerimpl.cpp | 4 +- 4 files changed, 31 insertions(+), 68 deletions(-) (limited to 'SQLiteStudio3/coreSQLiteStudio/services/impl') 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> paths; if (!globalPath.isNull() && !portablePath.isNull()) { if (QFileInfo(portablePath).exists()) { - paths << portablePath+"/"+DB_FILE_NAME; - paths << globalPath+"/"+DB_FILE_NAME; + paths << QPair(portablePath+"/"+DB_FILE_NAME, false); + paths << QPair(globalPath+"/"+DB_FILE_NAME, true); } else { - paths << globalPath+"/"+DB_FILE_NAME; - paths << portablePath+"/"+DB_FILE_NAME; + paths << QPair(globalPath+"/"+DB_FILE_NAME, true); + paths << QPair(portablePath+"/"+DB_FILE_NAME, false); } } else if (!globalPath.isNull()) { - paths << globalPath+"/"+DB_FILE_NAME; + paths << QPair(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(portablePath+"/"+DB_FILE_NAME, false); } // A fallback to in-memory db - paths << ":memory:"; + paths << QPair(":memory:", false); // Go through all candidates and pick one - QString path; - foreach (path, paths) + QDir dir; + for (const QPair& 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& 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 &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& 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(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"); -- cgit v1.2.3