diff options
| author | Léo Lam <leo@leolam.fr> | 2022-01-01 02:32:24 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-01-01 02:32:24 +0100 |
| commit | 9a61514073a95f378f705873921596e85e625f74 (patch) | |
| tree | ef14dce0f4db4ddbc5f766462d3475e92b4279be /Source/Core/Common/FileUtil.cpp | |
| parent | c6225e451cbc0243c2713e850d65fc92047c47fc (diff) | |
| parent | 269ae6f7e8615b3110ca7389897b7f237231ffe8 (diff) | |
Merge pull request #10241 from AdmiralCurtiss/user-dir-consistency
Ensure user paths are stored in a consistent manner.
Diffstat (limited to 'Source/Core/Common/FileUtil.cpp')
| -rw-r--r-- | Source/Core/Common/FileUtil.cpp | 28 |
1 files changed, 24 insertions, 4 deletions
diff --git a/Source/Core/Common/FileUtil.cpp b/Source/Core/Common/FileUtil.cpp index 0eac268b00..d84b725e70 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> @@ -931,7 +932,7 @@ static void RebuildUserDirectories(unsigned int dir_index) { case D_USER_IDX: s_user_paths[D_GCUSER_IDX] = s_user_paths[D_USER_IDX] + GC_USER_DIR DIR_SEP; - s_user_paths[D_WIIROOT_IDX] = s_user_paths[D_USER_IDX] + WII_USER_DIR; + s_user_paths[D_WIIROOT_IDX] = s_user_paths[D_USER_IDX] + WII_USER_DIR DIR_SEP; s_user_paths[D_CONFIG_IDX] = s_user_paths[D_USER_IDX] + CONFIG_DIR DIR_SEP; s_user_paths[D_GAMESETTINGS_IDX] = s_user_paths[D_USER_IDX] + GAMESETTINGS_DIR DIR_SEP; s_user_paths[D_MAPS_IDX] = s_user_paths[D_USER_IDX] + MAPS_DIR DIR_SEP; @@ -977,7 +978,7 @@ static void RebuildUserDirectories(unsigned int dir_index) s_user_paths[F_ARAMDUMP_IDX] = s_user_paths[D_DUMP_IDX] + ARAM_DUMP; s_user_paths[F_FAKEVMEMDUMP_IDX] = s_user_paths[D_DUMP_IDX] + FAKEVMEM_DUMP; s_user_paths[F_GCSRAM_IDX] = s_user_paths[D_GCUSER_IDX] + GC_SRAM; - s_user_paths[F_WIISDCARD_IDX] = s_user_paths[D_WIIROOT_IDX] + DIR_SEP WII_SDCARD; + s_user_paths[F_WIISDCARD_IDX] = s_user_paths[D_WIIROOT_IDX] + WII_SDCARD; s_user_paths[D_MEMORYWATCHER_IDX] = s_user_paths[D_USER_IDX] + MEMORYWATCHER_DIR DIR_SEP; s_user_paths[F_MEMORYWATCHERLOCATIONS_IDX] = @@ -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); } |
