From 4267169006fc4ed43f6d810e08426fb8058de9c0 Mon Sep 17 00:00:00 2001 From: kraibse <33869366+kraibse@users.noreply.github.com> Date: Mon, 2 Nov 2026 17:23:47 +0100 Subject: file_sys: let the NUP packer override and probe the name, icon and version PackOptions::metadata overrides the title name, icon and display version found in the dump. A version override is written to the base and to the newest update, since the NUP loader reads the version from the newest update first. ProbeMetadata reads what a dump would be packed with, the version coming from the newest update that reports one, else the base. Assisted-by: Claude Sonnet 5.5 (wrote the metadata overrides, ProbeMetadata and their test) --- src/tests/core/nup_writer.cpp | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'src/tests/core/nup_writer.cpp') diff --git a/src/tests/core/nup_writer.cpp b/src/tests/core/nup_writer.cpp index ce1a0717ed..bb0148139b 100644 --- a/src/tests/core/nup_writer.cpp +++ b/src/tests/core/nup_writer.cpp @@ -390,3 +390,34 @@ TEST_CASE("NUP output is reproducible", "[nup]") { } REQUIRE(hex == "df8446903ab2c39a51af0304935eb4aa5d8ead105440976ceae7ab97133f6143"); } + +TEST_CASE("NUP writes metadata overrides to the base and the newest update", "[nup]") { + TempDir t; + const auto root = t.path / "Game"; + MakeDump(root); + const auto probed = FileSys::Nup::ProbeMetadata(root); + REQUIRE(probed.title_name.empty()); + REQUIRE(probed.icon.empty()); + // The version comes from the RomFS resource size table of the newest update that has one. + REQUIRE(probed.display_version == "1.1.0"); + REQUIRE(probed.version_source == "update 65536"); + + FileSys::Nup::PackOptions options; + options.metadata.title_name = "Custom Name"; + options.metadata.icon = {0xFF, 0xD8, 0xFF, 0xD9}; + options.metadata.display_version = "9.8.7"; + const auto archive = t.path / "Game.nup"; + REQUIRE(FileSys::Nup::PackDump(root, archive, options) == FileSys::Nup::PackResult::Success); + + FileSys::RealVfsFilesystem real; + NupContainer nup{real.OpenFile(archive.string(), FileSys::OpenMode::Read)}; + REQUIRE(nup.GetStatus() == Loader::ResultStatus::Success); + const auto& packages = nup.GetPackages(); + REQUIRE(packages.size() == 4); + REQUIRE(packages[0].title_name == "Custom Name"); + REQUIRE(packages[0].icon == options.metadata.icon); + REQUIRE(packages[0].display_version == "9.8.7"); + REQUIRE(packages[2].version == 131072); + REQUIRE(packages[2].display_version == "9.8.7"); + REQUIRE(packages[1].display_version == "1.1.0"); +} -- cgit v1.2.3 From 8185d45d5d9d16bca860542f98d8a026e286dbf6 Mon Sep 17 00:00:00 2001 From: kraibse <33869366+kraibse@users.noreply.github.com> Date: Mon, 2 Nov 2026 17:23:47 +0100 Subject: loader: read the display version from GameDataList.Product.NNN too Donkey Kong Bananza names its resource size table without a version, so no version was found for a loose dump. Its GameData/GameDataList.Product .320.* files carry it (3.2.0), so read them as well and use the newest tag from either source. Assisted-by: Claude Sonnet 5.5 (wrote the GameDataList version lookup and its test) --- src/core/loader/deconstructed_rom_directory.cpp | 47 ++++++++++++++++--------- src/tests/core/nup_writer.cpp | 22 ++++++++++++ 2 files changed, 52 insertions(+), 17 deletions(-) (limited to 'src/tests/core/nup_writer.cpp') diff --git a/src/core/loader/deconstructed_rom_directory.cpp b/src/core/loader/deconstructed_rom_directory.cpp index 60cf87db14..4b1168a59b 100644 --- a/src/core/loader/deconstructed_rom_directory.cpp +++ b/src/core/loader/deconstructed_rom_directory.cpp @@ -117,27 +117,19 @@ FileSys::VirtualFile FindLooseRomFS(const FileSys::VirtualDir& exefs_dir) { return nullptr; } -// The display version of a dump without control data, from its RomFS: Nintendo EPD titles name -// their resource size tables after it (System/Resource/ResourceSizeTable.Product.180.* in Mario -// Kart World 1.8.0). A hotfix can keep its minor version's tables (Product.110 in a 1.1.1). -std::string RomFSProductVersion(const FileSys::VirtualDir& romfs_dir) { - if (romfs_dir == nullptr) { - return {}; - } - const auto system_dir = romfs_dir->GetSubdirectory("System"); - const auto resource_dir = system_dir != nullptr ? system_dir->GetSubdirectory("Resource") : nullptr; - if (resource_dir == nullptr) { - return {}; - } - constexpr std::string_view Prefix = "ResourceSizeTable.Product."; +// The newest three-digit tag in a directory's file names of the form NNN.. +std::string NewestProductTag(const FileSys::VirtualDir& dir, std::string_view prefix) { std::string best; - for (const auto& file : resource_dir->GetFiles()) { + if (dir == nullptr) { + return best; + } + for (const auto& file : dir->GetFiles()) { const std::string file_name = file->GetName(); - if (!file_name.starts_with(Prefix) || file_name.size() < Prefix.size() + 4) { + if (!file_name.starts_with(prefix) || file_name.size() < prefix.size() + 4) { continue; } - const std::string_view digits = std::string_view{file_name}.substr(Prefix.size(), 3); - if (file_name[Prefix.size() + 3] != '.' || + const std::string_view digits = std::string_view{file_name}.substr(prefix.size(), 3); + if (file_name[prefix.size() + 3] != '.' || !std::all_of(digits.begin(), digits.end(), [](char c) { return c >= '0' && c <= '9'; })) { continue; } @@ -145,6 +137,27 @@ std::string RomFSProductVersion(const FileSys::VirtualDir& romfs_dir) { best = version; } } + return best; +} + +// The display version of a dump without control data, from its RomFS: Nintendo EPD titles name +// their resource size tables after it (System/Resource/ResourceSizeTable.Product.180.* in Mario +// Kart World 1.8.0), and some name their game data list instead (GameData/GameDataList.Product.320.* +// in Donkey Kong Bananza 3.2.0). A hotfix can keep its minor version's tables (Product.110 in a +// 1.1.1). +std::string RomFSProductVersion(const FileSys::VirtualDir& romfs_dir) { + if (romfs_dir == nullptr) { + return {}; + } + const auto system_dir = romfs_dir->GetSubdirectory("System"); + std::string best = NewestProductTag( + system_dir != nullptr ? system_dir->GetSubdirectory("Resource") : nullptr, + "ResourceSizeTable.Product."); + if (const auto game_data = NewestProductTag(romfs_dir->GetSubdirectory("GameData"), + "GameDataList.Product."); + game_data > best) { + best = game_data; + } if (best.empty()) { return {}; } diff --git a/src/tests/core/nup_writer.cpp b/src/tests/core/nup_writer.cpp index bb0148139b..c0230d8694 100644 --- a/src/tests/core/nup_writer.cpp +++ b/src/tests/core/nup_writer.cpp @@ -421,3 +421,25 @@ TEST_CASE("NUP writes metadata overrides to the base and the newest update", "[n REQUIRE(packages[2].display_version == "9.8.7"); REQUIRE(packages[1].display_version == "1.1.0"); } + +TEST_CASE("NUP probes the version from the game data list tag", "[nup]") { + TempDir t; + const auto root = t.path / "Game"; + Put(root / "base/exefs/main", "main"); + Put(root / "base/exefs/main.npdm", Npdm(TitleId)); + Put(root / "base/romfs/GameData/GameDataList.Product.100.byml.zs", "x"); + Put(root / "base/romfs/System/Resource/ResourceSizeTable.Product.rsizetable.zs", "x"); + Put(root / "updates/458752/exefs/main", "main"); + Put(root / "updates/458752/exefs/main.npdm", Npdm(TitleId)); + Put(root / "updates/458752/romfs/GameData/GameDataList.Product.320.byml.zs", "x"); + Put(root / "updates/458752/romfs/GameData/GameDataList.Product.320.revision.txt", "1"); + + auto probed = FileSys::Nup::ProbeMetadata(root); + REQUIRE(probed.display_version == "3.2.0"); + REQUIRE(probed.version_source == "update 458752"); + + fs::remove_all(root / "updates"); + probed = FileSys::Nup::ProbeMetadata(root); + REQUIRE(probed.display_version == "1.0.0"); + REQUIRE(probed.version_source == "base"); +} -- cgit v1.2.3