yuzu-emu
/
yuzu-mainline
Archived
1
0
Fork 0

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.

This commit is contained in:
Andrew Pilley 2024-01-17 09:06:45 -08:00
parent 915efa4236
commit dff0a7c52a
4 changed files with 40 additions and 4 deletions

View File

@ -11,6 +11,7 @@
#include "common/fs/path_util.h" #include "common/fs/path_util.h"
#include "common/polyfill_ranges.h" #include "common/polyfill_ranges.h"
#include "common/settings.h" #include "common/settings.h"
#include "common/string_util.h"
#include "core/hle/service/acc/profile_manager.h" #include "core/hle/service/acc/profile_manager.h"
namespace Service::Account { namespace Service::Account {
@ -164,6 +165,22 @@ std::optional<std::size_t> ProfileManager::GetUserIndex(const ProfileInfo& user)
return GetUserIndex(user.user_uuid); 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 pusername = Common::StringFromFixedZeroTerminatedBuffer(
reinterpret_cast<const char*>(p.username.data()), p.username.size());
return username.compare(pusername) == 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:* /// 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 { bool ProfileManager::GetProfileBase(std::optional<std::size_t> index, ProfileBase& profile) const {
if (!index || index >= MAX_USERS) { if (!index || index >= MAX_USERS) {

View File

@ -70,6 +70,7 @@ public:
std::optional<Common::UUID> GetUser(std::size_t index) const; 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 Common::UUID& uuid) const;
std::optional<std::size_t> GetUserIndex(const ProfileInfo& user) 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(std::optional<std::size_t> index, ProfileBase& profile) const;
bool GetProfileBase(Common::UUID uuid, ProfileBase& profile) const; bool GetProfileBase(Common::UUID uuid, ProfileBase& profile) const;
bool GetProfileBase(const ProfileInfo& user, ProfileBase& profile) const; bool GetProfileBase(const ProfileInfo& user, ProfileBase& profile) const;

View File

@ -518,12 +518,21 @@ GMainWindow::GMainWindow(std::unique_ptr<QtConfig> config_, bool has_broken_vulk
continue; continue;
} }
int user_arg_idx = ++i;
bool argument_ok; bool argument_ok;
const std::size_t selected_user = args[++i].toUInt(&argument_ok); std::size_t selected_user = args[user_arg_idx].toUInt(&argument_ok);
if (!argument_ok) { if (!argument_ok) {
LOG_ERROR(Frontend, "Invalid user argument"); // try to look it up by username, only finds the first username that matches.
continue; const std::string user_arg_str = args[user_arg_idx].toStdString();
const auto user_idx = system->GetProfileManager().GetUserIndex(user_arg_str);
if (user_idx == std::nullopt) {
LOG_ERROR(Frontend, "Invalid user argument");
continue;
}
selected_user = user_idx.value();
} }
if (!system->GetProfileManager().UserExistsIndex(selected_user)) { if (!system->GetProfileManager().UserExistsIndex(selected_user)) {
@ -532,6 +541,8 @@ GMainWindow::GMainWindow(std::unique_ptr<QtConfig> config_, bool has_broken_vulk
} }
Settings::values.current_user = static_cast<s32>(selected_user); Settings::values.current_user = static_cast<s32>(selected_user);
user_flag_cmd_line = true;
continue; continue;
} }
@ -1942,7 +1953,7 @@ void GMainWindow::BootGame(const QString& filename, u64 program_id, std::size_t
Settings::LogSettings(); Settings::LogSettings();
if (UISettings::values.select_user_on_boot) { if (UISettings::values.select_user_on_boot && !user_flag_cmd_line) {
const Core::Frontend::ProfileSelectParameters parameters{ const Core::Frontend::ProfileSelectParameters parameters{
.mode = Service::AM::Applets::UiMode::UserSelector, .mode = Service::AM::Applets::UiMode::UserSelector,
.invalid_uid_list = {}, .invalid_uid_list = {},
@ -1954,6 +1965,11 @@ void GMainWindow::BootGame(const QString& filename, u64 program_id, std::size_t
} }
} }
// If the user specifies -u (successfully) on the cmd line, don't prompt for a user on first
// game startup only. If the user stops emulation and starts a new one, go back to the expected
// behavior of asking.
user_flag_cmd_line = false;
if (!LoadROM(filename, program_id, program_index, launch_type)) { if (!LoadROM(filename, program_id, program_index, launch_type)) {
return; return;
} }

View File

@ -523,6 +523,8 @@ private:
std::unique_ptr<EmuThread> emu_thread; std::unique_ptr<EmuThread> emu_thread;
// The path to the game currently running // The path to the game currently running
QString current_game_path; QString current_game_path;
// Whether a user was set on the command line (skips UserSelector if it's forced to show up)
bool user_flag_cmd_line = false;
bool auto_paused = false; bool auto_paused = false;
bool auto_muted = false; bool auto_muted = false;