summaryrefslogtreecommitdiff
path: root/Source/Core/UICommon
diff options
context:
space:
mode:
authorLéo Lam <leo@leolam.fr>2019-11-09 21:10:16 +0100
committerGitHub <noreply@github.com>2019-11-09 21:10:16 +0100
commitf4e12f85bce7f0ad3c3fcc5d19d7db495600a41b (patch)
tree5960897f371699d1b107c4c7007d541fb8694d79 /Source/Core/UICommon
parent6cb60f8d364fc9887bfb4779993036d5554902a2 (diff)
parentea8a3059bff1693ea640777a3aeb0c31daf18951 (diff)
Merge pull request #8393 from CookiePLMonster/long-paths
Support Windows 10 long paths
Diffstat (limited to 'Source/Core/UICommon')
-rw-r--r--Source/Core/UICommon/UICommon.cpp41
1 files changed, 26 insertions, 15 deletions
diff --git a/Source/Core/UICommon/UICommon.cpp b/Source/Core/UICommon/UICommon.cpp
index fd9a3d2d8b..ee0609ba26 100644
--- a/Source/Core/UICommon/UICommon.cpp
+++ b/Source/Core/UICommon/UICommon.cpp
@@ -226,46 +226,57 @@ void SetUserDirectory(const std::string& custom_path)
// -> Use GetExeDirectory()\User
// Check our registry keys
+ // TODO: Maybe use WIL when it's available?
HKEY hkey;
DWORD local = 0;
- TCHAR configPath[MAX_PATH] = {0};
+ std::unique_ptr<TCHAR[]> configPath;
if (RegOpenKeyEx(HKEY_CURRENT_USER, TEXT("Software\\Dolphin Emulator"), 0, KEY_QUERY_VALUE,
&hkey) == ERROR_SUCCESS)
{
DWORD size = 4;
if (RegQueryValueEx(hkey, TEXT("LocalUserConfig"), nullptr, nullptr,
reinterpret_cast<LPBYTE>(&local), &size) != ERROR_SUCCESS)
+ {
local = 0;
+ }
+
+ size = 0;
+ RegQueryValueEx(hkey, TEXT("UserConfigPath"), nullptr, nullptr, nullptr, &size);
+ configPath = std::make_unique<TCHAR[]>(size / sizeof(TCHAR));
+ if (RegQueryValueEx(hkey, TEXT("UserConfigPath"), nullptr, nullptr,
+ reinterpret_cast<LPBYTE>(configPath.get()), &size) != ERROR_SUCCESS)
+ {
+ configPath.reset();
+ }
- size = MAX_PATH;
- if (RegQueryValueEx(hkey, TEXT("UserConfigPath"), nullptr, nullptr, (LPBYTE)configPath,
- &size) != ERROR_SUCCESS)
- configPath[0] = 0;
RegCloseKey(hkey);
}
- local = local || File::Exists(File::GetExeDirectory() + DIR_SEP "portable.txt");
+ local = local != 0 || File::Exists(File::GetExeDirectory() + DIR_SEP "portable.txt");
- // Get Program Files path in case we need it.
- TCHAR my_documents[MAX_PATH];
- bool my_documents_found = SUCCEEDED(
- SHGetFolderPath(nullptr, CSIDL_MYDOCUMENTS, nullptr, SHGFP_TYPE_CURRENT, my_documents));
+ // Get Documents 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));
if (local) // Case 1-2
user_path = File::GetExeDirectory() + DIR_SEP USERDATA_DIR DIR_SEP;
- else if (configPath[0]) // Case 3
- user_path = TStrToUTF8(configPath);
+ 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 // Case 5
user_path = File::GetExeDirectory() + DIR_SEP USERDATA_DIR DIR_SEP;
+ CoTaskMemFree(my_documents);
+
// Prettify the path: it will be displayed in some places, we don't want a mix
// of \ and /.
- user_path = ReplaceAll(user_path, "\\", DIR_SEP);
+ user_path = ReplaceAll(std::move(user_path), "\\", DIR_SEP);
// Make sure it ends in DIR_SEP.
- if (*user_path.rbegin() != DIR_SEP_CHR)
+ if (user_path.back() != DIR_SEP_CHR)
user_path += DIR_SEP;
#else
@@ -340,7 +351,7 @@ void SetUserDirectory(const std::string& custom_path)
#endif
}
#endif
- File::SetUserPath(D_USER_IDX, user_path);
+ File::SetUserPath(D_USER_IDX, std::move(user_path));
}
void SaveWiimoteSources()