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:
Lioncash
2020-11-18 07:53:10 -05:00
parent abda366362
commit 6f8a06bac5
26 changed files with 259 additions and 157 deletions

View File

@ -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."));