diff options
| author | 2024-01-13 14:19:44 -0600 | |
|---|---|---|
| committer | 2024-01-13 14:28:29 -0600 | |
| commit | bee22540a1d8a7b3ebd9ff4c244bf257b5e9f8b7 (patch) | |
| tree | 0cba79e5f77d8940de057cf5eb439e5adf46c956 /src/core/hle/service/acc | |
| parent | Merge pull request #12653 from liamwhite/once-more (diff) | |
| download | yuzu-bee22540a1d8a7b3ebd9ff4c244bf257b5e9f8b7.tar.gz yuzu-bee22540a1d8a7b3ebd9ff4c244bf257b5e9f8b7.tar.xz yuzu-bee22540a1d8a7b3ebd9ff4c244bf257b5e9f8b7.zip | |
service: acc: Only save profiles when profiles have changed
Diffstat (limited to 'src/core/hle/service/acc')
| -rw-r--r-- | src/core/hle/service/acc/profile_manager.cpp | 19 | ||||
| -rw-r--r-- | src/core/hle/service/acc/profile_manager.h | 1 |
2 files changed, 17 insertions, 3 deletions
diff --git a/src/core/hle/service/acc/profile_manager.cpp b/src/core/hle/service/acc/profile_manager.cpp index 5542d6cbc..683f44e27 100644 --- a/src/core/hle/service/acc/profile_manager.cpp +++ b/src/core/hle/service/acc/profile_manager.cpp | |||
| @@ -61,9 +61,7 @@ ProfileManager::ProfileManager() { | |||
| 61 | OpenUser(*GetUser(current)); | 61 | OpenUser(*GetUser(current)); |
| 62 | } | 62 | } |
| 63 | 63 | ||
| 64 | ProfileManager::~ProfileManager() { | 64 | ProfileManager::~ProfileManager() = default; |
| 65 | WriteUserSaveFile(); | ||
| 66 | } | ||
| 67 | 65 | ||
| 68 | /// After a users creation it needs to be "registered" to the system. AddToProfiles handles the | 66 | /// After a users creation it needs to be "registered" to the system. AddToProfiles handles the |
| 69 | /// internal management of the users profiles | 67 | /// internal management of the users profiles |
| @@ -113,6 +111,8 @@ Result ProfileManager::CreateNewUser(UUID uuid, const ProfileUsername& username) | |||
| 113 | return ERROR_USER_ALREADY_EXISTS; | 111 | return ERROR_USER_ALREADY_EXISTS; |
| 114 | } | 112 | } |
| 115 | 113 | ||
| 114 | is_save_needed = true; | ||
| 115 | |||
| 116 | return AddUser({ | 116 | return AddUser({ |
| 117 | .user_uuid = uuid, | 117 | .user_uuid = uuid, |
| 118 | .username = username, | 118 | .username = username, |
| @@ -326,6 +326,9 @@ bool ProfileManager::RemoveUser(UUID uuid) { | |||
| 326 | profiles[*index] = ProfileInfo{}; | 326 | profiles[*index] = ProfileInfo{}; |
| 327 | std::stable_partition(profiles.begin(), profiles.end(), | 327 | std::stable_partition(profiles.begin(), profiles.end(), |
| 328 | [](const ProfileInfo& profile) { return profile.user_uuid.IsValid(); }); | 328 | [](const ProfileInfo& profile) { return profile.user_uuid.IsValid(); }); |
| 329 | |||
| 330 | is_save_needed = true; | ||
| 331 | |||
| 329 | return true; | 332 | return true; |
| 330 | } | 333 | } |
| 331 | 334 | ||
| @@ -340,6 +343,8 @@ bool ProfileManager::SetProfileBase(UUID uuid, const ProfileBase& profile_new) { | |||
| 340 | profile.username = profile_new.username; | 343 | profile.username = profile_new.username; |
| 341 | profile.creation_time = profile_new.timestamp; | 344 | profile.creation_time = profile_new.timestamp; |
| 342 | 345 | ||
| 346 | is_save_needed = true; | ||
| 347 | |||
| 343 | return true; | 348 | return true; |
| 344 | } | 349 | } |
| 345 | 350 | ||
| @@ -348,6 +353,7 @@ bool ProfileManager::SetProfileBaseAndData(Common::UUID uuid, const ProfileBase& | |||
| 348 | const auto index = GetUserIndex(uuid); | 353 | const auto index = GetUserIndex(uuid); |
| 349 | if (index.has_value() && SetProfileBase(uuid, profile_new)) { | 354 | if (index.has_value() && SetProfileBase(uuid, profile_new)) { |
| 350 | profiles[*index].data = data_new; | 355 | profiles[*index].data = data_new; |
| 356 | is_save_needed = true; | ||
| 351 | return true; | 357 | return true; |
| 352 | } | 358 | } |
| 353 | 359 | ||
| @@ -391,6 +397,10 @@ void ProfileManager::ParseUserSaveFile() { | |||
| 391 | } | 397 | } |
| 392 | 398 | ||
| 393 | void ProfileManager::WriteUserSaveFile() { | 399 | void ProfileManager::WriteUserSaveFile() { |
| 400 | if (!is_save_needed) { | ||
| 401 | return; | ||
| 402 | } | ||
| 403 | |||
| 394 | ProfileDataRaw raw{}; | 404 | ProfileDataRaw raw{}; |
| 395 | 405 | ||
| 396 | for (std::size_t i = 0; i < MAX_USERS; ++i) { | 406 | for (std::size_t i = 0; i < MAX_USERS; ++i) { |
| @@ -423,7 +433,10 @@ void ProfileManager::WriteUserSaveFile() { | |||
| 423 | if (!save.IsOpen() || !save.SetSize(sizeof(ProfileDataRaw)) || !save.WriteObject(raw)) { | 433 | if (!save.IsOpen() || !save.SetSize(sizeof(ProfileDataRaw)) || !save.WriteObject(raw)) { |
| 424 | LOG_WARNING(Service_ACC, "Failed to write save data to file... No changes to user data " | 434 | LOG_WARNING(Service_ACC, "Failed to write save data to file... No changes to user data " |
| 425 | "made in current session will be saved."); | 435 | "made in current session will be saved."); |
| 436 | return; | ||
| 426 | } | 437 | } |
| 438 | |||
| 439 | is_save_needed = false; | ||
| 427 | } | 440 | } |
| 428 | 441 | ||
| 429 | }; // namespace Service::Account | 442 | }; // namespace Service::Account |
diff --git a/src/core/hle/service/acc/profile_manager.h b/src/core/hle/service/acc/profile_manager.h index 900e32200..e21863e64 100644 --- a/src/core/hle/service/acc/profile_manager.h +++ b/src/core/hle/service/acc/profile_manager.h | |||
| @@ -103,6 +103,7 @@ private: | |||
| 103 | std::optional<std::size_t> AddToProfiles(const ProfileInfo& profile); | 103 | std::optional<std::size_t> AddToProfiles(const ProfileInfo& profile); |
| 104 | bool RemoveProfileAtIndex(std::size_t index); | 104 | bool RemoveProfileAtIndex(std::size_t index); |
| 105 | 105 | ||
| 106 | bool is_save_needed{}; | ||
| 106 | std::array<ProfileInfo, MAX_USERS> profiles{}; | 107 | std::array<ProfileInfo, MAX_USERS> profiles{}; |
| 107 | std::array<ProfileInfo, MAX_USERS> stored_opened_profiles{}; | 108 | std::array<ProfileInfo, MAX_USERS> stored_opened_profiles{}; |
| 108 | std::size_t user_count{}; | 109 | std::size_t user_count{}; |