Fixed incorrect applications directory path while using Flatpak build

This commit is contained in:
OpenSauce04 2024-08-13 20:25:25 +01:00 committed by OpenSauce
parent 3262515c89
commit a573f0f036
6 changed files with 35 additions and 9 deletions

View File

@ -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 <array>
#include <fstream>
#include <limits>
@ -707,8 +710,8 @@ std::string AppDataRoamingDirectory() {
/**
* @return The users 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) {

View File

@ -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 <array>
@ -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

View File

@ -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.

View File

@ -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

View File

@ -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 <array>
#include <cmath>
#include <QPainter>
#include <QStandardPaths>
#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
}

View File

@ -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<u8>& smdh_data);
* @return bool If the operation succeeded
*/
[[nodiscard]] bool SaveIconToFile(const std::filesystem::path& icon_path, const QImage& image);
/**
* @return The users applications directory
*/
[[nodiscard]] const std::string GetApplicationsDirectory();