diff options
| author | 2020-08-04 13:51:15 +1000 | |
|---|---|---|
| committer | 2020-08-04 13:51:15 +1000 | |
| commit | 25fb7cd16dc64e6fe1b8ef8e15cc846afebd5dfa (patch) | |
| tree | ed5e8dc3a82387c20158fe89caaebc8be1ed83b4 | |
| parent | Merge pull request #4473 from lioncash/cheat-desig (diff) | |
| parent | profile_manager: Make use of std::nullopt (diff) | |
| download | yuzu-25fb7cd16dc64e6fe1b8ef8e15cc846afebd5dfa.tar.gz yuzu-25fb7cd16dc64e6fe1b8ef8e15cc846afebd5dfa.tar.xz yuzu-25fb7cd16dc64e6fe1b8ef8e15cc846afebd5dfa.zip | |
Merge pull request #4474 from lioncash/hle-profile
profile_manager: Make use of designated initializers
| -rw-r--r-- | src/core/hle/service/acc/profile_manager.cpp | 43 |
1 files changed, 26 insertions, 17 deletions
diff --git a/src/core/hle/service/acc/profile_manager.cpp b/src/core/hle/service/acc/profile_manager.cpp index eb8c81645..a98d57b5c 100644 --- a/src/core/hle/service/acc/profile_manager.cpp +++ b/src/core/hle/service/acc/profile_manager.cpp | |||
| @@ -58,7 +58,7 @@ ProfileManager::~ProfileManager() { | |||
| 58 | /// internal management of the users profiles | 58 | /// internal management of the users profiles |
| 59 | std::optional<std::size_t> ProfileManager::AddToProfiles(const ProfileInfo& profile) { | 59 | std::optional<std::size_t> ProfileManager::AddToProfiles(const ProfileInfo& profile) { |
| 60 | if (user_count >= MAX_USERS) { | 60 | if (user_count >= MAX_USERS) { |
| 61 | return {}; | 61 | return std::nullopt; |
| 62 | } | 62 | } |
| 63 | profiles[user_count] = profile; | 63 | profiles[user_count] = profile; |
| 64 | return user_count++; | 64 | return user_count++; |
| @@ -101,13 +101,14 @@ ResultCode ProfileManager::CreateNewUser(UUID uuid, const ProfileUsername& usern | |||
| 101 | [&uuid](const ProfileInfo& profile) { return uuid == profile.user_uuid; })) { | 101 | [&uuid](const ProfileInfo& profile) { return uuid == profile.user_uuid; })) { |
| 102 | return ERROR_USER_ALREADY_EXISTS; | 102 | return ERROR_USER_ALREADY_EXISTS; |
| 103 | } | 103 | } |
| 104 | ProfileInfo profile; | 104 | |
| 105 | profile.user_uuid = uuid; | 105 | return AddUser({ |
| 106 | profile.username = username; | 106 | .user_uuid = uuid, |
| 107 | profile.data = {}; | 107 | .username = username, |
| 108 | profile.creation_time = 0x0; | 108 | .creation_time = 0, |
| 109 | profile.is_open = false; | 109 | .data = {}, |
| 110 | return AddUser(profile); | 110 | .is_open = false, |
| 111 | }); | ||
| 111 | } | 112 | } |
| 112 | 113 | ||
| 113 | /// Creates a new user on the system. This function allows a much simpler method of registration | 114 | /// Creates a new user on the system. This function allows a much simpler method of registration |
| @@ -126,7 +127,7 @@ ResultCode ProfileManager::CreateNewUser(UUID uuid, const std::string& username) | |||
| 126 | 127 | ||
| 127 | std::optional<UUID> ProfileManager::GetUser(std::size_t index) const { | 128 | std::optional<UUID> ProfileManager::GetUser(std::size_t index) const { |
| 128 | if (index >= MAX_USERS) { | 129 | if (index >= MAX_USERS) { |
| 129 | return {}; | 130 | return std::nullopt; |
| 130 | } | 131 | } |
| 131 | 132 | ||
| 132 | return profiles[index].user_uuid; | 133 | return profiles[index].user_uuid; |
| @@ -135,13 +136,13 @@ std::optional<UUID> ProfileManager::GetUser(std::size_t index) const { | |||
| 135 | /// Returns a users profile index based on their user id. | 136 | /// Returns a users profile index based on their user id. |
| 136 | std::optional<std::size_t> ProfileManager::GetUserIndex(const UUID& uuid) const { | 137 | std::optional<std::size_t> ProfileManager::GetUserIndex(const UUID& uuid) const { |
| 137 | if (!uuid) { | 138 | if (!uuid) { |
| 138 | return {}; | 139 | return std::nullopt; |
| 139 | } | 140 | } |
| 140 | 141 | ||
| 141 | const auto iter = std::find_if(profiles.begin(), profiles.end(), | 142 | const auto iter = std::find_if(profiles.begin(), profiles.end(), |
| 142 | [&uuid](const ProfileInfo& p) { return p.user_uuid == uuid; }); | 143 | [&uuid](const ProfileInfo& p) { return p.user_uuid == uuid; }); |
| 143 | if (iter == profiles.end()) { | 144 | if (iter == profiles.end()) { |
| 144 | return {}; | 145 | return std::nullopt; |
| 145 | } | 146 | } |
| 146 | 147 | ||
| 147 | return static_cast<std::size_t>(std::distance(profiles.begin(), iter)); | 148 | return static_cast<std::size_t>(std::distance(profiles.begin(), iter)); |
| @@ -339,7 +340,13 @@ void ProfileManager::ParseUserSaveFile() { | |||
| 339 | continue; | 340 | continue; |
| 340 | } | 341 | } |
| 341 | 342 | ||
| 342 | AddUser({user.uuid, user.username, user.timestamp, user.extra_data, false}); | 343 | AddUser({ |
| 344 | .user_uuid = user.uuid, | ||
| 345 | .username = user.username, | ||
| 346 | .creation_time = user.timestamp, | ||
| 347 | .data = user.extra_data, | ||
| 348 | .is_open = false, | ||
| 349 | }); | ||
| 343 | } | 350 | } |
| 344 | 351 | ||
| 345 | std::stable_partition(profiles.begin(), profiles.end(), | 352 | std::stable_partition(profiles.begin(), profiles.end(), |
| @@ -350,11 +357,13 @@ void ProfileManager::WriteUserSaveFile() { | |||
| 350 | ProfileDataRaw raw{}; | 357 | ProfileDataRaw raw{}; |
| 351 | 358 | ||
| 352 | for (std::size_t i = 0; i < MAX_USERS; ++i) { | 359 | for (std::size_t i = 0; i < MAX_USERS; ++i) { |
| 353 | raw.users[i].username = profiles[i].username; | 360 | raw.users[i] = { |
| 354 | raw.users[i].uuid2 = profiles[i].user_uuid; | 361 | .uuid = profiles[i].user_uuid, |
| 355 | raw.users[i].uuid = profiles[i].user_uuid; | 362 | .uuid2 = profiles[i].user_uuid, |
| 356 | raw.users[i].timestamp = profiles[i].creation_time; | 363 | .timestamp = profiles[i].creation_time, |
| 357 | raw.users[i].extra_data = profiles[i].data; | 364 | .username = profiles[i].username, |
| 365 | .extra_data = profiles[i].data, | ||
| 366 | }; | ||
| 358 | } | 367 | } |
| 359 | 368 | ||
| 360 | const auto raw_path = | 369 | const auto raw_path = |