diff options
| author | Admiral H. Curtiss <pikachu025@gmail.com> | 2021-11-22 03:00:15 +0100 |
|---|---|---|
| committer | Admiral H. Curtiss <pikachu025@gmail.com> | 2021-12-25 20:21:32 +0100 |
| commit | 3e1511ce987c8492effe62906e8c1255372b48af (patch) | |
| tree | e9546817a2042c9c8a43af42b830346f0471b511 /Source/Core/Common/FileUtil.cpp | |
| parent | a29d7625ddb67f29f6dc46858b2b1488b72fd42b (diff) | |
Common/FileUtil: Ensure consistency for custom user paths.
Diffstat (limited to 'Source/Core/Common/FileUtil.cpp')
| -rw-r--r-- | Source/Core/Common/FileUtil.cpp | 24 |
1 files changed, 22 insertions, 2 deletions
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 <windows.h> @@ -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); } |
