diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/core/hle/service/acc/profile_manager.cpp | 48 | ||||
| -rw-r--r-- | src/core/hle/service/acc/profile_manager.h | 2 | ||||
| -rw-r--r-- | src/yuzu/configuration/configure_system.cpp | 2 | ||||
| -rw-r--r-- | src/yuzu/configuration/configure_system.h | 8 |
4 files changed, 42 insertions, 18 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); | |||
| 30 | constexpr ResultCode ERROR_USER_ALREADY_EXISTS(ErrorModule::Account, -2); | 30 | constexpr ResultCode ERROR_USER_ALREADY_EXISTS(ErrorModule::Account, -2); |
| 31 | constexpr ResultCode ERROR_ARGUMENT_IS_NULL(ErrorModule::Account, 20); | 31 | constexpr ResultCode ERROR_ARGUMENT_IS_NULL(ErrorModule::Account, 20); |
| 32 | 32 | ||
| 33 | constexpr const char* ACC_SAVE_AVATORS_BASE_PATH = "/system/save/8000000000000010/su/avators/"; | 33 | constexpr char ACC_SAVE_AVATORS_BASE_PATH[] = "/system/save/8000000000000010/su/avators/"; |
| 34 | 34 | ||
| 35 | const UUID& UUID::Generate() { | 35 | UUID 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 | ||
| 44 | ProfileManager::ProfileManager() { | 42 | ProfileManager::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() { |
diff --git a/src/yuzu/configuration/configure_system.cpp b/src/yuzu/configuration/configure_system.cpp index 02e061ebc..a88fabc36 100644 --- a/src/yuzu/configuration/configure_system.cpp +++ b/src/yuzu/configuration/configure_system.cpp | |||
| @@ -163,7 +163,7 @@ void ConfigureSystem::UpdateCurrentUser() { | |||
| 163 | 163 | ||
| 164 | void ConfigureSystem::ReadSystemSettings() {} | 164 | void ConfigureSystem::ReadSystemSettings() {} |
| 165 | 165 | ||
| 166 | std::string ConfigureSystem::GetAccountUsername(Service::Account::UUID uuid) { | 166 | std::string ConfigureSystem::GetAccountUsername(Service::Account::UUID uuid) const { |
| 167 | Service::Account::ProfileBase profile; | 167 | Service::Account::ProfileBase profile; |
| 168 | if (!profile_manager->GetProfileBase(uuid, profile)) | 168 | if (!profile_manager->GetProfileBase(uuid, profile)) |
| 169 | return ""; | 169 | return ""; |
diff --git a/src/yuzu/configuration/configure_system.h b/src/yuzu/configuration/configure_system.h index 868bb8bdf..6adadfccf 100644 --- a/src/yuzu/configuration/configure_system.h +++ b/src/yuzu/configuration/configure_system.h | |||
| @@ -10,11 +10,11 @@ | |||
| 10 | #include <QWidget> | 10 | #include <QWidget> |
| 11 | #include "core/hle/service/acc/profile_manager.h" | 11 | #include "core/hle/service/acc/profile_manager.h" |
| 12 | 12 | ||
| 13 | class QVBoxLayout; | ||
| 14 | class QTreeView; | ||
| 15 | class QStandardItemModel; | ||
| 16 | class QGraphicsScene; | 13 | class QGraphicsScene; |
| 17 | class QStandardItem; | 14 | class QStandardItem; |
| 15 | class QStandardItemModel; | ||
| 16 | class QTreeView; | ||
| 17 | class QVBoxLayout; | ||
| 18 | 18 | ||
| 19 | namespace Ui { | 19 | namespace Ui { |
| 20 | class ConfigureSystem; | 20 | class ConfigureSystem; |
| @@ -45,7 +45,7 @@ public slots: | |||
| 45 | 45 | ||
| 46 | private: | 46 | private: |
| 47 | void ReadSystemSettings(); | 47 | void ReadSystemSettings(); |
| 48 | std::string GetAccountUsername(Service::Account::UUID uuid); | 48 | std::string GetAccountUsername(Service::Account::UUID uuid) const; |
| 49 | 49 | ||
| 50 | QVBoxLayout* layout; | 50 | QVBoxLayout* layout; |
| 51 | QTreeView* tree_view; | 51 | QTreeView* tree_view; |