patch_manager: Centralize Control-type NCA parsing

This commit is contained in:
Zach Hilman
2018-09-03 18:57:52 -04:00
parent 92e26df00f
commit 23a16c1720
6 changed files with 88 additions and 79 deletions

View File

@ -486,29 +486,11 @@ void GameList::RefreshGameDirectory() {
static void GetMetadataFromControlNCA(const FileSys::PatchManager& patch_manager,
const std::shared_ptr<FileSys::NCA>& nca,
std::vector<u8>& icon, std::string& name) {
const auto romfs = patch_manager.PatchRomFS(nca->GetRomFS(), nca->GetBaseIVFCOffset(),
FileSys::ContentRecordType::Control);
if (romfs == nullptr)
return;
const auto control_dir = FileSys::ExtractRomFS(romfs);
if (control_dir == nullptr)
return;
const auto nacp_file = control_dir->GetFile("control.nacp");
if (nacp_file == nullptr)
return;
FileSys::NACP nacp(nacp_file);
name = nacp.GetApplicationName();
FileSys::VirtualFile icon_file = nullptr;
for (const auto& language : FileSys::LANGUAGE_NAMES) {
icon_file = control_dir->GetFile("icon_" + std::string(language) + ".dat");
if (icon_file != nullptr) {
icon = icon_file->ReadAllBytes();
break;
}
}
auto [nacp, icon_file] = patch_manager.ParseControlNCA(nca);
if (icon_file != nullptr)
icon = icon_file->ReadAllBytes();
if (nacp != nullptr)
name = nacp->GetApplicationName();
}
GameListWorker::GameListWorker(

View File

@ -592,8 +592,16 @@ void GMainWindow::BootGame(const QString& filename) {
std::string title_name;
const auto res = Core::System::GetInstance().GetGameName(title_name);
if (res != Loader::ResultStatus::Success)
title_name = FileUtil::GetFilename(filename.toStdString());
if (res != Loader::ResultStatus::Success) {
const u64 program_id = Core::System::GetInstance().CurrentProcess()->program_id;
const auto [nacp, icon_file] = FileSys::PatchManager(program_id).GetControlMetadata();
if (nacp != nullptr)
title_name = nacp->GetApplicationName();
if (title_name.empty())
title_name = FileUtil::GetFilename(filename.toStdString());
}
setWindowTitle(QString("yuzu %1| %4 | %2-%3")
.arg(Common::g_build_name, Common::g_scm_branch, Common::g_scm_desc,