From 4da21a016e45cd8dfce314e36045f073d8df2e8d Mon Sep 17 00:00:00 2001 From: squidbus <175574877+squidbus@users.noreply.github.com> Date: Thu, 31 Oct 2024 03:36:51 -0700 Subject: [PATCH] path_util: Make sure macOS has current directory set and clean up path code. (#1463) --- src/common/path_util.cpp | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/src/common/path_util.cpp b/src/common/path_util.cpp index 7551d3b0..53eb123d 100644 --- a/src/common/path_util.cpp +++ b/src/common/path_util.cpp @@ -86,30 +86,27 @@ static std::filesystem::path GetBundleParentDirectory() { static auto UserPaths = [] { #ifdef __APPLE__ - // Start by assuming the base directory is the bundle's parent directory. - std::filesystem::path base_dir = GetBundleParentDirectory(); - std::filesystem::path user_dir = base_dir / PORTABLE_DIR; - // Check if the "user" directory exists in the current path: + // Set the current path to the directory containing the app bundle. + std::filesystem::current_path(GetBundleParentDirectory()); +#endif + + // Try the portable user directory first. + auto user_dir = std::filesystem::current_path() / PORTABLE_DIR; if (!std::filesystem::exists(user_dir)) { - // If it doesn't exist, use the new hardcoded path: + // If it doesn't exist, use the standard path for the platform instead. + // NOTE: On Windows we currently just create the portable directory instead. +#ifdef __APPLE__ user_dir = std::filesystem::path(getenv("HOME")) / "Library" / "Application Support" / "shadPS4"; - } #elif defined(__linux__) - auto user_dir = std::filesystem::current_path() / PORTABLE_DIR; - // Check if the "user" directory exists in the current path: - if (!std::filesystem::exists(user_dir)) { - // If it doesn't exist, use XDG_DATA_HOME if it is set, and provide a standard default const char* xdg_data_home = getenv("XDG_DATA_HOME"); if (xdg_data_home != nullptr && strlen(xdg_data_home) > 0) { user_dir = std::filesystem::path(xdg_data_home) / "shadPS4"; } else { user_dir = std::filesystem::path(getenv("HOME")) / ".local" / "share" / "shadPS4"; } - } -#else - const auto user_dir = std::filesystem::current_path() / PORTABLE_DIR; #endif + } std::unordered_map paths;