summaryrefslogtreecommitdiffstats
path: root/src/core/hle/service
diff options
context:
space:
mode:
authorliamwhite <liamwhite@users.noreply.github.com>2024-01-19 15:33:25 +0100
committerGitHub <noreply@github.com>2024-01-19 15:33:25 +0100
commita8c552e261149779018556acbec298489763642f (patch)
treef6944af6cd822c4be8b9186fcec7028931e213c3 /src/core/hle/service
parentMerge pull request #12709 from german77/npad-disc (diff)
parentUpdate based on feedback (diff)
downloadyuzu-a8c552e261149779018556acbec298489763642f.tar
yuzu-a8c552e261149779018556acbec298489763642f.tar.gz
yuzu-a8c552e261149779018556acbec298489763642f.tar.bz2
yuzu-a8c552e261149779018556acbec298489763642f.tar.lz
yuzu-a8c552e261149779018556acbec298489763642f.tar.xz
yuzu-a8c552e261149779018556acbec298489763642f.tar.zst
yuzu-a8c552e261149779018556acbec298489763642f.zip
Diffstat (limited to 'src/core/hle/service')
-rw-r--r--src/core/hle/service/acc/profile_manager.cpp17
-rw-r--r--src/core/hle/service/acc/profile_manager.h1
2 files changed, 18 insertions, 0 deletions
diff --git a/src/core/hle/service/acc/profile_manager.cpp b/src/core/hle/service/acc/profile_manager.cpp
index 683f44e27..29a10ad13 100644
--- a/src/core/hle/service/acc/profile_manager.cpp
+++ b/src/core/hle/service/acc/profile_manager.cpp
@@ -11,6 +11,7 @@
#include "common/fs/path_util.h"
#include "common/polyfill_ranges.h"
#include "common/settings.h"
+#include "common/string_util.h"
#include "core/hle/service/acc/profile_manager.h"
namespace Service::Account {
@@ -164,6 +165,22 @@ std::optional<std::size_t> ProfileManager::GetUserIndex(const ProfileInfo& user)
return GetUserIndex(user.user_uuid);
}
+/// Returns the first user profile seen based on username (which does not enforce uniqueness)
+std::optional<std::size_t> ProfileManager::GetUserIndex(const std::string& username) const {
+ const auto iter =
+ std::find_if(profiles.begin(), profiles.end(), [&username](const ProfileInfo& p) {
+ const std::string profile_username = Common::StringFromFixedZeroTerminatedBuffer(
+ reinterpret_cast<const char*>(p.username.data()), p.username.size());
+
+ return username.compare(profile_username) == 0;
+ });
+ if (iter == profiles.end()) {
+ return std::nullopt;
+ }
+
+ return static_cast<std::size_t>(std::distance(profiles.begin(), iter));
+}
+
/// Returns the data structure used by the switch when GetProfileBase is called on acc:*
bool ProfileManager::GetProfileBase(std::optional<std::size_t> index, ProfileBase& profile) const {
if (!index || index >= MAX_USERS) {
diff --git a/src/core/hle/service/acc/profile_manager.h b/src/core/hle/service/acc/profile_manager.h
index e21863e64..f94157300 100644
--- a/src/core/hle/service/acc/profile_manager.h
+++ b/src/core/hle/service/acc/profile_manager.h
@@ -70,6 +70,7 @@ public:
std::optional<Common::UUID> GetUser(std::size_t index) const;
std::optional<std::size_t> GetUserIndex(const Common::UUID& uuid) const;
std::optional<std::size_t> GetUserIndex(const ProfileInfo& user) const;
+ std::optional<std::size_t> GetUserIndex(const std::string& username) const;
bool GetProfileBase(std::optional<std::size_t> index, ProfileBase& profile) const;
bool GetProfileBase(Common::UUID uuid, ProfileBase& profile) const;
bool GetProfileBase(const ProfileInfo& user, ProfileBase& profile) const;