From 4ce53ffe6a61cb853f2fdd88211f35cec63e2f70 Mon Sep 17 00:00:00 2001 From: lat9nq <22451773+lat9nq@users.noreply.github.com> Date: Fri, 30 Jul 2021 09:32:26 -0400 Subject: [PATCH] game_list: Remove global instances of Core::System --- src/yuzu/game_list.cpp | 7 ++++--- src/yuzu/game_list.h | 5 ++++- src/yuzu/game_list_worker.cpp | 10 +++------- src/yuzu/game_list_worker.h | 8 +++++++- src/yuzu/main.cpp | 2 +- 5 files changed, 19 insertions(+), 13 deletions(-) diff --git a/src/yuzu/game_list.cpp b/src/yuzu/game_list.cpp index f9d949e75f..99c91a6a82 100644 --- a/src/yuzu/game_list.cpp +++ b/src/yuzu/game_list.cpp @@ -305,8 +305,8 @@ void GameList::OnFilterCloseClicked() { } GameList::GameList(FileSys::VirtualFilesystem vfs, FileSys::ManualContentProvider* provider, - GMainWindow* parent) - : QWidget{parent}, vfs(std::move(vfs)), provider(provider) { + Core::System& system_, GMainWindow* parent) + : QWidget{parent}, vfs(std::move(vfs)), provider(provider), system{system_} { watcher = new QFileSystemWatcher(this); connect(watcher, &QFileSystemWatcher::directoryChanged, this, &GameList::RefreshGameDirectory); @@ -738,7 +738,8 @@ void GameList::PopulateAsync(QVector& game_dirs) { emit ShouldCancelWorker(); - GameListWorker* worker = new GameListWorker(vfs, provider, game_dirs, compatibility_list); + GameListWorker* worker = + new GameListWorker(vfs, provider, game_dirs, compatibility_list, system); connect(worker, &GameListWorker::EntryReady, this, &GameList::AddEntry, Qt::QueuedConnection); connect(worker, &GameListWorker::DirEntryReady, this, &GameList::AddDirEntry, diff --git a/src/yuzu/game_list.h b/src/yuzu/game_list.h index 10339dcca2..675469e669 100644 --- a/src/yuzu/game_list.h +++ b/src/yuzu/game_list.h @@ -72,7 +72,8 @@ public: }; explicit GameList(std::shared_ptr vfs, - FileSys::ManualContentProvider* provider, GMainWindow* parent = nullptr); + FileSys::ManualContentProvider* provider, Core::System& system_, + GMainWindow* parent = nullptr); ~GameList() override; QString GetLastFilterResultItem() const; @@ -145,6 +146,8 @@ private: CompatibilityList compatibility_list; friend class GameListSearchField; + + Core::System& system; }; class GameListPlaceholder : public QWidget { diff --git a/src/yuzu/game_list_worker.cpp b/src/yuzu/game_list_worker.cpp index 2d5492157b..fd92b36df7 100644 --- a/src/yuzu/game_list_worker.cpp +++ b/src/yuzu/game_list_worker.cpp @@ -228,16 +228,15 @@ QList MakeGameListEntry(const std::string& path, const std::stri GameListWorker::GameListWorker(FileSys::VirtualFilesystem vfs, FileSys::ManualContentProvider* provider, QVector& game_dirs, - const CompatibilityList& compatibility_list) + const CompatibilityList& compatibility_list, Core::System& system_) : vfs(std::move(vfs)), provider(provider), game_dirs(game_dirs), - compatibility_list(compatibility_list) {} + compatibility_list(compatibility_list), system{system_} {} GameListWorker::~GameListWorker() = default; void GameListWorker::AddTitlesToGameList(GameListDir* parent_dir) { using namespace FileSys; - auto& system = Core::System::GetInstance(); const auto& cache = dynamic_cast(system.GetContentProvider()); auto installed_games = cache.ListEntriesFilterOrigin(std::nullopt, TitleType::Application, @@ -285,10 +284,7 @@ void GameListWorker::AddTitlesToGameList(GameListDir* parent_dir) { void GameListWorker::ScanFileSystem(ScanTarget target, const std::string& dir_path, bool deep_scan, GameListDir* parent_dir) { - auto& system = Core::System::GetInstance(); - - const auto callback = [this, target, parent_dir, - &system](const std::filesystem::path& path) -> bool { + const auto callback = [this, target, parent_dir](const std::filesystem::path& path) -> bool { if (stop_processing) { // Breaks the callback loop. return false; diff --git a/src/yuzu/game_list_worker.h b/src/yuzu/game_list_worker.h index 396bb2623e..1383e9fbcf 100644 --- a/src/yuzu/game_list_worker.h +++ b/src/yuzu/game_list_worker.h @@ -19,6 +19,10 @@ #include "common/common_types.h" #include "yuzu/compatibility_list.h" +namespace Core { +class System; +} + class QStandardItem; namespace FileSys { @@ -37,7 +41,7 @@ public: explicit GameListWorker(std::shared_ptr vfs, FileSys::ManualContentProvider* provider, QVector& game_dirs, - const CompatibilityList& compatibility_list); + const CompatibilityList& compatibility_list, Core::System& system_); ~GameListWorker() override; /// Starts the processing of directory tree information. @@ -80,4 +84,6 @@ private: QStringList watch_list; std::atomic_bool stop_processing; + + Core::System& system; }; diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp index 056f7da36e..1d9e0f79d8 100644 --- a/src/yuzu/main.cpp +++ b/src/yuzu/main.cpp @@ -701,7 +701,7 @@ void GMainWindow::InitializeWidgets() { render_window = new GRenderWindow(this, emu_thread.get(), input_subsystem, system); render_window->hide(); - game_list = new GameList(vfs, provider.get(), this); + game_list = new GameList(vfs, provider.get(), system, this); ui.horizontalLayout->addWidget(game_list); game_list_placeholder = new GameListPlaceholder(this);