From 3c63cecb968f0eab285afc6428c51c9ab3fb67d4 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Thu, 25 Oct 2018 16:43:42 -0400 Subject: [PATCH 1/7] configure_system: Make public slots private These are only used within this class, so we can make them private to keep their use contained. This also gets rid of the pre-Qt5 'slot' identifier, since Qt 5's connection syntax doesn't require a function to be declared a slot anymore. --- src/yuzu/configuration/configure_system.h | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/yuzu/configuration/configure_system.h b/src/yuzu/configuration/configure_system.h index b73e0719cb..a30ab84994 100644 --- a/src/yuzu/configuration/configure_system.h +++ b/src/yuzu/configuration/configure_system.h @@ -34,23 +34,21 @@ public: void applyConfiguration(); void setConfiguration(); - void PopulateUserList(); - void UpdateCurrentUser(); +private: + void ReadSystemSettings(); + std::string GetAccountUsername(Service::Account::UUID uuid) const; -public slots: void updateBirthdayComboBox(int birthmonth_index); void refreshConsoleID(); + void PopulateUserList(); + void UpdateCurrentUser(); void SelectUser(const QModelIndex& index); void AddUser(); void RenameUser(); void DeleteUser(); void SetUserImage(); -private: - void ReadSystemSettings(); - std::string GetAccountUsername(Service::Account::UUID uuid) const; - QVBoxLayout* layout; QTreeView* tree_view; QStandardItemModel* item_model; From 2347e1b8c530fb1cf88e61c40b2369746d4636a8 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Thu, 25 Oct 2018 16:45:13 -0400 Subject: [PATCH 2/7] configure_system: Add missing override specifier on the destructor --- src/yuzu/configuration/configure_system.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/yuzu/configuration/configure_system.h b/src/yuzu/configuration/configure_system.h index a30ab84994..ea724e3170 100644 --- a/src/yuzu/configuration/configure_system.h +++ b/src/yuzu/configuration/configure_system.h @@ -29,7 +29,7 @@ class ConfigureSystem : public QWidget { public: explicit ConfigureSystem(QWidget* parent = nullptr); - ~ConfigureSystem(); + ~ConfigureSystem() override; void applyConfiguration(); void setConfiguration(); From a6addb5332eca0cecd3baca0c9660805396d235b Mon Sep 17 00:00:00 2001 From: Lioncash Date: Thu, 25 Oct 2018 16:47:09 -0400 Subject: [PATCH 3/7] configure_system: Amend function casing --- src/yuzu/configuration/configure_system.cpp | 8 ++++---- src/yuzu/configuration/configure_system.h | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/yuzu/configuration/configure_system.cpp b/src/yuzu/configuration/configure_system.cpp index 0bc307e99d..d4ed7d5d3c 100644 --- a/src/yuzu/configuration/configure_system.cpp +++ b/src/yuzu/configuration/configure_system.cpp @@ -58,9 +58,9 @@ ConfigureSystem::ConfigureSystem(QWidget* parent) ui->setupUi(this); connect(ui->combo_birthmonth, static_cast(&QComboBox::currentIndexChanged), this, - &ConfigureSystem::updateBirthdayComboBox); + &ConfigureSystem::UpdateBirthdayComboBox); connect(ui->button_regenerate_console_id, &QPushButton::clicked, this, - &ConfigureSystem::refreshConsoleID); + &ConfigureSystem::RefreshConsoleID); layout = new QVBoxLayout; tree_view = new QTreeView; @@ -180,7 +180,7 @@ void ConfigureSystem::applyConfiguration() { Settings::Apply(); } -void ConfigureSystem::updateBirthdayComboBox(int birthmonth_index) { +void ConfigureSystem::UpdateBirthdayComboBox(int birthmonth_index) { if (birthmonth_index < 0 || birthmonth_index >= 12) return; @@ -205,7 +205,7 @@ void ConfigureSystem::updateBirthdayComboBox(int birthmonth_index) { ui->combo_birthday->setCurrentIndex(birthday_index); } -void ConfigureSystem::refreshConsoleID() { +void ConfigureSystem::RefreshConsoleID() { QMessageBox::StandardButton reply; QString warning_text = tr("This will replace your current virtual Switch with a new one. " "Your current virtual Switch will not be recoverable. " diff --git a/src/yuzu/configuration/configure_system.h b/src/yuzu/configuration/configure_system.h index ea724e3170..86269ccd5a 100644 --- a/src/yuzu/configuration/configure_system.h +++ b/src/yuzu/configuration/configure_system.h @@ -38,8 +38,8 @@ private: void ReadSystemSettings(); std::string GetAccountUsername(Service::Account::UUID uuid) const; - void updateBirthdayComboBox(int birthmonth_index); - void refreshConsoleID(); + void UpdateBirthdayComboBox(int birthmonth_index); + void RefreshConsoleID(); void PopulateUserList(); void UpdateCurrentUser(); From 8806e69f596f3e046f802cda068af86ec0c3f553 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Thu, 25 Oct 2018 16:50:05 -0400 Subject: [PATCH 4/7] configure_system: Simplify UUID generation call in AddUser() This is a static function so we can just perform an assignment directly. --- src/yuzu/configuration/configure_system.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/yuzu/configuration/configure_system.cpp b/src/yuzu/configuration/configure_system.cpp index d4ed7d5d3c..3aa9ca07ed 100644 --- a/src/yuzu/configuration/configure_system.cpp +++ b/src/yuzu/configuration/configure_system.cpp @@ -232,8 +232,7 @@ void ConfigureSystem::SelectUser(const QModelIndex& index) { } void ConfigureSystem::AddUser() { - Service::Account::UUID uuid; - uuid.Generate(); + const auto uuid = Service::Account::UUID::Generate(); bool ok = false; const auto username = From bf7da804c5435a589909466d45e5ddf9a772cd45 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Thu, 25 Oct 2018 16:52:21 -0400 Subject: [PATCH 5/7] configure_system: Default initialize member variables These should be initialized to deterministic values so it's easier to catch improper behavior, as it'll always be reproducable, instead of performing uninitialized reads. --- src/yuzu/configuration/configure_system.h | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/yuzu/configuration/configure_system.h b/src/yuzu/configuration/configure_system.h index 86269ccd5a..0d15d9ac4f 100644 --- a/src/yuzu/configuration/configure_system.h +++ b/src/yuzu/configuration/configure_system.h @@ -57,11 +57,12 @@ private: std::vector> list_items; std::unique_ptr ui; - bool enabled; + bool enabled = false; - int birthmonth, birthday; - int language_index; - int sound_index; + int birthmonth = 0; + int birthday = 0; + int language_index = 0; + int sound_index = 0; std::unique_ptr profile_manager; }; From 5172354e29fed02cbceee8d55564d32ca361d58f Mon Sep 17 00:00:00 2001 From: Lioncash Date: Thu, 25 Oct 2018 16:58:37 -0400 Subject: [PATCH 6/7] configure_system: Make GetAccountUsername() an internal function We can just make the function accept an arbitrary ProfileManager reference and operate on that instead of tying the function to the class itself. This allows us to keep the function internal to the cpp file and removes the need to forward declare the UUID struct. --- src/yuzu/configuration/configure_system.cpp | 43 ++++++++++++--------- src/yuzu/configuration/configure_system.h | 10 ++--- 2 files changed, 28 insertions(+), 25 deletions(-) diff --git a/src/yuzu/configuration/configure_system.cpp b/src/yuzu/configuration/configure_system.cpp index 3aa9ca07ed..a9bd5465d9 100644 --- a/src/yuzu/configuration/configure_system.cpp +++ b/src/yuzu/configuration/configure_system.cpp @@ -21,12 +21,8 @@ #include "yuzu/configuration/configure_system.h" #include "yuzu/main.h" -static std::string GetImagePath(Service::Account::UUID uuid) { - return FileUtil::GetUserPath(FileUtil::UserPath::NANDDir) + - "/system/save/8000000000000010/su/avators/" + uuid.FormatSwitch() + ".jpg"; -} - -static const std::array days_in_month = {{ +namespace { +constexpr std::array days_in_month = {{ 31, 29, 31, @@ -42,7 +38,7 @@ static const std::array days_in_month = {{ }}; // Same backup JPEG used by acc IProfile::GetImage if no jpeg found -static constexpr std::array backup_jpeg{ +constexpr std::array backup_jpeg{ 0xff, 0xd8, 0xff, 0xdb, 0x00, 0x43, 0x00, 0x03, 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x02, 0x02, 0x02, 0x03, 0x03, 0x03, 0x03, 0x04, 0x06, 0x04, 0x04, 0x04, 0x04, 0x04, 0x08, 0x06, 0x06, 0x05, 0x06, 0x09, 0x08, 0x0a, 0x0a, 0x09, 0x08, 0x09, 0x09, 0x0a, 0x0c, 0x0f, 0x0c, 0x0a, 0x0b, 0x0e, @@ -52,6 +48,23 @@ static constexpr std::array backup_jpeg{ 0x01, 0x01, 0x00, 0x00, 0x3f, 0x00, 0xd2, 0xcf, 0x20, 0xff, 0xd9, }; +std::string GetImagePath(Service::Account::UUID uuid) { + return FileUtil::GetUserPath(FileUtil::UserPath::NANDDir) + + "/system/save/8000000000000010/su/avators/" + uuid.FormatSwitch() + ".jpg"; +} + +std::string GetAccountUsername(const Service::Account::ProfileManager& manager, + Service::Account::UUID uuid) { + Service::Account::ProfileBase profile; + if (!manager.GetProfileBase(uuid, profile)) { + return ""; + } + + return Common::StringFromFixedZeroTerminatedBuffer( + reinterpret_cast(profile.username.data()), profile.username.size()); +} +} // Anonymous namespace + ConfigureSystem::ConfigureSystem(QWidget* parent) : QWidget(parent), ui(new Ui::ConfigureSystem), profile_manager(std::make_unique()) { @@ -154,7 +167,7 @@ void ConfigureSystem::UpdateCurrentUser() { const auto& current_user = profile_manager->GetUser(Settings::values.current_user); ASSERT(current_user != std::nullopt); - const auto username = GetAccountUsername(*current_user); + const auto username = GetAccountUsername(*profile_manager, *current_user); scene->clear(); scene->addPixmap( @@ -164,14 +177,6 @@ void ConfigureSystem::UpdateCurrentUser() { void ConfigureSystem::ReadSystemSettings() {} -std::string ConfigureSystem::GetAccountUsername(Service::Account::UUID uuid) const { - Service::Account::ProfileBase profile; - if (!profile_manager->GetProfileBase(uuid, profile)) - return ""; - return Common::StringFromFixedZeroTerminatedBuffer( - reinterpret_cast(profile.username.data()), profile.username.size()); -} - void ConfigureSystem::applyConfiguration() { if (!enabled) return; @@ -252,7 +257,7 @@ void ConfigureSystem::RenameUser() { const auto user = tree_view->currentIndex().row(); const auto uuid = profile_manager->GetUser(user); ASSERT(uuid != std::nullopt); - const auto username = GetAccountUsername(*uuid); + const auto username = GetAccountUsername(*profile_manager, *uuid); Service::Account::ProfileBase profile; if (!profile_manager->GetProfileBase(*uuid, profile)) @@ -292,7 +297,7 @@ void ConfigureSystem::DeleteUser() { const auto index = tree_view->currentIndex().row(); const auto uuid = profile_manager->GetUser(index); ASSERT(uuid != std::nullopt); - const auto username = GetAccountUsername(*uuid); + const auto username = GetAccountUsername(*profile_manager, *uuid); const auto confirm = QMessageBox::question(this, tr("Confirm Delete"), @@ -320,7 +325,7 @@ void ConfigureSystem::SetUserImage() { const auto index = tree_view->currentIndex().row(); const auto uuid = profile_manager->GetUser(index); ASSERT(uuid != std::nullopt); - const auto username = GetAccountUsername(*uuid); + const auto username = GetAccountUsername(*profile_manager, *uuid); const auto file = QFileDialog::getOpenFileName(this, tr("Select User Image"), QString(), "JPEG Images (*.jpg *.jpeg)"); diff --git a/src/yuzu/configuration/configure_system.h b/src/yuzu/configuration/configure_system.h index 0d15d9ac4f..07764e1f71 100644 --- a/src/yuzu/configuration/configure_system.h +++ b/src/yuzu/configuration/configure_system.h @@ -9,17 +9,16 @@ #include #include -namespace Service::Account { -class ProfileManager; -struct UUID; -} // namespace Service::Account - class QGraphicsScene; class QStandardItem; class QStandardItemModel; class QTreeView; class QVBoxLayout; +namespace Service::Account { +class ProfileManager; +} + namespace Ui { class ConfigureSystem; } @@ -36,7 +35,6 @@ public: private: void ReadSystemSettings(); - std::string GetAccountUsername(Service::Account::UUID uuid) const; void UpdateBirthdayComboBox(int birthmonth_index); void RefreshConsoleID(); From 85285b09b0d3243858badb7c044507f3eb6fcb45 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Thu, 25 Oct 2018 17:03:31 -0400 Subject: [PATCH 7/7] configure_system: Make the file selector text translatable This should be localizable, since it's user-facing text. --- src/yuzu/configuration/configure_system.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/yuzu/configuration/configure_system.cpp b/src/yuzu/configuration/configure_system.cpp index a9bd5465d9..20ffb0a9a3 100644 --- a/src/yuzu/configuration/configure_system.cpp +++ b/src/yuzu/configuration/configure_system.cpp @@ -328,7 +328,7 @@ void ConfigureSystem::SetUserImage() { const auto username = GetAccountUsername(*profile_manager, *uuid); const auto file = QFileDialog::getOpenFileName(this, tr("Select User Image"), QString(), - "JPEG Images (*.jpg *.jpeg)"); + tr("JPEG Images (*.jpg *.jpeg)")); if (file.isEmpty()) return;