summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorGravatar Zach Hilman2018-10-14 14:49:32 -0400
committerGravatar Zach Hilman2018-10-23 19:31:28 -0400
commitbfad41b0c12a308b0a5a10e3162d74140e3c121a (patch)
tree7b70074ff9454f499146b5b41377b640eccae501 /src/core
parentacc: Fix account UUID duplication error (diff)
downloadyuzu-bfad41b0c12a308b0a5a10e3162d74140e3c121a.tar.gz
yuzu-bfad41b0c12a308b0a5a10e3162d74140e3c121a.tar.xz
yuzu-bfad41b0c12a308b0a5a10e3162d74140e3c121a.zip
profile_manager: Create save data if it doesn't exist on use
Diffstat (limited to 'src/core')
-rw-r--r--src/core/hle/service/acc/profile_manager.cpp48
-rw-r--r--src/core/hle/service/acc/profile_manager.h2
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);
30constexpr ResultCode ERROR_USER_ALREADY_EXISTS(ErrorModule::Account, -2); 30constexpr ResultCode ERROR_USER_ALREADY_EXISTS(ErrorModule::Account, -2);
31constexpr ResultCode ERROR_ARGUMENT_IS_NULL(ErrorModule::Account, 20); 31constexpr ResultCode ERROR_ARGUMENT_IS_NULL(ErrorModule::Account, 20);
32 32
33constexpr const char* ACC_SAVE_AVATORS_BASE_PATH = "/system/save/8000000000000010/su/avators/"; 33constexpr char ACC_SAVE_AVATORS_BASE_PATH[] = "/system/save/8000000000000010/su/avators/";
34 34
35const UUID& UUID::Generate() { 35UUID UUID::Generate() {
36 std::random_device device; 36 std::random_device device;
37 std::mt19937 gen(device()); 37 std::mt19937 gen(device());
38 std::uniform_int_distribution<u64> distribution(1, std::numeric_limits<u64>::max()); 38 std::uniform_int_distribution<u64> distribution(1, std::numeric_limits<u64>::max());
39 uuid[0] = distribution(gen); 39 return UUID{distribution(gen), distribution(gen)};
40 uuid[1] = distribution(gen);
41 return *this;
42} 40}
43 41
44ProfileManager::ProfileManager() { 42ProfileManager::ProfileManager() {
45 ParseUserSaveFile(); 43 ParseUserSaveFile();
46 44
47 if (user_count == 0) 45 if (user_count == 0)
48 CreateNewUser(UUID{}.Generate(), "yuzu"); 46 CreateNewUser(UUID::Generate(), "yuzu");
49 47
50 auto current = std::clamp<int>(Settings::values.current_user, 0, MAX_USERS - 1); 48 auto current = std::clamp<int>(Settings::values.current_user, 0, MAX_USERS - 1);
51 if (UserExistsIndex(current)) 49 if (UserExistsIndex(current))
@@ -309,10 +307,18 @@ void ProfileManager::ParseUserSaveFile() {
309 ACC_SAVE_AVATORS_BASE_PATH + "profiles.dat", 307 ACC_SAVE_AVATORS_BASE_PATH + "profiles.dat",
310 "rb"); 308 "rb");
311 309
310 if (!save.IsOpen()) {
311 LOG_WARNING(Service_ACC, "Failed to load profile data from save data... Generating new "
312 "user 'yuzu' with random UUID.");
313 return;
314 }
315
312 ProfileDataRaw data; 316 ProfileDataRaw data;
313 save.Seek(0, SEEK_SET); 317 if (save.ReadBytes(&data, sizeof(ProfileDataRaw)) != sizeof(ProfileDataRaw)) {
314 if (save.ReadBytes(&data, sizeof(ProfileDataRaw)) != sizeof(ProfileDataRaw)) 318 LOG_WARNING(Service_ACC, "profiles.dat is smaller than expected... Generating new user "
319 "'yuzu' with random UUID.");
315 return; 320 return;
321 }
316 322
317 for (std::size_t i = 0; i < MAX_USERS; ++i) { 323 for (std::size_t i = 0; i < MAX_USERS; ++i) {
318 const auto& user = data.users[i]; 324 const auto& user = data.users[i];
@@ -335,12 +341,30 @@ void ProfileManager::WriteUserSaveFile() {
335 raw.users[i].timestamp = profiles[i].creation_time; 341 raw.users[i].timestamp = profiles[i].creation_time;
336 } 342 }
337 343
338 FileUtil::IOFile save(FileUtil::GetUserPath(FileUtil::UserPath::NANDDir) + 344 const auto raw_path =
339 ACC_SAVE_AVATORS_BASE_PATH + "profiles.dat", 345 FileUtil::GetUserPath(FileUtil::UserPath::NANDDir) + "/system/save/8000000000000010";
340 "wb"); 346 if (FileUtil::Exists(raw_path) && !FileUtil::IsDirectory(raw_path))
347 FileUtil::Delete(raw_path);
348
349 const auto path = FileUtil::GetUserPath(FileUtil::UserPath::NANDDir) +
350 ACC_SAVE_AVATORS_BASE_PATH + "profiles.dat";
351
352 if (!FileUtil::CreateFullPath(path)) {
353 LOG_WARNING(Service_ACC, "Failed to create full path of profiles.dat. Create the directory "
354 "nand/system/save/8000000000000010/su/avators to mitigate this "
355 "issue.");
356 return;
357 }
358
359 FileUtil::IOFile save(path, "wb");
360
361 if (!save.IsOpen()) {
362 LOG_WARNING(Service_ACC, "Failed to write save data to file... No changes to user data "
363 "made in current session will be saved.");
364 return;
365 }
341 366
342 save.Resize(sizeof(ProfileDataRaw)); 367 save.Resize(sizeof(ProfileDataRaw));
343 save.Seek(0, SEEK_SET);
344 save.WriteBytes(&raw, sizeof(ProfileDataRaw)); 368 save.WriteBytes(&raw, sizeof(ProfileDataRaw));
345} 369}
346 370
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 {
36 } 36 }
37 37
38 // TODO(ogniK): Properly generate uuids based on RFC-4122 38 // TODO(ogniK): Properly generate uuids based on RFC-4122
39 const UUID& Generate(); 39 static UUID Generate();
40 40
41 // Set the UUID to {0,0} to be considered an invalid user 41 // Set the UUID to {0,0} to be considered an invalid user
42 void Invalidate() { 42 void Invalidate() {