diff options
author | Jonathan White <support@dmapps.us> | 2020-09-27 19:05:33 +0300 |
---|---|---|
committer | Jonathan White <support@dmapps.us> | 2020-09-27 19:11:02 +0300 |
commit | e1c2537084651c4cfeb466b28f5bcd71d05dc4ff (patch) | |
tree | 2c86608d0537fcf82ed02e9d631e9043357c2c95 /src/core | |
parent | ac5c1af829bd7da63295b60426d3001840a5f158 (diff) | |
parent | 9fd9d65995e0c1a7ed96fbd025f42b696c40a3d9 (diff) |
Merge branch 'release/2.6.2' into develop
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/Config.cpp | 90 | ||||
-rw-r--r-- | src/core/Config.h | 7 | ||||
-rw-r--r-- | src/core/Tools.cpp | 3 |
3 files changed, 57 insertions, 43 deletions
diff --git a/src/core/Config.cpp b/src/core/Config.cpp index e29b42d43..e9f5f1a77 100644 --- a/src/core/Config.cpp +++ b/src/core/Config.cpp @@ -22,6 +22,7 @@ #include <QCoreApplication> #include <QDir> #include <QHash> +#include <QProcessEnvironment> #include <QSettings> #include <QSize> #include <QStandardPaths> @@ -419,49 +420,17 @@ void Config::migrate() sync(); } -Config::Config(const QString& fileName, QObject* parent) +Config::Config(const QString& configFileName, const QString& localConfigFileName, QObject* parent) : QObject(parent) { - init(fileName); + init(configFileName, localConfigFileName); } Config::Config(QObject* parent) : QObject(parent) { - // Check if we are running in portable mode, if so store the config files local to the app - auto portablePath = QCoreApplication::applicationDirPath().append("/%1"); - if (QFile::exists(portablePath.arg(".portable"))) { - init(portablePath.arg("config/keepassxc.ini"), portablePath.arg("config/keepassxc_local.ini")); - return; - } - - QString configPath; - QString localConfigPath; - -#if defined(Q_OS_WIN) - configPath = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation); - localConfigPath = QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation); -#elif defined(Q_OS_MACOS) - configPath = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation); - localConfigPath = QStandardPaths::writableLocation(QStandardPaths::CacheLocation); -#else - // On case-sensitive Operating Systems, force use of lowercase app directories - configPath = QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation) + "/keepassxc"; - localConfigPath = QStandardPaths::writableLocation(QStandardPaths::GenericCacheLocation) + "/keepassxc"; -#endif - - configPath += "/keepassxc"; - localConfigPath += "/keepassxc"; - -#ifdef QT_DEBUG - configPath += "_debug"; - localConfigPath += "_debug"; -#endif - - configPath += ".ini"; - localConfigPath += ".ini"; - - init(QDir::toNativeSeparators(configPath), QDir::toNativeSeparators(localConfigPath)); + auto configFiles = defaultConfigFiles(); + init(configFiles.first, configFiles.second); } Config::~Config() @@ -489,6 +458,45 @@ void Config::init(const QString& configFileName, const QString& localConfigFileN connect(qApp, &QCoreApplication::aboutToQuit, this, &Config::sync); } +QPair<QString, QString> Config::defaultConfigFiles() +{ + // Check if we are running in portable mode, if so store the config files local to the app + auto portablePath = QCoreApplication::applicationDirPath().append("/%1"); + if (QFile::exists(portablePath.arg(".portable"))) { + return {portablePath.arg("config/keepassxc.ini"), portablePath.arg("config/keepassxc_local.ini")}; + } + + QString configPath; + QString localConfigPath; + +#if defined(Q_OS_WIN) + configPath = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation); + localConfigPath = QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation); +#elif defined(Q_OS_MACOS) + configPath = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation); + localConfigPath = QStandardPaths::writableLocation(QStandardPaths::CacheLocation); +#else + // On case-sensitive Operating Systems, force use of lowercase app directories + configPath = QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation) + "/keepassxc"; + localConfigPath = QStandardPaths::writableLocation(QStandardPaths::GenericCacheLocation) + "/keepassxc"; +#endif + + QString suffix; +#ifdef QT_DEBUG + suffix = "_debug"; +#endif + + configPath += QString("/keepassxc%1.ini").arg(suffix); + localConfigPath += QString("/keepassxc%1.ini").arg(suffix); + + // Allow overriding the default location with env vars + const auto& env = QProcessEnvironment::systemEnvironment(); + configPath = env.value("KPXC_CONFIG", configPath); + localConfigPath = env.value("KPXC_CONFIG_LOCAL", localConfigPath); + + return {QDir::toNativeSeparators(configPath), QDir::toNativeSeparators(localConfigPath)}; +} + Config* Config::instance() { if (!m_instance) { @@ -498,12 +506,16 @@ Config* Config::instance() return m_instance; } -void Config::createConfigFromFile(const QString& file) +void Config::createConfigFromFile(const QString& configFileName, const QString& localConfigFileName) { if (m_instance) { delete m_instance; } - m_instance = new Config(file, qApp); + + auto defaultFiles = defaultConfigFiles(); + m_instance = new Config(configFileName.isEmpty() ? defaultFiles.first : configFileName, + localConfigFileName.isEmpty() ? defaultFiles.second : localConfigFileName, + qApp); } void Config::createTempFileInstance() @@ -515,7 +527,7 @@ void Config::createTempFileInstance() bool openResult = tmpFile->open(); Q_ASSERT(openResult); Q_UNUSED(openResult); - m_instance = new Config(tmpFile->fileName(), qApp); + m_instance = new Config(tmpFile->fileName(), "", qApp); tmpFile->setParent(m_instance); } diff --git a/src/core/Config.h b/src/core/Config.h index 28a75082e..1c3f1e941 100644 --- a/src/core/Config.h +++ b/src/core/Config.h @@ -199,17 +199,18 @@ public: void resetToDefaults(); static Config* instance(); - static void createConfigFromFile(const QString& file); + static void createConfigFromFile(const QString& configFileName, const QString& localConfigFileName = {}); static void createTempFileInstance(); signals: void changed(ConfigKey key); private: - Config(const QString& fileName, QObject* parent = nullptr); + Config(const QString& configFileName, const QString& localConfigFileName, QObject* parent); explicit Config(QObject* parent); - void init(const QString& configFileName, const QString& localConfigFileName = ""); + void init(const QString& configFileName, const QString& localConfigFileName); void migrate(); + static QPair<QString, QString> defaultConfigFiles(); static QPointer<Config> m_instance; diff --git a/src/core/Tools.cpp b/src/core/Tools.cpp index d29e92bff..7e2b65bcd 100644 --- a/src/core/Tools.cpp +++ b/src/core/Tools.cpp @@ -263,7 +263,8 @@ namespace Tools bool checkUrlValid(const QString& urlField) { - if (urlField.isEmpty() || urlField.startsWith("cmd://", Qt::CaseInsensitive)) { + if (urlField.isEmpty() || urlField.startsWith("cmd://", Qt::CaseInsensitive) + || urlField.startsWith("{REF:A", Qt::CaseInsensitive)) { return true; } |