org.DolphinEmu.dolphin-emu/detectflatpak.patch
Carles Pastor adb663c710 Detect flatpak rather than forcing xdg directories
the earlier patch was rather blunt and forced xdg directories in all
cases, this new solution is less ugly and will be easier to upstream.
2022-04-01 17:34:16 +02:00

57 lines
2.4 KiB
Diff

diff --git a/Source/Core/UICommon/UICommon.cpp b/Source/Core/UICommon/UICommon.cpp
index cb857fd3c7..47a012c4f0 100644
--- a/Source/Core/UICommon/UICommon.cpp
+++ b/Source/Core/UICommon/UICommon.cpp
@@ -306,19 +306,45 @@ void SetUserDirectory(std::string custom_path)
user_path = home_path + DOLPHIN_DATA_DIR DIR_SEP;
}
#else
- // We are on a non-Apple and non-Android POSIX system, there are 4 cases:
- // 1. GetExeDirectory()/portable.txt exists
+ // We are on a non-Apple and non-Android POSIX system, there are 5 cases:
+ // 1. Running inside flatpak sandbox
+ // -> Use XDG basedir
+ // 2. GetExeDirectory()/portable.txt exists
// -> Use GetExeDirectory()/User
- // 2. $DOLPHIN_EMU_USERPATH is set
+ // 3. $DOLPHIN_EMU_USERPATH is set
// -> Use $DOLPHIN_EMU_USERPATH
- // 3. ~/.dolphin-emu directory exists
+ // 4. ~/.dolphin-emu directory exists
// -> Use ~/.dolphin-emu
- // 4. Default
+ // 5. Default
// -> Use XDG basedir, see
// http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html
user_path = home_path + "." DOLPHIN_DATA_DIR DIR_SEP;
std::string exe_path = File::GetExeDirectory();
- if (File::Exists(exe_path + DIR_SEP "portable.txt"))
+ if (File::Exists(DIR_SEP ".flatpak-info"))
+ {
+ const char* data_home = getenv("XDG_DATA_HOME");
+ std::string data_path =
+ std::string(data_home && data_home[0] == '/' ? data_home :
+ (home_path + ".local" DIR_SEP "share")) +
+ DIR_SEP DOLPHIN_DATA_DIR DIR_SEP;
+
+ const char* config_home = getenv("XDG_CONFIG_HOME");
+ std::string config_path =
+ std::string(config_home && config_home[0] == '/' ? config_home :
+ (home_path + ".config")) +
+ DIR_SEP DOLPHIN_DATA_DIR DIR_SEP;
+
+ const char* cache_home = getenv("XDG_CACHE_HOME");
+ std::string cache_path =
+ std::string(cache_home && cache_home[0] == '/' ? cache_home : (home_path + ".cache")) +
+ DIR_SEP DOLPHIN_DATA_DIR DIR_SEP;
+
+ File::SetUserPath(D_USER_IDX, data_path);
+ File::SetUserPath(D_CONFIG_IDX, config_path);
+ File::SetUserPath(D_CACHE_IDX, cache_path);
+ return;
+ }
+ else if (File::Exists(exe_path + DIR_SEP "portable.txt"))
{
user_path = exe_path + DIR_SEP "User" DIR_SEP;
}