From 846eef2a0578ccbacd1ab5cda8d3c3871bdb2a4c Mon Sep 17 00:00:00 2001 From: OatmealDome Date: Tue, 17 Jan 2023 14:13:14 -0500 Subject: [PATCH 1/7] CommonPaths: Rename USERDATA_DIR to PORTABLE_USER_DIR --- Source/Core/Common/CommonPaths.h | 10 +++++----- Source/Core/UICommon/UICommon.cpp | 8 ++++---- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Source/Core/Common/CommonPaths.h b/Source/Core/Common/CommonPaths.h index 187231f743..0eadb0b2b7 100644 --- a/Source/Core/Common/CommonPaths.h +++ b/Source/Core/Common/CommonPaths.h @@ -10,20 +10,20 @@ // The user data dir #define ROOT_DIR "." #ifdef _WIN32 -#define USERDATA_DIR "User" +#define PORTABLE_USER_DIR "User" #define DOLPHIN_DATA_DIR "Dolphin" #elif defined __APPLE__ -// On OS X, USERDATA_DIR exists within the .app, but *always* reference +// On OS X, PORTABLE_USER_DIR exists within the .app, but *always* reference // the copy in Application Support instead! (Copied on first run) // You can use the File::GetUserPath() util for this -#define USERDATA_DIR "Contents/Resources/User" +#define PORTABLE_USER_DIR "Contents/Resources/User" #define DOLPHIN_DATA_DIR "Library/Application Support/Dolphin" #elif defined ANDROID -#define USERDATA_DIR "user" +#define PORTABLE_USER_DIR "user" #define DOLPHIN_DATA_DIR "/sdcard/dolphin-emu" #define NOMEDIA_FILE ".nomedia" #else -#define USERDATA_DIR "user" +#define PORTABLE_USER_DIR "user" #define DOLPHIN_DATA_DIR "dolphin-emu" #endif diff --git a/Source/Core/UICommon/UICommon.cpp b/Source/Core/UICommon/UICommon.cpp index 96e469d0aa..8525bd43d4 100644 --- a/Source/Core/UICommon/UICommon.cpp +++ b/Source/Core/UICommon/UICommon.cpp @@ -345,7 +345,7 @@ void SetUserDirectory(std::string custom_path) if (local) // Case 1-2 { - user_path = File::GetExeDirectory() + DIR_SEP USERDATA_DIR DIR_SEP; + user_path = File::GetExeDirectory() + DIR_SEP PORTABLE_USER_DIR DIR_SEP; } else if (configPath) // Case 3 { @@ -370,15 +370,15 @@ void SetUserDirectory(std::string custom_path) } else // Case 6 { - user_path = File::GetExeDirectory() + DIR_SEP USERDATA_DIR DIR_SEP; + user_path = File::GetExeDirectory() + DIR_SEP PORTABLE_USER_DIR DIR_SEP; } CoTaskMemFree(appdata); CoTaskMemFree(documents); #else - if (File::IsDirectory(ROOT_DIR DIR_SEP USERDATA_DIR)) + if (File::IsDirectory(ROOT_DIR DIR_SEP PORTABLE_USER_DIR)) { - user_path = ROOT_DIR DIR_SEP USERDATA_DIR DIR_SEP; + user_path = ROOT_DIR DIR_SEP PORTABLE_USER_DIR DIR_SEP; } else { From 5e3d77adae3bb41db8194300c32d1549718af0ac Mon Sep 17 00:00:00 2001 From: OatmealDome Date: Tue, 17 Jan 2023 14:13:36 -0500 Subject: [PATCH 2/7] CommonPaths: Rename DOLPHIN_DATA_DIR to NORMAL_USER_DIR --- Source/Core/Common/CommonPaths.h | 8 ++++---- Source/Core/UICommon/UICommon.cpp | 10 +++++----- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Source/Core/Common/CommonPaths.h b/Source/Core/Common/CommonPaths.h index 0eadb0b2b7..9826131241 100644 --- a/Source/Core/Common/CommonPaths.h +++ b/Source/Core/Common/CommonPaths.h @@ -11,20 +11,20 @@ #define ROOT_DIR "." #ifdef _WIN32 #define PORTABLE_USER_DIR "User" -#define DOLPHIN_DATA_DIR "Dolphin" +#define NORMAL_USER_DIR "Dolphin" #elif defined __APPLE__ // On OS X, PORTABLE_USER_DIR exists within the .app, but *always* reference // the copy in Application Support instead! (Copied on first run) // You can use the File::GetUserPath() util for this #define PORTABLE_USER_DIR "Contents/Resources/User" -#define DOLPHIN_DATA_DIR "Library/Application Support/Dolphin" +#define NORMAL_USER_DIR "Library/Application Support/Dolphin" #elif defined ANDROID #define PORTABLE_USER_DIR "user" -#define DOLPHIN_DATA_DIR "/sdcard/dolphin-emu" +#define NORMAL_USER_DIR "/sdcard/dolphin-emu" #define NOMEDIA_FILE ".nomedia" #else #define PORTABLE_USER_DIR "user" -#define DOLPHIN_DATA_DIR "dolphin-emu" +#define NORMAL_USER_DIR "dolphin-emu" #endif // Dirs in both User and Sys diff --git a/Source/Core/UICommon/UICommon.cpp b/Source/Core/UICommon/UICommon.cpp index 8525bd43d4..98f823e546 100644 --- a/Source/Core/UICommon/UICommon.cpp +++ b/Source/Core/UICommon/UICommon.cpp @@ -421,12 +421,12 @@ void SetUserDirectory(std::string custom_path) #if defined(__APPLE__) || defined(ANDROID) else { - user_path = home_path + DOLPHIN_DATA_DIR DIR_SEP; + user_path = home_path + NORMAL_USER_DIR DIR_SEP; } #else else { - user_path = home_path + "." DOLPHIN_DATA_DIR DIR_SEP; + user_path = home_path + "." NORMAL_USER_DIR DIR_SEP; if (!File::Exists(user_path)) { @@ -434,18 +434,18 @@ void SetUserDirectory(std::string custom_path) 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; + DIR_SEP NORMAL_USER_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; + DIR_SEP NORMAL_USER_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; + DIR_SEP NORMAL_USER_DIR DIR_SEP; File::SetUserPath(D_USER_IDX, data_path); File::SetUserPath(D_CONFIG_IDX, config_path); From 7f962a414684a69298839d23414e76c3200b5807 Mon Sep 17 00:00:00 2001 From: OatmealDome Date: Tue, 17 Jan 2023 14:14:05 -0500 Subject: [PATCH 3/7] UICommon: Use NORMAL_USER_DIR for Windows --- Source/Core/Common/CommonPaths.h | 2 +- Source/Core/UICommon/UICommon.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Source/Core/Common/CommonPaths.h b/Source/Core/Common/CommonPaths.h index 9826131241..eeef21aa85 100644 --- a/Source/Core/Common/CommonPaths.h +++ b/Source/Core/Common/CommonPaths.h @@ -11,7 +11,7 @@ #define ROOT_DIR "." #ifdef _WIN32 #define PORTABLE_USER_DIR "User" -#define NORMAL_USER_DIR "Dolphin" +#define NORMAL_USER_DIR "Dolphin Emulator" #elif defined __APPLE__ // On OS X, PORTABLE_USER_DIR exists within the .app, but *always* reference // the copy in Application Support instead! (Copied on first run) diff --git a/Source/Core/UICommon/UICommon.cpp b/Source/Core/UICommon/UICommon.cpp index 98f823e546..b2dd20dc41 100644 --- a/Source/Core/UICommon/UICommon.cpp +++ b/Source/Core/UICommon/UICommon.cpp @@ -340,7 +340,7 @@ void SetUserDirectory(std::string custom_path) std::optional old_user_folder; if (documents_found) { - old_user_folder = TStrToUTF8(documents) + DIR_SEP "Dolphin Emulator" DIR_SEP; + old_user_folder = TStrToUTF8(documents) + DIR_SEP NORMAL_USER_DIR DIR_SEP; } if (local) // Case 1-2 @@ -357,7 +357,7 @@ void SetUserDirectory(std::string custom_path) } else if (appdata_found) // Case 5 { - user_path = TStrToUTF8(appdata) + DIR_SEP "Dolphin Emulator" DIR_SEP; + user_path = TStrToUTF8(appdata) + DIR_SEP NORMAL_USER_DIR DIR_SEP; // Set the UserConfigPath value in the registry for backwards compatibility with older Dolphin // builds, which will look for the default User directory in Documents. If we set this key, From af33d4f13f0de58144b3aace54800bf3fbdbc111 Mon Sep 17 00:00:00 2001 From: OatmealDome Date: Tue, 17 Jan 2023 14:17:10 -0500 Subject: [PATCH 4/7] CommonPaths: Split PORTABLE_USER_DIR into "portable" and "embedded" to accomodate macOS --- Source/Core/Common/CommonPaths.h | 9 ++++----- Source/Core/UICommon/UICommon.cpp | 6 +++--- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/Source/Core/Common/CommonPaths.h b/Source/Core/Common/CommonPaths.h index eeef21aa85..987a99d8cf 100644 --- a/Source/Core/Common/CommonPaths.h +++ b/Source/Core/Common/CommonPaths.h @@ -7,23 +7,22 @@ #define DIR_SEP "/" #define DIR_SEP_CHR '/' -// The user data dir #define ROOT_DIR "." #ifdef _WIN32 #define PORTABLE_USER_DIR "User" #define NORMAL_USER_DIR "Dolphin Emulator" #elif defined __APPLE__ -// On OS X, PORTABLE_USER_DIR exists within the .app, but *always* reference -// the copy in Application Support instead! (Copied on first run) -// You can use the File::GetUserPath() util for this -#define PORTABLE_USER_DIR "Contents/Resources/User" +#define PORTABLE_USER_DIR "User" +#define EMBEDDED_USER_DIR "Contents/Resources/User" #define NORMAL_USER_DIR "Library/Application Support/Dolphin" #elif defined ANDROID #define PORTABLE_USER_DIR "user" +#define EMBEDDED_USER_DIR PORTABLE_USER_DIR #define NORMAL_USER_DIR "/sdcard/dolphin-emu" #define NOMEDIA_FILE ".nomedia" #else #define PORTABLE_USER_DIR "user" +#define EMBEDDED_USER_DIR PORTABLE_USER_DIR #define NORMAL_USER_DIR "dolphin-emu" #endif diff --git a/Source/Core/UICommon/UICommon.cpp b/Source/Core/UICommon/UICommon.cpp index b2dd20dc41..3bf143b133 100644 --- a/Source/Core/UICommon/UICommon.cpp +++ b/Source/Core/UICommon/UICommon.cpp @@ -376,9 +376,9 @@ void SetUserDirectory(std::string custom_path) CoTaskMemFree(appdata); CoTaskMemFree(documents); #else - if (File::IsDirectory(ROOT_DIR DIR_SEP PORTABLE_USER_DIR)) + if (File::IsDirectory(ROOT_DIR DIR_SEP EMBEDDED_USER_DIR)) { - user_path = ROOT_DIR DIR_SEP PORTABLE_USER_DIR DIR_SEP; + user_path = ROOT_DIR DIR_SEP EMBEDDED_USER_DIR DIR_SEP; } else { @@ -412,7 +412,7 @@ void SetUserDirectory(std::string custom_path) std::string exe_path = File::GetExeDirectory(); if (File::Exists(exe_path + DIR_SEP "portable.txt")) { - user_path = exe_path + DIR_SEP "User" DIR_SEP; + user_path = exe_path + DIR_SEP PORTABLE_USER_DIR DIR_SEP; } else if (env_path) { From 59a44bea505ef802e4d8d15ca161c62be3d49a8f Mon Sep 17 00:00:00 2001 From: OatmealDome Date: Tue, 17 Jan 2023 14:20:57 -0500 Subject: [PATCH 5/7] CommonPaths: Split platform-specific definitions for user directories into two blocks --- Source/Core/Common/CommonPaths.h | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/Source/Core/Common/CommonPaths.h b/Source/Core/Common/CommonPaths.h index 987a99d8cf..ab141eb450 100644 --- a/Source/Core/Common/CommonPaths.h +++ b/Source/Core/Common/CommonPaths.h @@ -7,25 +7,34 @@ #define DIR_SEP "/" #define DIR_SEP_CHR '/' +// The current working directory #define ROOT_DIR "." + +// The normal user directory +#ifdef _WIN32 +#define NORMAL_USER_DIR "Dolphin Emulator" +#elif defined(__APPLE__) +#define NORMAL_USER_DIR "Library/Application Support/Dolphin" +#elif defined(ANDROID) +#define NORMAL_USER_DIR "/sdcard/dolphin-emu" +#else +#define NORMAL_USER_DIR "dolphin-emu" +#endif + +// The portable user directory #ifdef _WIN32 #define PORTABLE_USER_DIR "User" -#define NORMAL_USER_DIR "Dolphin Emulator" -#elif defined __APPLE__ +#elif defined(__APPLE__) #define PORTABLE_USER_DIR "User" #define EMBEDDED_USER_DIR "Contents/Resources/User" -#define NORMAL_USER_DIR "Library/Application Support/Dolphin" -#elif defined ANDROID -#define PORTABLE_USER_DIR "user" -#define EMBEDDED_USER_DIR PORTABLE_USER_DIR -#define NORMAL_USER_DIR "/sdcard/dolphin-emu" -#define NOMEDIA_FILE ".nomedia" #else #define PORTABLE_USER_DIR "user" #define EMBEDDED_USER_DIR PORTABLE_USER_DIR -#define NORMAL_USER_DIR "dolphin-emu" #endif +// Flag file to prevent media scanning from indexing a directory +#define NOMEDIA_FILE ".nomedia" + // Dirs in both User and Sys // Legacy setups used /JAP/ while newer setups use /JPN/ by default. #define EUR_DIR "EUR" From 7240290382dc33a7557b6a31c869829023535c38 Mon Sep 17 00:00:00 2001 From: OatmealDome Date: Tue, 17 Jan 2023 14:22:55 -0500 Subject: [PATCH 6/7] CommonPaths: Add Steam-specific user directory --- Source/Core/Common/CommonPaths.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Source/Core/Common/CommonPaths.h b/Source/Core/Common/CommonPaths.h index ab141eb450..047f5dc967 100644 --- a/Source/Core/Common/CommonPaths.h +++ b/Source/Core/Common/CommonPaths.h @@ -11,6 +11,7 @@ #define ROOT_DIR "." // The normal user directory +#ifndef STEAM #ifdef _WIN32 #define NORMAL_USER_DIR "Dolphin Emulator" #elif defined(__APPLE__) @@ -20,6 +21,15 @@ #else #define NORMAL_USER_DIR "dolphin-emu" #endif +#else // ifndef STEAM +#ifdef _WIN32 +#define NORMAL_USER_DIR "Dolphin Emulator (Steam)" +#elif defined(__APPLE__) +#define NORMAL_USER_DIR "Library/Application Support/Dolphin (Steam)" +#else +#define NORMAL_USER_DIR "dolphin-emu-steam" +#endif +#endif // The portable user directory #ifdef _WIN32 From 234de8af0906ea1c68c2a68ce57ce2d939c587f7 Mon Sep 17 00:00:00 2001 From: OatmealDome Date: Tue, 17 Jan 2023 15:03:11 -0500 Subject: [PATCH 7/7] UICommon: Don't check the registry key or use the old user directory path on Windows builds for Steam --- Source/Core/UICommon/UICommon.cpp | 38 +++++++++++++++++++++++++------ 1 file changed, 31 insertions(+), 7 deletions(-) diff --git a/Source/Core/UICommon/UICommon.cpp b/Source/Core/UICommon/UICommon.cpp index 3bf143b133..60f8ff3575 100644 --- a/Source/Core/UICommon/UICommon.cpp +++ b/Source/Core/UICommon/UICommon.cpp @@ -295,7 +295,22 @@ void SetUserDirectory(std::string custom_path) // -> Use AppData\Roaming\Dolphin Emulator as the User directory path // 6. Default // -> Use GetExeDirectory()\User + // + // On Steam builds, we take a simplified approach: + // 1. GetExeDirectory()\portable.txt exists + // -> Use GetExeDirectory()\User + // 2. AppData\Roaming exists + // -> Use AppData\Roaming\Dolphin Emulator (Steam) as the User directory path + // 3. Default + // -> Use GetExeDirectory()\User + // Get AppData path in case we need it. + // TODO: Maybe use WIL when it's available? + PWSTR appdata = nullptr; + bool appdata_found = + SUCCEEDED(SHGetKnownFolderPath(FOLDERID_RoamingAppData, KF_FLAG_DEFAULT, nullptr, &appdata)); + +#ifndef STEAM // Check our registry keys // TODO: Maybe use WIL when it's available? HKEY hkey; @@ -325,12 +340,6 @@ void SetUserDirectory(std::string custom_path) local = local != 0 || File::Exists(File::GetExeDirectory() + DIR_SEP "portable.txt"); - // Get AppData path in case we need it. - // TODO: Maybe use WIL when it's available? - PWSTR appdata = nullptr; - bool appdata_found = - SUCCEEDED(SHGetKnownFolderPath(FOLDERID_RoamingAppData, KF_FLAG_DEFAULT, nullptr, &appdata)); - // Attempt to check if the old User directory exists in My Documents. // TODO: Maybe use WIL when it's available? PWSTR documents = nullptr; @@ -373,8 +382,23 @@ void SetUserDirectory(std::string custom_path) user_path = File::GetExeDirectory() + DIR_SEP PORTABLE_USER_DIR DIR_SEP; } - CoTaskMemFree(appdata); CoTaskMemFree(documents); +#else // ifndef STEAM + if (File::Exists(File::GetExeDirectory() + DIR_SEP "portable.txt")) // Case 1 + { + user_path = File::GetExeDirectory() + DIR_SEP PORTABLE_USER_DIR DIR_SEP; + } + else if (appdata_found) // Case 2 + { + user_path = TStrToUTF8(appdata) + DIR_SEP NORMAL_USER_DIR DIR_SEP; + } + else // Case 3 + { + user_path = File::GetExeDirectory() + DIR_SEP PORTABLE_USER_DIR DIR_SEP; + } +#endif + + CoTaskMemFree(appdata); #else if (File::IsDirectory(ROOT_DIR DIR_SEP EMBEDDED_USER_DIR)) {