core: Use single instance of profile manager

This commit is contained in:
german77 2023-12-09 23:28:18 -06:00
parent 875568bb3e
commit a22a025c5b
13 changed files with 94 additions and 73 deletions

View file

@ -291,9 +291,6 @@ Core::SystemResultStatus EmulationSession::InitializeEmulation(const std::string
// Initialize filesystem. // Initialize filesystem.
ConfigureFilesystemProvider(filepath); ConfigureFilesystemProvider(filepath);
// Initialize account manager
m_profile_manager = std::make_unique<Service::Account::ProfileManager>();
// Load the ROM. // Load the ROM.
m_load_result = m_system.Load(EmulationSession::GetInstance().Window(), filepath); m_load_result = m_system.Load(EmulationSession::GetInstance().Window(), filepath);
if (m_load_result != Core::SystemResultStatus::Success) { if (m_load_result != Core::SystemResultStatus::Success) {
@ -736,8 +733,8 @@ void Java_org_yuzu_yuzu_1emu_NativeLibrary_initializeEmptyUserDirectory(JNIEnv*
auto vfs_nand_dir = EmulationSession::GetInstance().System().GetFilesystem()->OpenDirectory( auto vfs_nand_dir = EmulationSession::GetInstance().System().GetFilesystem()->OpenDirectory(
Common::FS::PathToUTF8String(nand_dir), FileSys::Mode::Read); Common::FS::PathToUTF8String(nand_dir), FileSys::Mode::Read);
Service::Account::ProfileManager manager; const auto user_id = EmulationSession::GetInstance().System().GetProfileManager().GetUser(
const auto user_id = manager.GetUser(static_cast<std::size_t>(0)); static_cast<std::size_t>(0));
ASSERT(user_id); ASSERT(user_id);
const auto user_save_data_path = FileSys::SaveDataFactory::GetFullPath( const auto user_save_data_path = FileSys::SaveDataFactory::GetFullPath(

View file

@ -73,7 +73,6 @@ private:
std::atomic<bool> m_is_running = false; std::atomic<bool> m_is_running = false;
std::atomic<bool> m_is_paused = false; std::atomic<bool> m_is_paused = false;
SoftwareKeyboard::AndroidKeyboard* m_software_keyboard{}; SoftwareKeyboard::AndroidKeyboard* m_software_keyboard{};
std::unique_ptr<Service::Account::ProfileManager> m_profile_manager;
std::unique_ptr<FileSys::ManualContentProvider> m_manual_provider; std::unique_ptr<FileSys::ManualContentProvider> m_manual_provider;
// GPU driver parameters // GPU driver parameters

View file

@ -36,6 +36,7 @@
#include "core/hle/kernel/k_scheduler.h" #include "core/hle/kernel/k_scheduler.h"
#include "core/hle/kernel/kernel.h" #include "core/hle/kernel/kernel.h"
#include "core/hle/kernel/physical_core.h" #include "core/hle/kernel/physical_core.h"
#include "core/hle/service/acc/profile_manager.h"
#include "core/hle/service/am/applets/applets.h" #include "core/hle/service/am/applets/applets.h"
#include "core/hle/service/apm/apm_controller.h" #include "core/hle/service/apm/apm_controller.h"
#include "core/hle/service/filesystem/filesystem.h" #include "core/hle/service/filesystem/filesystem.h"
@ -130,8 +131,8 @@ FileSys::VirtualFile GetGameFileFromPath(const FileSys::VirtualFilesystem& vfs,
struct System::Impl { struct System::Impl {
explicit Impl(System& system) explicit Impl(System& system)
: kernel{system}, fs_controller{system}, memory{system}, hid_core{}, room_network{}, : kernel{system}, fs_controller{system}, memory{system}, hid_core{}, room_network{},
cpu_manager{system}, reporter{system}, applet_manager{system}, time_manager{system}, cpu_manager{system}, reporter{system}, applet_manager{system}, profile_manager{},
gpu_dirty_memory_write_manager{} { time_manager{system}, gpu_dirty_memory_write_manager{} {
memory.SetGPUDirtyManagers(gpu_dirty_memory_write_manager); memory.SetGPUDirtyManagers(gpu_dirty_memory_write_manager);
} }
@ -532,6 +533,7 @@ struct System::Impl {
/// Service State /// Service State
Service::Glue::ARPManager arp_manager; Service::Glue::ARPManager arp_manager;
Service::Account::ProfileManager profile_manager;
Service::Time::TimeManager time_manager; Service::Time::TimeManager time_manager;
/// Service manager /// Service manager
@ -921,6 +923,14 @@ const Service::APM::Controller& System::GetAPMController() const {
return impl->apm_controller; return impl->apm_controller;
} }
Service::Account::ProfileManager& System::GetProfileManager() {
return impl->profile_manager;
}
const Service::Account::ProfileManager& System::GetProfileManager() const {
return impl->profile_manager;
}
Service::Time::TimeManager& System::GetTimeManager() { Service::Time::TimeManager& System::GetTimeManager() {
return impl->time_manager; return impl->time_manager;
} }

View file

@ -45,6 +45,10 @@ class Memory;
namespace Service { namespace Service {
namespace Account {
class ProfileManager;
} // namespace Account
namespace AM::Applets { namespace AM::Applets {
struct AppletFrontendSet; struct AppletFrontendSet;
class AppletManager; class AppletManager;
@ -383,6 +387,9 @@ public:
[[nodiscard]] Service::APM::Controller& GetAPMController(); [[nodiscard]] Service::APM::Controller& GetAPMController();
[[nodiscard]] const Service::APM::Controller& GetAPMController() const; [[nodiscard]] const Service::APM::Controller& GetAPMController() const;
[[nodiscard]] Service::Account::ProfileManager& GetProfileManager();
[[nodiscard]] const Service::Account::ProfileManager& GetProfileManager() const;
[[nodiscard]] Service::Time::TimeManager& GetTimeManager(); [[nodiscard]] Service::Time::TimeManager& GetTimeManager();
[[nodiscard]] const Service::Time::TimeManager& GetTimeManager() const; [[nodiscard]] const Service::Time::TimeManager& GetTimeManager() const;

View file

@ -14,6 +14,8 @@
#include "common/fs/path_util.h" #include "common/fs/path_util.h"
#include "common/string_util.h" #include "common/string_util.h"
#include "core/constants.h" #include "core/constants.h"
#include "core/core.h"
#include "core/hle/service/acc/profile_manager.h"
#include "yuzu/applets/qt_profile_select.h" #include "yuzu/applets/qt_profile_select.h"
#include "yuzu/main.h" #include "yuzu/main.h"
#include "yuzu/util/controller_navigation.h" #include "yuzu/util/controller_navigation.h"
@ -47,9 +49,9 @@ QPixmap GetIcon(Common::UUID uuid) {
} // Anonymous namespace } // Anonymous namespace
QtProfileSelectionDialog::QtProfileSelectionDialog( QtProfileSelectionDialog::QtProfileSelectionDialog(
Core::HID::HIDCore& hid_core, QWidget* parent, Core::System& system, QWidget* parent,
const Core::Frontend::ProfileSelectParameters& parameters) const Core::Frontend::ProfileSelectParameters& parameters)
: QDialog(parent), profile_manager(std::make_unique<Service::Account::ProfileManager>()) { : QDialog(parent), profile_manager{system.GetProfileManager()} {
outer_layout = new QVBoxLayout; outer_layout = new QVBoxLayout;
instruction_label = new QLabel(); instruction_label = new QLabel();
@ -68,7 +70,7 @@ QtProfileSelectionDialog::QtProfileSelectionDialog(
tree_view = new QTreeView; tree_view = new QTreeView;
item_model = new QStandardItemModel(tree_view); item_model = new QStandardItemModel(tree_view);
tree_view->setModel(item_model); tree_view->setModel(item_model);
controller_navigation = new ControllerNavigation(hid_core, this); controller_navigation = new ControllerNavigation(system.HIDCore(), this);
tree_view->setAlternatingRowColors(true); tree_view->setAlternatingRowColors(true);
tree_view->setSelectionMode(QHeaderView::SingleSelection); tree_view->setSelectionMode(QHeaderView::SingleSelection);
@ -106,10 +108,10 @@ QtProfileSelectionDialog::QtProfileSelectionDialog(
SelectUser(tree_view->currentIndex()); SelectUser(tree_view->currentIndex());
}); });
const auto& profiles = profile_manager->GetAllUsers(); const auto& profiles = profile_manager.GetAllUsers();
for (const auto& user : profiles) { for (const auto& user : profiles) {
Service::Account::ProfileBase profile{}; Service::Account::ProfileBase profile{};
if (!profile_manager->GetProfileBase(user, profile)) if (!profile_manager.GetProfileBase(user, profile))
continue; continue;
const auto username = Common::StringFromFixedZeroTerminatedBuffer( const auto username = Common::StringFromFixedZeroTerminatedBuffer(
@ -134,7 +136,7 @@ QtProfileSelectionDialog::~QtProfileSelectionDialog() {
int QtProfileSelectionDialog::exec() { int QtProfileSelectionDialog::exec() {
// Skip profile selection when there's only one. // Skip profile selection when there's only one.
if (profile_manager->GetUserCount() == 1) { if (profile_manager.GetUserCount() == 1) {
user_index = 0; user_index = 0;
return QDialog::Accepted; return QDialog::Accepted;
} }

View file

@ -7,7 +7,6 @@
#include <QDialog> #include <QDialog>
#include <QList> #include <QList>
#include "core/frontend/applets/profile_select.h" #include "core/frontend/applets/profile_select.h"
#include "core/hle/service/acc/profile_manager.h"
class ControllerNavigation; class ControllerNavigation;
class GMainWindow; class GMainWindow;
@ -20,15 +19,19 @@ class QStandardItemModel;
class QTreeView; class QTreeView;
class QVBoxLayout; class QVBoxLayout;
namespace Core::HID { namespace Core {
class HIDCore; class System;
} // namespace Core::HID }
namespace Service::Account {
class ProfileManager;
}
class QtProfileSelectionDialog final : public QDialog { class QtProfileSelectionDialog final : public QDialog {
Q_OBJECT Q_OBJECT
public: public:
explicit QtProfileSelectionDialog(Core::HID::HIDCore& hid_core, QWidget* parent, explicit QtProfileSelectionDialog(Core::System& system, QWidget* parent,
const Core::Frontend::ProfileSelectParameters& parameters); const Core::Frontend::ProfileSelectParameters& parameters);
~QtProfileSelectionDialog() override; ~QtProfileSelectionDialog() override;
@ -58,7 +61,7 @@ private:
QScrollArea* scroll_area; QScrollArea* scroll_area;
QDialogButtonBox* buttons; QDialogButtonBox* buttons;
std::unique_ptr<Service::Account::ProfileManager> profile_manager; Service::Account::ProfileManager& profile_manager;
ControllerNavigation* controller_navigation = nullptr; ControllerNavigation* controller_navigation = nullptr;
}; };

View file

@ -76,9 +76,9 @@ QString GetProfileUsernameFromUser(QWidget* parent, const QString& description_t
} }
} // Anonymous namespace } // Anonymous namespace
ConfigureProfileManager::ConfigureProfileManager(const Core::System& system_, QWidget* parent) ConfigureProfileManager::ConfigureProfileManager(Core::System& system_, QWidget* parent)
: QWidget(parent), ui{std::make_unique<Ui::ConfigureProfileManager>()}, : QWidget(parent), ui{std::make_unique<Ui::ConfigureProfileManager>()},
profile_manager(std::make_unique<Service::Account::ProfileManager>()), system{system_} { profile_manager{system_.GetProfileManager()}, system{system_} {
ui->setupUi(this); ui->setupUi(this);
tree_view = new QTreeView; tree_view = new QTreeView;
@ -149,10 +149,10 @@ void ConfigureProfileManager::SetConfiguration() {
} }
void ConfigureProfileManager::PopulateUserList() { void ConfigureProfileManager::PopulateUserList() {
const auto& profiles = profile_manager->GetAllUsers(); const auto& profiles = profile_manager.GetAllUsers();
for (const auto& user : profiles) { for (const auto& user : profiles) {
Service::Account::ProfileBase profile{}; Service::Account::ProfileBase profile{};
if (!profile_manager->GetProfileBase(user, profile)) if (!profile_manager.GetProfileBase(user, profile))
continue; continue;
const auto username = Common::StringFromFixedZeroTerminatedBuffer( const auto username = Common::StringFromFixedZeroTerminatedBuffer(
@ -167,11 +167,11 @@ void ConfigureProfileManager::PopulateUserList() {
} }
void ConfigureProfileManager::UpdateCurrentUser() { void ConfigureProfileManager::UpdateCurrentUser() {
ui->pm_add->setEnabled(profile_manager->GetUserCount() < Service::Account::MAX_USERS); ui->pm_add->setEnabled(profile_manager.GetUserCount() < Service::Account::MAX_USERS);
const auto& current_user = profile_manager->GetUser(Settings::values.current_user.GetValue()); const auto& current_user = profile_manager.GetUser(Settings::values.current_user.GetValue());
ASSERT(current_user); ASSERT(current_user);
const auto username = GetAccountUsername(*profile_manager, *current_user); const auto username = GetAccountUsername(profile_manager, *current_user);
scene->clear(); scene->clear();
scene->addPixmap( scene->addPixmap(
@ -187,11 +187,11 @@ void ConfigureProfileManager::ApplyConfiguration() {
void ConfigureProfileManager::SelectUser(const QModelIndex& index) { void ConfigureProfileManager::SelectUser(const QModelIndex& index) {
Settings::values.current_user = Settings::values.current_user =
std::clamp<s32>(index.row(), 0, static_cast<s32>(profile_manager->GetUserCount() - 1)); std::clamp<s32>(index.row(), 0, static_cast<s32>(profile_manager.GetUserCount() - 1));
UpdateCurrentUser(); UpdateCurrentUser();
ui->pm_remove->setEnabled(profile_manager->GetUserCount() >= 2); ui->pm_remove->setEnabled(profile_manager.GetUserCount() >= 2);
ui->pm_rename->setEnabled(true); ui->pm_rename->setEnabled(true);
ui->pm_set_image->setEnabled(true); ui->pm_set_image->setEnabled(true);
} }
@ -204,18 +204,18 @@ void ConfigureProfileManager::AddUser() {
} }
const auto uuid = Common::UUID::MakeRandom(); const auto uuid = Common::UUID::MakeRandom();
profile_manager->CreateNewUser(uuid, username.toStdString()); profile_manager.CreateNewUser(uuid, username.toStdString());
item_model->appendRow(new QStandardItem{GetIcon(uuid), FormatUserEntryText(username, uuid)}); item_model->appendRow(new QStandardItem{GetIcon(uuid), FormatUserEntryText(username, uuid)});
} }
void ConfigureProfileManager::RenameUser() { void ConfigureProfileManager::RenameUser() {
const auto user = tree_view->currentIndex().row(); const auto user = tree_view->currentIndex().row();
const auto uuid = profile_manager->GetUser(user); const auto uuid = profile_manager.GetUser(user);
ASSERT(uuid); ASSERT(uuid);
Service::Account::ProfileBase profile{}; Service::Account::ProfileBase profile{};
if (!profile_manager->GetProfileBase(*uuid, profile)) if (!profile_manager.GetProfileBase(*uuid, profile))
return; return;
const auto new_username = GetProfileUsernameFromUser(this, tr("Enter a new username:")); const auto new_username = GetProfileUsernameFromUser(this, tr("Enter a new username:"));
@ -227,7 +227,7 @@ void ConfigureProfileManager::RenameUser() {
std::fill(profile.username.begin(), profile.username.end(), '\0'); std::fill(profile.username.begin(), profile.username.end(), '\0');
std::copy(username_std.begin(), username_std.end(), profile.username.begin()); std::copy(username_std.begin(), username_std.end(), profile.username.begin());
profile_manager->SetProfileBase(*uuid, profile); profile_manager.SetProfileBase(*uuid, profile);
item_model->setItem( item_model->setItem(
user, 0, user, 0,
@ -238,9 +238,9 @@ void ConfigureProfileManager::RenameUser() {
void ConfigureProfileManager::ConfirmDeleteUser() { void ConfigureProfileManager::ConfirmDeleteUser() {
const auto index = tree_view->currentIndex().row(); const auto index = tree_view->currentIndex().row();
const auto uuid = profile_manager->GetUser(index); const auto uuid = profile_manager.GetUser(index);
ASSERT(uuid); ASSERT(uuid);
const auto username = GetAccountUsername(*profile_manager, *uuid); const auto username = GetAccountUsername(profile_manager, *uuid);
confirm_dialog->SetInfo(username, *uuid, [this, uuid]() { DeleteUser(*uuid); }); confirm_dialog->SetInfo(username, *uuid, [this, uuid]() { DeleteUser(*uuid); });
confirm_dialog->show(); confirm_dialog->show();
@ -252,7 +252,7 @@ void ConfigureProfileManager::DeleteUser(const Common::UUID& uuid) {
} }
UpdateCurrentUser(); UpdateCurrentUser();
if (!profile_manager->RemoveUser(uuid)) { if (!profile_manager.RemoveUser(uuid)) {
return; return;
} }
@ -265,7 +265,7 @@ void ConfigureProfileManager::DeleteUser(const Common::UUID& uuid) {
void ConfigureProfileManager::SetUserImage() { void ConfigureProfileManager::SetUserImage() {
const auto index = tree_view->currentIndex().row(); const auto index = tree_view->currentIndex().row();
const auto uuid = profile_manager->GetUser(index); const auto uuid = profile_manager.GetUser(index);
ASSERT(uuid); ASSERT(uuid);
const auto file = QFileDialog::getOpenFileName(this, tr("Select User Image"), QString(), const auto file = QFileDialog::getOpenFileName(this, tr("Select User Image"), QString(),
@ -317,7 +317,7 @@ void ConfigureProfileManager::SetUserImage() {
} }
} }
const auto username = GetAccountUsername(*profile_manager, *uuid); const auto username = GetAccountUsername(profile_manager, *uuid);
item_model->setItem(index, 0, item_model->setItem(index, 0,
new QStandardItem{GetIcon(*uuid), FormatUserEntryText(username, *uuid)}); new QStandardItem{GetIcon(*uuid), FormatUserEntryText(username, *uuid)});
UpdateCurrentUser(); UpdateCurrentUser();

View file

@ -52,7 +52,7 @@ class ConfigureProfileManager : public QWidget {
Q_OBJECT Q_OBJECT
public: public:
explicit ConfigureProfileManager(const Core::System& system_, QWidget* parent = nullptr); explicit ConfigureProfileManager(Core::System& system_, QWidget* parent = nullptr);
~ConfigureProfileManager() override; ~ConfigureProfileManager() override;
void ApplyConfiguration(); void ApplyConfiguration();
@ -85,7 +85,6 @@ private:
std::unique_ptr<Ui::ConfigureProfileManager> ui; std::unique_ptr<Ui::ConfigureProfileManager> ui;
bool enabled = false; bool enabled = false;
std::unique_ptr<Service::Account::ProfileManager> profile_manager; Service::Account::ProfileManager& profile_manager;
const Core::System& system; const Core::System& system;
}; };

View file

@ -346,7 +346,7 @@ GMainWindow::GMainWindow(std::unique_ptr<QtConfig> config_, bool has_broken_vulk
SetDiscordEnabled(UISettings::values.enable_discord_presence.GetValue()); SetDiscordEnabled(UISettings::values.enable_discord_presence.GetValue());
discord_rpc->Update(); discord_rpc->Update();
play_time_manager = std::make_unique<PlayTime::PlayTimeManager>(); play_time_manager = std::make_unique<PlayTime::PlayTimeManager>(system->GetProfileManager());
system->GetRoomNetwork().Init(); system->GetRoomNetwork().Init();
@ -526,8 +526,7 @@ GMainWindow::GMainWindow(std::unique_ptr<QtConfig> config_, bool has_broken_vulk
continue; continue;
} }
const Service::Account::ProfileManager manager; if (!system->GetProfileManager().UserExistsIndex(selected_user)) {
if (!manager.UserExistsIndex(selected_user)) {
LOG_ERROR(Frontend, "Selected user doesn't exist"); LOG_ERROR(Frontend, "Selected user doesn't exist");
continue; continue;
} }
@ -691,7 +690,7 @@ void GMainWindow::ControllerSelectorRequestExit() {
void GMainWindow::ProfileSelectorSelectProfile( void GMainWindow::ProfileSelectorSelectProfile(
const Core::Frontend::ProfileSelectParameters& parameters) { const Core::Frontend::ProfileSelectParameters& parameters) {
profile_select_applet = new QtProfileSelectionDialog(system->HIDCore(), this, parameters); profile_select_applet = new QtProfileSelectionDialog(*system, this, parameters);
SCOPE_EXIT({ SCOPE_EXIT({
profile_select_applet->deleteLater(); profile_select_applet->deleteLater();
profile_select_applet = nullptr; profile_select_applet = nullptr;
@ -706,8 +705,8 @@ void GMainWindow::ProfileSelectorSelectProfile(
return; return;
} }
const Service::Account::ProfileManager manager; const auto uuid = system->GetProfileManager().GetUser(
const auto uuid = manager.GetUser(static_cast<std::size_t>(profile_select_applet->GetIndex())); static_cast<std::size_t>(profile_select_applet->GetIndex()));
if (!uuid.has_value()) { if (!uuid.has_value()) {
emit ProfileSelectorFinishedSelection(std::nullopt); emit ProfileSelectorFinishedSelection(std::nullopt);
return; return;
@ -1856,7 +1855,7 @@ bool GMainWindow::LoadROM(const QString& filename, u64 program_id, std::size_t p
bool GMainWindow::SelectAndSetCurrentUser( bool GMainWindow::SelectAndSetCurrentUser(
const Core::Frontend::ProfileSelectParameters& parameters) { const Core::Frontend::ProfileSelectParameters& parameters) {
QtProfileSelectionDialog dialog(system->HIDCore(), this, parameters); QtProfileSelectionDialog dialog(*system, this, parameters);
dialog.setWindowFlags(Qt::Dialog | Qt::CustomizeWindowHint | Qt::WindowTitleHint | dialog.setWindowFlags(Qt::Dialog | Qt::CustomizeWindowHint | Qt::WindowTitleHint |
Qt::WindowSystemMenuHint | Qt::WindowCloseButtonHint); Qt::WindowSystemMenuHint | Qt::WindowCloseButtonHint);
dialog.setWindowModality(Qt::WindowModal); dialog.setWindowModality(Qt::WindowModal);
@ -2271,7 +2270,7 @@ void GMainWindow::OnGameListOpenFolder(u64 program_id, GameListOpenTarget target
.display_options = {}, .display_options = {},
.purpose = Service::AM::Applets::UserSelectionPurpose::General, .purpose = Service::AM::Applets::UserSelectionPurpose::General,
}; };
QtProfileSelectionDialog dialog(system->HIDCore(), this, parameters); QtProfileSelectionDialog dialog(*system, this, parameters);
dialog.setWindowFlags(Qt::Dialog | Qt::CustomizeWindowHint | Qt::WindowTitleHint | dialog.setWindowFlags(Qt::Dialog | Qt::CustomizeWindowHint | Qt::WindowTitleHint |
Qt::WindowSystemMenuHint | Qt::WindowCloseButtonHint); Qt::WindowSystemMenuHint | Qt::WindowCloseButtonHint);
dialog.setWindowModality(Qt::WindowModal); dialog.setWindowModality(Qt::WindowModal);
@ -2288,8 +2287,8 @@ void GMainWindow::OnGameListOpenFolder(u64 program_id, GameListOpenTarget target
return; return;
} }
Service::Account::ProfileManager manager; const auto user_id =
const auto user_id = manager.GetUser(static_cast<std::size_t>(index)); system->GetProfileManager().GetUser(static_cast<std::size_t>(index));
ASSERT(user_id); ASSERT(user_id);
const auto user_save_data_path = FileSys::SaveDataFactory::GetFullPath( const auto user_save_data_path = FileSys::SaveDataFactory::GetFullPath(

View file

@ -27,9 +27,9 @@
Lobby::Lobby(QWidget* parent, QStandardItemModel* list, Lobby::Lobby(QWidget* parent, QStandardItemModel* list,
std::shared_ptr<Core::AnnounceMultiplayerSession> session, Core::System& system_) std::shared_ptr<Core::AnnounceMultiplayerSession> session, Core::System& system_)
: QDialog(parent, Qt::WindowTitleHint | Qt::WindowCloseButtonHint | Qt::WindowSystemMenuHint), : QDialog(parent, Qt::WindowTitleHint | Qt::WindowCloseButtonHint | Qt::WindowSystemMenuHint),
ui(std::make_unique<Ui::Lobby>()), announce_multiplayer_session(session), ui(std::make_unique<Ui::Lobby>()),
profile_manager(std::make_unique<Service::Account::ProfileManager>()), system{system_}, announce_multiplayer_session(session), system{system_}, room_network{
room_network{system.GetRoomNetwork()} { system.GetRoomNetwork()} {
ui->setupUi(this); ui->setupUi(this);
// setup the watcher for background connections // setup the watcher for background connections
@ -299,14 +299,15 @@ void Lobby::OnRefreshLobby() {
} }
std::string Lobby::GetProfileUsername() { std::string Lobby::GetProfileUsername() {
const auto& current_user = profile_manager->GetUser(Settings::values.current_user.GetValue()); const auto& current_user =
system.GetProfileManager().GetUser(Settings::values.current_user.GetValue());
Service::Account::ProfileBase profile{}; Service::Account::ProfileBase profile{};
if (!current_user.has_value()) { if (!current_user.has_value()) {
return ""; return "";
} }
if (!profile_manager->GetProfileBase(*current_user, profile)) { if (!system.GetProfileManager().GetProfileBase(*current_user, profile)) {
return ""; return "";
} }

View file

@ -24,10 +24,6 @@ namespace Core {
class System; class System;
} }
namespace Service::Account {
class ProfileManager;
}
/** /**
* Listing of all public games pulled from services. The lobby should be simple enough for users to * Listing of all public games pulled from services. The lobby should be simple enough for users to
* find the game they want to play, and join it. * find the game they want to play, and join it.
@ -103,7 +99,6 @@ private:
QFutureWatcher<AnnounceMultiplayerRoom::RoomList> room_list_watcher; QFutureWatcher<AnnounceMultiplayerRoom::RoomList> room_list_watcher;
std::weak_ptr<Core::AnnounceMultiplayerSession> announce_multiplayer_session; std::weak_ptr<Core::AnnounceMultiplayerSession> announce_multiplayer_session;
std::unique_ptr<Service::Account::ProfileManager> profile_manager;
QFutureWatcher<void>* watcher; QFutureWatcher<void>* watcher;
Validation validation; Validation validation;
Core::System& system; Core::System& system;

View file

@ -20,8 +20,8 @@ struct PlayTimeElement {
PlayTime play_time; PlayTime play_time;
}; };
std::optional<std::filesystem::path> GetCurrentUserPlayTimePath() { std::optional<std::filesystem::path> GetCurrentUserPlayTimePath(
const Service::Account::ProfileManager manager; const Service::Account::ProfileManager& manager) {
const auto uuid = manager.GetUser(static_cast<s32>(Settings::values.current_user)); const auto uuid = manager.GetUser(static_cast<s32>(Settings::values.current_user));
if (!uuid.has_value()) { if (!uuid.has_value()) {
return std::nullopt; return std::nullopt;
@ -30,8 +30,9 @@ std::optional<std::filesystem::path> GetCurrentUserPlayTimePath() {
uuid->RawString().append(".bin"); uuid->RawString().append(".bin");
} }
[[nodiscard]] bool ReadPlayTimeFile(PlayTimeDatabase& out_play_time_db) { [[nodiscard]] bool ReadPlayTimeFile(PlayTimeDatabase& out_play_time_db,
const auto filename = GetCurrentUserPlayTimePath(); const Service::Account::ProfileManager& manager) {
const auto filename = GetCurrentUserPlayTimePath(manager);
if (!filename.has_value()) { if (!filename.has_value()) {
LOG_ERROR(Frontend, "Failed to get current user path"); LOG_ERROR(Frontend, "Failed to get current user path");
@ -66,8 +67,9 @@ std::optional<std::filesystem::path> GetCurrentUserPlayTimePath() {
return true; return true;
} }
[[nodiscard]] bool WritePlayTimeFile(const PlayTimeDatabase& play_time_db) { [[nodiscard]] bool WritePlayTimeFile(const PlayTimeDatabase& play_time_db,
const auto filename = GetCurrentUserPlayTimePath(); const Service::Account::ProfileManager& manager) {
const auto filename = GetCurrentUserPlayTimePath(manager);
if (!filename.has_value()) { if (!filename.has_value()) {
LOG_ERROR(Frontend, "Failed to get current user path"); LOG_ERROR(Frontend, "Failed to get current user path");
@ -96,8 +98,9 @@ std::optional<std::filesystem::path> GetCurrentUserPlayTimePath() {
} // namespace } // namespace
PlayTimeManager::PlayTimeManager() { PlayTimeManager::PlayTimeManager(Service::Account::ProfileManager& profile_manager)
if (!ReadPlayTimeFile(database)) { : manager{profile_manager} {
if (!ReadPlayTimeFile(database, manager)) {
LOG_ERROR(Frontend, "Failed to read play time database! Resetting to default."); LOG_ERROR(Frontend, "Failed to read play time database! Resetting to default.");
} }
} }
@ -142,7 +145,7 @@ void PlayTimeManager::AutoTimestamp(std::stop_token stop_token) {
} }
void PlayTimeManager::Save() { void PlayTimeManager::Save() {
if (!WritePlayTimeFile(database)) { if (!WritePlayTimeFile(database, manager)) {
LOG_ERROR(Frontend, "Failed to update play time database!"); LOG_ERROR(Frontend, "Failed to update play time database!");
} }
} }

View file

@ -11,6 +11,10 @@
#include "common/common_types.h" #include "common/common_types.h"
#include "common/polyfill_thread.h" #include "common/polyfill_thread.h"
namespace Service::Account {
class ProfileManager;
}
namespace PlayTime { namespace PlayTime {
using ProgramId = u64; using ProgramId = u64;
@ -19,7 +23,7 @@ using PlayTimeDatabase = std::map<ProgramId, PlayTime>;
class PlayTimeManager { class PlayTimeManager {
public: public:
explicit PlayTimeManager(); explicit PlayTimeManager(Service::Account::ProfileManager& profile_manager);
~PlayTimeManager(); ~PlayTimeManager();
YUZU_NON_COPYABLE(PlayTimeManager); YUZU_NON_COPYABLE(PlayTimeManager);
@ -32,11 +36,13 @@ public:
void Stop(); void Stop();
private: private:
void AutoTimestamp(std::stop_token stop_token);
void Save();
PlayTimeDatabase database; PlayTimeDatabase database;
u64 running_program_id; u64 running_program_id;
std::jthread play_time_thread; std::jthread play_time_thread;
void AutoTimestamp(std::stop_token stop_token); Service::Account::ProfileManager& manager;
void Save();
}; };
QString ReadablePlayTime(qulonglong time_seconds); QString ReadablePlayTime(qulonglong time_seconds);