summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar David Marcec2018-08-11 18:26:13 +1000
committerGravatar David Marcec2018-08-11 18:26:13 +1000
commitdfea525cbe3a337d3a1fa30136029599ae47ee71 (patch)
treeced572df6134a023b31716dae274dd3d042c06fb /src
parentFirst round of account changes (diff)
downloadyuzu-dfea525cbe3a337d3a1fa30136029599ae47ee71.tar.gz
yuzu-dfea525cbe3a337d3a1fa30136029599ae47ee71.tar.xz
yuzu-dfea525cbe3a337d3a1fa30136029599ae47ee71.zip
Second round of account changes
Diffstat (limited to 'src')
-rw-r--r--src/core/hle/service/acc/acc.h2
-rw-r--r--src/core/hle/service/acc/profile_manager.cpp27
-rw-r--r--src/core/hle/service/acc/profile_manager.h10
3 files changed, 21 insertions, 18 deletions
diff --git a/src/core/hle/service/acc/acc.h b/src/core/hle/service/acc/acc.h
index a94e6f588..d7c6d2415 100644
--- a/src/core/hle/service/acc/acc.h
+++ b/src/core/hle/service/acc/acc.h
@@ -4,8 +4,8 @@
4 4
5#pragma once 5#pragma once
6 6
7#include "core/hle/service/acc/profile_manager.h"
7#include "core/hle/service/service.h" 8#include "core/hle/service/service.h"
8#include "profile_manager.h"
9 9
10namespace Service::Account { 10namespace Service::Account {
11 11
diff --git a/src/core/hle/service/acc/profile_manager.cpp b/src/core/hle/service/acc/profile_manager.cpp
index fda796966..14d65ff1b 100644
--- a/src/core/hle/service/acc/profile_manager.cpp
+++ b/src/core/hle/service/acc/profile_manager.cpp
@@ -2,8 +2,8 @@
2// Licensed under GPLv2 or any later version 2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included. 3// Refer to the license.txt file included.
4 4
5#include "core/hle/service/acc/profile_manager.h"
5#include "core/settings.h" 6#include "core/settings.h"
6#include "profile_manager.h"
7 7
8namespace Service::Account { 8namespace Service::Account {
9// TODO(ogniK): Get actual error codes 9// TODO(ogniK): Get actual error codes
@@ -28,10 +28,9 @@ size_t ProfileManager::AddToProfiles(const ProfileInfo& user) {
28bool ProfileManager::RemoveProfileAtIdx(size_t index) { 28bool ProfileManager::RemoveProfileAtIdx(size_t index) {
29 if (index >= MAX_USERS || index >= user_count) 29 if (index >= MAX_USERS || index >= user_count)
30 return false; 30 return false;
31 profiles[index] = ProfileInfo{};
32 if (index < user_count - 1) 31 if (index < user_count - 1)
33 for (size_t i = index; i < user_count - 1; i++) 32 std::rotate(profiles.begin() + index, profiles.begin() + index + 1, profiles.end());
34 profiles[i] = profiles[i + 1]; // Shift upper profiles down 33 profiles.back() = {};
35 user_count--; 34 user_count--;
36 return true; 35 return true;
37} 36}
@@ -50,9 +49,10 @@ ResultCode ProfileManager::CreateNewUser(UUID uuid, std::array<u8, 0x20>& userna
50 return ERROR_ARGUMENT_IS_NULL; 49 return ERROR_ARGUMENT_IS_NULL;
51 if (username[0] == 0x0) 50 if (username[0] == 0x0)
52 return ERROR_ARGUMENT_IS_NULL; 51 return ERROR_ARGUMENT_IS_NULL;
53 for (unsigned i = 0; i < user_count; i++) 52 if (std::any_of(profiles.begin(), profiles.end(),
54 if (uuid == profiles[i].user_uuid) 53 [&uuid](const ProfileInfo& profile) { return uuid == profile.user_uuid; })) {
55 return ERROR_USER_ALREADY_EXISTS; 54 return ERROR_USER_ALREADY_EXISTS;
55 }
56 ProfileInfo prof_inf; 56 ProfileInfo prof_inf;
57 prof_inf.user_uuid = std::move(uuid); 57 prof_inf.user_uuid = std::move(uuid);
58 prof_inf.username = std::move(username); 58 prof_inf.username = std::move(username);
@@ -62,7 +62,7 @@ ResultCode ProfileManager::CreateNewUser(UUID uuid, std::array<u8, 0x20>& userna
62 return AddUser(prof_inf); 62 return AddUser(prof_inf);
63} 63}
64 64
65ResultCode ProfileManager::CreateNewUser(UUID uuid, std::string username) { 65ResultCode ProfileManager::CreateNewUser(UUID uuid, const std::string& username) {
66 std::array<u8, 0x20> username_output; 66 std::array<u8, 0x20> username_output;
67 if (username.size() > username_output.size()) 67 if (username.size() > username_output.size())
68 std::copy_n(username.begin(), username_output.size(), username_output.begin()); 68 std::copy_n(username.begin(), username_output.size(), username_output.begin());
@@ -74,10 +74,13 @@ ResultCode ProfileManager::CreateNewUser(UUID uuid, std::string username) {
74size_t ProfileManager::GetUserIndex(const UUID& uuid) const { 74size_t ProfileManager::GetUserIndex(const UUID& uuid) const {
75 if (!uuid) 75 if (!uuid)
76 return std::numeric_limits<size_t>::max(); 76 return std::numeric_limits<size_t>::max();
77 for (unsigned i = 0; i < user_count; i++) 77
78 if (profiles[i].user_uuid == uuid) 78 auto iter = std::find_if(profiles.begin(), profiles.end(),
79 return i; 79 [&uuid](const ProfileInfo& p) { return p.user_uuid == uuid; });
80 return std::numeric_limits<size_t>::max(); 80 if (iter == profiles.end()) {
81 return std::numeric_limits<size_t>::max();
82 }
83 return static_cast<size_t>(std::distance(profiles.begin(), iter));
81} 84}
82 85
83size_t ProfileManager::GetUserIndex(ProfileInfo user) const { 86size_t ProfileManager::GetUserIndex(ProfileInfo user) const {
diff --git a/src/core/hle/service/acc/profile_manager.h b/src/core/hle/service/acc/profile_manager.h
index ad4c20db0..121206954 100644
--- a/src/core/hle/service/acc/profile_manager.h
+++ b/src/core/hle/service/acc/profile_manager.h
@@ -12,10 +12,11 @@
12namespace Service::Account { 12namespace Service::Account {
13constexpr size_t MAX_USERS = 8; 13constexpr size_t MAX_USERS = 8;
14constexpr size_t MAX_DATA = 128; 14constexpr size_t MAX_DATA = 128;
15static const u128 INVALID_UUID = {0, 0};
15 16
16struct UUID { 17struct UUID {
17 // UUIDs which are 0 are considered invalid! 18 // UUIDs which are 0 are considered invalid!
18 u128 uuid{0, 0}; 19 u128 uuid = INVALID_UUID;
19 UUID() = default; 20 UUID() = default;
20 explicit UUID(const u128& id) : uuid{id} {} 21 explicit UUID(const u128& id) : uuid{id} {}
21 explicit UUID(const u64 lo, const u64 hi) { 22 explicit UUID(const u64 lo, const u64 hi) {
@@ -23,7 +24,7 @@ struct UUID {
23 uuid[1] = hi; 24 uuid[1] = hi;
24 }; 25 };
25 explicit operator bool() const { 26 explicit operator bool() const {
26 return uuid[0] != 0x0 || uuid[1] != 0x0; 27 return uuid[0] != INVALID_UUID[0] && uuid[1] != INVALID_UUID[1];
27 } 28 }
28 29
29 bool operator==(const UUID& rhs) const { 30 bool operator==(const UUID& rhs) const {
@@ -41,8 +42,7 @@ struct UUID {
41 return *this; 42 return *this;
42 } 43 }
43 void Invalidate() { 44 void Invalidate() {
44 uuid[0] = 0; 45 uuid = INVALID_UUID;
45 uuid[1] = 0;
46 } 46 }
47 std::string Format() const { 47 std::string Format() const {
48 return fmt::format("0x{:016X}{:016X}", uuid[1], uuid[0]); 48 return fmt::format("0x{:016X}{:016X}", uuid[1], uuid[0]);
@@ -81,7 +81,7 @@ public:
81 ProfileManager(); // TODO(ogniK): Load from system save 81 ProfileManager(); // TODO(ogniK): Load from system save
82 ResultCode AddUser(ProfileInfo user); 82 ResultCode AddUser(ProfileInfo user);
83 ResultCode CreateNewUser(UUID uuid, std::array<u8, 0x20>& username); 83 ResultCode CreateNewUser(UUID uuid, std::array<u8, 0x20>& username);
84 ResultCode CreateNewUser(UUID uuid, std::string username); 84 ResultCode CreateNewUser(UUID uuid, const std::string& username);
85 size_t GetUserIndex(const UUID& uuid) const; 85 size_t GetUserIndex(const UUID& uuid) const;
86 size_t GetUserIndex(ProfileInfo user) const; 86 size_t GetUserIndex(ProfileInfo user) const;
87 bool GetProfileBase(size_t index, ProfileBase& profile) const; 87 bool GetProfileBase(size_t index, ProfileBase& profile) const;