From: tobtoht Date: Sun, 22 May 2022 17:52:03 +0000 (+0200) Subject: Portable mode: accept 'portable.txt' X-Git-Url: https://git.nutra.tk/v2?a=commitdiff_plain;h=4fcf746c3a6d92425fc61a83ed3d14ee2437842b;p=gamesguru%2Ffeather.git Portable mode: accept 'portable.txt' --- diff --git a/src/utils/Utils.cpp b/src/utils/Utils.cpp index 499c3cf3..8bcba474 100644 --- a/src/utils/Utils.cpp +++ b/src/utils/Utils.cpp @@ -102,10 +102,18 @@ bool dirExists(const QString &path) { return pathDir.exists(); } +bool portableFileExists(const QString &dir) { + QStringList portableFiles = {".portable", ".portable.txt", "portable.txt"}; + + return std::find_if(portableFiles.begin(), portableFiles.end(), [dir](const QString &portableFile){ + return QFile::exists(dir + "/" + portableFile); + }) != portableFiles.end(); +} + QString defaultWalletDir() { - QString portablePath = QCoreApplication::applicationDirPath().append("/%1"); - if (QFile::exists(portablePath.arg(".portable")) || QFile::exists(portablePath.arg(".portable.txt"))) { - return portablePath.arg("feather_data/wallets"); + QString portablePath = QCoreApplication::applicationDirPath(); + if (Utils::portableFileExists(portablePath)) { + return portablePath + "/feather_data/wallets"; } if (TailsOS::detect()) { diff --git a/src/utils/Utils.h b/src/utils/Utils.h index 349bf2fc..ecdf8063 100644 --- a/src/utils/Utils.h +++ b/src/utils/Utils.h @@ -22,6 +22,7 @@ namespace Utils QStringList fileFind(const QRegularExpression &pattern, const QString &baseDir, int level, int depth, int maxPerDir); bool dirExists(const QString &path); + bool portableFileExists(const QString &dir); QString defaultWalletDir(); QString applicationPath(); diff --git a/src/utils/config.cpp b/src/utils/config.cpp index 24dc35fa..dfdda028 100644 --- a/src/utils/config.cpp +++ b/src/utils/config.cpp @@ -168,9 +168,9 @@ Config::Config(QObject* parent) } QDir Config::defaultConfigDir() { - QString portablePath = QCoreApplication::applicationDirPath().append("/%1"); - if (QFile::exists(portablePath.arg(".portable")) || QFile::exists(portablePath.arg(".portable.txt"))) { - return portablePath.arg("feather_data"); + QString portablePath = QCoreApplication::applicationDirPath(); + if (Utils::portableFileExists(portablePath)) { + return portablePath + "/feather_data"; } if (TailsOS::detect()) {