Detect flatpak rather than forcing xdg

My earlier patch forcexdg.patch outright deleted the code block
responsible for determining where to place the configuration files.

This one takes a more subtle approach by actually detecting the flatpak
sandbox and leaving the rest of the code intact.

My plan is to submit this patch to upstream dolphin, if they accept it
we'll be able to drop both this patch and nodirtyversion.patch which is
only required as a side-effect of this.
This commit is contained in:
Carles Pastor 2022-04-02 14:52:38 +02:00
parent 4fe3c11c41
commit 602582230f
3 changed files with 59 additions and 46 deletions

56
detectflatpak.patch Normal file
View file

@ -0,0 +1,56 @@
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;
}

View file

@ -1,45 +0,0 @@
diff --git a/Source/Core/UICommon/UICommon.cpp b/Source/Core/UICommon/UICommon.cpp
index 2055c4d863..163a15f8a5 100644
--- a/Source/Core/UICommon/UICommon.cpp
+++ b/Source/Core/UICommon/UICommon.cpp
@@ -273,28 +273,11 @@ void SetUserDirectory(const 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
- // -> Use GetExeDirectory()/User
- // 2. $DOLPHIN_EMU_USERPATH is set
- // -> Use $DOLPHIN_EMU_USERPATH
- // 3. ~/.dolphin-emu directory exists
- // -> Use ~/.dolphin-emu
// 4. 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"))
- {
- user_path = exe_path + DIR_SEP "User" DIR_SEP;
- }
- else if (env_path)
- {
- user_path = env_path;
- }
- else if (!File::Exists(user_path))
- {
const char* data_home = getenv("XDG_DATA_HOME");
std::string data_path =
std::string(data_home && data_home[0] == '/' ? data_home :
@@ -316,11 +299,9 @@ void SetUserDirectory(const std::string& custom_path)
File::SetUserPath(D_CONFIG_IDX, config_path);
File::SetUserPath(D_CACHE_IDX, cache_path);
return;
- }
#endif
}
#endif
- File::SetUserPath(D_USER_IDX, std::move(user_path));
}
void SaveWiimoteSources()

View file

@ -110,11 +110,13 @@ modules:
- type: git
url: https://github.com/shiiion/dolphin.git
commit: 9ca0eb888bd6f8ed13a4efb92d808fbf0705ffa4
# detects whether dolphin is running in a flatpak sandbox
# and makes it use xdg directories if it is.
# prevents dolphin from attempting to write conf files
# in non-writable paths, typically happens when a user
# has leftover files from a previous non-flatpak install
- type: patch
path: forcexdg.patch
path: detectflatpak.patch
# version strings must match exactly for online multiplayer
- type: patch
path: nodirtyversion.patch