From a573f0f036d33c064e7483cca04f398bd56bd1b0 Mon Sep 17 00:00:00 2001 From: OpenSauce04 Date: Tue, 13 Aug 2024 20:25:25 +0100 Subject: [PATCH] Fixed incorrect applications directory path while using Flatpak build --- src/common/file_util.cpp | 9 ++++++--- src/common/file_util.h | 6 +++++- src/lime/lime.cpp | 2 +- src/lime_qt/main.cpp | 3 +-- src/lime_qt/util/util.cpp | 17 ++++++++++++++++- src/lime_qt/util/util.h | 7 ++++++- 6 files changed, 35 insertions(+), 9 deletions(-) diff --git a/src/common/file_util.cpp b/src/common/file_util.cpp index 08bafc37c..c9fe12002 100644 --- a/src/common/file_util.cpp +++ b/src/common/file_util.cpp @@ -1,7 +1,10 @@ -// Copyright 2013 Dolphin Emulator Project / 2014 Citra Emulator Project +// Copyright Citra Emulator Project / Lime3DS Emulator Project // Licensed under GPLv2 or any later version // Refer to the license.txt file included. +// Copyright Dolphin Emulator Project +// Licensed under GPLv2 or any later version + #include #include #include @@ -707,8 +710,8 @@ std::string AppDataRoamingDirectory() { /** * @return The user’s home directory on POSIX systems */ -static const std::string& GetHomeDirectory() { - static std::string home_path; +const std::string GetHomeDirectory() { + std::string home_path; if (home_path.empty()) { const char* envvar = getenv("HOME"); if (envvar) { diff --git a/src/common/file_util.h b/src/common/file_util.h index c0fa49d7d..f0c53c15f 100644 --- a/src/common/file_util.h +++ b/src/common/file_util.h @@ -1,7 +1,10 @@ -// Copyright 2013 Dolphin Emulator Project / 2014 Citra Emulator Project +// Copyright Citra Emulator Project / Lime3DS Emulator Project // Licensed under GPLv2 or any later version // Refer to the license.txt file included. +// Copyright Dolphin Emulator Project +// Licensed under GPLv2 or any later version + #pragma once #include @@ -207,6 +210,7 @@ void UpdateUserPath(UserPath path, const std::string& filename); [[nodiscard]] const std::string& GetExeDirectory(); [[nodiscard]] std::string AppDataRoamingDirectory(); #else +[[nodiscard]] const std::string GetHomeDirectory(); [[nodiscard]] const std::string GetUserDirectory(const std::string& envvar); #endif diff --git a/src/lime/lime.cpp b/src/lime/lime.cpp index b89a83c2a..f7a41cdd5 100644 --- a/src/lime/lime.cpp +++ b/src/lime/lime.cpp @@ -1,4 +1,4 @@ -// Copyright Citra Emulator Project / Lime3DS Emulator Project +// Copyright 2014 Citra Emulator Project // Licensed under GPLv2 or any later version // Refer to the license.txt file included. diff --git a/src/lime_qt/main.cpp b/src/lime_qt/main.cpp index bcfbaf7f0..7c968d594 100644 --- a/src/lime_qt/main.cpp +++ b/src/lime_qt/main.cpp @@ -1947,8 +1947,7 @@ void GMainWindow::OnGameListCreateShortcut(u64 program_id, const std::string& ga shortcut_path = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation).toStdString(); } else if (target == GameListShortcutTarget::Applications) { - shortcut_path = - QStandardPaths::writableLocation(QStandardPaths::ApplicationsLocation).toStdString(); + shortcut_path = GetApplicationsDirectory(); } // Icon path and title diff --git a/src/lime_qt/util/util.cpp b/src/lime_qt/util/util.cpp index cb14d376b..874b81012 100644 --- a/src/lime_qt/util/util.cpp +++ b/src/lime_qt/util/util.cpp @@ -1,10 +1,13 @@ -// Copyright 2015 Citra Emulator Project +// Copyright Citra Emulator Project / Lime3DS Emulator Project // Licensed under GPLv2 or any later version // Refer to the license.txt file included. #include #include #include +#include +#include "common/common_paths.h" +#include "common/file_util.h" #include "common/logging/log.h" #include "core/loader/smdh.h" #include "lime_qt/util/util.h" @@ -160,3 +163,15 @@ bool SaveIconToFile(const std::filesystem::path& icon_path, const QImage& image) return false; #endif } + +const std::string GetApplicationsDirectory() { +// This alternate method is required for Flatpak compatibility as +// QStandardPaths::ApplicationsLocation returns a path inside the Flatpak data directory instead of +// $HOME/.local/share +#if defined(__linux__) || defined(__FreeBSD__) + return FileUtil::GetHomeDirectory() + DIR_SEP + ".local" + DIR_SEP + "share" + DIR_SEP + + "applications"; +#else + return QStandardPaths::writableLocation(QStandardPaths::ApplicationsLocation).toStdString(); +#endif +} \ No newline at end of file diff --git a/src/lime_qt/util/util.h b/src/lime_qt/util/util.h index 67bd51a90..428d69ffd 100644 --- a/src/lime_qt/util/util.h +++ b/src/lime_qt/util/util.h @@ -1,4 +1,4 @@ -// Copyright 2015 Citra Emulator Project +// Copyright Citra Emulator Project / Lime3DS Emulator Project // Licensed under GPLv2 or any later version // Refer to the license.txt file included. @@ -36,3 +36,8 @@ QPixmap GetQPixmapFromSMDH(const std::vector& smdh_data); * @return bool If the operation succeeded */ [[nodiscard]] bool SaveIconToFile(const std::filesystem::path& icon_path, const QImage& image); + +/** + * @return The user’s applications directory + */ +[[nodiscard]] const std::string GetApplicationsDirectory();