From 75d87ff90ef728eaf257bbc12986171462583857 Mon Sep 17 00:00:00 2001 From: OatmealDome Date: Sun, 29 May 2022 18:10:10 -0400 Subject: [PATCH 1/3] UICommon: Change default User directory location to AppData --- Source/Core/UICommon/UICommon.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/Source/Core/UICommon/UICommon.cpp b/Source/Core/UICommon/UICommon.cpp index 349b21d52e..e942a72f13 100644 --- a/Source/Core/UICommon/UICommon.cpp +++ b/Source/Core/UICommon/UICommon.cpp @@ -289,8 +289,8 @@ void SetUserDirectory(std::string custom_path) // -> Use GetExeDirectory()\User // 3. HKCU\Software\Dolphin Emulator\UserConfigPath exists // -> Use this as the user directory path - // 4. My Documents exists - // -> Use My Documents\Dolphin Emulator as the User directory path + // 4. AppData\Roaming exists + // -> Use AppData\Roaming\Dolphin Emulator as the User directory path // 5. Default // -> Use GetExeDirectory()\User @@ -323,22 +323,22 @@ void SetUserDirectory(std::string custom_path) local = local != 0 || File::Exists(File::GetExeDirectory() + DIR_SEP "portable.txt"); - // Get Documents path in case we need it. + // Get AppData path in case we need it. // TODO: Maybe use WIL when it's available? - PWSTR my_documents = nullptr; - bool my_documents_found = - SUCCEEDED(SHGetKnownFolderPath(FOLDERID_Documents, KF_FLAG_DEFAULT, nullptr, &my_documents)); + PWSTR appdata = nullptr; + bool appdata_found = + SUCCEEDED(SHGetKnownFolderPath(FOLDERID_RoamingAppData, KF_FLAG_DEFAULT, nullptr, &appdata)); if (local) // Case 1-2 user_path = File::GetExeDirectory() + DIR_SEP USERDATA_DIR DIR_SEP; else if (configPath) // Case 3 user_path = TStrToUTF8(configPath.get()); - else if (my_documents_found) // Case 4 - user_path = TStrToUTF8(my_documents) + DIR_SEP "Dolphin Emulator" DIR_SEP; + else if (appdata_found) // Case 4 + user_path = TStrToUTF8(appdata) + DIR_SEP "Dolphin Emulator" DIR_SEP; else // Case 5 user_path = File::GetExeDirectory() + DIR_SEP USERDATA_DIR DIR_SEP; - CoTaskMemFree(my_documents); + CoTaskMemFree(appdata); #else if (File::IsDirectory(ROOT_DIR DIR_SEP USERDATA_DIR)) { From 3896934d5ee153c4dbbf435ed6dc480165676b6c Mon Sep 17 00:00:00 2001 From: OatmealDome Date: Sun, 29 May 2022 18:31:17 -0400 Subject: [PATCH 2/3] UICommon: Use the old User directory in Documents if it exists --- Source/Core/UICommon/UICommon.cpp | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/Source/Core/UICommon/UICommon.cpp b/Source/Core/UICommon/UICommon.cpp index e942a72f13..b2a16918b0 100644 --- a/Source/Core/UICommon/UICommon.cpp +++ b/Source/Core/UICommon/UICommon.cpp @@ -289,9 +289,11 @@ void SetUserDirectory(std::string custom_path) // -> Use GetExeDirectory()\User // 3. HKCU\Software\Dolphin Emulator\UserConfigPath exists // -> Use this as the user directory path - // 4. AppData\Roaming exists + // 4. My Documents\Dolphin Emulator exists (default user folder before PR 10708) + // -> Use this as the user directory path + // 5. AppData\Roaming exists // -> Use AppData\Roaming\Dolphin Emulator as the User directory path - // 5. Default + // 6. Default // -> Use GetExeDirectory()\User // Check our registry keys @@ -329,16 +331,31 @@ void SetUserDirectory(std::string custom_path) 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; + bool documents_found = + SUCCEEDED(SHGetKnownFolderPath(FOLDERID_Documents, KF_FLAG_DEFAULT, nullptr, &documents)); + + std::optional old_user_folder; + if (documents_found) + { + old_user_folder = TStrToUTF8(documents) + DIR_SEP "Dolphin Emulator" DIR_SEP; + } + if (local) // Case 1-2 user_path = File::GetExeDirectory() + DIR_SEP USERDATA_DIR DIR_SEP; else if (configPath) // Case 3 user_path = TStrToUTF8(configPath.get()); - else if (appdata_found) // Case 4 + else if (old_user_folder && File::Exists(old_user_folder.value())) // Case 4 + user_path = old_user_folder.value(); + else if (appdata_found) // Case 5 user_path = TStrToUTF8(appdata) + DIR_SEP "Dolphin Emulator" DIR_SEP; - else // Case 5 + else // Case 6 user_path = File::GetExeDirectory() + DIR_SEP USERDATA_DIR DIR_SEP; CoTaskMemFree(appdata); + CoTaskMemFree(documents); #else if (File::IsDirectory(ROOT_DIR DIR_SEP USERDATA_DIR)) { From cc68d5321f2986407a00e66635bf2cd512a60940 Mon Sep 17 00:00:00 2001 From: OatmealDome Date: Sun, 29 May 2022 19:20:41 -0400 Subject: [PATCH 3/3] UICommon: Set UserConfigPath in the registry to AppData User for backwards compatibility --- Source/Core/UICommon/UICommon.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/Source/Core/UICommon/UICommon.cpp b/Source/Core/UICommon/UICommon.cpp index b2a16918b0..96e469d0aa 100644 --- a/Source/Core/UICommon/UICommon.cpp +++ b/Source/Core/UICommon/UICommon.cpp @@ -344,15 +344,34 @@ void SetUserDirectory(std::string custom_path) } if (local) // Case 1-2 + { user_path = File::GetExeDirectory() + DIR_SEP USERDATA_DIR DIR_SEP; + } else if (configPath) // Case 3 + { user_path = TStrToUTF8(configPath.get()); + } else if (old_user_folder && File::Exists(old_user_folder.value())) // Case 4 + { user_path = old_user_folder.value(); + } else if (appdata_found) // Case 5 + { user_path = TStrToUTF8(appdata) + DIR_SEP "Dolphin Emulator" 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, + // they will use this as the User directory instead. + // (If we're in this case, then this key doesn't exist, so it's OK to set it.) + std::wstring wstr_path = UTF8ToWString(user_path); + RegSetKeyValueW(HKEY_CURRENT_USER, TEXT("Software\\Dolphin Emulator"), TEXT("UserConfigPath"), + REG_SZ, wstr_path.c_str(), + static_cast((wstr_path.size() + 1) * sizeof(wchar_t))); + } else // Case 6 + { user_path = File::GetExeDirectory() + DIR_SEP USERDATA_DIR DIR_SEP; + } CoTaskMemFree(appdata); CoTaskMemFree(documents);