summaryrefslogtreecommitdiffstats
path: root/src/core/hle/service/acc/profile_manager.cpp
diff options
context:
space:
mode:
authorZach Hilman <zachhilman@gmail.com>2018-10-13 19:02:33 +0200
committerZach Hilman <zachhilman@gmail.com>2018-10-24 01:31:28 +0200
commit45f2a2fe29373f261144c097d169dad8b65fe012 (patch)
tree610b04ce839b40eaab1fe297c625b34eaf76e9cd /src/core/hle/service/acc/profile_manager.cpp
parentconfigure_system: Clear selection after user delete (diff)
downloadyuzu-45f2a2fe29373f261144c097d169dad8b65fe012.tar
yuzu-45f2a2fe29373f261144c097d169dad8b65fe012.tar.gz
yuzu-45f2a2fe29373f261144c097d169dad8b65fe012.tar.bz2
yuzu-45f2a2fe29373f261144c097d169dad8b65fe012.tar.lz
yuzu-45f2a2fe29373f261144c097d169dad8b65fe012.tar.xz
yuzu-45f2a2fe29373f261144c097d169dad8b65fe012.tar.zst
yuzu-45f2a2fe29373f261144c097d169dad8b65fe012.zip
Diffstat (limited to '')
-rw-r--r--src/core/hle/service/acc/profile_manager.cpp24
1 files changed, 19 insertions, 5 deletions
diff --git a/src/core/hle/service/acc/profile_manager.cpp b/src/core/hle/service/acc/profile_manager.cpp
index 43743d39e..e6f1a0ae8 100644
--- a/src/core/hle/service/acc/profile_manager.cpp
+++ b/src/core/hle/service/acc/profile_manager.cpp
@@ -30,6 +30,8 @@ constexpr ResultCode ERROR_TOO_MANY_USERS(ErrorModule::Account, -1);
constexpr ResultCode ERROR_USER_ALREADY_EXISTS(ErrorModule::Account, -2);
constexpr ResultCode ERROR_ARGUMENT_IS_NULL(ErrorModule::Account, 20);
+constexpr const char* ACC_SAVE_AVATORS_BASE_PATH = "/system/save/8000000000000010/su/avators/";
+
const UUID& UUID::Generate() {
std::random_device device;
std::mt19937 gen(device());
@@ -45,11 +47,11 @@ ProfileManager::ProfileManager() {
if (user_count == 0)
CreateNewUser(UUID{}.Generate(), "yuzu");
- auto current = Settings::values.current_user;
- if (!GetAllUsers()[current])
+ auto current = std::clamp<int>(Settings::values.current_user, 0, MAX_USERS - 1);
+ if (UserExistsIndex(current))
current = 0;
- OpenUser(GetAllUsers()[current]);
+ OpenUser(*GetUser(current));
}
ProfileManager::~ProfileManager() {
@@ -126,6 +128,12 @@ ResultCode ProfileManager::CreateNewUser(UUID uuid, const std::string& username)
return CreateNewUser(uuid, username_output);
}
+boost::optional<UUID> ProfileManager::GetUser(std::size_t index) const {
+ if (index >= MAX_USERS)
+ return boost::none;
+ return profiles[index].user_uuid;
+}
+
/// Returns a users profile index based on their user id.
boost::optional<std::size_t> ProfileManager::GetUserIndex(const UUID& uuid) const {
if (!uuid) {
@@ -189,6 +197,12 @@ bool ProfileManager::UserExists(UUID uuid) const {
return (GetUserIndex(uuid) != boost::none);
}
+bool ProfileManager::UserExistsIndex(std::size_t index) const {
+ if (index >= MAX_USERS)
+ return false;
+ return profiles[index].user_uuid.uuid != INVALID_UUID;
+}
+
/// Opens a specific user
void ProfileManager::OpenUser(UUID uuid) {
auto idx = GetUserIndex(uuid);
@@ -292,7 +306,7 @@ bool ProfileManager::SetProfileBase(UUID uuid, const ProfileBase& profile_new) {
void ProfileManager::ParseUserSaveFile() {
FileUtil::IOFile save(FileUtil::GetUserPath(FileUtil::UserPath::NANDDir) +
- "/system/save/8000000000000010/su/avators/profiles.dat",
+ ACC_SAVE_AVATORS_BASE_PATH + "profiles.dat",
"rb");
ProfileDataRaw data;
@@ -322,7 +336,7 @@ void ProfileManager::WriteUserSaveFile() {
}
FileUtil::IOFile save(FileUtil::GetUserPath(FileUtil::UserPath::NANDDir) +
- "/system/save/8000000000000010/su/avators/profiles.dat",
+ ACC_SAVE_AVATORS_BASE_PATH + "profiles.dat",
"wb");
save.Resize(sizeof(ProfileDataRaw));