summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorliamwhite <liamwhite@users.noreply.github.com>2023-12-12 17:06:37 +0100
committerGitHub <noreply@github.com>2023-12-12 17:06:37 +0100
commit15bebf1695246c85852835b0fae58d795626dc39 (patch)
tree03de654621e65cb185b2a2e3511f71b933b005ef
parentMerge pull request #12333 from german77/aruid_free (diff)
parentcore: Use single instance of profile manager (diff)
downloadyuzu-15bebf1695246c85852835b0fae58d795626dc39.tar
yuzu-15bebf1695246c85852835b0fae58d795626dc39.tar.gz
yuzu-15bebf1695246c85852835b0fae58d795626dc39.tar.bz2
yuzu-15bebf1695246c85852835b0fae58d795626dc39.tar.lz
yuzu-15bebf1695246c85852835b0fae58d795626dc39.tar.xz
yuzu-15bebf1695246c85852835b0fae58d795626dc39.tar.zst
yuzu-15bebf1695246c85852835b0fae58d795626dc39.zip
-rw-r--r--src/android/app/src/main/jni/native.cpp7
-rw-r--r--src/android/app/src/main/jni/native.h1
-rw-r--r--src/core/core.cpp14
-rw-r--r--src/core/core.h7
-rw-r--r--src/yuzu/applets/qt_profile_select.cpp14
-rw-r--r--src/yuzu/applets/qt_profile_select.h15
-rw-r--r--src/yuzu/configuration/configure_profile_manager.cpp36
-rw-r--r--src/yuzu/configuration/configure_profile_manager.h5
-rw-r--r--src/yuzu/main.cpp19
-rw-r--r--src/yuzu/multiplayer/lobby.cpp11
-rw-r--r--src/yuzu/multiplayer/lobby.h5
-rw-r--r--src/yuzu/play_time_manager.cpp21
-rw-r--r--src/yuzu/play_time_manager.h12
13 files changed, 94 insertions, 73 deletions
diff --git a/src/android/app/src/main/jni/native.cpp b/src/android/app/src/main/jni/native.cpp
index 3d795b57f..e5d3158c8 100644
--- a/src/android/app/src/main/jni/native.cpp
+++ b/src/android/app/src/main/jni/native.cpp
@@ -291,9 +291,6 @@ Core::SystemResultStatus EmulationSession::InitializeEmulation(const std::string
// Initialize filesystem.
ConfigureFilesystemProvider(filepath);
- // Initialize account manager
- m_profile_manager = std::make_unique<Service::Account::ProfileManager>();
-
// Load the ROM.
m_load_result = m_system.Load(EmulationSession::GetInstance().Window(), filepath);
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(
Common::FS::PathToUTF8String(nand_dir), FileSys::Mode::Read);
- Service::Account::ProfileManager manager;
- const auto user_id = manager.GetUser(static_cast<std::size_t>(0));
+ const auto user_id = EmulationSession::GetInstance().System().GetProfileManager().GetUser(
+ static_cast<std::size_t>(0));
ASSERT(user_id);
const auto user_save_data_path = FileSys::SaveDataFactory::GetFullPath(
diff --git a/src/android/app/src/main/jni/native.h b/src/android/app/src/main/jni/native.h
index 78ef96802..f1457bd1f 100644
--- a/src/android/app/src/main/jni/native.h
+++ b/src/android/app/src/main/jni/native.h
@@ -73,7 +73,6 @@ private:
std::atomic<bool> m_is_running = false;
std::atomic<bool> m_is_paused = false;
SoftwareKeyboard::AndroidKeyboard* m_software_keyboard{};
- std::unique_ptr<Service::Account::ProfileManager> m_profile_manager;
std::unique_ptr<FileSys::ManualContentProvider> m_manual_provider;
// GPU driver parameters
diff --git a/src/core/core.cpp b/src/core/core.cpp
index 229cb879c..b14f74976 100644
--- a/src/core/core.cpp
+++ b/src/core/core.cpp
@@ -36,6 +36,7 @@
#include "core/hle/kernel/k_scheduler.h"
#include "core/hle/kernel/kernel.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/apm/apm_controller.h"
#include "core/hle/service/filesystem/filesystem.h"
@@ -130,8 +131,8 @@ FileSys::VirtualFile GetGameFileFromPath(const FileSys::VirtualFilesystem& vfs,
struct System::Impl {
explicit Impl(System& system)
: kernel{system}, fs_controller{system}, memory{system}, hid_core{}, room_network{},
- cpu_manager{system}, reporter{system}, applet_manager{system}, time_manager{system},
- gpu_dirty_memory_write_manager{} {
+ cpu_manager{system}, reporter{system}, applet_manager{system}, profile_manager{},
+ time_manager{system}, gpu_dirty_memory_write_manager{} {
memory.SetGPUDirtyManagers(gpu_dirty_memory_write_manager);
}
@@ -532,6 +533,7 @@ struct System::Impl {
/// Service State
Service::Glue::ARPManager arp_manager;
+ Service::Account::ProfileManager profile_manager;
Service::Time::TimeManager time_manager;
/// Service manager
@@ -921,6 +923,14 @@ const Service::APM::Controller& System::GetAPMController() const {
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() {
return impl->time_manager;
}
diff --git a/src/core/core.h b/src/core/core.h
index 05a222f5c..473204db7 100644
--- a/src/core/core.h
+++ b/src/core/core.h
@@ -45,6 +45,10 @@ class Memory;
namespace Service {
+namespace Account {
+class ProfileManager;
+} // namespace Account
+
namespace AM::Applets {
struct AppletFrontendSet;
class AppletManager;
@@ -383,6 +387,9 @@ public:
[[nodiscard]] Service::APM::Controller& GetAPMController();
[[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]] const Service::Time::TimeManager& GetTimeManager() const;
diff --git a/src/yuzu/applets/qt_profile_select.cpp b/src/yuzu/applets/qt_profile_select.cpp
index 1f3f23038..79162a491 100644
--- a/src/yuzu/applets/qt_profile_select.cpp
+++ b/src/yuzu/applets/qt_profile_select.cpp
@@ -14,6 +14,8 @@
#include "common/fs/path_util.h"
#include "common/string_util.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/main.h"
#include "yuzu/util/controller_navigation.h"
@@ -47,9 +49,9 @@ QPixmap GetIcon(Common::UUID uuid) {
} // Anonymous namespace
QtProfileSelectionDialog::QtProfileSelectionDialog(
- Core::HID::HIDCore& hid_core, QWidget* parent,
+ Core::System& system, QWidget* parent,
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;
instruction_label = new QLabel();
@@ -68,7 +70,7 @@ QtProfileSelectionDialog::QtProfileSelectionDialog(
tree_view = new QTreeView;
item_model = new QStandardItemModel(tree_view);
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->setSelectionMode(QHeaderView::SingleSelection);
@@ -106,10 +108,10 @@ QtProfileSelectionDialog::QtProfileSelectionDialog(
SelectUser(tree_view->currentIndex());
});
- const auto& profiles = profile_manager->GetAllUsers();
+ const auto& profiles = profile_manager.GetAllUsers();
for (const auto& user : profiles) {
Service::Account::ProfileBase profile{};
- if (!profile_manager->GetProfileBase(user, profile))
+ if (!profile_manager.GetProfileBase(user, profile))
continue;
const auto username = Common::StringFromFixedZeroTerminatedBuffer(
@@ -134,7 +136,7 @@ QtProfileSelectionDialog::~QtProfileSelectionDialog() {
int QtProfileSelectionDialog::exec() {
// Skip profile selection when there's only one.
- if (profile_manager->GetUserCount() == 1) {
+ if (profile_manager.GetUserCount() == 1) {
user_index = 0;
return QDialog::Accepted;
}
diff --git a/src/yuzu/applets/qt_profile_select.h b/src/yuzu/applets/qt_profile_select.h
index 99056e274..607f1777c 100644
--- a/src/yuzu/applets/qt_profile_select.h
+++ b/src/yuzu/applets/qt_profile_select.h
@@ -7,7 +7,6 @@
#include <QDialog>
#include <QList>
#include "core/frontend/applets/profile_select.h"
-#include "core/hle/service/acc/profile_manager.h"
class ControllerNavigation;
class GMainWindow;
@@ -20,15 +19,19 @@ class QStandardItemModel;
class QTreeView;
class QVBoxLayout;
-namespace Core::HID {
-class HIDCore;
-} // namespace Core::HID
+namespace Core {
+class System;
+}
+
+namespace Service::Account {
+class ProfileManager;
+}
class QtProfileSelectionDialog final : public QDialog {
Q_OBJECT
public:
- explicit QtProfileSelectionDialog(Core::HID::HIDCore& hid_core, QWidget* parent,
+ explicit QtProfileSelectionDialog(Core::System& system, QWidget* parent,
const Core::Frontend::ProfileSelectParameters& parameters);
~QtProfileSelectionDialog() override;
@@ -58,7 +61,7 @@ private:
QScrollArea* scroll_area;
QDialogButtonBox* buttons;
- std::unique_ptr<Service::Account::ProfileManager> profile_manager;
+ Service::Account::ProfileManager& profile_manager;
ControllerNavigation* controller_navigation = nullptr;
};
diff --git a/src/yuzu/configuration/configure_profile_manager.cpp b/src/yuzu/configuration/configure_profile_manager.cpp
index 6d2219bf5..fa5f383d6 100644
--- a/src/yuzu/configuration/configure_profile_manager.cpp
+++ b/src/yuzu/configuration/configure_profile_manager.cpp
@@ -76,9 +76,9 @@ QString GetProfileUsernameFromUser(QWidget* parent, const QString& description_t
}
} // 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>()},
- profile_manager(std::make_unique<Service::Account::ProfileManager>()), system{system_} {
+ profile_manager{system_.GetProfileManager()}, system{system_} {
ui->setupUi(this);
tree_view = new QTreeView;
@@ -149,10 +149,10 @@ void ConfigureProfileManager::SetConfiguration() {
}
void ConfigureProfileManager::PopulateUserList() {
- const auto& profiles = profile_manager->GetAllUsers();
+ const auto& profiles = profile_manager.GetAllUsers();
for (const auto& user : profiles) {
Service::Account::ProfileBase profile{};
- if (!profile_manager->GetProfileBase(user, profile))
+ if (!profile_manager.GetProfileBase(user, profile))
continue;
const auto username = Common::StringFromFixedZeroTerminatedBuffer(
@@ -167,11 +167,11 @@ void ConfigureProfileManager::PopulateUserList() {
}
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);
- const auto username = GetAccountUsername(*profile_manager, *current_user);
+ const auto username = GetAccountUsername(profile_manager, *current_user);
scene->clear();
scene->addPixmap(
@@ -187,11 +187,11 @@ void ConfigureProfileManager::ApplyConfiguration() {
void ConfigureProfileManager::SelectUser(const QModelIndex& index) {
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();
- ui->pm_remove->setEnabled(profile_manager->GetUserCount() >= 2);
+ ui->pm_remove->setEnabled(profile_manager.GetUserCount() >= 2);
ui->pm_rename->setEnabled(true);
ui->pm_set_image->setEnabled(true);
}
@@ -204,18 +204,18 @@ void ConfigureProfileManager::AddUser() {
}
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)});
}
void ConfigureProfileManager::RenameUser() {
const auto user = tree_view->currentIndex().row();
- const auto uuid = profile_manager->GetUser(user);
+ const auto uuid = profile_manager.GetUser(user);
ASSERT(uuid);
Service::Account::ProfileBase profile{};
- if (!profile_manager->GetProfileBase(*uuid, profile))
+ if (!profile_manager.GetProfileBase(*uuid, profile))
return;
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::copy(username_std.begin(), username_std.end(), profile.username.begin());
- profile_manager->SetProfileBase(*uuid, profile);
+ profile_manager.SetProfileBase(*uuid, profile);
item_model->setItem(
user, 0,
@@ -238,9 +238,9 @@ void ConfigureProfileManager::RenameUser() {
void ConfigureProfileManager::ConfirmDeleteUser() {
const auto index = tree_view->currentIndex().row();
- const auto uuid = profile_manager->GetUser(index);
+ const auto uuid = profile_manager.GetUser(index);
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->show();
@@ -252,7 +252,7 @@ void ConfigureProfileManager::DeleteUser(const Common::UUID& uuid) {
}
UpdateCurrentUser();
- if (!profile_manager->RemoveUser(uuid)) {
+ if (!profile_manager.RemoveUser(uuid)) {
return;
}
@@ -265,7 +265,7 @@ void ConfigureProfileManager::DeleteUser(const Common::UUID& uuid) {
void ConfigureProfileManager::SetUserImage() {
const auto index = tree_view->currentIndex().row();
- const auto uuid = profile_manager->GetUser(index);
+ const auto uuid = profile_manager.GetUser(index);
ASSERT(uuid);
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,
new QStandardItem{GetIcon(*uuid), FormatUserEntryText(username, *uuid)});
UpdateCurrentUser();
diff --git a/src/yuzu/configuration/configure_profile_manager.h b/src/yuzu/configuration/configure_profile_manager.h
index c4b1a334e..39560fdd9 100644
--- a/src/yuzu/configuration/configure_profile_manager.h
+++ b/src/yuzu/configuration/configure_profile_manager.h
@@ -52,7 +52,7 @@ class ConfigureProfileManager : public QWidget {
Q_OBJECT
public:
- explicit ConfigureProfileManager(const Core::System& system_, QWidget* parent = nullptr);
+ explicit ConfigureProfileManager(Core::System& system_, QWidget* parent = nullptr);
~ConfigureProfileManager() override;
void ApplyConfiguration();
@@ -85,7 +85,6 @@ private:
std::unique_ptr<Ui::ConfigureProfileManager> ui;
bool enabled = false;
- std::unique_ptr<Service::Account::ProfileManager> profile_manager;
-
+ Service::Account::ProfileManager& profile_manager;
const Core::System& system;
};
diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp
index b056c3717..f31ed7ebb 100644
--- a/src/yuzu/main.cpp
+++ b/src/yuzu/main.cpp
@@ -346,7 +346,7 @@ GMainWindow::GMainWindow(std::unique_ptr<QtConfig> config_, bool has_broken_vulk
SetDiscordEnabled(UISettings::values.enable_discord_presence.GetValue());
discord_rpc->Update();
- play_time_manager = std::make_unique<PlayTime::PlayTimeManager>();
+ play_time_manager = std::make_unique<PlayTime::PlayTimeManager>(system->GetProfileManager());
system->GetRoomNetwork().Init();
@@ -526,8 +526,7 @@ GMainWindow::GMainWindow(std::unique_ptr<QtConfig> config_, bool has_broken_vulk
continue;
}
- const Service::Account::ProfileManager manager;
- if (!manager.UserExistsIndex(selected_user)) {
+ if (!system->GetProfileManager().UserExistsIndex(selected_user)) {
LOG_ERROR(Frontend, "Selected user doesn't exist");
continue;
}
@@ -691,7 +690,7 @@ void GMainWindow::ControllerSelectorRequestExit() {
void GMainWindow::ProfileSelectorSelectProfile(
const Core::Frontend::ProfileSelectParameters& parameters) {
- profile_select_applet = new QtProfileSelectionDialog(system->HIDCore(), this, parameters);
+ profile_select_applet = new QtProfileSelectionDialog(*system, this, parameters);
SCOPE_EXIT({
profile_select_applet->deleteLater();
profile_select_applet = nullptr;
@@ -706,8 +705,8 @@ void GMainWindow::ProfileSelectorSelectProfile(
return;
}
- const Service::Account::ProfileManager manager;
- const auto uuid = manager.GetUser(static_cast<std::size_t>(profile_select_applet->GetIndex()));
+ const auto uuid = system->GetProfileManager().GetUser(
+ static_cast<std::size_t>(profile_select_applet->GetIndex()));
if (!uuid.has_value()) {
emit ProfileSelectorFinishedSelection(std::nullopt);
return;
@@ -1856,7 +1855,7 @@ bool GMainWindow::LoadROM(const QString& filename, u64 program_id, std::size_t p
bool GMainWindow::SelectAndSetCurrentUser(
const Core::Frontend::ProfileSelectParameters& parameters) {
- QtProfileSelectionDialog dialog(system->HIDCore(), this, parameters);
+ QtProfileSelectionDialog dialog(*system, this, parameters);
dialog.setWindowFlags(Qt::Dialog | Qt::CustomizeWindowHint | Qt::WindowTitleHint |
Qt::WindowSystemMenuHint | Qt::WindowCloseButtonHint);
dialog.setWindowModality(Qt::WindowModal);
@@ -2271,7 +2270,7 @@ void GMainWindow::OnGameListOpenFolder(u64 program_id, GameListOpenTarget target
.display_options = {},
.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 |
Qt::WindowSystemMenuHint | Qt::WindowCloseButtonHint);
dialog.setWindowModality(Qt::WindowModal);
@@ -2288,8 +2287,8 @@ void GMainWindow::OnGameListOpenFolder(u64 program_id, GameListOpenTarget target
return;
}
- Service::Account::ProfileManager manager;
- const auto user_id = manager.GetUser(static_cast<std::size_t>(index));
+ const auto user_id =
+ system->GetProfileManager().GetUser(static_cast<std::size_t>(index));
ASSERT(user_id);
const auto user_save_data_path = FileSys::SaveDataFactory::GetFullPath(
diff --git a/src/yuzu/multiplayer/lobby.cpp b/src/yuzu/multiplayer/lobby.cpp
index 603e9ae3d..41692c05b 100644
--- a/src/yuzu/multiplayer/lobby.cpp
+++ b/src/yuzu/multiplayer/lobby.cpp
@@ -27,9 +27,9 @@
Lobby::Lobby(QWidget* parent, QStandardItemModel* list,
std::shared_ptr<Core::AnnounceMultiplayerSession> session, Core::System& system_)
: QDialog(parent, Qt::WindowTitleHint | Qt::WindowCloseButtonHint | Qt::WindowSystemMenuHint),
- ui(std::make_unique<Ui::Lobby>()), announce_multiplayer_session(session),
- profile_manager(std::make_unique<Service::Account::ProfileManager>()), system{system_},
- room_network{system.GetRoomNetwork()} {
+ ui(std::make_unique<Ui::Lobby>()),
+ announce_multiplayer_session(session), system{system_}, room_network{
+ system.GetRoomNetwork()} {
ui->setupUi(this);
// setup the watcher for background connections
@@ -299,14 +299,15 @@ void Lobby::OnRefreshLobby() {
}
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{};
if (!current_user.has_value()) {
return "";
}
- if (!profile_manager->GetProfileBase(*current_user, profile)) {
+ if (!system.GetProfileManager().GetProfileBase(*current_user, profile)) {
return "";
}
diff --git a/src/yuzu/multiplayer/lobby.h b/src/yuzu/multiplayer/lobby.h
index 2674ae7c3..e78c9cae3 100644
--- a/src/yuzu/multiplayer/lobby.h
+++ b/src/yuzu/multiplayer/lobby.h
@@ -24,10 +24,6 @@ namespace Core {
class System;
}
-namespace Service::Account {
-class ProfileManager;
-}
-
/**
* 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.
@@ -103,7 +99,6 @@ private:
QFutureWatcher<AnnounceMultiplayerRoom::RoomList> room_list_watcher;
std::weak_ptr<Core::AnnounceMultiplayerSession> announce_multiplayer_session;
- std::unique_ptr<Service::Account::ProfileManager> profile_manager;
QFutureWatcher<void>* watcher;
Validation validation;
Core::System& system;
diff --git a/src/yuzu/play_time_manager.cpp b/src/yuzu/play_time_manager.cpp
index 155c36b7d..94c99274d 100644
--- a/src/yuzu/play_time_manager.cpp
+++ b/src/yuzu/play_time_manager.cpp
@@ -20,8 +20,8 @@ struct PlayTimeElement {
PlayTime play_time;
};
-std::optional<std::filesystem::path> GetCurrentUserPlayTimePath() {
- const Service::Account::ProfileManager manager;
+std::optional<std::filesystem::path> GetCurrentUserPlayTimePath(
+ const Service::Account::ProfileManager& manager) {
const auto uuid = manager.GetUser(static_cast<s32>(Settings::values.current_user));
if (!uuid.has_value()) {
return std::nullopt;
@@ -30,8 +30,9 @@ std::optional<std::filesystem::path> GetCurrentUserPlayTimePath() {
uuid->RawString().append(".bin");
}
-[[nodiscard]] bool ReadPlayTimeFile(PlayTimeDatabase& out_play_time_db) {
- const auto filename = GetCurrentUserPlayTimePath();
+[[nodiscard]] bool ReadPlayTimeFile(PlayTimeDatabase& out_play_time_db,
+ const Service::Account::ProfileManager& manager) {
+ const auto filename = GetCurrentUserPlayTimePath(manager);
if (!filename.has_value()) {
LOG_ERROR(Frontend, "Failed to get current user path");
@@ -66,8 +67,9 @@ std::optional<std::filesystem::path> GetCurrentUserPlayTimePath() {
return true;
}
-[[nodiscard]] bool WritePlayTimeFile(const PlayTimeDatabase& play_time_db) {
- const auto filename = GetCurrentUserPlayTimePath();
+[[nodiscard]] bool WritePlayTimeFile(const PlayTimeDatabase& play_time_db,
+ const Service::Account::ProfileManager& manager) {
+ const auto filename = GetCurrentUserPlayTimePath(manager);
if (!filename.has_value()) {
LOG_ERROR(Frontend, "Failed to get current user path");
@@ -96,8 +98,9 @@ std::optional<std::filesystem::path> GetCurrentUserPlayTimePath() {
} // namespace
-PlayTimeManager::PlayTimeManager() {
- if (!ReadPlayTimeFile(database)) {
+PlayTimeManager::PlayTimeManager(Service::Account::ProfileManager& profile_manager)
+ : manager{profile_manager} {
+ if (!ReadPlayTimeFile(database, manager)) {
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() {
- if (!WritePlayTimeFile(database)) {
+ if (!WritePlayTimeFile(database, manager)) {
LOG_ERROR(Frontend, "Failed to update play time database!");
}
}
diff --git a/src/yuzu/play_time_manager.h b/src/yuzu/play_time_manager.h
index 5f96f3447..1714b9131 100644
--- a/src/yuzu/play_time_manager.h
+++ b/src/yuzu/play_time_manager.h
@@ -11,6 +11,10 @@
#include "common/common_types.h"
#include "common/polyfill_thread.h"
+namespace Service::Account {
+class ProfileManager;
+}
+
namespace PlayTime {
using ProgramId = u64;
@@ -19,7 +23,7 @@ using PlayTimeDatabase = std::map<ProgramId, PlayTime>;
class PlayTimeManager {
public:
- explicit PlayTimeManager();
+ explicit PlayTimeManager(Service::Account::ProfileManager& profile_manager);
~PlayTimeManager();
YUZU_NON_COPYABLE(PlayTimeManager);
@@ -32,11 +36,13 @@ public:
void Stop();
private:
+ void AutoTimestamp(std::stop_token stop_token);
+ void Save();
+
PlayTimeDatabase database;
u64 running_program_id;
std::jthread play_time_thread;
- void AutoTimestamp(std::stop_token stop_token);
- void Save();
+ Service::Account::ProfileManager& manager;
};
QString ReadablePlayTime(qulonglong time_seconds);