From 2f9e768c26fda659e53a105104fcb67443ddcfec Mon Sep 17 00:00:00 2001 From: TrickyLeifa Date: Wed, 3 Jul 2024 20:39:00 +0200 Subject: [PATCH 1/4] 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 --- src/file_functions.cpp | 51 ++++++++++++++++++++++++--------- src/file_functions.h | 2 ++ src/lobby.cpp | 2 +- src/text_file_functions.cpp | 2 +- src/widgets/aooptionsdialog.cpp | 4 +-- 5 files changed, 44 insertions(+), 17 deletions(-) diff --git a/src/file_functions.cpp b/src/file_functions.cpp index fef34f549..e808bd9fb 100644 --- a/src/file_functions.cpp +++ b/src/file_functions.cpp @@ -1,5 +1,7 @@ #include "file_functions.h" +#include + bool file_exists(QString file_path) { if (file_path.isEmpty()) @@ -31,24 +33,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 = app_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"); } diff --git a/src/file_functions.h b/src/file_functions.h index ca1eeb5ec..ef05f34d5 100644 --- a/src/file_functions.h +++ b/src/file_functions.h @@ -8,4 +8,6 @@ bool file_exists(QString file_path); bool dir_exists(QString file_path); bool exists(QString p_path); + +QString get_app_path(); QString get_base_path(); diff --git a/src/lobby.cpp b/src/lobby.cpp index f853380fd..aba9f606d 100644 --- a/src/lobby.cpp +++ b/src/lobby.cpp @@ -425,7 +425,7 @@ void Lobby::on_demo_clicked(QTreeWidgetItem *item, int column) return; } - QString l_filepath = (QApplication::applicationDirPath() + "/logs/%1/%2").arg(item->data(0, Qt::DisplayRole).toString(), item->data(1, Qt::DisplayRole).toString()); + QString l_filepath = (get_app_path() + "/logs/%1/%2").arg(item->data(0, Qt::DisplayRole).toString(), item->data(1, Qt::DisplayRole).toString()); ao_app->demo_server->start_server(); ServerInfo demo_server; demo_server.ip = "127.0.0.1"; diff --git a/src/text_file_functions.cpp b/src/text_file_functions.cpp index 418de47c0..35efe20c3 100644 --- a/src/text_file_functions.cpp +++ b/src/text_file_functions.cpp @@ -133,7 +133,7 @@ bool AOApplication::append_to_file(QString p_text, QString p_file, bool make_dir QMultiMap AOApplication::load_demo_logs_list() const { - QString l_log_path = applicationDirPath() + "/logs/"; + QString l_log_path = get_app_path() + "/logs/"; QDir l_log_folder(l_log_path); l_log_folder.setFilter(QDir::NoDotAndDotDot | QDir::Dirs); diff --git a/src/widgets/aooptionsdialog.cpp b/src/widgets/aooptionsdialog.cpp index a0b7d7ce5..4d55652eb 100644 --- a/src/widgets/aooptionsdialog.cpp +++ b/src/widgets/aooptionsdialog.cpp @@ -436,12 +436,12 @@ void AOOptionsDialog::setupUI() FROM_UI(QPushButton, mount_add); connect(ui_mount_add, &QPushButton::clicked, this, [this] { - QString path = QFileDialog::getExistingDirectory(this, tr("Select a base folder"), QApplication::applicationDirPath(), QFileDialog::ShowDirsOnly); + QString path = QFileDialog::getExistingDirectory(this, tr("Select a base folder"), get_app_path(), QFileDialog::ShowDirsOnly); if (path.isEmpty()) { return; } - QDir dir(QApplication::applicationDirPath()); + QDir dir(get_app_path()); QString relative = dir.relativeFilePath(path); if (!relative.contains("../")) { From a1bf400296e57bb2decc84b82ca26003a05f7283 Mon Sep 17 00:00:00 2001 From: TrickyLeifa Date: Wed, 3 Jul 2024 20:53:07 +0200 Subject: [PATCH 2/4] Append separator to base path --- src/file_functions.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/file_functions.cpp b/src/file_functions.cpp index e808bd9fb..68d491d4d 100644 --- a/src/file_functions.cpp +++ b/src/file_functions.cpp @@ -75,5 +75,5 @@ QString get_app_path() QString get_base_path() { - return QDir(get_app_path()).absoluteFilePath("base"); + return QDir(get_app_path()).absoluteFilePath("base") + "/"; } From 2ee10f81bb85e2ffe3647ba37aca0beb2acbf43b Mon Sep 17 00:00:00 2001 From: TrickyLeifa Date: Wed, 3 Jul 2024 21:08:24 +0200 Subject: [PATCH 3/4] Moved headers where they are needed. (Dunno why they were here.) --- src/file_functions.cpp | 2 ++ src/file_functions.h | 3 --- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/file_functions.cpp b/src/file_functions.cpp index 68d491d4d..775a1b1d3 100644 --- a/src/file_functions.cpp +++ b/src/file_functions.cpp @@ -1,6 +1,8 @@ #include "file_functions.h" +#include #include +#include bool file_exists(QString file_path) { diff --git a/src/file_functions.h b/src/file_functions.h index ef05f34d5..252148fd0 100644 --- a/src/file_functions.h +++ b/src/file_functions.h @@ -1,8 +1,5 @@ #pragma once -#include -#include -#include #include bool file_exists(QString file_path); From 29311a7b673f6656f00d0bf40d79cc2fe3475dda Mon Sep 17 00:00:00 2001 From: Leifa <26681464+TrickyLeifa@users.noreply.github.com> Date: Sat, 6 Jul 2024 14:48:03 +0200 Subject: [PATCH 4/4] Proper pathing for AppImage --- src/file_functions.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/file_functions.cpp b/src/file_functions.cpp index 775a1b1d3..cbdd640d1 100644 --- a/src/file_functions.cpp +++ b/src/file_functions.cpp @@ -59,7 +59,7 @@ QString get_app_path() QString app_path = qgetenv("APPIMAGE"); if (!app_path.isEmpty()) { - path = app_path; + path = QFileInfo(app_path).absoluteDir().path(); } #endif