forked from suyu/suyu
First round of account changes
This commit is contained in:
parent
4fa4d80c68
commit
82fa0bcea7
3 changed files with 55 additions and 49 deletions
|
@ -165,7 +165,7 @@ void Module::Interface::GetLastOpenedUser(Kernel::HLERequestContext& ctx) {
|
||||||
LOG_INFO(Service_ACC, "called");
|
LOG_INFO(Service_ACC, "called");
|
||||||
IPC::ResponseBuilder rb{ctx, 6};
|
IPC::ResponseBuilder rb{ctx, 6};
|
||||||
rb.Push(RESULT_SUCCESS);
|
rb.Push(RESULT_SUCCESS);
|
||||||
rb.PushRaw<UUID>(profile_manager->GetLastOpennedUser());
|
rb.PushRaw<UUID>(profile_manager->GetLastOpenedUser());
|
||||||
}
|
}
|
||||||
|
|
||||||
void Module::Interface::GetProfile(Kernel::HLERequestContext& ctx) {
|
void Module::Interface::GetProfile(Kernel::HLERequestContext& ctx) {
|
||||||
|
|
|
@ -1,3 +1,7 @@
|
||||||
|
// Copyright 2018 yuzu emulator team
|
||||||
|
// Licensed under GPLv2 or any later version
|
||||||
|
// Refer to the license.txt file included.
|
||||||
|
|
||||||
#include "core/settings.h"
|
#include "core/settings.h"
|
||||||
#include "profile_manager.h"
|
#include "profile_manager.h"
|
||||||
|
|
||||||
|
@ -15,14 +19,14 @@ ProfileManager::ProfileManager() {
|
||||||
|
|
||||||
size_t ProfileManager::AddToProfiles(const ProfileInfo& user) {
|
size_t ProfileManager::AddToProfiles(const ProfileInfo& user) {
|
||||||
if (user_count >= MAX_USERS) {
|
if (user_count >= MAX_USERS) {
|
||||||
return -1;
|
return std::numeric_limits<size_t>::max();
|
||||||
}
|
}
|
||||||
profiles[user_count] = std::move(user);
|
profiles[user_count] = std::move(user);
|
||||||
return user_count++;
|
return user_count++;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ProfileManager::RemoveProfileAtIdx(size_t index) {
|
bool ProfileManager::RemoveProfileAtIdx(size_t index) {
|
||||||
if (index >= MAX_USERS || index < 0 || index >= user_count)
|
if (index >= MAX_USERS || index >= user_count)
|
||||||
return false;
|
return false;
|
||||||
profiles[index] = ProfileInfo{};
|
profiles[index] = ProfileInfo{};
|
||||||
if (index < user_count - 1)
|
if (index < user_count - 1)
|
||||||
|
@ -33,13 +37,13 @@ bool ProfileManager::RemoveProfileAtIdx(size_t index) {
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultCode ProfileManager::AddUser(ProfileInfo user) {
|
ResultCode ProfileManager::AddUser(ProfileInfo user) {
|
||||||
if (AddToProfiles(user) == -1) {
|
if (AddToProfiles(user) == std::numeric_limits<size_t>::max()) {
|
||||||
return ERROR_TOO_MANY_USERS;
|
return ERROR_TOO_MANY_USERS;
|
||||||
}
|
}
|
||||||
return RESULT_SUCCESS;
|
return RESULT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultCode ProfileManager::CreateNewUser(UUID uuid, std::array<u8, 0x20> username) {
|
ResultCode ProfileManager::CreateNewUser(UUID uuid, std::array<u8, 0x20>& username) {
|
||||||
if (user_count == MAX_USERS)
|
if (user_count == MAX_USERS)
|
||||||
return ERROR_TOO_MANY_USERS;
|
return ERROR_TOO_MANY_USERS;
|
||||||
if (!uuid)
|
if (!uuid)
|
||||||
|
@ -64,67 +68,67 @@ ResultCode ProfileManager::CreateNewUser(UUID uuid, std::string username) {
|
||||||
std::copy_n(username.begin(), username_output.size(), username_output.begin());
|
std::copy_n(username.begin(), username_output.size(), username_output.begin());
|
||||||
else
|
else
|
||||||
std::copy(username.begin(), username.end(), username_output.begin());
|
std::copy(username.begin(), username.end(), username_output.begin());
|
||||||
return CreateNewUser(uuid, std::move(username_output));
|
return CreateNewUser(uuid, username_output);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t ProfileManager::GetUserIndex(UUID uuid) {
|
size_t ProfileManager::GetUserIndex(const UUID& uuid) const {
|
||||||
if (!uuid)
|
if (!uuid)
|
||||||
return -1;
|
return std::numeric_limits<size_t>::max();
|
||||||
for (unsigned i = 0; i < user_count; i++)
|
for (unsigned i = 0; i < user_count; i++)
|
||||||
if (profiles[i].user_uuid == uuid)
|
if (profiles[i].user_uuid == uuid)
|
||||||
return i;
|
return i;
|
||||||
return -1;
|
return std::numeric_limits<size_t>::max();
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t ProfileManager::GetUserIndex(ProfileInfo user) {
|
size_t ProfileManager::GetUserIndex(ProfileInfo user) const {
|
||||||
return GetUserIndex(user.user_uuid);
|
return GetUserIndex(user.user_uuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ProfileManager::GetProfileBase(size_t index, ProfileBase& profile) {
|
bool ProfileManager::GetProfileBase(size_t index, ProfileBase& profile) const {
|
||||||
if (index >= MAX_USERS) {
|
if (index >= MAX_USERS) {
|
||||||
profile.Invalidate();
|
profile.Invalidate();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
auto prof_info = profiles[index];
|
const auto& prof_info = profiles[index];
|
||||||
profile.user_uuid = prof_info.user_uuid;
|
profile.user_uuid = prof_info.user_uuid;
|
||||||
profile.username = prof_info.username;
|
profile.username = prof_info.username;
|
||||||
profile.timestamp = prof_info.creation_time;
|
profile.timestamp = prof_info.creation_time;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ProfileManager::GetProfileBase(UUID uuid, ProfileBase& profile) {
|
bool ProfileManager::GetProfileBase(UUID uuid, ProfileBase& profile) const {
|
||||||
auto idx = GetUserIndex(uuid);
|
auto idx = GetUserIndex(uuid);
|
||||||
return GetProfileBase(idx, profile);
|
return GetProfileBase(idx, profile);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ProfileManager::GetProfileBase(ProfileInfo user, ProfileBase& profile) {
|
bool ProfileManager::GetProfileBase(ProfileInfo user, ProfileBase& profile) const {
|
||||||
return GetProfileBase(user.user_uuid, profile);
|
return GetProfileBase(user.user_uuid, profile);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t ProfileManager::GetUserCount() {
|
size_t ProfileManager::GetUserCount() const {
|
||||||
return user_count;
|
return user_count;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ProfileManager::UserExists(UUID uuid) {
|
bool ProfileManager::UserExists(UUID uuid) const {
|
||||||
return (GetUserIndex(uuid) != -1);
|
return (GetUserIndex(uuid) != std::numeric_limits<size_t>::max());
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProfileManager::OpenUser(UUID uuid) {
|
void ProfileManager::OpenUser(UUID uuid) {
|
||||||
auto idx = GetUserIndex(uuid);
|
auto idx = GetUserIndex(uuid);
|
||||||
if (idx == -1)
|
if (idx == std::numeric_limits<size_t>::max())
|
||||||
return;
|
return;
|
||||||
profiles[idx].is_open = true;
|
profiles[idx].is_open = true;
|
||||||
last_openned_user = uuid;
|
last_opened_user = uuid;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProfileManager::CloseUser(UUID uuid) {
|
void ProfileManager::CloseUser(UUID uuid) {
|
||||||
auto idx = GetUserIndex(uuid);
|
auto idx = GetUserIndex(uuid);
|
||||||
if (idx == -1)
|
if (idx == std::numeric_limits<size_t>::max())
|
||||||
return;
|
return;
|
||||||
profiles[idx].is_open = false;
|
profiles[idx].is_open = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::array<UUID, MAX_USERS> ProfileManager::GetAllUsers() {
|
std::array<UUID, MAX_USERS> ProfileManager::GetAllUsers() const {
|
||||||
std::array<UUID, MAX_USERS> output;
|
std::array<UUID, MAX_USERS> output;
|
||||||
for (unsigned i = 0; i < user_count; i++) {
|
for (unsigned i = 0; i < user_count; i++) {
|
||||||
output[i] = profiles[i].user_uuid;
|
output[i] = profiles[i].user_uuid;
|
||||||
|
@ -132,7 +136,7 @@ std::array<UUID, MAX_USERS> ProfileManager::GetAllUsers() {
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::array<UUID, MAX_USERS> ProfileManager::GetOpenUsers() {
|
std::array<UUID, MAX_USERS> ProfileManager::GetOpenUsers() const {
|
||||||
std::array<UUID, MAX_USERS> output;
|
std::array<UUID, MAX_USERS> output;
|
||||||
unsigned user_idx = 0;
|
unsigned user_idx = 0;
|
||||||
for (unsigned i = 0; i < user_count; i++) {
|
for (unsigned i = 0; i < user_count; i++) {
|
||||||
|
@ -143,8 +147,8 @@ std::array<UUID, MAX_USERS> ProfileManager::GetOpenUsers() {
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
const UUID& ProfileManager::GetLastOpennedUser() {
|
UUID ProfileManager::GetLastOpenedUser() const {
|
||||||
return last_openned_user;
|
return last_opened_user;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ProfileManager::GetProfileBaseAndData(size_t index, ProfileBase& profile,
|
bool ProfileManager::GetProfileBaseAndData(size_t index, ProfileBase& profile,
|
||||||
|
@ -166,7 +170,7 @@ bool ProfileManager::GetProfileBaseAndData(ProfileInfo user, ProfileBase& profil
|
||||||
return GetProfileBaseAndData(user.user_uuid, profile, data);
|
return GetProfileBaseAndData(user.user_uuid, profile, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ProfileManager::CanSystemRegisterUser() {
|
bool ProfileManager::CanSystemRegisterUser() const {
|
||||||
return false; // TODO(ogniK): Games shouldn't have
|
return false; // TODO(ogniK): Games shouldn't have
|
||||||
// access to user registration, when we
|
// access to user registration, when we
|
||||||
// emulate qlaunch. Update this to dynamically change.
|
// emulate qlaunch. Update this to dynamically change.
|
||||||
|
|
|
@ -1,4 +1,9 @@
|
||||||
|
// Copyright 2018 yuzu emulator team
|
||||||
|
// Licensed under GPLv2 or any later version
|
||||||
|
// Refer to the license.txt file included.
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <array>
|
#include <array>
|
||||||
#include "common/common_types.h"
|
#include "common/common_types.h"
|
||||||
#include "common/swap.h"
|
#include "common/swap.h"
|
||||||
|
@ -12,24 +17,21 @@ struct UUID {
|
||||||
// UUIDs which are 0 are considered invalid!
|
// UUIDs which are 0 are considered invalid!
|
||||||
u128 uuid{0, 0};
|
u128 uuid{0, 0};
|
||||||
UUID() = default;
|
UUID() = default;
|
||||||
explicit UUID(const u128& id) {
|
explicit UUID(const u128& id) : uuid{id} {}
|
||||||
uuid[0] = id[0];
|
explicit UUID(const u64 lo, const u64 hi) {
|
||||||
uuid[1] = id[1];
|
|
||||||
};
|
|
||||||
explicit UUID(const u64& lo, const u64& hi) {
|
|
||||||
uuid[0] = lo;
|
uuid[0] = lo;
|
||||||
uuid[1] = hi;
|
uuid[1] = hi;
|
||||||
};
|
};
|
||||||
operator bool() const {
|
explicit operator bool() const {
|
||||||
return uuid[0] != 0x0 || uuid[1] != 0x0;
|
return uuid[0] != 0x0 || uuid[1] != 0x0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator==(const UUID& rhs) {
|
bool operator==(const UUID& rhs) const {
|
||||||
return uuid[0] == rhs.uuid[0] && uuid[1] == rhs.uuid[1];
|
return std::tie(uuid[0], uuid[1]) == std::tie(rhs.uuid[0], rhs.uuid[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator!=(const UUID& rhs) {
|
bool operator!=(const UUID& rhs) const {
|
||||||
return uuid[0] != rhs.uuid[0] || uuid[1] != rhs.uuid[1];
|
return !operator==(rhs);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(ogniK): Properly generate uuids based on RFC-4122
|
// TODO(ogniK): Properly generate uuids based on RFC-4122
|
||||||
|
@ -42,7 +44,7 @@ struct UUID {
|
||||||
uuid[0] = 0;
|
uuid[0] = 0;
|
||||||
uuid[1] = 0;
|
uuid[1] = 0;
|
||||||
}
|
}
|
||||||
std::string Format() {
|
std::string Format() const {
|
||||||
return fmt::format("0x{:016X}{:016X}", uuid[1], uuid[0]);
|
return fmt::format("0x{:016X}{:016X}", uuid[1], uuid[0]);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -78,33 +80,33 @@ class ProfileManager {
|
||||||
public:
|
public:
|
||||||
ProfileManager(); // TODO(ogniK): Load from system save
|
ProfileManager(); // TODO(ogniK): Load from system save
|
||||||
ResultCode AddUser(ProfileInfo user);
|
ResultCode AddUser(ProfileInfo user);
|
||||||
ResultCode CreateNewUser(UUID uuid, std::array<u8, 0x20> username);
|
ResultCode CreateNewUser(UUID uuid, std::array<u8, 0x20>& username);
|
||||||
ResultCode CreateNewUser(UUID uuid, std::string username);
|
ResultCode CreateNewUser(UUID uuid, std::string username);
|
||||||
size_t GetUserIndex(UUID uuid);
|
size_t GetUserIndex(const UUID& uuid) const;
|
||||||
size_t GetUserIndex(ProfileInfo user);
|
size_t GetUserIndex(ProfileInfo user) const;
|
||||||
bool GetProfileBase(size_t index, ProfileBase& profile);
|
bool GetProfileBase(size_t index, ProfileBase& profile) const;
|
||||||
bool GetProfileBase(UUID uuid, ProfileBase& profile);
|
bool GetProfileBase(UUID uuid, ProfileBase& profile) const;
|
||||||
bool GetProfileBase(ProfileInfo user, ProfileBase& profile);
|
bool GetProfileBase(ProfileInfo user, ProfileBase& profile) const;
|
||||||
bool GetProfileBaseAndData(size_t index, ProfileBase& profile, std::array<u8, MAX_DATA>& data);
|
bool GetProfileBaseAndData(size_t index, ProfileBase& profile, std::array<u8, MAX_DATA>& data);
|
||||||
bool GetProfileBaseAndData(UUID uuid, ProfileBase& profile, std::array<u8, MAX_DATA>& data);
|
bool GetProfileBaseAndData(UUID uuid, ProfileBase& profile, std::array<u8, MAX_DATA>& data);
|
||||||
bool GetProfileBaseAndData(ProfileInfo user, ProfileBase& profile,
|
bool GetProfileBaseAndData(ProfileInfo user, ProfileBase& profile,
|
||||||
std::array<u8, MAX_DATA>& data);
|
std::array<u8, MAX_DATA>& data);
|
||||||
size_t GetUserCount();
|
size_t GetUserCount() const;
|
||||||
bool UserExists(UUID uuid);
|
bool UserExists(UUID uuid) const;
|
||||||
void OpenUser(UUID uuid);
|
void OpenUser(UUID uuid);
|
||||||
void CloseUser(UUID uuid);
|
void CloseUser(UUID uuid);
|
||||||
std::array<UUID, MAX_USERS> GetOpenUsers();
|
std::array<UUID, MAX_USERS> GetOpenUsers() const;
|
||||||
std::array<UUID, MAX_USERS> GetAllUsers();
|
std::array<UUID, MAX_USERS> GetAllUsers() const;
|
||||||
const UUID& GetLastOpennedUser();
|
UUID GetLastOpenedUser() const;
|
||||||
|
|
||||||
bool CanSystemRegisterUser();
|
bool CanSystemRegisterUser() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::array<ProfileInfo, MAX_USERS> profiles{};
|
std::array<ProfileInfo, MAX_USERS> profiles{};
|
||||||
size_t user_count = 0;
|
size_t user_count = 0;
|
||||||
size_t AddToProfiles(const ProfileInfo& profile);
|
size_t AddToProfiles(const ProfileInfo& profile);
|
||||||
bool RemoveProfileAtIdx(size_t index);
|
bool RemoveProfileAtIdx(size_t index);
|
||||||
UUID last_openned_user{0, 0};
|
UUID last_opened_user{0, 0};
|
||||||
};
|
};
|
||||||
using ProfileManagerPtr = std::unique_ptr<ProfileManager>;
|
using ProfileManagerPtr = std::unique_ptr<ProfileManager>;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue