mirror of
https://github.com/yuzu-emu/yuzu-android
synced 2025-08-08 02:22:33 -07:00
patch_manager: Remove usages of the global system instance
With this, only 19 usages of the global system instance remain within the core library. We're almost there.
This commit is contained in:
@@ -16,6 +16,7 @@
|
||||
|
||||
#include "common/common_paths.h"
|
||||
#include "common/file_util.h"
|
||||
#include "core/core.h"
|
||||
#include "core/file_sys/control_metadata.h"
|
||||
#include "core/file_sys/patch_manager.h"
|
||||
#include "core/file_sys/xts_archive.h"
|
||||
@@ -89,9 +90,11 @@ void ConfigurePerGame::LoadConfiguration() {
|
||||
ui->display_title_id->setText(
|
||||
QStringLiteral("%1").arg(title_id, 16, 16, QLatin1Char{'0'}).toUpper());
|
||||
|
||||
FileSys::PatchManager pm{title_id};
|
||||
auto& system = Core::System::GetInstance();
|
||||
const FileSys::PatchManager pm{title_id, system.GetFileSystemController(),
|
||||
system.GetContentProvider()};
|
||||
const auto control = pm.GetControlMetadata();
|
||||
const auto loader = Loader::GetLoader(file);
|
||||
const auto loader = Loader::GetLoader(system, file);
|
||||
|
||||
if (control.first != nullptr) {
|
||||
ui->display_version->setText(QString::fromStdString(control.first->GetVersionString()));
|
||||
|
@@ -112,8 +112,10 @@ void ConfigurePerGameAddons::LoadConfiguration() {
|
||||
return;
|
||||
}
|
||||
|
||||
FileSys::PatchManager pm{title_id};
|
||||
const auto loader = Loader::GetLoader(file);
|
||||
auto& system = Core::System::GetInstance();
|
||||
const FileSys::PatchManager pm{title_id, system.GetFileSystemController(),
|
||||
system.GetContentProvider()};
|
||||
const auto loader = Loader::GetLoader(system, file);
|
||||
|
||||
FileSys::VirtualFile update_raw;
|
||||
loader->ReadUpdateRaw(update_raw);
|
||||
|
@@ -235,12 +235,11 @@ GameListWorker::~GameListWorker() = default;
|
||||
void GameListWorker::AddTitlesToGameList(GameListDir* parent_dir) {
|
||||
using namespace FileSys;
|
||||
|
||||
const auto& cache =
|
||||
dynamic_cast<ContentProviderUnion&>(Core::System::GetInstance().GetContentProvider());
|
||||
auto& system = Core::System::GetInstance();
|
||||
const auto& cache = dynamic_cast<ContentProviderUnion&>(system.GetContentProvider());
|
||||
|
||||
std::vector<std::pair<ContentProviderUnionSlot, ContentProviderEntry>> installed_games;
|
||||
installed_games = cache.ListEntriesFilterOrigin(std::nullopt, TitleType::Application,
|
||||
ContentRecordType::Program);
|
||||
auto installed_games = cache.ListEntriesFilterOrigin(std::nullopt, TitleType::Application,
|
||||
ContentRecordType::Program);
|
||||
|
||||
if (parent_dir->type() == static_cast<int>(GameListItemType::SdmcDir)) {
|
||||
installed_games = cache.ListEntriesFilterOrigin(
|
||||
@@ -254,23 +253,27 @@ void GameListWorker::AddTitlesToGameList(GameListDir* parent_dir) {
|
||||
}
|
||||
|
||||
for (const auto& [slot, game] : installed_games) {
|
||||
if (slot == ContentProviderUnionSlot::FrontendManual)
|
||||
if (slot == ContentProviderUnionSlot::FrontendManual) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const auto file = cache.GetEntryUnparsed(game.title_id, game.type);
|
||||
std::unique_ptr<Loader::AppLoader> loader = Loader::GetLoader(file);
|
||||
if (!loader)
|
||||
std::unique_ptr<Loader::AppLoader> loader = Loader::GetLoader(system, file);
|
||||
if (!loader) {
|
||||
continue;
|
||||
}
|
||||
|
||||
std::vector<u8> icon;
|
||||
std::string name;
|
||||
u64 program_id = 0;
|
||||
loader->ReadProgramId(program_id);
|
||||
|
||||
const PatchManager patch{program_id};
|
||||
const PatchManager patch{program_id, system.GetFileSystemController(),
|
||||
system.GetContentProvider()};
|
||||
const auto control = cache.GetEntry(game.title_id, ContentRecordType::Control);
|
||||
if (control != nullptr)
|
||||
if (control != nullptr) {
|
||||
GetMetadataFromControlNCA(patch, *control, icon, name);
|
||||
}
|
||||
|
||||
emit EntryReady(MakeGameListEntry(file->GetFullPath(), name, icon, *loader, program_id,
|
||||
compatibility_list, patch),
|
||||
@@ -280,9 +283,11 @@ void GameListWorker::AddTitlesToGameList(GameListDir* parent_dir) {
|
||||
|
||||
void GameListWorker::ScanFileSystem(ScanTarget target, const std::string& dir_path,
|
||||
unsigned int recursion, GameListDir* parent_dir) {
|
||||
const auto callback = [this, target, recursion,
|
||||
parent_dir](u64* num_entries_out, const std::string& directory,
|
||||
const std::string& virtual_name) -> bool {
|
||||
auto& system = Core::System::GetInstance();
|
||||
|
||||
const auto callback = [this, target, recursion, parent_dir,
|
||||
&system](u64* num_entries_out, const std::string& directory,
|
||||
const std::string& virtual_name) -> bool {
|
||||
if (stop_processing) {
|
||||
// Breaks the callback loop.
|
||||
return false;
|
||||
@@ -293,7 +298,7 @@ void GameListWorker::ScanFileSystem(ScanTarget target, const std::string& dir_pa
|
||||
if (!is_dir &&
|
||||
(HasSupportedFileExtension(physical_name) || IsExtractedNCAMain(physical_name))) {
|
||||
const auto file = vfs->OpenFile(physical_name, FileSys::Mode::Read);
|
||||
auto loader = Loader::GetLoader(file);
|
||||
auto loader = Loader::GetLoader(system, file);
|
||||
if (!loader) {
|
||||
return true;
|
||||
}
|
||||
@@ -331,7 +336,8 @@ void GameListWorker::ScanFileSystem(ScanTarget target, const std::string& dir_pa
|
||||
std::string name = " ";
|
||||
[[maybe_unused]] const auto res3 = loader->ReadTitle(name);
|
||||
|
||||
const FileSys::PatchManager patch{program_id};
|
||||
const FileSys::PatchManager patch{program_id, system.GetFileSystemController(),
|
||||
system.GetContentProvider()};
|
||||
|
||||
emit EntryReady(MakeGameListEntry(physical_name, name, icon, *loader, program_id,
|
||||
compatibility_list, patch),
|
||||
|
@@ -1090,9 +1090,9 @@ void GMainWindow::BootGame(const QString& filename) {
|
||||
StoreRecentFile(filename); // Put the filename on top of the list
|
||||
|
||||
u64 title_id{0};
|
||||
|
||||
auto& system = Core::System::GetInstance();
|
||||
const auto v_file = Core::GetGameFileFromPath(vfs, filename.toUtf8().constData());
|
||||
const auto loader = Loader::GetLoader(v_file);
|
||||
const auto loader = Loader::GetLoader(system, v_file);
|
||||
if (!(loader == nullptr || loader->ReadProgramId(title_id) != Loader::ResultStatus::Success)) {
|
||||
// Load per game settings
|
||||
Config per_game_config(fmt::format("{:016X}", title_id), Config::ConfigType::PerGameConfig);
|
||||
@@ -1144,9 +1144,13 @@ void GMainWindow::BootGame(const QString& filename) {
|
||||
|
||||
std::string title_name;
|
||||
std::string title_version;
|
||||
const auto res = Core::System::GetInstance().GetGameName(title_name);
|
||||
const auto res = system.GetGameName(title_name);
|
||||
|
||||
const auto metadata = FileSys::PatchManager(title_id).GetControlMetadata();
|
||||
const auto metadata = [&system, title_id] {
|
||||
const FileSys::PatchManager pm(title_id, system.GetFileSystemController(),
|
||||
system.GetContentProvider());
|
||||
return pm.GetControlMetadata();
|
||||
}();
|
||||
if (metadata.first != nullptr) {
|
||||
title_version = metadata.first->GetVersionString();
|
||||
title_name = metadata.first->GetApplicationName();
|
||||
@@ -1157,7 +1161,7 @@ void GMainWindow::BootGame(const QString& filename) {
|
||||
LOG_INFO(Frontend, "Booting game: {:016X} | {} | {}", title_id, title_name, title_version);
|
||||
UpdateWindowTitle(title_name, title_version);
|
||||
|
||||
loading_screen->Prepare(Core::System::GetInstance().GetAppLoader());
|
||||
loading_screen->Prepare(system.GetAppLoader());
|
||||
loading_screen->show();
|
||||
|
||||
emulation_running = true;
|
||||
@@ -1276,16 +1280,18 @@ void GMainWindow::OnGameListOpenFolder(u64 program_id, GameListOpenTarget target
|
||||
const std::string& game_path) {
|
||||
std::string path;
|
||||
QString open_target;
|
||||
auto& system = Core::System::GetInstance();
|
||||
|
||||
const auto [user_save_size, device_save_size] = [this, &program_id, &game_path] {
|
||||
FileSys::PatchManager pm{program_id};
|
||||
const auto [user_save_size, device_save_size] = [this, &game_path, &program_id, &system] {
|
||||
const FileSys::PatchManager pm{program_id, system.GetFileSystemController(),
|
||||
system.GetContentProvider()};
|
||||
const auto control = pm.GetControlMetadata().first;
|
||||
if (control != nullptr) {
|
||||
return std::make_pair(control->GetDefaultNormalSaveSize(),
|
||||
control->GetDeviceSaveDataSize());
|
||||
} else {
|
||||
const auto file = Core::GetGameFileFromPath(vfs, game_path);
|
||||
const auto loader = Loader::GetLoader(file);
|
||||
const auto loader = Loader::GetLoader(system, file);
|
||||
|
||||
FileSys::NACP nacp{};
|
||||
loader->ReadControlData(nacp);
|
||||
@@ -1612,7 +1618,8 @@ void GMainWindow::OnGameListDumpRomFS(u64 program_id, const std::string& game_pa
|
||||
"cancelled the operation."));
|
||||
};
|
||||
|
||||
const auto loader = Loader::GetLoader(vfs->OpenFile(game_path, FileSys::Mode::Read));
|
||||
auto& system = Core::System::GetInstance();
|
||||
const auto loader = Loader::GetLoader(system, vfs->OpenFile(game_path, FileSys::Mode::Read));
|
||||
if (loader == nullptr) {
|
||||
failed();
|
||||
return;
|
||||
@@ -1624,7 +1631,7 @@ void GMainWindow::OnGameListDumpRomFS(u64 program_id, const std::string& game_pa
|
||||
return;
|
||||
}
|
||||
|
||||
const auto& installed = Core::System::GetInstance().GetContentProvider();
|
||||
const auto& installed = system.GetContentProvider();
|
||||
const auto romfs_title_id = SelectRomFSDumpTarget(installed, program_id);
|
||||
|
||||
if (!romfs_title_id) {
|
||||
@@ -1639,7 +1646,7 @@ void GMainWindow::OnGameListDumpRomFS(u64 program_id, const std::string& game_pa
|
||||
|
||||
if (*romfs_title_id == program_id) {
|
||||
const u64 ivfc_offset = loader->ReadRomFSIVFCOffset();
|
||||
FileSys::PatchManager pm{program_id};
|
||||
const FileSys::PatchManager pm{program_id, system.GetFileSystemController(), installed};
|
||||
romfs = pm.PatchRomFS(file, ivfc_offset, FileSys::ContentRecordType::Program);
|
||||
} else {
|
||||
romfs = installed.GetEntry(*romfs_title_id, FileSys::ContentRecordType::Data)->GetRomFS();
|
||||
@@ -1756,7 +1763,8 @@ void GMainWindow::OnGameListShowList(bool show) {
|
||||
void GMainWindow::OnGameListOpenPerGameProperties(const std::string& file) {
|
||||
u64 title_id{};
|
||||
const auto v_file = Core::GetGameFileFromPath(vfs, file);
|
||||
const auto loader = Loader::GetLoader(v_file);
|
||||
const auto loader = Loader::GetLoader(Core::System::GetInstance(), v_file);
|
||||
|
||||
if (loader == nullptr || loader->ReadProgramId(title_id) != Loader::ResultStatus::Success) {
|
||||
QMessageBox::information(this, tr("Properties"),
|
||||
tr("The game properties could not be loaded."));
|
||||
|
Reference in New Issue
Block a user