From 4fbd018fea806e6693080d535054cd6d0ddb8052 Mon Sep 17 00:00:00 2001 From: crueter Date: Sat, 8 Nov 2025 15:40:15 -0500 Subject: [PATCH] [desktop] use one-profile fallback in DataManager Signed-off-by: crueter --- src/yuzu/data_dialog.cpp | 60 +++++++++------------------------------- src/yuzu/data_dialog.ui | 25 ----------------- src/yuzu/main_window.cpp | 49 +------------------------------- src/yuzu/main_window.h | 3 -- src/yuzu/util/util.cpp | 50 +++++++++++++++++++++++++++++++++ src/yuzu/util/util.h | 16 +++++++++++ 6 files changed, 80 insertions(+), 123 deletions(-) diff --git a/src/yuzu/data_dialog.cpp b/src/yuzu/data_dialog.cpp index 147c985f83..4aaa12ce41 100644 --- a/src/yuzu/data_dialog.cpp +++ b/src/yuzu/data_dialog.cpp @@ -2,12 +2,11 @@ // SPDX-License-Identifier: GPL-3.0-or-later #include "data_dialog.h" -#include "core/hle/service/acc/profile_manager.h" #include "frontend_common/data_manager.h" -#include "qt_common/qt_common.h" #include "qt_common/util/content.h" #include "qt_common/qt_string_lookup.h" #include "ui_data_dialog.h" +#include "util/util.h" #include #include @@ -26,17 +25,18 @@ DataDialog::DataDialog(QWidget *parent) ui->setupUi(this); // TODO: Should we make this a single widget that pulls data from a model? -#define WIDGET(name) \ +#define WIDGET(label, name) \ ui->page->addWidget(new DataWidget(FrontendCommon::DataManager::DataDir::name, \ QtCommon::StringLookup::name##Tooltip, \ QStringLiteral(#name), \ - this)); + this)); \ + ui->labels->addItem(label); - WIDGET(Shaders) - WIDGET(UserNand) - WIDGET(SysNand) - WIDGET(Mods) - WIDGET(Saves) + WIDGET(tr("Shaders"), Shaders) + WIDGET(tr("UserNAND"), UserNand) + WIDGET(tr("SysNAND"), SysNand) + WIDGET(tr("Mods"), Mods) + WIDGET(tr("Saves"), Saves) #undef WIDGET @@ -82,7 +82,7 @@ void DataWidget::clear() { std::string user_id{}; if (m_dir == FrontendCommon::DataManager::DataDir::Saves) { - user_id = selectProfile(); + user_id = GetProfileIDString(); } QtCommon::Content::ClearDataDir(m_dir, user_id); scan(); @@ -92,7 +92,7 @@ void DataWidget::open() { std::string user_id{}; if (m_dir == FrontendCommon::DataManager::DataDir::Saves) { - user_id = selectProfile(); + user_id = GetProfileIDString(); } QDesktopServices::openUrl(QUrl::fromLocalFile( QString::fromStdString(FrontendCommon::DataManager::GetDataDirString(m_dir, user_id)))); @@ -102,7 +102,7 @@ void DataWidget::upload() { std::string user_id{}; if (m_dir == FrontendCommon::DataManager::DataDir::Saves) { - user_id = selectProfile(); + user_id = GetProfileIDString(); } QtCommon::Content::ExportDataDir(m_dir, user_id, m_exportName); } @@ -111,7 +111,7 @@ void DataWidget::download() { std::string user_id{}; if (m_dir == FrontendCommon::DataManager::DataDir::Saves) { - user_id = selectProfile(); + user_id = GetProfileIDString(); } QtCommon::Content::ImportDataDir(m_dir, user_id, std::bind(&DataWidget::scan, this)); } @@ -131,37 +131,3 @@ void DataWidget::scan() { watcher->setFuture( QtConcurrent::run([this]() { return FrontendCommon::DataManager::DataDirSize(m_dir); })); } - -std::string DataWidget::selectProfile() -{ - const auto select_profile = [this] { - const Core::Frontend::ProfileSelectParameters parameters{ - .mode = Service::AM::Frontend::UiMode::UserSelector, - .invalid_uid_list = {}, - .display_options = {}, - .purpose = Service::AM::Frontend::UserSelectionPurpose::General, - }; - QtProfileSelectionDialog dialog(*QtCommon::system, this, parameters); - 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 ""; - } - - const auto uuid = QtCommon::system->GetProfileManager().GetUser(static_cast(index)); - ASSERT(uuid); - - const auto user_id = uuid->AsU128(); - - return fmt::format("{:016X}{:016X}", user_id[1], user_id[0]); -} diff --git a/src/yuzu/data_dialog.ui b/src/yuzu/data_dialog.ui index 2c735f3bc2..02e674d856 100644 --- a/src/yuzu/data_dialog.ui +++ b/src/yuzu/data_dialog.ui @@ -36,31 +36,6 @@ 0 - - - Shaders - - - - - UserNAND - - - - - SysNAND - - - - - Mods - - - - - Saves - - diff --git a/src/yuzu/main_window.cpp b/src/yuzu/main_window.cpp index cee3498ea8..b26baf7202 100644 --- a/src/yuzu/main_window.cpp +++ b/src/yuzu/main_window.cpp @@ -21,6 +21,7 @@ #include "loading_screen.h" #include "ryujinx_dialog.h" #include "set_play_time_dialog.h" +#include "util/util.h" #include "vk_device_info.h" #include "applets/qt_amiibo_settings.h" @@ -2798,54 +2799,6 @@ void MainWindow::OnGameListOpenPerGameProperties(const std::string& file) { OpenPerGameConfiguration(title_id, file); } -const std::optional MainWindow::GetProfileID() -{ - // if there's only a single profile, the user probably wants to use that... right? - const auto& profiles = QtCommon::system->GetProfileManager().FindExistingProfileUUIDs(); - if (profiles.size() == 1) { - return profiles[0]; - } - - const auto select_profile = [this] { - const Core::Frontend::ProfileSelectParameters parameters{ - .mode = Service::AM::Frontend::UiMode::UserSelector, - .invalid_uid_list = {}, - .display_options = {}, - .purpose = Service::AM::Frontend::UserSelectionPurpose::General, - }; - QtProfileSelectionDialog dialog(*QtCommon::system, this, parameters); - 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 std::nullopt; - } - - const auto uuid = QtCommon::system->GetProfileManager().GetUser(static_cast(index)); - ASSERT(uuid); - - return uuid; -} - -std::string MainWindow::GetProfileIDString() -{ - const auto uuid = GetProfileID(); - if (!uuid) return ""; - - auto user_id = uuid->AsU128(); - - return fmt::format("{:016X}{:016X}", user_id[1], user_id[0]); -} - void MainWindow::OnLinkToRyujinx(const u64& program_id) { namespace fs = std::filesystem; diff --git a/src/yuzu/main_window.h b/src/yuzu/main_window.h index a5e23aaa80..2ba92d476c 100644 --- a/src/yuzu/main_window.h +++ b/src/yuzu/main_window.h @@ -469,9 +469,6 @@ private: QMessageBox::StandardButtons(QMessageBox::Yes | QMessageBox::No), QMessageBox::StandardButton defaultButton = QMessageBox::NoButton); - const std::optional GetProfileID(); - std::string GetProfileIDString(); - std::unique_ptr ui; std::unique_ptr discord_rpc; diff --git a/src/yuzu/util/util.cpp b/src/yuzu/util/util.cpp index 844da5c401..0c035e5058 100644 --- a/src/yuzu/util/util.cpp +++ b/src/yuzu/util/util.cpp @@ -8,7 +8,11 @@ #include #include +#include "applets/qt_profile_select.h" #include "common/logging/log.h" +#include "core/frontend/applets/profile_select.h" +#include "core/hle/service/acc/profile_manager.h" +#include "qt_common/qt_common.h" #include "yuzu/util/util.h" #ifdef _WIN32 @@ -153,3 +157,49 @@ bool SaveIconToFile(const std::filesystem::path& icon_path, const QImage& image) return false; #endif } +const std::optional GetProfileID() { + // if there's only a single profile, the user probably wants to use that... right? + const auto& profiles = QtCommon::system->GetProfileManager().FindExistingProfileUUIDs(); + if (profiles.size() == 1) { + return profiles[0]; + } + + const auto select_profile = [] { + const Core::Frontend::ProfileSelectParameters parameters{ + .mode = Service::AM::Frontend::UiMode::UserSelector, + .invalid_uid_list = {}, + .display_options = {}, + .purpose = Service::AM::Frontend::UserSelectionPurpose::General, + }; + QtProfileSelectionDialog dialog(*QtCommon::system, QtCommon::rootObject, parameters); + 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 std::nullopt; + } + + const auto uuid = + QtCommon::system->GetProfileManager().GetUser(static_cast(index)); + ASSERT(uuid); + + return uuid; +} +std::string GetProfileIDString() { + const auto uuid = GetProfileID(); + if (!uuid) + return ""; + + auto user_id = uuid->AsU128(); + + return fmt::format("{:016X}{:016X}", user_id[1], user_id[0]); +} diff --git a/src/yuzu/util/util.h b/src/yuzu/util/util.h index 4094cf6c2b..7b482aa11d 100644 --- a/src/yuzu/util/util.h +++ b/src/yuzu/util/util.h @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project +// SPDX-License-Identifier: GPL-3.0-or-later + // SPDX-FileCopyrightText: 2015 Citra Emulator Project // SPDX-License-Identifier: GPL-2.0-or-later @@ -6,6 +9,7 @@ #include #include #include +#include "common/uuid.h" /// Returns a QFont object appropriate to use as a monospace font for debugging widgets, etc. [[nodiscard]] QFont GetMonospaceFont(); @@ -27,3 +31,15 @@ * @return bool If the operation succeeded */ [[nodiscard]] bool SaveIconToFile(const std::filesystem::path& icon_path, const QImage& image); + +/** + * Prompt the user for a profile ID. If there is only one valid profile, returns that profile. + * @return The selected profile, or an std::nullopt if none were selected + */ +const std::optional GetProfileID(); + +/** + * Prompt the user for a profile ID. If there is only one valid profile, returns that profile. + * @return A string representation of the selected profile, or an empty string if none were seleeced + */ +std::string GetProfileIDString();