mirror of
https://github.com/yuzu-emu/yuzu-mainline.git
synced 2024-12-23 16:55:36 +00:00
profile_manager: Use std::optional instead of boost::optional
Now that we can actually use std::optional on macOS, we don't need to continue using boost::optional here.
This commit is contained in:
parent
77e705a8fa
commit
4a31f99a02
|
@ -3,7 +3,7 @@
|
||||||
// Refer to the license.txt file included.
|
// Refer to the license.txt file included.
|
||||||
|
|
||||||
#include <random>
|
#include <random>
|
||||||
#include <boost/optional.hpp>
|
|
||||||
#include "common/file_util.h"
|
#include "common/file_util.h"
|
||||||
#include "core/hle/service/acc/profile_manager.h"
|
#include "core/hle/service/acc/profile_manager.h"
|
||||||
#include "core/settings.h"
|
#include "core/settings.h"
|
||||||
|
@ -58,11 +58,11 @@ ProfileManager::~ProfileManager() {
|
||||||
|
|
||||||
/// After a users creation it needs to be "registered" to the system. AddToProfiles handles the
|
/// After a users creation it needs to be "registered" to the system. AddToProfiles handles the
|
||||||
/// internal management of the users profiles
|
/// internal management of the users profiles
|
||||||
boost::optional<std::size_t> ProfileManager::AddToProfiles(const ProfileInfo& user) {
|
std::optional<std::size_t> ProfileManager::AddToProfiles(const ProfileInfo& profile) {
|
||||||
if (user_count >= MAX_USERS) {
|
if (user_count >= MAX_USERS) {
|
||||||
return boost::none;
|
return {};
|
||||||
}
|
}
|
||||||
profiles[user_count] = user;
|
profiles[user_count] = profile;
|
||||||
return user_count++;
|
return user_count++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -81,7 +81,7 @@ bool ProfileManager::RemoveProfileAtIndex(std::size_t index) {
|
||||||
|
|
||||||
/// Helper function to register a user to the system
|
/// Helper function to register a user to the system
|
||||||
ResultCode ProfileManager::AddUser(const ProfileInfo& user) {
|
ResultCode ProfileManager::AddUser(const ProfileInfo& user) {
|
||||||
if (AddToProfiles(user) == boost::none) {
|
if (!AddToProfiles(user)) {
|
||||||
return ERROR_TOO_MANY_USERS;
|
return ERROR_TOO_MANY_USERS;
|
||||||
}
|
}
|
||||||
return RESULT_SUCCESS;
|
return RESULT_SUCCESS;
|
||||||
|
@ -126,37 +126,40 @@ ResultCode ProfileManager::CreateNewUser(UUID uuid, const std::string& username)
|
||||||
return CreateNewUser(uuid, username_output);
|
return CreateNewUser(uuid, username_output);
|
||||||
}
|
}
|
||||||
|
|
||||||
boost::optional<UUID> ProfileManager::GetUser(std::size_t index) const {
|
std::optional<UUID> ProfileManager::GetUser(std::size_t index) const {
|
||||||
if (index >= MAX_USERS)
|
if (index >= MAX_USERS) {
|
||||||
return boost::none;
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
return profiles[index].user_uuid;
|
return profiles[index].user_uuid;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns a users profile index based on their user id.
|
/// Returns a users profile index based on their user id.
|
||||||
boost::optional<std::size_t> ProfileManager::GetUserIndex(const UUID& uuid) const {
|
std::optional<std::size_t> ProfileManager::GetUserIndex(const UUID& uuid) const {
|
||||||
if (!uuid) {
|
if (!uuid) {
|
||||||
return boost::none;
|
return {};
|
||||||
}
|
}
|
||||||
auto iter = std::find_if(profiles.begin(), profiles.end(),
|
|
||||||
[&uuid](const ProfileInfo& p) { return p.user_uuid == uuid; });
|
const auto iter = std::find_if(profiles.begin(), profiles.end(),
|
||||||
|
[&uuid](const ProfileInfo& p) { return p.user_uuid == uuid; });
|
||||||
if (iter == profiles.end()) {
|
if (iter == profiles.end()) {
|
||||||
return boost::none;
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
return static_cast<std::size_t>(std::distance(profiles.begin(), iter));
|
return static_cast<std::size_t>(std::distance(profiles.begin(), iter));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns a users profile index based on their profile
|
/// Returns a users profile index based on their profile
|
||||||
boost::optional<std::size_t> ProfileManager::GetUserIndex(const ProfileInfo& user) const {
|
std::optional<std::size_t> ProfileManager::GetUserIndex(const ProfileInfo& user) const {
|
||||||
return GetUserIndex(user.user_uuid);
|
return GetUserIndex(user.user_uuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the data structure used by the switch when GetProfileBase is called on acc:*
|
/// Returns the data structure used by the switch when GetProfileBase is called on acc:*
|
||||||
bool ProfileManager::GetProfileBase(boost::optional<std::size_t> index,
|
bool ProfileManager::GetProfileBase(std::optional<std::size_t> index, ProfileBase& profile) const {
|
||||||
ProfileBase& profile) const {
|
if (!index || index >= MAX_USERS) {
|
||||||
if (index == boost::none || index >= MAX_USERS) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
const auto& prof_info = profiles[index.get()];
|
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;
|
||||||
|
@ -165,7 +168,7 @@ bool ProfileManager::GetProfileBase(boost::optional<std::size_t> index,
|
||||||
|
|
||||||
/// Returns the data structure used by the switch when GetProfileBase is called on acc:*
|
/// Returns the data structure used by the switch when GetProfileBase is called on acc:*
|
||||||
bool ProfileManager::GetProfileBase(UUID uuid, ProfileBase& profile) const {
|
bool ProfileManager::GetProfileBase(UUID uuid, ProfileBase& profile) const {
|
||||||
auto idx = GetUserIndex(uuid);
|
const auto idx = GetUserIndex(uuid);
|
||||||
return GetProfileBase(idx, profile);
|
return GetProfileBase(idx, profile);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -192,7 +195,7 @@ std::size_t ProfileManager::GetOpenUserCount() const {
|
||||||
|
|
||||||
/// Checks if a user id exists in our profile manager
|
/// Checks if a user id exists in our profile manager
|
||||||
bool ProfileManager::UserExists(UUID uuid) const {
|
bool ProfileManager::UserExists(UUID uuid) const {
|
||||||
return (GetUserIndex(uuid) != boost::none);
|
return GetUserIndex(uuid) != std::nullopt;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ProfileManager::UserExistsIndex(std::size_t index) const {
|
bool ProfileManager::UserExistsIndex(std::size_t index) const {
|
||||||
|
@ -203,21 +206,23 @@ bool ProfileManager::UserExistsIndex(std::size_t index) const {
|
||||||
|
|
||||||
/// Opens a specific user
|
/// Opens a specific user
|
||||||
void ProfileManager::OpenUser(UUID uuid) {
|
void ProfileManager::OpenUser(UUID uuid) {
|
||||||
auto idx = GetUserIndex(uuid);
|
const auto idx = GetUserIndex(uuid);
|
||||||
if (idx == boost::none) {
|
if (!idx) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
profiles[idx.get()].is_open = true;
|
|
||||||
|
profiles[*idx].is_open = true;
|
||||||
last_opened_user = uuid;
|
last_opened_user = uuid;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Closes a specific user
|
/// Closes a specific user
|
||||||
void ProfileManager::CloseUser(UUID uuid) {
|
void ProfileManager::CloseUser(UUID uuid) {
|
||||||
auto idx = GetUserIndex(uuid);
|
const auto idx = GetUserIndex(uuid);
|
||||||
if (idx == boost::none) {
|
if (!idx) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
profiles[idx.get()].is_open = false;
|
|
||||||
|
profiles[*idx].is_open = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Gets all valid user ids on the system
|
/// Gets all valid user ids on the system
|
||||||
|
@ -247,10 +252,10 @@ UUID ProfileManager::GetLastOpenedUser() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Return the users profile base and the unknown arbitary data.
|
/// Return the users profile base and the unknown arbitary data.
|
||||||
bool ProfileManager::GetProfileBaseAndData(boost::optional<std::size_t> index, ProfileBase& profile,
|
bool ProfileManager::GetProfileBaseAndData(std::optional<std::size_t> index, ProfileBase& profile,
|
||||||
ProfileData& data) const {
|
ProfileData& data) const {
|
||||||
if (GetProfileBase(index, profile)) {
|
if (GetProfileBase(index, profile)) {
|
||||||
data = profiles[index.get()].data;
|
data = profiles[*index].data;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -259,7 +264,7 @@ bool ProfileManager::GetProfileBaseAndData(boost::optional<std::size_t> index, P
|
||||||
/// Return the users profile base and the unknown arbitary data.
|
/// Return the users profile base and the unknown arbitary data.
|
||||||
bool ProfileManager::GetProfileBaseAndData(UUID uuid, ProfileBase& profile,
|
bool ProfileManager::GetProfileBaseAndData(UUID uuid, ProfileBase& profile,
|
||||||
ProfileData& data) const {
|
ProfileData& data) const {
|
||||||
auto idx = GetUserIndex(uuid);
|
const auto idx = GetUserIndex(uuid);
|
||||||
return GetProfileBaseAndData(idx, profile, data);
|
return GetProfileBaseAndData(idx, profile, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -277,8 +282,8 @@ bool ProfileManager::CanSystemRegisterUser() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ProfileManager::RemoveUser(UUID uuid) {
|
bool ProfileManager::RemoveUser(UUID uuid) {
|
||||||
auto index = GetUserIndex(uuid);
|
const auto index = GetUserIndex(uuid);
|
||||||
if (index == boost::none) {
|
if (!index) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -289,8 +294,8 @@ bool ProfileManager::RemoveUser(UUID uuid) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ProfileManager::SetProfileBase(UUID uuid, const ProfileBase& profile_new) {
|
bool ProfileManager::SetProfileBase(UUID uuid, const ProfileBase& profile_new) {
|
||||||
auto index = GetUserIndex(uuid);
|
const auto index = GetUserIndex(uuid);
|
||||||
if (profile_new.user_uuid == UUID(INVALID_UUID) || index == boost::none) {
|
if (!index || profile_new.user_uuid == UUID(INVALID_UUID)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,8 +5,8 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <array>
|
#include <array>
|
||||||
|
#include <optional>
|
||||||
|
|
||||||
#include "boost/optional.hpp"
|
|
||||||
#include "common/common_types.h"
|
#include "common/common_types.h"
|
||||||
#include "common/swap.h"
|
#include "common/swap.h"
|
||||||
#include "core/hle/result.h"
|
#include "core/hle/result.h"
|
||||||
|
@ -96,13 +96,13 @@ public:
|
||||||
ResultCode AddUser(const ProfileInfo& user);
|
ResultCode AddUser(const ProfileInfo& user);
|
||||||
ResultCode CreateNewUser(UUID uuid, const ProfileUsername& username);
|
ResultCode CreateNewUser(UUID uuid, const ProfileUsername& username);
|
||||||
ResultCode CreateNewUser(UUID uuid, const std::string& username);
|
ResultCode CreateNewUser(UUID uuid, const std::string& username);
|
||||||
boost::optional<UUID> GetUser(std::size_t index) const;
|
std::optional<UUID> GetUser(std::size_t index) const;
|
||||||
boost::optional<std::size_t> GetUserIndex(const UUID& uuid) const;
|
std::optional<std::size_t> GetUserIndex(const UUID& uuid) const;
|
||||||
boost::optional<std::size_t> GetUserIndex(const ProfileInfo& user) const;
|
std::optional<std::size_t> GetUserIndex(const ProfileInfo& user) const;
|
||||||
bool GetProfileBase(boost::optional<std::size_t> index, ProfileBase& profile) const;
|
bool GetProfileBase(std::optional<std::size_t> index, ProfileBase& profile) const;
|
||||||
bool GetProfileBase(UUID uuid, ProfileBase& profile) const;
|
bool GetProfileBase(UUID uuid, ProfileBase& profile) const;
|
||||||
bool GetProfileBase(const ProfileInfo& user, ProfileBase& profile) const;
|
bool GetProfileBase(const ProfileInfo& user, ProfileBase& profile) const;
|
||||||
bool GetProfileBaseAndData(boost::optional<std::size_t> index, ProfileBase& profile,
|
bool GetProfileBaseAndData(std::optional<std::size_t> index, ProfileBase& profile,
|
||||||
ProfileData& data) const;
|
ProfileData& data) const;
|
||||||
bool GetProfileBaseAndData(UUID uuid, ProfileBase& profile, ProfileData& data) const;
|
bool GetProfileBaseAndData(UUID uuid, ProfileBase& profile, ProfileData& data) const;
|
||||||
bool GetProfileBaseAndData(const ProfileInfo& user, ProfileBase& profile,
|
bool GetProfileBaseAndData(const ProfileInfo& user, ProfileBase& profile,
|
||||||
|
@ -120,16 +120,16 @@ public:
|
||||||
bool CanSystemRegisterUser() const;
|
bool CanSystemRegisterUser() const;
|
||||||
|
|
||||||
bool RemoveUser(UUID uuid);
|
bool RemoveUser(UUID uuid);
|
||||||
bool SetProfileBase(UUID uuid, const ProfileBase& profile);
|
bool SetProfileBase(UUID uuid, const ProfileBase& profile_new);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void ParseUserSaveFile();
|
void ParseUserSaveFile();
|
||||||
void WriteUserSaveFile();
|
void WriteUserSaveFile();
|
||||||
|
std::optional<std::size_t> AddToProfiles(const ProfileInfo& profile);
|
||||||
|
bool RemoveProfileAtIndex(std::size_t index);
|
||||||
|
|
||||||
std::array<ProfileInfo, MAX_USERS> profiles{};
|
std::array<ProfileInfo, MAX_USERS> profiles{};
|
||||||
std::size_t user_count = 0;
|
std::size_t user_count = 0;
|
||||||
boost::optional<std::size_t> AddToProfiles(const ProfileInfo& profile);
|
|
||||||
bool RemoveProfileAtIndex(std::size_t index);
|
|
||||||
UUID last_opened_user{INVALID_UUID};
|
UUID last_opened_user{INVALID_UUID};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -743,7 +743,7 @@ void IApplicationFunctions::PopLaunchParameter(Kernel::HLERequestContext& ctx) {
|
||||||
|
|
||||||
Account::ProfileManager profile_manager{};
|
Account::ProfileManager profile_manager{};
|
||||||
const auto uuid = profile_manager.GetUser(Settings::values.current_user);
|
const auto uuid = profile_manager.GetUser(Settings::values.current_user);
|
||||||
ASSERT(uuid != boost::none);
|
ASSERT(uuid != std::nullopt);
|
||||||
params.current_user = uuid->uuid;
|
params.current_user = uuid->uuid;
|
||||||
|
|
||||||
IPC::ResponseBuilder rb{ctx, 2, 0, 1};
|
IPC::ResponseBuilder rb{ctx, 2, 0, 1};
|
||||||
|
|
|
@ -153,7 +153,7 @@ void ConfigureSystem::UpdateCurrentUser() {
|
||||||
ui->pm_add->setEnabled(profile_manager->GetUserCount() < Service::Account::MAX_USERS);
|
ui->pm_add->setEnabled(profile_manager->GetUserCount() < Service::Account::MAX_USERS);
|
||||||
|
|
||||||
const auto& current_user = profile_manager->GetUser(Settings::values.current_user);
|
const auto& current_user = profile_manager->GetUser(Settings::values.current_user);
|
||||||
ASSERT(current_user != boost::none);
|
ASSERT(current_user != std::nullopt);
|
||||||
const auto username = GetAccountUsername(*current_user);
|
const auto username = GetAccountUsername(*current_user);
|
||||||
|
|
||||||
scene->clear();
|
scene->clear();
|
||||||
|
@ -252,7 +252,7 @@ void ConfigureSystem::AddUser() {
|
||||||
void ConfigureSystem::RenameUser() {
|
void ConfigureSystem::RenameUser() {
|
||||||
const auto user = tree_view->currentIndex().row();
|
const auto user = tree_view->currentIndex().row();
|
||||||
const auto uuid = profile_manager->GetUser(user);
|
const auto uuid = profile_manager->GetUser(user);
|
||||||
ASSERT(uuid != boost::none);
|
ASSERT(uuid != std::nullopt);
|
||||||
const auto username = GetAccountUsername(*uuid);
|
const auto username = GetAccountUsername(*uuid);
|
||||||
|
|
||||||
Service::Account::ProfileBase profile;
|
Service::Account::ProfileBase profile;
|
||||||
|
@ -292,7 +292,7 @@ void ConfigureSystem::RenameUser() {
|
||||||
void ConfigureSystem::DeleteUser() {
|
void ConfigureSystem::DeleteUser() {
|
||||||
const auto index = tree_view->currentIndex().row();
|
const auto index = tree_view->currentIndex().row();
|
||||||
const auto uuid = profile_manager->GetUser(index);
|
const auto uuid = profile_manager->GetUser(index);
|
||||||
ASSERT(uuid != boost::none);
|
ASSERT(uuid != std::nullopt);
|
||||||
const auto username = GetAccountUsername(*uuid);
|
const auto username = GetAccountUsername(*uuid);
|
||||||
|
|
||||||
const auto confirm =
|
const auto confirm =
|
||||||
|
@ -320,7 +320,7 @@ void ConfigureSystem::DeleteUser() {
|
||||||
void ConfigureSystem::SetUserImage() {
|
void ConfigureSystem::SetUserImage() {
|
||||||
const auto index = tree_view->currentIndex().row();
|
const auto index = tree_view->currentIndex().row();
|
||||||
const auto uuid = profile_manager->GetUser(index);
|
const auto uuid = profile_manager->GetUser(index);
|
||||||
ASSERT(uuid != boost::none);
|
ASSERT(uuid != std::nullopt);
|
||||||
const auto username = GetAccountUsername(*uuid);
|
const auto username = GetAccountUsername(*uuid);
|
||||||
|
|
||||||
const auto file = QFileDialog::getOpenFileName(this, tr("Select User Image"), QString(),
|
const auto file = QFileDialog::getOpenFileName(this, tr("Select User Image"), QString(),
|
||||||
|
|
|
@ -785,7 +785,7 @@ void GMainWindow::OnGameListOpenFolder(u64 program_id, GameListOpenTarget target
|
||||||
ASSERT(index != -1 && index < 8);
|
ASSERT(index != -1 && index < 8);
|
||||||
|
|
||||||
const auto user_id = manager.GetUser(index);
|
const auto user_id = manager.GetUser(index);
|
||||||
ASSERT(user_id != boost::none);
|
ASSERT(user_id != std::nullopt);
|
||||||
path = nand_dir + FileSys::SaveDataFactory::GetFullPath(FileSys::SaveDataSpaceId::NandUser,
|
path = nand_dir + FileSys::SaveDataFactory::GetFullPath(FileSys::SaveDataSpaceId::NandUser,
|
||||||
FileSys::SaveDataType::SaveData,
|
FileSys::SaveDataType::SaveData,
|
||||||
program_id, user_id->uuid, 0);
|
program_id, user_id->uuid, 0);
|
||||||
|
|
Loading…
Reference in a new issue