diff options
| author | Leifa <26681464+TrickyLeifa@users.noreply.github.com> | 2024-07-06 18:05:48 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-07-06 18:05:48 +0200 |
| commit | 03025119c4a7316e83f5336756d3afc9d1ff82b1 (patch) | |
| tree | 72661dd1ec0c1149e3fcf5641bc92c14cd2fae71 /src/file_functions.cpp | |
| parent | a1e13f62fd47f09dc973e7c36987e161ecb19cdf (diff) | |
Improve OS detection and add APPIMAGE support to pathing code (#1003)
* Added get_app_path, tweaked pathing to adjust itself for Linux, ...
* Added get_app_path
* This should be used instead of QCoreApplication::applicationDirPath()
* Tweaked pathing to adjust itself for Linux
* Append separator to base path
* Moved headers where they are needed. (Dunno why they were here.)
* Proper pathing for AppImage
Diffstat (limited to 'src/file_functions.cpp')
| -rw-r--r-- | src/file_functions.cpp | 53 |
1 files changed, 40 insertions, 13 deletions
diff --git a/src/file_functions.cpp b/src/file_functions.cpp index fef34f54..cbdd640d 100644 --- a/src/file_functions.cpp +++ b/src/file_functions.cpp @@ -1,5 +1,9 @@ #include "file_functions.h" +#include <QCoreApplication> +#include <QDir> +#include <QFileInfo> + bool file_exists(QString file_path) { if (file_path.isEmpty()) @@ -31,24 +35,47 @@ bool exists(QString p_path) return file.exists(); } -QString get_base_path() +QString get_app_path() { - QString base_path; -#ifdef ANDROID - QString sdcard_storage = getenv("SECONDARY_STORAGE"); - if (dir_exists(sdcard_storage + "/base/")) + QString path = QCoreApplication::applicationDirPath(); + +#ifdef Q_OS_ANDROID + QString storage_path = qgetenv("SECONDARY_STORAGE"); + if (dir_exists(storage_path)) { - base_path = sdcard_storage + "/base/"; + path = storage_path; } else { - QString external_storage = getenv("EXTERNAL_STORAGE"); - base_path = external_storage + "/base/"; + QString external_path = qgetenv("EXTERNAL_STORAGE"); + if (dir_exists(external_path)) + { + path = external_path; + } } -#elif defined(__APPLE__) - base_path = QCoreApplication::applicationDirPath() + "/../../../base/"; -#else - base_path = QCoreApplication::applicationDirPath() + "/base/"; #endif - return base_path; + +#ifdef Q_OS_LINUX + QString app_path = qgetenv("APPIMAGE"); + if (!app_path.isEmpty()) + { + path = QFileInfo(app_path).absoluteDir().path(); + } +#endif + +#ifdef Q_OS_MAC + path += "/../../.."; +#endif + + if (path.endsWith(QDir::separator())) + { + path.chop(1); + } + + return path; +} + +QString get_base_path() +{ + return QDir(get_app_path()).absoluteFilePath("base") + "/"; } |
