]> Nutra Git (v1) - gamesguru/feather.git/commitdiff
Portable mode: accept 'portable.txt'
authortobtoht <thotbot@protonmail.com>
Sun, 22 May 2022 17:52:03 +0000 (19:52 +0200)
committertobtoht <thotbot@protonmail.com>
Sun, 22 May 2022 17:52:03 +0000 (19:52 +0200)
src/utils/Utils.cpp
src/utils/Utils.h
src/utils/config.cpp

index 499c3cf35470b334b16e0ff183379c02e99ca7e8..8bcba474091a8070458c03b90f4f4c0c891deaa3 100644 (file)
@@ -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()) {
index 349bf2fc6f89d153c76468d154a5d6f5d8d0af21..ecdf80639f1ac4ee7fdad6f09c124a12272faff9 100644 (file)
@@ -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();
 
index 24dc35faca1b87db258a6ba7c20bfb87f13c9ebf..dfdda0286358ec5e109feb9a23fb6f357fe38bda 100644 (file)
@@ -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()) {