diff options
author | Zach Hilman <zachhilman@gmail.com> | 2018-10-11 03:49:20 +0200 |
---|---|---|
committer | Zach Hilman <zachhilman@gmail.com> | 2018-10-24 01:31:28 +0200 |
commit | 702622b8f1eaa1b297a27a305ac56faeadf542d7 (patch) | |
tree | 8bd4dd63015771d124b5b599240b06d08bfe203f /src/core/hle/service/acc/profile_manager.cpp | |
parent | acc: Load user images from config dir (diff) | |
download | yuzu-702622b8f1eaa1b297a27a305ac56faeadf542d7.tar yuzu-702622b8f1eaa1b297a27a305ac56faeadf542d7.tar.gz yuzu-702622b8f1eaa1b297a27a305ac56faeadf542d7.tar.bz2 yuzu-702622b8f1eaa1b297a27a305ac56faeadf542d7.tar.lz yuzu-702622b8f1eaa1b297a27a305ac56faeadf542d7.tar.xz yuzu-702622b8f1eaa1b297a27a305ac56faeadf542d7.tar.zst yuzu-702622b8f1eaa1b297a27a305ac56faeadf542d7.zip |
Diffstat (limited to '')
-rw-r--r-- | src/core/hle/service/acc/profile_manager.cpp | 101 |
1 files changed, 95 insertions, 6 deletions
diff --git a/src/core/hle/service/acc/profile_manager.cpp b/src/core/hle/service/acc/profile_manager.cpp index b4b4b52b7..b0ea06b48 100644 --- a/src/core/hle/service/acc/profile_manager.cpp +++ b/src/core/hle/service/acc/profile_manager.cpp @@ -4,10 +4,27 @@ #include <random> #include <boost/optional.hpp> +#include "common/file_util.h" #include "core/hle/service/acc/profile_manager.h" #include "core/settings.h" namespace Service::Account { + +struct UserRaw { + UUID uuid; + UUID uuid2; + u64 timestamp; + ProfileUsername username; + INSERT_PADDING_BYTES(0x80); +}; +static_assert(sizeof(UserRaw) == 0xC8, "UserRaw has incorrect size."); + +struct ProfileDataRaw { + INSERT_PADDING_BYTES(0x10); + std::array<UserRaw, MAX_USERS> users; +}; +static_assert(sizeof(ProfileDataRaw) == 0x650, "ProfileDataRaw has incorrect size."); + // TODO(ogniK): Get actual error codes constexpr ResultCode ERROR_TOO_MANY_USERS(ErrorModule::Account, -1); constexpr ResultCode ERROR_USER_ALREADY_EXISTS(ErrorModule::Account, -2); @@ -23,15 +40,21 @@ const UUID& UUID::Generate() { } ProfileManager::ProfileManager() { - for (std::size_t i = 0; i < Settings::values.users.size(); ++i) { - const auto& val = Settings::values.users[i]; - ASSERT(CreateNewUser(val.second, val.first).IsSuccess()); - } + ParseUserSaveFile(); + + if (user_count == 0) + CreateNewUser(UUID{}.Generate(), "yuzu"); + + auto current = Settings::values.current_user; + if (!GetAllUsers()[current]) + current = 0; - OpenUser(Settings::values.users[Settings::values.current_user].second); + OpenUser(GetAllUsers()[current]); } -ProfileManager::~ProfileManager() = default; +ProfileManager::~ProfileManager() { + WriteUserSaveFile(); +} /// After a users creation it needs to be "registered" to the system. AddToProfiles handles the /// internal management of the users profiles @@ -241,4 +264,70 @@ bool ProfileManager::CanSystemRegisterUser() const { // emulate qlaunch. Update this to dynamically change. } +bool ProfileManager::RemoveUser(UUID uuid) { + auto index = GetUserIndex(uuid); + if (index == boost::none) { + return false; + } + + profiles[*index] = ProfileInfo{}; + std::stable_partition(profiles.begin(), profiles.end(), + [](const ProfileInfo& profile) { return profile.user_uuid; }); + return true; +} + +bool ProfileManager::SetProfileBase(UUID uuid, const ProfileBase& profile_new) { + auto index = GetUserIndex(uuid); + if (profile_new.user_uuid == UUID(INVALID_UUID) || index == boost::none) { + return false; + } + + auto& profile = profiles[*index]; + profile.user_uuid = profile_new.user_uuid; + profile.username = profile_new.username; + profile.creation_time = profile_new.timestamp; + + return true; +} + +void ProfileManager::ParseUserSaveFile() { + FileUtil::IOFile save(FileUtil::GetUserPath(FileUtil::UserPath::NANDDir) + + "/system/save/8000000000000010/su/avators/profiles.dat", + "rb"); + + ProfileDataRaw data; + save.Seek(0, SEEK_SET); + if (save.ReadBytes(&data, sizeof(ProfileDataRaw)) != sizeof(ProfileDataRaw)) + return; + + for (std::size_t i = 0; i < MAX_USERS; ++i) { + const auto& user = data.users[i]; + + if (user.uuid != UUID(INVALID_UUID)) + AddUser({user.uuid, user.username, user.timestamp, {}, false}); + } + + std::stable_partition(profiles.begin(), profiles.end(), + [](const ProfileInfo& profile) { return profile.user_uuid; }); +} + +void ProfileManager::WriteUserSaveFile() { + ProfileDataRaw raw{}; + + for (std::size_t i = 0; i < MAX_USERS; ++i) { + raw.users[i].username = profiles[i].username; + raw.users[i].uuid2 = profiles[i].user_uuid; + raw.users[i].uuid = profiles[i].user_uuid; + raw.users[i].timestamp = profiles[i].creation_time; + } + + FileUtil::IOFile save(FileUtil::GetUserPath(FileUtil::UserPath::NANDDir) + + "/system/save/8000000000000010/su/avators/profiles.dat", + "rb"); + + save.Resize(sizeof(ProfileDataRaw)); + save.Seek(0, SEEK_SET); + save.WriteBytes(&raw, sizeof(ProfileDataRaw)); +} + }; // namespace Service::Account |