mirror of
https://git.suyu.dev/suyu/suyu.git
synced 2024-11-27 09:12:46 +01:00
game_list: Populate control data from installed NAND
This commit is contained in:
parent
e5504a060d
commit
10812f8407
2 changed files with 35 additions and 31 deletions
|
@ -403,6 +403,28 @@ void GameList::RefreshGameDirectory() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void GetMetadataFromControlNCA(const std::shared_ptr<FileSys::NCA>& nca,
|
||||||
|
std::vector<u8>& icon, std::string& name) {
|
||||||
|
const auto control_dir = FileSys::ExtractRomFS(nca->GetRomFS());
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void GameListWorker::AddFstEntriesToGameList(const std::string& dir_path, unsigned int recursion) {
|
void GameListWorker::AddFstEntriesToGameList(const std::string& dir_path, unsigned int recursion) {
|
||||||
const auto usernand = Service::FileSystem::GetUserNANDContents();
|
const auto usernand = Service::FileSystem::GetUserNANDContents();
|
||||||
const auto installed_games = usernand->ListEntriesFilter(FileSys::TitleType::Application,
|
const auto installed_games = usernand->ListEntriesFilter(FileSys::TitleType::Application,
|
||||||
|
@ -421,22 +443,8 @@ void GameListWorker::AddFstEntriesToGameList(const std::string& dir_path, unsign
|
||||||
|
|
||||||
const auto& control =
|
const auto& control =
|
||||||
usernand->GetEntry(game.title_id, FileSys::ContentRecordType::Control);
|
usernand->GetEntry(game.title_id, FileSys::ContentRecordType::Control);
|
||||||
if (control != nullptr) {
|
if (control != nullptr)
|
||||||
const auto control_dir = FileSys::ExtractRomFS(control->GetRomFS());
|
GetMetadataFromControlNCA(control, icon, name);
|
||||||
|
|
||||||
const auto nacp_file = control_dir->GetFile("control.nacp");
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
emit EntryReady({
|
emit EntryReady({
|
||||||
new GameListItemPath(
|
new GameListItemPath(
|
||||||
FormatGameName(file->GetFullPath()), icon, QString::fromStdString(name),
|
FormatGameName(file->GetFullPath()), icon, QString::fromStdString(name),
|
||||||
|
@ -450,6 +458,15 @@ void GameListWorker::AddFstEntriesToGameList(const std::string& dir_path, unsign
|
||||||
|
|
||||||
boost::container::flat_map<u64, std::shared_ptr<FileSys::NCA>> nca_control_map;
|
boost::container::flat_map<u64, std::shared_ptr<FileSys::NCA>> nca_control_map;
|
||||||
|
|
||||||
|
const auto control_data = usernand->ListEntriesFilter(FileSys::TitleType::Application,
|
||||||
|
FileSys::ContentRecordType::Control);
|
||||||
|
|
||||||
|
for (const auto& entry : control_data) {
|
||||||
|
const auto nca = usernand->GetEntry(entry);
|
||||||
|
if (nca != nullptr)
|
||||||
|
nca_control_map.insert_or_assign(entry.title_id, nca);
|
||||||
|
}
|
||||||
|
|
||||||
const auto nca_control_callback =
|
const auto nca_control_callback =
|
||||||
[this, &nca_control_map](u64* num_entries_out, const std::string& directory,
|
[this, &nca_control_map](u64* num_entries_out, const std::string& directory,
|
||||||
const std::string& virtual_name) -> bool {
|
const std::string& virtual_name) -> bool {
|
||||||
|
@ -503,20 +520,7 @@ void GameListWorker::AddFstEntriesToGameList(const std::string& dir_path, unsign
|
||||||
// Use from metadata pool.
|
// Use from metadata pool.
|
||||||
if (nca_control_map.find(program_id) != nca_control_map.end()) {
|
if (nca_control_map.find(program_id) != nca_control_map.end()) {
|
||||||
const auto nca = nca_control_map[program_id];
|
const auto nca = nca_control_map[program_id];
|
||||||
const auto control_dir = FileSys::ExtractRomFS(nca->GetRomFS());
|
GetMetadataFromControlNCA(nca, icon, name);
|
||||||
|
|
||||||
const auto nacp_file = control_dir->GetFile("control.nacp");
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -682,7 +682,7 @@ void GMainWindow::OnMenuInstallToNAND() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (index >= 5)
|
if (index >= 5)
|
||||||
index += 0x80;
|
index += 0x7B;
|
||||||
|
|
||||||
if (Service::FileSystem::GetUserNANDContents()->InstallEntry(
|
if (Service::FileSystem::GetUserNANDContents()->InstallEntry(
|
||||||
nca, static_cast<FileSys::TitleType>(index))) {
|
nca, static_cast<FileSys::TitleType>(index))) {
|
||||||
|
|
Loading…
Reference in a new issue