0
0
mirror of https://github.com/keepassxreboot/keepassxc.git synced 2024-09-20 12:22:16 +02:00

Add support for portable config settings (#645)

* Add support for portable config settings

* Use applicationDirPath instead of currentPath
This commit is contained in:
Jonathan White 2017-06-19 10:49:03 -04:00 committed by louib
parent b75b9fb7d6
commit 8d70167acf

View File

@ -60,39 +60,43 @@ Config::Config(const QString& fileName, QObject* parent)
Config::Config(QObject* parent)
: QObject(parent)
{
// Check if portable config is present. If not, find it in user's directory
QString portablePath = QCoreApplication::applicationDirPath() + "/keepassxc.ini";
if (QFile::exists(portablePath)) {
init(portablePath);
} else {
QString userPath;
QString homePath = QDir::homePath();
#if defined(Q_OS_UNIX) && !defined(Q_OS_MAC)
#if defined(Q_OS_UNIX) && !defined(Q_OS_MAC)
// we can't use QStandardPaths on X11 as it uses XDG_DATA_HOME instead of XDG_CONFIG_HOME
QByteArray env = qgetenv("XDG_CONFIG_HOME");
if (env.isEmpty()) {
userPath = homePath;
userPath += "/.config";
}
else if (env[0] == '/') {
} else if (env[0] == '/') {
userPath = QFile::decodeName(env);
}
else {
} else {
userPath = homePath;
userPath += '/';
userPath += QFile::decodeName(env);
}
userPath += "/keepassxc/";
#else
#else
userPath = QDir::fromNativeSeparators(QStandardPaths::writableLocation(QStandardPaths::DataLocation));
// storageLocation() appends the application name ("/keepassxc") to the end
userPath += "/";
#endif
#endif
#ifdef QT_DEBUG
#ifdef QT_DEBUG
userPath += "keepassxc_debug.ini";
#else
#else
userPath += "keepassxc.ini";
#endif
#endif
init(userPath);
}
}
Config::~Config()