mirror of
https://github.com/Vita3K/Vita3K.git
synced 2026-07-11 01:34:23 +02:00
vita3k: Rework linux default paths (#3967)
This commit is contained in:
committed by
GitHub
parent
1fd6f4ee13
commit
d7c48ec07c
+40
-34
@@ -70,6 +70,10 @@
|
|||||||
#include <SDL3/SDL_system.h>
|
#include <SDL3/SDL_system.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef __linux__
|
||||||
|
#include <pwd.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
|
||||||
@@ -236,6 +240,7 @@ void set_current_config(EmuEnvState &emuenv, const std::string &app_path) {
|
|||||||
lang::set_locale(emuenv.cfg.current_config.sys_lang);
|
lang::set_locale(emuenv.cfg.current_config.sys_lang);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Initializes paths to their respective defaults, to be changed later by settings or CLI
|
||||||
void init_paths(Root &root_paths) {
|
void init_paths(Root &root_paths) {
|
||||||
#ifdef __ANDROID__
|
#ifdef __ANDROID__
|
||||||
fs::path internal_storage_path = fs::path(SDL_GetAndroidExternalStoragePath()) / "";
|
fs::path internal_storage_path = fs::path(SDL_GetAndroidExternalStoragePath()) / "";
|
||||||
@@ -311,61 +316,62 @@ void init_paths(Root &root_paths) {
|
|||||||
|
|
||||||
#if defined(__linux__)
|
#if defined(__linux__)
|
||||||
// XDG Data Dirs.
|
// XDG Data Dirs.
|
||||||
|
char home_path[PATH_MAX] = {};
|
||||||
auto env_home = getenv("HOME");
|
auto env_home = getenv("HOME");
|
||||||
auto XDG_DATA_DIRS = getenv("XDG_DATA_DIRS");
|
if (env_home != NULL)
|
||||||
|
strncpy(home_path, env_home, PATH_MAX - 1);
|
||||||
|
else {
|
||||||
|
struct passwd *pw = getpwuid(getuid());
|
||||||
|
if (pw) {
|
||||||
|
strncpy(home_path, pw->pw_dir, PATH_MAX - 1);
|
||||||
|
} else {
|
||||||
|
LOG_CRITICAL("Failed to get home directory path");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
auto XDG_DATA_HOME = getenv("XDG_DATA_HOME");
|
auto XDG_DATA_HOME = getenv("XDG_DATA_HOME");
|
||||||
auto XDG_CACHE_HOME = getenv("XDG_CACHE_HOME");
|
auto XDG_CACHE_HOME = getenv("XDG_CACHE_HOME");
|
||||||
auto XDG_CONFIG_HOME = getenv("XDG_CONFIG_HOME");
|
auto XDG_CONFIG_HOME = getenv("XDG_CONFIG_HOME");
|
||||||
auto APPDIR = getenv("APPDIR"); // Used in AppImage
|
auto APPDIR = getenv("APPDIR"); // Used in AppImage
|
||||||
|
|
||||||
if (XDG_DATA_HOME != NULL)
|
// Config and game-specific configs
|
||||||
root_paths.set_pref_path(fs::path(XDG_DATA_HOME) / app_name / app_name / "");
|
|
||||||
|
|
||||||
if (XDG_CONFIG_HOME != NULL)
|
if (XDG_CONFIG_HOME != NULL)
|
||||||
root_paths.set_config_path(fs::path(XDG_CONFIG_HOME) / app_name / "");
|
root_paths.set_config_path(fs::path(XDG_CONFIG_HOME) / app_name / "");
|
||||||
else if (env_home != NULL)
|
else if (home_path[0] != '\0')
|
||||||
root_paths.set_config_path(fs::path(env_home) / ".config" / app_name / "");
|
root_paths.set_config_path(fs::path(home_path) / ".config" / app_name / "");
|
||||||
|
|
||||||
|
// Logs, cache and dumps
|
||||||
if (XDG_CACHE_HOME != NULL) {
|
if (XDG_CACHE_HOME != NULL) {
|
||||||
root_paths.set_cache_path(fs::path(XDG_CACHE_HOME) / app_name / "");
|
root_paths.set_cache_path(fs::path(XDG_CACHE_HOME) / app_name / "");
|
||||||
root_paths.set_log_path(fs::path(XDG_CACHE_HOME) / app_name / "");
|
root_paths.set_log_path(fs::path(XDG_CACHE_HOME) / app_name / "");
|
||||||
} else if (env_home != NULL) {
|
} else if (home_path[0] != '\0') {
|
||||||
root_paths.set_cache_path(fs::path(env_home) / ".cache" / app_name / "");
|
root_paths.set_cache_path(fs::path(home_path) / ".cache" / app_name / "");
|
||||||
root_paths.set_log_path(fs::path(env_home) / ".cache" / app_name / "");
|
root_paths.set_log_path(fs::path(home_path) / ".cache" / app_name / "");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Don't assume that base_path is portable.
|
// Static assets sorted by least to most priority, so that higher priority ones can override lower priority ones.
|
||||||
if (fs::exists(root_paths.get_base_path() / "data") && fs::exists(root_paths.get_base_path() / "shaders-builtin"))
|
if (fs::exists("/usr/share/Vita3K")) {
|
||||||
|
root_paths.set_static_assets_path("/usr/share/Vita3K");
|
||||||
|
} else if (fs::exists("/usr/local/share/Vita3K")) {
|
||||||
|
root_paths.set_static_assets_path("/usr/local/share/Vita3K");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Only really used in standalone (rare) or development
|
||||||
|
if (fs::exists(root_paths.get_base_path() / "shaders-builtin"))
|
||||||
root_paths.set_static_assets_path(root_paths.get_base_path());
|
root_paths.set_static_assets_path(root_paths.get_base_path());
|
||||||
else if (env_home != NULL)
|
|
||||||
root_paths.set_static_assets_path(fs::path(env_home) / ".local/share" / app_name / "");
|
|
||||||
|
|
||||||
if (XDG_DATA_DIRS != NULL) {
|
// AppImage root
|
||||||
auto env_paths = string_utils::split_string(XDG_DATA_DIRS, ':');
|
if (APPDIR != NULL && fs::exists(fs::path(APPDIR) / "usr/share/Vita3K"))
|
||||||
for (auto &i : env_paths) {
|
|
||||||
if (fs::exists(fs::path(i) / app_name)) {
|
|
||||||
root_paths.set_static_assets_path(fs::path(i) / app_name / "");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (XDG_DATA_HOME != NULL) {
|
|
||||||
if (fs::exists(fs::path(XDG_DATA_HOME) / app_name / "data") && fs::exists(fs::path(XDG_DATA_HOME) / app_name / "shaders-builtin"))
|
|
||||||
root_paths.set_static_assets_path(fs::path(XDG_DATA_HOME) / app_name / "");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (APPDIR != NULL && fs::exists(fs::path(APPDIR) / "usr/share/Vita3K")) {
|
|
||||||
root_paths.set_static_assets_path(fs::path(APPDIR) / "usr/share/Vita3K");
|
root_paths.set_static_assets_path(fs::path(APPDIR) / "usr/share/Vita3K");
|
||||||
}
|
|
||||||
|
|
||||||
// shared path
|
// shared path
|
||||||
if (env_home != NULL)
|
if (XDG_DATA_HOME != NULL)
|
||||||
root_paths.set_shared_path(fs::path(env_home) / ".local/share" / app_name / "");
|
|
||||||
|
|
||||||
if (XDG_DATA_HOME != NULL) {
|
|
||||||
root_paths.set_shared_path(fs::path(XDG_DATA_HOME) / app_name / "");
|
root_paths.set_shared_path(fs::path(XDG_DATA_HOME) / app_name / "");
|
||||||
}
|
else if (home_path[0] != '\0')
|
||||||
|
root_paths.set_shared_path(fs::path(home_path) / ".local/share" / app_name / "");
|
||||||
|
|
||||||
// patch path should be in shared path
|
// These default to being in shared path
|
||||||
|
root_paths.set_pref_path(root_paths.get_shared_path() / app_name / "");
|
||||||
root_paths.set_patch_path(root_paths.get_shared_path() / "patch" / "");
|
root_paths.set_patch_path(root_paths.get_shared_path() / "patch" / "");
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -193,11 +193,6 @@ static std::string resolve_existing_path(const EmuEnvState &emuenv, const fs::pa
|
|||||||
const std::array<fs::path, 7> roots = {
|
const std::array<fs::path, 7> roots = {
|
||||||
emuenv.pref_path,
|
emuenv.pref_path,
|
||||||
emuenv.default_path,
|
emuenv.default_path,
|
||||||
emuenv.shared_path,
|
|
||||||
emuenv.static_assets_path,
|
|
||||||
emuenv.base_path,
|
|
||||||
emuenv.config_path,
|
|
||||||
emuenv.cache_path,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
for (const auto &root : roots) {
|
for (const auto &root : roots) {
|
||||||
|
|||||||
@@ -124,15 +124,15 @@ public:
|
|||||||
std::string license_content_id{};
|
std::string license_content_id{};
|
||||||
std::string license_title_id{};
|
std::string license_title_id{};
|
||||||
std::string current_app_title{};
|
std::string current_app_title{};
|
||||||
fs::path base_path{};
|
fs::path base_path{}; // Base for the path of binaries/executable
|
||||||
fs::path default_path{};
|
fs::path default_path{};
|
||||||
fs::path config_path{};
|
fs::path config_path{}; // Path for config files
|
||||||
fs::path log_path{};
|
fs::path log_path{}; // Path for log file
|
||||||
fs::path cache_path{};
|
fs::path cache_path{}; // Path for cache files (shaders, elf/texture dumps, and compat cache)
|
||||||
fs::path pref_path{};
|
fs::path pref_path{}; // Path for VitaFS (TODO: rename to vita_path)
|
||||||
fs::path static_assets_path{};
|
fs::path static_assets_path{}; // Path for static assets (shaders, icons, etc)
|
||||||
fs::path shared_path{};
|
fs::path shared_path{}; // Path for files (UI themes, textures, etc)
|
||||||
fs::path patch_path{};
|
fs::path patch_path{}; // Path for patch files
|
||||||
std::string self_name{};
|
std::string self_name{};
|
||||||
std::string self_path{};
|
std::string self_path{};
|
||||||
Config &cfg;
|
Config &cfg;
|
||||||
|
|||||||
Reference in New Issue
Block a user