Merge pull request #10241 from AdmiralCurtiss/user-dir-consistency

Ensure user paths are stored in a consistent manner.
This commit is contained in:
Léo Lam
2022-01-01 02:32:24 +01:00
committed by GitHub
10 changed files with 50 additions and 35 deletions

View File

@ -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);
}

View File

@ -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);

View File

@ -19,7 +19,9 @@ namespace Common
std::string RootUserPath(FromWhichRoot from)
{
int idx = from == FROM_CONFIGURED_ROOT ? D_WIIROOT_IDX : D_SESSION_WIIROOT_IDX;
return File::GetUserPath(idx);
std::string dir = File::GetUserPath(idx);
dir.pop_back(); // remove trailing path separator
return dir;
}
static std::string RootUserPath(std::optional<FromWhichRoot> from)