diff options
| author | 2015-05-12 16:19:40 -0400 | |
|---|---|---|
| committer | 2015-05-12 16:19:40 -0400 | |
| commit | 9618f0ebbf4b88045247c01ce8c8f58203508ebf (patch) | |
| tree | 20c9894691353ee8bab4eec668e9b0b6c6426e0f /SQLiteStudio3/coreSQLiteStudio/services/impl | |
| parent | a308f430f694423064ebc86fd0506c8c6fdb3d93 (diff) | |
Imported Upstream version 3.0.6upstream/3.0.6
Diffstat (limited to 'SQLiteStudio3/coreSQLiteStudio/services/impl')
4 files changed, 31 insertions, 68 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"); |
