summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar David Marcec2018-08-11 16:47:33 +1000
committerGravatar David Marcec2018-08-11 16:47:33 +1000
commit82fa0bcea7c0231742716f7c79255eb107d4a933 (patch)
tree9c5837bac4b580d60315f840d1a80ae49a6a143b /src
parentRebase with dynarmic master (diff)
downloadyuzu-82fa0bcea7c0231742716f7c79255eb107d4a933.tar.gz
yuzu-82fa0bcea7c0231742716f7c79255eb107d4a933.tar.xz
yuzu-82fa0bcea7c0231742716f7c79255eb107d4a933.zip
First round of account changes
Diffstat (limited to 'src')
-rw-r--r--src/core/hle/service/acc/acc.cpp2
-rw-r--r--src/core/hle/service/acc/profile_manager.cpp52
-rw-r--r--src/core/hle/service/acc/profile_manager.h50
3 files changed, 55 insertions, 49 deletions
diff --git a/src/core/hle/service/acc/acc.cpp b/src/core/hle/service/acc/acc.cpp
index 22e44368a..9a7c3b9f4 100644
--- a/src/core/hle/service/acc/acc.cpp
+++ b/src/core/hle/service/acc/acc.cpp
@@ -165,7 +165,7 @@ void Module::Interface::GetLastOpenedUser(Kernel::HLERequestContext& ctx) {
165 LOG_INFO(Service_ACC, "called"); 165 LOG_INFO(Service_ACC, "called");
166 IPC::ResponseBuilder rb{ctx, 6}; 166 IPC::ResponseBuilder rb{ctx, 6};
167 rb.Push(RESULT_SUCCESS); 167 rb.Push(RESULT_SUCCESS);
168 rb.PushRaw<UUID>(profile_manager->GetLastOpennedUser()); 168 rb.PushRaw<UUID>(profile_manager->GetLastOpenedUser());
169} 169}
170 170
171void Module::Interface::GetProfile(Kernel::HLERequestContext& ctx) { 171void Module::Interface::GetProfile(Kernel::HLERequestContext& ctx) {
diff --git a/src/core/hle/service/acc/profile_manager.cpp b/src/core/hle/service/acc/profile_manager.cpp
index 8e7d7194c..fda796966 100644
--- a/src/core/hle/service/acc/profile_manager.cpp
+++ b/src/core/hle/service/acc/profile_manager.cpp
@@ -1,3 +1,7 @@
1// Copyright 2018 yuzu emulator team
2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included.
4
1#include "core/settings.h" 5#include "core/settings.h"
2#include "profile_manager.h" 6#include "profile_manager.h"
3 7
@@ -15,14 +19,14 @@ ProfileManager::ProfileManager() {
15 19
16size_t ProfileManager::AddToProfiles(const ProfileInfo& user) { 20size_t ProfileManager::AddToProfiles(const ProfileInfo& user) {
17 if (user_count >= MAX_USERS) { 21 if (user_count >= MAX_USERS) {
18 return -1; 22 return std::numeric_limits<size_t>::max();
19 } 23 }
20 profiles[user_count] = std::move(user); 24 profiles[user_count] = std::move(user);
21 return user_count++; 25 return user_count++;
22} 26}
23 27
24bool ProfileManager::RemoveProfileAtIdx(size_t index) { 28bool ProfileManager::RemoveProfileAtIdx(size_t index) {
25 if (index >= MAX_USERS || index < 0 || index >= user_count) 29 if (index >= MAX_USERS || index >= user_count)
26 return false; 30 return false;
27 profiles[index] = ProfileInfo{}; 31 profiles[index] = ProfileInfo{};
28 if (index < user_count - 1) 32 if (index < user_count - 1)
@@ -33,13 +37,13 @@ bool ProfileManager::RemoveProfileAtIdx(size_t index) {
33} 37}
34 38
35ResultCode ProfileManager::AddUser(ProfileInfo user) { 39ResultCode ProfileManager::AddUser(ProfileInfo user) {
36 if (AddToProfiles(user) == -1) { 40 if (AddToProfiles(user) == std::numeric_limits<size_t>::max()) {
37 return ERROR_TOO_MANY_USERS; 41 return ERROR_TOO_MANY_USERS;
38 } 42 }
39 return RESULT_SUCCESS; 43 return RESULT_SUCCESS;
40} 44}
41 45
42ResultCode ProfileManager::CreateNewUser(UUID uuid, std::array<u8, 0x20> username) { 46ResultCode ProfileManager::CreateNewUser(UUID uuid, std::array<u8, 0x20>& username) {
43 if (user_count == MAX_USERS) 47 if (user_count == MAX_USERS)
44 return ERROR_TOO_MANY_USERS; 48 return ERROR_TOO_MANY_USERS;
45 if (!uuid) 49 if (!uuid)
@@ -64,67 +68,67 @@ ResultCode ProfileManager::CreateNewUser(UUID uuid, std::string username) {
64 std::copy_n(username.begin(), username_output.size(), username_output.begin()); 68 std::copy_n(username.begin(), username_output.size(), username_output.begin());
65 else 69 else
66 std::copy(username.begin(), username.end(), username_output.begin()); 70 std::copy(username.begin(), username.end(), username_output.begin());
67 return CreateNewUser(uuid, std::move(username_output)); 71 return CreateNewUser(uuid, username_output);
68} 72}
69 73
70size_t ProfileManager::GetUserIndex(UUID uuid) { 74size_t ProfileManager::GetUserIndex(const UUID& uuid) const {
71 if (!uuid) 75 if (!uuid)
72 return -1; 76 return std::numeric_limits<size_t>::max();
73 for (unsigned i = 0; i < user_count; i++) 77 for (unsigned i = 0; i < user_count; i++)
74 if (profiles[i].user_uuid == uuid) 78 if (profiles[i].user_uuid == uuid)
75 return i; 79 return i;
76 return -1; 80 return std::numeric_limits<size_t>::max();
77} 81}
78 82
79size_t ProfileManager::GetUserIndex(ProfileInfo user) { 83size_t ProfileManager::GetUserIndex(ProfileInfo user) const {
80 return GetUserIndex(user.user_uuid); 84 return GetUserIndex(user.user_uuid);
81} 85}
82 86
83bool ProfileManager::GetProfileBase(size_t index, ProfileBase& profile) { 87bool ProfileManager::GetProfileBase(size_t index, ProfileBase& profile) const {
84 if (index >= MAX_USERS) { 88 if (index >= MAX_USERS) {
85 profile.Invalidate(); 89 profile.Invalidate();
86 return false; 90 return false;
87 } 91 }
88 auto prof_info = profiles[index]; 92 const auto& prof_info = profiles[index];
89 profile.user_uuid = prof_info.user_uuid; 93 profile.user_uuid = prof_info.user_uuid;
90 profile.username = prof_info.username; 94 profile.username = prof_info.username;
91 profile.timestamp = prof_info.creation_time; 95 profile.timestamp = prof_info.creation_time;
92 return true; 96 return true;
93} 97}
94 98
95bool ProfileManager::GetProfileBase(UUID uuid, ProfileBase& profile) { 99bool ProfileManager::GetProfileBase(UUID uuid, ProfileBase& profile) const {
96 auto idx = GetUserIndex(uuid); 100 auto idx = GetUserIndex(uuid);
97 return GetProfileBase(idx, profile); 101 return GetProfileBase(idx, profile);
98} 102}
99 103
100bool ProfileManager::GetProfileBase(ProfileInfo user, ProfileBase& profile) { 104bool ProfileManager::GetProfileBase(ProfileInfo user, ProfileBase& profile) const {
101 return GetProfileBase(user.user_uuid, profile); 105 return GetProfileBase(user.user_uuid, profile);
102} 106}
103 107
104size_t ProfileManager::GetUserCount() { 108size_t ProfileManager::GetUserCount() const {
105 return user_count; 109 return user_count;
106} 110}
107 111
108bool ProfileManager::UserExists(UUID uuid) { 112bool ProfileManager::UserExists(UUID uuid) const {
109 return (GetUserIndex(uuid) != -1); 113 return (GetUserIndex(uuid) != std::numeric_limits<size_t>::max());
110} 114}
111 115
112void ProfileManager::OpenUser(UUID uuid) { 116void ProfileManager::OpenUser(UUID uuid) {
113 auto idx = GetUserIndex(uuid); 117 auto idx = GetUserIndex(uuid);
114 if (idx == -1) 118 if (idx == std::numeric_limits<size_t>::max())
115 return; 119 return;
116 profiles[idx].is_open = true; 120 profiles[idx].is_open = true;
117 last_openned_user = uuid; 121 last_opened_user = uuid;
118} 122}
119 123
120void ProfileManager::CloseUser(UUID uuid) { 124void ProfileManager::CloseUser(UUID uuid) {
121 auto idx = GetUserIndex(uuid); 125 auto idx = GetUserIndex(uuid);
122 if (idx == -1) 126 if (idx == std::numeric_limits<size_t>::max())
123 return; 127 return;
124 profiles[idx].is_open = false; 128 profiles[idx].is_open = false;
125} 129}
126 130
127std::array<UUID, MAX_USERS> ProfileManager::GetAllUsers() { 131std::array<UUID, MAX_USERS> ProfileManager::GetAllUsers() const {
128 std::array<UUID, MAX_USERS> output; 132 std::array<UUID, MAX_USERS> output;
129 for (unsigned i = 0; i < user_count; i++) { 133 for (unsigned i = 0; i < user_count; i++) {
130 output[i] = profiles[i].user_uuid; 134 output[i] = profiles[i].user_uuid;
@@ -132,7 +136,7 @@ std::array<UUID, MAX_USERS> ProfileManager::GetAllUsers() {
132 return output; 136 return output;
133} 137}
134 138
135std::array<UUID, MAX_USERS> ProfileManager::GetOpenUsers() { 139std::array<UUID, MAX_USERS> ProfileManager::GetOpenUsers() const {
136 std::array<UUID, MAX_USERS> output; 140 std::array<UUID, MAX_USERS> output;
137 unsigned user_idx = 0; 141 unsigned user_idx = 0;
138 for (unsigned i = 0; i < user_count; i++) { 142 for (unsigned i = 0; i < user_count; i++) {
@@ -143,8 +147,8 @@ std::array<UUID, MAX_USERS> ProfileManager::GetOpenUsers() {
143 return output; 147 return output;
144} 148}
145 149
146const UUID& ProfileManager::GetLastOpennedUser() { 150UUID ProfileManager::GetLastOpenedUser() const {
147 return last_openned_user; 151 return last_opened_user;
148} 152}
149 153
150bool ProfileManager::GetProfileBaseAndData(size_t index, ProfileBase& profile, 154bool ProfileManager::GetProfileBaseAndData(size_t index, ProfileBase& profile,
@@ -166,7 +170,7 @@ bool ProfileManager::GetProfileBaseAndData(ProfileInfo user, ProfileBase& profil
166 return GetProfileBaseAndData(user.user_uuid, profile, data); 170 return GetProfileBaseAndData(user.user_uuid, profile, data);
167} 171}
168 172
169bool ProfileManager::CanSystemRegisterUser() { 173bool ProfileManager::CanSystemRegisterUser() const {
170 return false; // TODO(ogniK): Games shouldn't have 174 return false; // TODO(ogniK): Games shouldn't have
171 // access to user registration, when we 175 // access to user registration, when we
172 // emulate qlaunch. Update this to dynamically change. 176 // emulate qlaunch. Update this to dynamically change.
diff --git a/src/core/hle/service/acc/profile_manager.h b/src/core/hle/service/acc/profile_manager.h
index 64371ea16..ad4c20db0 100644
--- a/src/core/hle/service/acc/profile_manager.h
+++ b/src/core/hle/service/acc/profile_manager.h
@@ -1,4 +1,9 @@
1// Copyright 2018 yuzu emulator team
2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included.
4
1#pragma once 5#pragma once
6
2#include <array> 7#include <array>
3#include "common/common_types.h" 8#include "common/common_types.h"
4#include "common/swap.h" 9#include "common/swap.h"
@@ -12,24 +17,21 @@ struct UUID {
12 // UUIDs which are 0 are considered invalid! 17 // UUIDs which are 0 are considered invalid!
13 u128 uuid{0, 0}; 18 u128 uuid{0, 0};
14 UUID() = default; 19 UUID() = default;
15 explicit UUID(const u128& id) { 20 explicit UUID(const u128& id) : uuid{id} {}
16 uuid[0] = id[0]; 21 explicit UUID(const u64 lo, const u64 hi) {
17 uuid[1] = id[1];
18 };
19 explicit UUID(const u64& lo, const u64& hi) {
20 uuid[0] = lo; 22 uuid[0] = lo;
21 uuid[1] = hi; 23 uuid[1] = hi;
22 }; 24 };
23 operator bool() const { 25 explicit operator bool() const {
24 return uuid[0] != 0x0 || uuid[1] != 0x0; 26 return uuid[0] != 0x0 || uuid[1] != 0x0;
25 } 27 }
26 28
27 bool operator==(const UUID& rhs) { 29 bool operator==(const UUID& rhs) const {
28 return uuid[0] == rhs.uuid[0] && uuid[1] == rhs.uuid[1]; 30 return std::tie(uuid[0], uuid[1]) == std::tie(rhs.uuid[0], rhs.uuid[1]);
29 } 31 }
30 32
31 bool operator!=(const UUID& rhs) { 33 bool operator!=(const UUID& rhs) const {
32 return uuid[0] != rhs.uuid[0] || uuid[1] != rhs.uuid[1]; 34 return !operator==(rhs);
33 } 35 }
34 36
35 // TODO(ogniK): Properly generate uuids based on RFC-4122 37 // TODO(ogniK): Properly generate uuids based on RFC-4122
@@ -42,7 +44,7 @@ struct UUID {
42 uuid[0] = 0; 44 uuid[0] = 0;
43 uuid[1] = 0; 45 uuid[1] = 0;
44 } 46 }
45 std::string Format() { 47 std::string Format() const {
46 return fmt::format("0x{:016X}{:016X}", uuid[1], uuid[0]); 48 return fmt::format("0x{:016X}{:016X}", uuid[1], uuid[0]);
47 } 49 }
48}; 50};
@@ -78,33 +80,33 @@ class ProfileManager {
78public: 80public:
79 ProfileManager(); // TODO(ogniK): Load from system save 81 ProfileManager(); // TODO(ogniK): Load from system save
80 ResultCode AddUser(ProfileInfo user); 82 ResultCode AddUser(ProfileInfo user);
81 ResultCode CreateNewUser(UUID uuid, std::array<u8, 0x20> username); 83 ResultCode CreateNewUser(UUID uuid, std::array<u8, 0x20>& username);
82 ResultCode CreateNewUser(UUID uuid, std::string username); 84 ResultCode CreateNewUser(UUID uuid, std::string username);
83 size_t GetUserIndex(UUID uuid); 85 size_t GetUserIndex(const UUID& uuid) const;
84 size_t GetUserIndex(ProfileInfo user); 86 size_t GetUserIndex(ProfileInfo user) const;
85 bool GetProfileBase(size_t index, ProfileBase& profile); 87 bool GetProfileBase(size_t index, ProfileBase& profile) const;
86 bool GetProfileBase(UUID uuid, ProfileBase& profile); 88 bool GetProfileBase(UUID uuid, ProfileBase& profile) const;
87 bool GetProfileBase(ProfileInfo user, ProfileBase& profile); 89 bool GetProfileBase(ProfileInfo user, ProfileBase& profile) const;
88 bool GetProfileBaseAndData(size_t index, ProfileBase& profile, std::array<u8, MAX_DATA>& data); 90 bool GetProfileBaseAndData(size_t index, ProfileBase& profile, std::array<u8, MAX_DATA>& data);
89 bool GetProfileBaseAndData(UUID uuid, ProfileBase& profile, std::array<u8, MAX_DATA>& data); 91 bool GetProfileBaseAndData(UUID uuid, ProfileBase& profile, std::array<u8, MAX_DATA>& data);
90 bool GetProfileBaseAndData(ProfileInfo user, ProfileBase& profile, 92 bool GetProfileBaseAndData(ProfileInfo user, ProfileBase& profile,
91 std::array<u8, MAX_DATA>& data); 93 std::array<u8, MAX_DATA>& data);
92 size_t GetUserCount(); 94 size_t GetUserCount() const;
93 bool UserExists(UUID uuid); 95 bool UserExists(UUID uuid) const;
94 void OpenUser(UUID uuid); 96 void OpenUser(UUID uuid);
95 void CloseUser(UUID uuid); 97 void CloseUser(UUID uuid);
96 std::array<UUID, MAX_USERS> GetOpenUsers(); 98 std::array<UUID, MAX_USERS> GetOpenUsers() const;
97 std::array<UUID, MAX_USERS> GetAllUsers(); 99 std::array<UUID, MAX_USERS> GetAllUsers() const;
98 const UUID& GetLastOpennedUser(); 100 UUID GetLastOpenedUser() const;
99 101
100 bool CanSystemRegisterUser(); 102 bool CanSystemRegisterUser() const;
101 103
102private: 104private:
103 std::array<ProfileInfo, MAX_USERS> profiles{}; 105 std::array<ProfileInfo, MAX_USERS> profiles{};
104 size_t user_count = 0; 106 size_t user_count = 0;
105 size_t AddToProfiles(const ProfileInfo& profile); 107 size_t AddToProfiles(const ProfileInfo& profile);
106 bool RemoveProfileAtIdx(size_t index); 108 bool RemoveProfileAtIdx(size_t index);
107 UUID last_openned_user{0, 0}; 109 UUID last_opened_user{0, 0};
108}; 110};
109using ProfileManagerPtr = std::unique_ptr<ProfileManager>; 111using ProfileManagerPtr = std::unique_ptr<ProfileManager>;
110 112