diff --git a/Source/Core/Common/Src/FileUtil.cpp b/Source/Core/Common/Src/FileUtil.cpp index 8792321bf0..d2be401fb1 100644 --- a/Source/Core/Common/Src/FileUtil.cpp +++ b/Source/Core/Common/Src/FileUtil.cpp @@ -665,7 +665,52 @@ const std::string& GetUserPath(const unsigned int DirIDX, const std::string &new if (paths[D_USER_IDX].empty()) { #ifdef _WIN32 - paths[D_USER_IDX] = GetExeDirectory() + DIR_SEP USERDATA_DIR DIR_SEP; + // Detect where the User directory is. There are four different cases (on top of the + // command line flag, which overrides all this): + // 1. HKCU\Software\Dolphin Emulator\LocalUserConfig exists and is true + // -> Use GetExeDirectory()\User + // 2. HKCU\Software\Dolphin Emulator\UserConfigPath exists + // -> Use this as the user directory path + // 3. My Documents exists + // -> Use My Documents\Dolphin Emulator as the User directory path + // 4. Default + // -> Use GetExeDirectory()\User + + // Check our registry keys + HKEY hkey; + DWORD local = 0; + TCHAR configPath[MAX_PATH] = {0}; + if (RegOpenKeyEx(HKEY_CURRENT_USER, TEXT("Software\\Dolphin Emulator"), NULL, KEY_QUERY_VALUE, &hkey) == ERROR_SUCCESS) + { + DWORD size = 4; + if (RegQueryValueEx(hkey, TEXT("LocalUserConfig"), NULL, NULL, reinterpret_cast(&local), &size) != ERROR_SUCCESS) + local = 0; + + size = MAX_PATH; + if (RegQueryValueEx(hkey, TEXT("UserConfigPath"), NULL, NULL, (LPBYTE)configPath, &size) != ERROR_SUCCESS) + configPath[0] = 0; + RegCloseKey(hkey); + } + + // Get Program Files path in case we need it. + TCHAR my_documents[MAX_PATH]; + bool my_documents_found = SUCCEEDED(SHGetFolderPath(NULL, CSIDL_MYDOCUMENTS, NULL, SHGFP_TYPE_CURRENT, my_documents)); + + if (local) // Case 1 + paths[D_USER_IDX] = GetExeDirectory() + DIR_SEP USERDATA_DIR DIR_SEP; + else if (configPath[0]) // Case 2 + paths[D_USER_IDX] = TStrToUTF8(configPath); + else if (my_documents_found) // Case 3 + paths[D_USER_IDX] = TStrToUTF8(my_documents) + DIR_SEP "Dolphin Emulator" DIR_SEP; + else // Case 4 + paths[D_USER_IDX] = GetExeDirectory() + DIR_SEP USERDATA_DIR DIR_SEP; + + // Prettify the path: it will be displayed in some places, we don't want a mix of \ and /. + paths[D_USER_IDX] = ReplaceAll(paths[D_USER_IDX], "\\", DIR_SEP); + + // Make sure it ends in DIR_SEP. + if (*paths[D_USER_IDX].rbegin() != DIR_SEP_CHR) + paths[D_USER_IDX] += DIR_SEP; #else if (File::Exists(ROOT_DIR DIR_SEP USERDATA_DIR)) paths[D_USER_IDX] = ROOT_DIR DIR_SEP USERDATA_DIR DIR_SEP; diff --git a/Source/Core/Core/Src/CoreParameter.cpp b/Source/Core/Core/Src/CoreParameter.cpp index 93dd4be5a2..462a7e8474 100644 --- a/Source/Core/Core/Src/CoreParameter.cpp +++ b/Source/Core/Core/Src/CoreParameter.cpp @@ -351,11 +351,7 @@ void SCoreStartupParameter::CheckMemcardPath(std::string& memcardPath, std::stri { // Use default memcard path if there is no user defined name std::string defaultFilename = isSlotA ? GC_MEMCARDA : GC_MEMCARDB; - #ifdef _WIN32 - memcardPath = "." + File::GetUserPath(D_GCUSER_IDX).substr(File::GetExeDirectory().size()) + defaultFilename + ext; - #else - memcardPath = File::GetUserPath(D_GCUSER_IDX) + defaultFilename + ext; - #endif + memcardPath = File::GetUserPath(D_GCUSER_IDX) + defaultFilename + ext; } else { diff --git a/Source/Core/DolphinWX/Src/Main.cpp b/Source/Core/DolphinWX/Src/Main.cpp index 30593ac637..6e55ec1501 100644 --- a/Source/Core/DolphinWX/Src/Main.cpp +++ b/Source/Core/DolphinWX/Src/Main.cpp @@ -268,6 +268,7 @@ bool DolphinApp::OnInit() File::CopyDir(std::string(SHARED_USER_DIR OPENCL_DIR DIR_SEP), File::GetUserPath(D_OPENCL_IDX)); #endif + File::CreateFullPath(File::GetUserPath(D_USER_IDX)); File::CreateFullPath(File::GetUserPath(D_CONFIG_IDX)); File::CreateFullPath(File::GetUserPath(D_GCUSER_IDX)); File::CreateFullPath(File::GetUserPath(D_CACHE_IDX));