From dff0a7c52a73a3989b788b5328a782e995f07c8c Mon Sep 17 00:00:00 2001 From: Andrew Pilley Date: Wed, 17 Jan 2024 09:06:45 -0800 Subject: Allow -u to accept a username string in addition to index, and suppress the User selector even if settings requires it to be shown for one instance only. --- src/core/hle/service/acc/profile_manager.cpp | 17 +++++++++++++++++ src/core/hle/service/acc/profile_manager.h | 1 + 2 files changed, 18 insertions(+) (limited to 'src/core/hle/service/acc') diff --git a/src/core/hle/service/acc/profile_manager.cpp b/src/core/hle/service/acc/profile_manager.cpp index 683f44e27..aff97b999 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 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 ProfileManager::GetUserIndex(const std::string& username) const { + const auto iter = + std::find_if(profiles.begin(), profiles.end(), [&username](const ProfileInfo& p) { + const std::string pusername = Common::StringFromFixedZeroTerminatedBuffer( + reinterpret_cast(p.username.data()), p.username.size()); + + return username.compare(pusername) == 0; + }); + if (iter == profiles.end()) { + return std::nullopt; + } + + return static_cast(std::distance(profiles.begin(), iter)); +} + /// Returns the data structure used by the switch when GetProfileBase is called on acc:* bool ProfileManager::GetProfileBase(std::optional 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 GetUser(std::size_t index) const; std::optional GetUserIndex(const Common::UUID& uuid) const; std::optional GetUserIndex(const ProfileInfo& user) const; + std::optional GetUserIndex(const std::string& username) const; bool GetProfileBase(std::optional index, ProfileBase& profile) const; bool GetProfileBase(Common::UUID uuid, ProfileBase& profile) const; bool GetProfileBase(const ProfileInfo& user, ProfileBase& profile) const; -- cgit v1.2.3