mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2024-12-27 16:29:44 -05:00
Add support for portable config settings (#645)
* Add support for portable config settings * Use applicationDirPath instead of currentPath
This commit is contained in:
parent
b75b9fb7d6
commit
8d70167acf
@ -60,39 +60,43 @@ Config::Config(const QString& fileName, QObject* parent)
|
||||
Config::Config(QObject* parent)
|
||||
: QObject(parent)
|
||||
{
|
||||
QString userPath;
|
||||
QString homePath = QDir::homePath();
|
||||
// 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)
|
||||
// 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";
|
||||
#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] == '/') {
|
||||
userPath = QFile::decodeName(env);
|
||||
} else {
|
||||
userPath = homePath;
|
||||
userPath += '/';
|
||||
userPath += QFile::decodeName(env);
|
||||
}
|
||||
|
||||
userPath += "/keepassxc/";
|
||||
#else
|
||||
userPath = QDir::fromNativeSeparators(QStandardPaths::writableLocation(QStandardPaths::DataLocation));
|
||||
// storageLocation() appends the application name ("/keepassxc") to the end
|
||||
userPath += "/";
|
||||
#endif
|
||||
|
||||
#ifdef QT_DEBUG
|
||||
userPath += "keepassxc_debug.ini";
|
||||
#else
|
||||
userPath += "keepassxc.ini";
|
||||
#endif
|
||||
|
||||
init(userPath);
|
||||
}
|
||||
else if (env[0] == '/') {
|
||||
userPath = QFile::decodeName(env);
|
||||
}
|
||||
else {
|
||||
userPath = homePath;
|
||||
userPath += '/';
|
||||
userPath += QFile::decodeName(env);
|
||||
}
|
||||
|
||||
userPath += "/keepassxc/";
|
||||
#else
|
||||
userPath = QDir::fromNativeSeparators(QStandardPaths::writableLocation(QStandardPaths::DataLocation));
|
||||
// storageLocation() appends the application name ("/keepassxc") to the end
|
||||
userPath += "/";
|
||||
#endif
|
||||
|
||||
#ifdef QT_DEBUG
|
||||
userPath += "keepassxc_debug.ini";
|
||||
#else
|
||||
userPath += "keepassxc.ini";
|
||||
#endif
|
||||
|
||||
init(userPath);
|
||||
}
|
||||
|
||||
Config::~Config()
|
||||
|
Loading…
Reference in New Issue
Block a user