diff --git a/Source/Core/Common/FileUtil.cpp b/Source/Core/Common/FileUtil.cpp index 0eac268b00..742fbb546f 100644 --- a/Source/Core/Common/FileUtil.cpp +++ b/Source/Core/Common/FileUtil.cpp @@ -26,6 +26,7 @@ #endif #include "Common/IOFile.h" #include "Common/Logging/Log.h" +#include "Common/StringUtil.h" #ifdef _WIN32 #include @@ -1052,12 +1053,31 @@ const std::string& GetUserPath(unsigned int dir_index) // Sets a user directory path // Rebuilds internal directory structure to compensate for the new directory -void SetUserPath(unsigned int dir_index, const std::string& path) +void SetUserPath(unsigned int dir_index, std::string path) { if (path.empty()) return; - s_user_paths[dir_index] = path; +#ifdef _WIN32 + // On Windows, replace all '\' with '/' since we assume the latter in various places in the + // codebase. + for (char& c : path) + { + if (c == '\\') + c = '/'; + } +#endif + + // Directories should end with a separator, files should not. + while (StringEndsWith(path, "/")) + path.pop_back(); + if (path.empty()) + return; + const bool is_directory = dir_index < FIRST_FILE_USER_PATH_IDX; + if (is_directory) + path.push_back('/'); + + s_user_paths[dir_index] = std::move(path); RebuildUserDirectories(dir_index); } diff --git a/Source/Core/Common/FileUtil.h b/Source/Core/Common/FileUtil.h index 415c3fd102..0542cb3402 100644 --- a/Source/Core/Common/FileUtil.h +++ b/Source/Core/Common/FileUtil.h @@ -62,7 +62,8 @@ enum D_DYNAMICINPUT_IDX, D_GBAUSER_IDX, D_GBASAVES_IDX, - F_DOLPHINCONFIG_IDX, + FIRST_FILE_USER_PATH_IDX, + F_DOLPHINCONFIG_IDX = FIRST_FILE_USER_PATH_IDX, F_GCPADCONFIG_IDX, F_WIIPADCONFIG_IDX, F_GCKEYBOARDCONFIG_IDX, @@ -208,7 +209,7 @@ const std::string& GetUserPath(unsigned int dir_index); // Sets a user directory path // Rebuilds internal directory structure to compensate for the new directory -void SetUserPath(unsigned int dir_index, const std::string& path); +void SetUserPath(unsigned int dir_index, std::string path); // probably doesn't belong here std::string GetThemeDir(const std::string& theme_name);