diff options
| author | 2024-01-17 09:06:45 -0800 | |
|---|---|---|
| committer | 2024-01-17 10:31:00 -0800 | |
| commit | dff0a7c52a73a3989b788b5328a782e995f07c8c (patch) | |
| tree | 810018315b3a2399de10e952095adaabb28cc7ad | |
| parent | Merge pull request #12689 from liamwhite/remove-format (diff) | |
| download | yuzu-dff0a7c52a73a3989b788b5328a782e995f07c8c.tar.gz yuzu-dff0a7c52a73a3989b788b5328a782e995f07c8c.tar.xz yuzu-dff0a7c52a73a3989b788b5328a782e995f07c8c.zip | |
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.
| -rw-r--r-- | src/core/hle/service/acc/profile_manager.cpp | 17 | ||||
| -rw-r--r-- | src/core/hle/service/acc/profile_manager.h | 1 | ||||
| -rw-r--r-- | src/yuzu/main.cpp | 24 | ||||
| -rw-r--r-- | src/yuzu/main.h | 2 |
4 files changed, 40 insertions, 4 deletions
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 @@ | |||
| 11 | #include "common/fs/path_util.h" | 11 | #include "common/fs/path_util.h" |
| 12 | #include "common/polyfill_ranges.h" | 12 | #include "common/polyfill_ranges.h" |
| 13 | #include "common/settings.h" | 13 | #include "common/settings.h" |
| 14 | #include "common/string_util.h" | ||
| 14 | #include "core/hle/service/acc/profile_manager.h" | 15 | #include "core/hle/service/acc/profile_manager.h" |
| 15 | 16 | ||
| 16 | namespace Service::Account { | 17 | namespace Service::Account { |
| @@ -164,6 +165,22 @@ std::optional<std::size_t> ProfileManager::GetUserIndex(const ProfileInfo& user) | |||
| 164 | return GetUserIndex(user.user_uuid); | 165 | return GetUserIndex(user.user_uuid); |
| 165 | } | 166 | } |
| 166 | 167 | ||
| 168 | /// Returns the first user profile seen based on username (which does not enforce uniqueness) | ||
| 169 | std::optional<std::size_t> ProfileManager::GetUserIndex(const std::string& username) const { | ||
| 170 | const auto iter = | ||
| 171 | std::find_if(profiles.begin(), profiles.end(), [&username](const ProfileInfo& p) { | ||
| 172 | const std::string pusername = Common::StringFromFixedZeroTerminatedBuffer( | ||
| 173 | reinterpret_cast<const char*>(p.username.data()), p.username.size()); | ||
| 174 | |||
| 175 | return username.compare(pusername) == 0; | ||
| 176 | }); | ||
| 177 | if (iter == profiles.end()) { | ||
| 178 | return std::nullopt; | ||
| 179 | } | ||
| 180 | |||
| 181 | return static_cast<std::size_t>(std::distance(profiles.begin(), iter)); | ||
| 182 | } | ||
| 183 | |||
| 167 | /// Returns the data structure used by the switch when GetProfileBase is called on acc:* | 184 | /// Returns the data structure used by the switch when GetProfileBase is called on acc:* |
| 168 | bool ProfileManager::GetProfileBase(std::optional<std::size_t> index, ProfileBase& profile) const { | 185 | bool ProfileManager::GetProfileBase(std::optional<std::size_t> index, ProfileBase& profile) const { |
| 169 | if (!index || index >= MAX_USERS) { | 186 | 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: | |||
| 70 | std::optional<Common::UUID> GetUser(std::size_t index) const; | 70 | std::optional<Common::UUID> GetUser(std::size_t index) const; |
| 71 | std::optional<std::size_t> GetUserIndex(const Common::UUID& uuid) const; | 71 | std::optional<std::size_t> GetUserIndex(const Common::UUID& uuid) const; |
| 72 | std::optional<std::size_t> GetUserIndex(const ProfileInfo& user) const; | 72 | std::optional<std::size_t> GetUserIndex(const ProfileInfo& user) const; |
| 73 | std::optional<std::size_t> GetUserIndex(const std::string& username) const; | ||
| 73 | bool GetProfileBase(std::optional<std::size_t> index, ProfileBase& profile) const; | 74 | bool GetProfileBase(std::optional<std::size_t> index, ProfileBase& profile) const; |
| 74 | bool GetProfileBase(Common::UUID uuid, ProfileBase& profile) const; | 75 | bool GetProfileBase(Common::UUID uuid, ProfileBase& profile) const; |
| 75 | bool GetProfileBase(const ProfileInfo& user, ProfileBase& profile) const; | 76 | bool GetProfileBase(const ProfileInfo& user, ProfileBase& profile) const; |
diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp index 33756febf..3c562e3b2 100644 --- a/src/yuzu/main.cpp +++ b/src/yuzu/main.cpp | |||
| @@ -518,12 +518,21 @@ GMainWindow::GMainWindow(std::unique_ptr<QtConfig> config_, bool has_broken_vulk | |||
| 518 | continue; | 518 | continue; |
| 519 | } | 519 | } |
| 520 | 520 | ||
| 521 | int user_arg_idx = ++i; | ||
| 521 | bool argument_ok; | 522 | bool argument_ok; |
| 522 | const std::size_t selected_user = args[++i].toUInt(&argument_ok); | 523 | std::size_t selected_user = args[user_arg_idx].toUInt(&argument_ok); |
| 523 | 524 | ||
| 524 | if (!argument_ok) { | 525 | if (!argument_ok) { |
| 525 | LOG_ERROR(Frontend, "Invalid user argument"); | 526 | // try to look it up by username, only finds the first username that matches. |
| 526 | continue; | 527 | const std::string user_arg_str = args[user_arg_idx].toStdString(); |
| 528 | const auto user_idx = system->GetProfileManager().GetUserIndex(user_arg_str); | ||
| 529 | |||
| 530 | if (user_idx == std::nullopt) { | ||
| 531 | LOG_ERROR(Frontend, "Invalid user argument"); | ||
| 532 | continue; | ||
| 533 | } | ||
| 534 | |||
| 535 | selected_user = user_idx.value(); | ||
| 527 | } | 536 | } |
| 528 | 537 | ||
| 529 | if (!system->GetProfileManager().UserExistsIndex(selected_user)) { | 538 | if (!system->GetProfileManager().UserExistsIndex(selected_user)) { |
| @@ -532,6 +541,8 @@ GMainWindow::GMainWindow(std::unique_ptr<QtConfig> config_, bool has_broken_vulk | |||
| 532 | } | 541 | } |
| 533 | 542 | ||
| 534 | Settings::values.current_user = static_cast<s32>(selected_user); | 543 | Settings::values.current_user = static_cast<s32>(selected_user); |
| 544 | |||
| 545 | user_flag_cmd_line = true; | ||
| 535 | continue; | 546 | continue; |
| 536 | } | 547 | } |
| 537 | 548 | ||
| @@ -1942,7 +1953,7 @@ void GMainWindow::BootGame(const QString& filename, u64 program_id, std::size_t | |||
| 1942 | 1953 | ||
| 1943 | Settings::LogSettings(); | 1954 | Settings::LogSettings(); |
| 1944 | 1955 | ||
| 1945 | if (UISettings::values.select_user_on_boot) { | 1956 | if (UISettings::values.select_user_on_boot && !user_flag_cmd_line) { |
| 1946 | const Core::Frontend::ProfileSelectParameters parameters{ | 1957 | const Core::Frontend::ProfileSelectParameters parameters{ |
| 1947 | .mode = Service::AM::Applets::UiMode::UserSelector, | 1958 | .mode = Service::AM::Applets::UiMode::UserSelector, |
| 1948 | .invalid_uid_list = {}, | 1959 | .invalid_uid_list = {}, |
| @@ -1954,6 +1965,11 @@ void GMainWindow::BootGame(const QString& filename, u64 program_id, std::size_t | |||
| 1954 | } | 1965 | } |
| 1955 | } | 1966 | } |
| 1956 | 1967 | ||
| 1968 | // If the user specifies -u (successfully) on the cmd line, don't prompt for a user on first | ||
| 1969 | // game startup only. If the user stops emulation and starts a new one, go back to the expected | ||
| 1970 | // behavior of asking. | ||
| 1971 | user_flag_cmd_line = false; | ||
| 1972 | |||
| 1957 | if (!LoadROM(filename, program_id, program_index, launch_type)) { | 1973 | if (!LoadROM(filename, program_id, program_index, launch_type)) { |
| 1958 | return; | 1974 | return; |
| 1959 | } | 1975 | } |
diff --git a/src/yuzu/main.h b/src/yuzu/main.h index 366e806d5..f3276da64 100644 --- a/src/yuzu/main.h +++ b/src/yuzu/main.h | |||
| @@ -523,6 +523,8 @@ private: | |||
| 523 | std::unique_ptr<EmuThread> emu_thread; | 523 | std::unique_ptr<EmuThread> emu_thread; |
| 524 | // The path to the game currently running | 524 | // The path to the game currently running |
| 525 | QString current_game_path; | 525 | QString current_game_path; |
| 526 | // Whether a user was set on the command line (skips UserSelector if it's forced to show up) | ||
| 527 | bool user_flag_cmd_line = false; | ||
| 526 | 528 | ||
| 527 | bool auto_paused = false; | 529 | bool auto_paused = false; |
| 528 | bool auto_muted = false; | 530 | bool auto_muted = false; |