diff options
author | Zach Hilman <zachhilman@gmail.com> | 2018-10-14 20:49:32 +0200 |
---|---|---|
committer | Zach Hilman <zachhilman@gmail.com> | 2018-10-24 01:31:28 +0200 |
commit | bfad41b0c12a308b0a5a10e3162d74140e3c121a (patch) | |
tree | 7b70074ff9454f499146b5b41377b640eccae501 /src/core/hle/service | |
parent | acc: Fix account UUID duplication error (diff) | |
download | yuzu-bfad41b0c12a308b0a5a10e3162d74140e3c121a.tar yuzu-bfad41b0c12a308b0a5a10e3162d74140e3c121a.tar.gz yuzu-bfad41b0c12a308b0a5a10e3162d74140e3c121a.tar.bz2 yuzu-bfad41b0c12a308b0a5a10e3162d74140e3c121a.tar.lz yuzu-bfad41b0c12a308b0a5a10e3162d74140e3c121a.tar.xz yuzu-bfad41b0c12a308b0a5a10e3162d74140e3c121a.tar.zst yuzu-bfad41b0c12a308b0a5a10e3162d74140e3c121a.zip |
Diffstat (limited to 'src/core/hle/service')
-rw-r--r-- | src/core/hle/service/acc/profile_manager.cpp | 48 | ||||
-rw-r--r-- | src/core/hle/service/acc/profile_manager.h | 2 |
2 files changed, 37 insertions, 13 deletions
diff --git a/src/core/hle/service/acc/profile_manager.cpp b/src/core/hle/service/acc/profile_manager.cpp index e6f1a0ae8..06f7d1b15 100644 --- a/src/core/hle/service/acc/profile_manager.cpp +++ b/src/core/hle/service/acc/profile_manager.cpp @@ -30,22 +30,20 @@ constexpr ResultCode ERROR_TOO_MANY_USERS(ErrorModule::Account, -1); constexpr ResultCode ERROR_USER_ALREADY_EXISTS(ErrorModule::Account, -2); constexpr ResultCode ERROR_ARGUMENT_IS_NULL(ErrorModule::Account, 20); -constexpr const char* ACC_SAVE_AVATORS_BASE_PATH = "/system/save/8000000000000010/su/avators/"; +constexpr char ACC_SAVE_AVATORS_BASE_PATH[] = "/system/save/8000000000000010/su/avators/"; -const UUID& UUID::Generate() { +UUID UUID::Generate() { std::random_device device; std::mt19937 gen(device()); std::uniform_int_distribution<u64> distribution(1, std::numeric_limits<u64>::max()); - uuid[0] = distribution(gen); - uuid[1] = distribution(gen); - return *this; + return UUID{distribution(gen), distribution(gen)}; } ProfileManager::ProfileManager() { ParseUserSaveFile(); if (user_count == 0) - CreateNewUser(UUID{}.Generate(), "yuzu"); + CreateNewUser(UUID::Generate(), "yuzu"); auto current = std::clamp<int>(Settings::values.current_user, 0, MAX_USERS - 1); if (UserExistsIndex(current)) @@ -309,10 +307,18 @@ void ProfileManager::ParseUserSaveFile() { ACC_SAVE_AVATORS_BASE_PATH + "profiles.dat", "rb"); + if (!save.IsOpen()) { + LOG_WARNING(Service_ACC, "Failed to load profile data from save data... Generating new " + "user 'yuzu' with random UUID."); + return; + } + ProfileDataRaw data; - save.Seek(0, SEEK_SET); - if (save.ReadBytes(&data, sizeof(ProfileDataRaw)) != sizeof(ProfileDataRaw)) + if (save.ReadBytes(&data, sizeof(ProfileDataRaw)) != sizeof(ProfileDataRaw)) { + LOG_WARNING(Service_ACC, "profiles.dat is smaller than expected... Generating new user " + "'yuzu' with random UUID."); return; + } for (std::size_t i = 0; i < MAX_USERS; ++i) { const auto& user = data.users[i]; @@ -335,12 +341,30 @@ void ProfileManager::WriteUserSaveFile() { raw.users[i].timestamp = profiles[i].creation_time; } - FileUtil::IOFile save(FileUtil::GetUserPath(FileUtil::UserPath::NANDDir) + - ACC_SAVE_AVATORS_BASE_PATH + "profiles.dat", - "wb"); + const auto raw_path = + FileUtil::GetUserPath(FileUtil::UserPath::NANDDir) + "/system/save/8000000000000010"; + if (FileUtil::Exists(raw_path) && !FileUtil::IsDirectory(raw_path)) + FileUtil::Delete(raw_path); + + const auto path = FileUtil::GetUserPath(FileUtil::UserPath::NANDDir) + + ACC_SAVE_AVATORS_BASE_PATH + "profiles.dat"; + + if (!FileUtil::CreateFullPath(path)) { + LOG_WARNING(Service_ACC, "Failed to create full path of profiles.dat. Create the directory " + "nand/system/save/8000000000000010/su/avators to mitigate this " + "issue."); + return; + } + + FileUtil::IOFile save(path, "wb"); + + if (!save.IsOpen()) { + LOG_WARNING(Service_ACC, "Failed to write save data to file... No changes to user data " + "made in current session will be saved."); + return; + } save.Resize(sizeof(ProfileDataRaw)); - save.Seek(0, SEEK_SET); save.WriteBytes(&raw, sizeof(ProfileDataRaw)); } diff --git a/src/core/hle/service/acc/profile_manager.h b/src/core/hle/service/acc/profile_manager.h index 482c1d8a9..235208d56 100644 --- a/src/core/hle/service/acc/profile_manager.h +++ b/src/core/hle/service/acc/profile_manager.h @@ -36,7 +36,7 @@ struct UUID { } // TODO(ogniK): Properly generate uuids based on RFC-4122 - const UUID& Generate(); + static UUID Generate(); // Set the UUID to {0,0} to be considered an invalid user void Invalidate() { |