From d8b83aa8f5a267278e06d5a113063663c8eed138 Mon Sep 17 00:00:00 2001 From: Godkratos Date: Mon, 18 May 2020 00:08:41 +1200 Subject: [PATCH 1/6] Add button to show and update current user profile on status bar --- src/yuzu/main.cpp | 58 +++++++++++++++++++++++++++++++++++++++++++++++ src/yuzu/main.h | 1 + 2 files changed, 59 insertions(+) diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp index 0b291c7d0c..92f2d2e70e 100644 --- a/src/yuzu/main.cpp +++ b/src/yuzu/main.cpp @@ -441,6 +441,20 @@ void GMainWindow::WebBrowserOpenPage(std::string_view filename, std::string_view #endif +QString GetAccountUsername() { + Service::Account::ProfileManager manager; + const auto current_user = manager.GetUser(Settings::values.current_user); + ASSERT(current_user); + Service::Account::ProfileBase profile; + if (!manager.GetProfileBase(*current_user, profile)) { + return {}; + } + + const auto text = Common::StringFromFixedZeroTerminatedBuffer( + reinterpret_cast(profile.username.data()), profile.username.size()); + return QString::fromStdString(text); +} + void GMainWindow::InitializeWidgets() { #ifdef YUZU_ENABLE_COMPATIBILITY_REPORTING ui.action_Report_Compatibility->setVisible(true); @@ -493,6 +507,48 @@ void GMainWindow::InitializeWidgets() { statusBar()->addPermanentWidget(label); } + // Setup Profile button + profile_status_button = new QPushButton(); + profile_status_button->setObjectName(QStringLiteral("TogglableStatusBarButton")); + profile_status_button->setCheckable(true); + profile_status_button->setChecked(true); + profile_status_button->setFocusPolicy(Qt::NoFocus); + const auto username = GetAccountUsername(); + profile_status_button->setText(username); + connect(profile_status_button, &QPushButton::clicked, [=] { + profile_status_button->setChecked(true); + + if (emulation_running) { + return; + } + + // User save data + const auto select_profile = [this] { + QtProfileSelectionDialog dialog(this); + dialog.setWindowFlags(Qt::Dialog | Qt::CustomizeWindowHint | Qt::WindowTitleHint | + Qt::WindowSystemMenuHint | Qt::WindowCloseButtonHint); + dialog.setWindowModality(Qt::WindowModal); + + if (dialog.exec() == QDialog::Rejected) { + return -1; + } + + return dialog.GetIndex(); + }; + + const auto index = select_profile(); + if (index == -1) { + return; + } + + Settings::values.current_user = index; + Settings::Apply(); + + const auto username = GetAccountUsername(); + profile_status_button->setText(username); + }); + statusBar()->insertPermanentWidget(0, profile_status_button); + // Setup Dock button dock_status_button = new QPushButton(); dock_status_button->setObjectName(QStringLiteral("TogglableStatusBarButton")); @@ -1902,6 +1958,8 @@ void GMainWindow::OnConfigure() { ui.centralwidget->setMouseTracking(false); } + const auto username = GetAccountUsername(); + profile_status_button->setText(username); dock_status_button->setChecked(Settings::values.use_docked_mode); async_status_button->setChecked(Settings::values.use_asynchronous_gpu_emulation); #ifdef HAS_VULKAN diff --git a/src/yuzu/main.h b/src/yuzu/main.h index 4f4c8ddbee..589081fa2e 100644 --- a/src/yuzu/main.h +++ b/src/yuzu/main.h @@ -233,6 +233,7 @@ private: QLabel* emu_speed_label = nullptr; QLabel* game_fps_label = nullptr; QLabel* emu_frametime_label = nullptr; + QPushButton* profile_status_button = nullptr; QPushButton* async_status_button = nullptr; QPushButton* renderer_status_button = nullptr; QPushButton* dock_status_button = nullptr; From c2522f3e433021b4cea27bdbba61965e89a19310 Mon Sep 17 00:00:00 2001 From: Godkratos Date: Mon, 18 May 2020 00:55:32 +1200 Subject: [PATCH 2/6] Move new method into anonymous namespace --- src/yuzu/main.cpp | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp index 92f2d2e70e..c10f77d2fe 100644 --- a/src/yuzu/main.cpp +++ b/src/yuzu/main.cpp @@ -135,6 +135,24 @@ __declspec(dllexport) int AmdPowerXpressRequestHighPerformance = 1; } #endif +namespace { + + QString GetAccountUsername() { + Service::Account::ProfileManager manager; + const auto current_user = manager.GetUser(Settings::values.current_user); + ASSERT(current_user); + Service::Account::ProfileBase profile; + if (!manager.GetProfileBase(*current_user, profile)) { + return {}; + } + + const auto text = Common::StringFromFixedZeroTerminatedBuffer( + reinterpret_cast(profile.username.data()), profile.username.size()); + return QString::fromStdString(text); + } + +} + constexpr int default_mouse_timeout = 2500; constexpr u64 DLC_BASE_TITLE_ID_MASK = 0xFFFFFFFFFFFFE000; @@ -441,20 +459,6 @@ void GMainWindow::WebBrowserOpenPage(std::string_view filename, std::string_view #endif -QString GetAccountUsername() { - Service::Account::ProfileManager manager; - const auto current_user = manager.GetUser(Settings::values.current_user); - ASSERT(current_user); - Service::Account::ProfileBase profile; - if (!manager.GetProfileBase(*current_user, profile)) { - return {}; - } - - const auto text = Common::StringFromFixedZeroTerminatedBuffer( - reinterpret_cast(profile.username.data()), profile.username.size()); - return QString::fromStdString(text); -} - void GMainWindow::InitializeWidgets() { #ifdef YUZU_ENABLE_COMPATIBILITY_REPORTING ui.action_Report_Compatibility->setVisible(true); From de1ef273b3e8e5b0de2cc080f00e45424af0e120 Mon Sep 17 00:00:00 2001 From: Godkratos Date: Mon, 18 May 2020 01:01:40 +1200 Subject: [PATCH 3/6] Clang formatting --- src/yuzu/main.cpp | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp index c10f77d2fe..355a6e5e05 100644 --- a/src/yuzu/main.cpp +++ b/src/yuzu/main.cpp @@ -137,22 +137,22 @@ __declspec(dllexport) int AmdPowerXpressRequestHighPerformance = 1; namespace { - QString GetAccountUsername() { - Service::Account::ProfileManager manager; - const auto current_user = manager.GetUser(Settings::values.current_user); - ASSERT(current_user); - Service::Account::ProfileBase profile; - if (!manager.GetProfileBase(*current_user, profile)) { - return {}; - } - - const auto text = Common::StringFromFixedZeroTerminatedBuffer( - reinterpret_cast(profile.username.data()), profile.username.size()); - return QString::fromStdString(text); +QString GetAccountUsername() { + Service::Account::ProfileManager manager; + const auto current_user = manager.GetUser(Settings::values.current_user); + ASSERT(current_user); + Service::Account::ProfileBase profile; + if (!manager.GetProfileBase(*current_user, profile)) { + return {}; } + const auto text = Common::StringFromFixedZeroTerminatedBuffer( + reinterpret_cast(profile.username.data()), profile.username.size()); + return QString::fromStdString(text); } +} // Anonymous namespace + constexpr int default_mouse_timeout = 2500; constexpr u64 DLC_BASE_TITLE_ID_MASK = 0xFFFFFFFFFFFFE000; From d011f89f1555a405ff9471fb3c7ec8783488b57c Mon Sep 17 00:00:00 2001 From: Godkratos Date: Mon, 18 May 2020 10:37:25 +1200 Subject: [PATCH 4/6] Validate username before returning --- src/yuzu/main.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp index 355a6e5e05..9a236eb9b8 100644 --- a/src/yuzu/main.cpp +++ b/src/yuzu/main.cpp @@ -148,7 +148,8 @@ QString GetAccountUsername() { const auto text = Common::StringFromFixedZeroTerminatedBuffer( reinterpret_cast(profile.username.data()), profile.username.size()); - return QString::fromStdString(text); + + return QString::fromStdString(text.empty() ? "No User" : text); } } // Anonymous namespace From 7341257fc4c8a8359975edf0dbb75e5e70719673 Mon Sep 17 00:00:00 2001 From: Godkratos Date: Mon, 18 May 2020 11:10:12 +1200 Subject: [PATCH 5/6] Validate uuid and fix returns --- src/yuzu/main.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp index 9a236eb9b8..62c1f91612 100644 --- a/src/yuzu/main.cpp +++ b/src/yuzu/main.cpp @@ -138,18 +138,21 @@ __declspec(dllexport) int AmdPowerXpressRequestHighPerformance = 1; namespace { QString GetAccountUsername() { + const QString nouser = QString::fromStdString("No User"); Service::Account::ProfileManager manager; const auto current_user = manager.GetUser(Settings::values.current_user); - ASSERT(current_user); + if (!current_user.has_value()) { + return nouser; + } Service::Account::ProfileBase profile; if (!manager.GetProfileBase(*current_user, profile)) { - return {}; + return nouser; } const auto text = Common::StringFromFixedZeroTerminatedBuffer( reinterpret_cast(profile.username.data()), profile.username.size()); - return QString::fromStdString(text.empty() ? "No User" : text); + return text.empty() ? nouser : QString::fromStdString(text); } } // Anonymous namespace From 60b184377ee15e487e630a3cadc18f3c1b4312b3 Mon Sep 17 00:00:00 2001 From: GodKratos Date: Sun, 24 May 2020 01:13:49 +1200 Subject: [PATCH 6/6] add UUID validation check Co-authored-by: VolcaEM <63682805+VolcaEM@users.noreply.github.com> --- src/yuzu/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp index 62c1f91612..c370bbd7a9 100644 --- a/src/yuzu/main.cpp +++ b/src/yuzu/main.cpp @@ -141,7 +141,7 @@ QString GetAccountUsername() { const QString nouser = QString::fromStdString("No User"); Service::Account::ProfileManager manager; const auto current_user = manager.GetUser(Settings::values.current_user); - if (!current_user.has_value()) { + if (!current_user.has_value() || (current_user == Common::UUID{})) { return nouser; } Service::Account::ProfileBase profile;