fix(xbox): a bundle with resource packages installs from its application package (#3172)

* fix(xbox): a bundle with resource packages installs from its application package

* fix(xbox): repair the patch hunk for the hoist tests
This commit is contained in:
Kurt Himebauch authored and GitHub committed 2026-11-24 18:32:38 -05:00
1 parent 826853fff5
commit 3e1fc3e60e
1 file changed
+93 -3
+93 -3
View File
@@ -154,7 +154,7 @@ new file mode 100755
index 0000000..d43c5fc
--- /dev/null
+++ b/crates/xodus-cli/src/commands/legacy_install.rs
@@ -0,0 +1,1285 @@
@@ -0,0 +1,1375 @@
+//! Installs a legacy Store title: resolve, license, download, extract.
+//!
+//! `streaming` only understands MSIXVC, where the container *is* the game and
@@ -1108,10 +1108,14 @@ index 0000000..d43c5fc
+ if candidates.is_empty() {
+ return Ok(());
+ }
+ let found = candidates.len();
+ let applications = application_packages(candidates.clone());
+ if !applications.is_empty() || found != 1 {
+ candidates = applications;
+ }
+ if candidates.len() != 1 {
+ return Err(format!(
+ "Extraction left {} package folders; expected exactly one",
+ candidates.len()
+ "Extraction left {found} package folders; expected exactly one application package"
+ ));
+ }
+ let inner = candidates.remove(0);
@@ -1153,6 +1157,39 @@ index 0000000..d43c5fc
+ Ok(())
+}
+
+/// A bundle can extract its application package beside resource packages (languages,
+/// scales) that declare no application; only the application package holds the game.
+/// When several declare one, the x64 package wins if it is the only x64 one.
+fn application_packages(candidates: Vec<PathBuf>) -> Vec<PathBuf> {
+ let applications: Vec<PathBuf> = candidates.into_iter().filter(|folder| declares_application(folder)).collect();
+ if applications.len() > 1 {
+ let x64: Vec<PathBuf> = applications
+ .iter()
+ .filter(|folder| manifest_text(folder).contains("processorarchitecture=\"x64\""))
+ .cloned()
+ .collect();
+ if x64.len() == 1 {
+ return x64;
+ }
+ }
+ applications
+}
+
+fn manifest_text(folder: &Path) -> String {
+ [LEGACY_MANIFEST, MANIFEST]
+ .iter()
+ .filter_map(|name| std::fs::read_to_string(folder.join(name)).ok())
+ .collect::<Vec<_>>()
+ .join("
+")
+ .to_ascii_lowercase()
+}
+
+fn declares_application(folder: &Path) -> bool {
+ let text = manifest_text(folder);
+ text.contains("<application ") || text.contains("<executable ")
+}
+
+/// Files a package container carries about itself. A bundle leaves its own copies at
+/// the top of the game folder, so the lifted package's copies replace them.
+fn is_package_metadata(name: &std::ffi::OsStr) -> bool {
@@ -1334,6 +1371,59 @@ index 0000000..d43c5fc
+ }
+
+ #[test]
+ fn hoist_lifts_the_application_package_and_leaves_resource_packages() {
+ let root = scratch("resource-packages");
+ let app = root.join("Game.x64");
+ std::fs::create_dir_all(&app).unwrap();
+ std::fs::write(app.join(LEGACY_MANIFEST), "<Package><Applications><Application Id=\"App\"/></Applications></Package>").unwrap();
+ std::fs::write(app.join("Game.exe"), b"MZ").unwrap();
+ for language in ["Game.language-de", "Game.language-fr", "Game.scale-200"] {
+ let resource = root.join(language);
+ std::fs::create_dir_all(&resource).unwrap();
+ std::fs::write(resource.join(LEGACY_MANIFEST), "<Package><Resources/></Package>").unwrap();
+ }
+
+ hoist(&root).unwrap();
+
+ assert!(root.join("Game.exe").is_file());
+ assert!(root.join(LEGACY_MANIFEST).is_file());
+ assert!(root.join("Game.language-de").join(LEGACY_MANIFEST).is_file());
+ std::fs::remove_dir_all(&root).ok();
+ }
+
+ #[test]
+ fn hoist_prefers_the_x64_package_when_several_declare_an_application() {
+ let root = scratch("two-applications");
+ for (name, arch) in [("Game.x86", "x86"), ("Game.x64", "x64")] {
+ let folder = root.join(name);
+ std::fs::create_dir_all(&folder).unwrap();
+ let manifest = format!("<Package><Identity ProcessorArchitecture=\"{arch}\"/><Applications><Application Id=\"App\"/></Applications></Package>");
+ std::fs::write(folder.join(LEGACY_MANIFEST), manifest).unwrap();
+ std::fs::write(folder.join(format!("{arch}.exe")), b"MZ").unwrap();
+ }
+
+ hoist(&root).unwrap();
+
+ assert!(root.join("x64.exe").is_file());
+ assert!(!root.join("x86.exe").exists());
+ std::fs::remove_dir_all(&root).ok();
+ }
+
+ #[test]
+ fn hoist_still_refuses_when_several_packages_declare_an_application() {
+ let root = scratch("ambiguous-applications");
+ for name in ["One", "Two"] {
+ let folder = root.join(name);
+ std::fs::create_dir_all(&folder).unwrap();
+ std::fs::write(folder.join(LEGACY_MANIFEST), "<Package><Applications><Application Id=\"App\"/></Applications></Package>").unwrap();
+ }
+
+ assert!(hoist(&root).unwrap_err().contains("expected exactly one"));
+ std::fs::remove_dir_all(&root).ok();
+ }
+
+
+ #[test]
+ fn hoist_still_refuses_to_overwrite_a_game_file_on_a_fresh_install() {
+ let root = scratch("fresh-collision");
+ std::fs::write(root.join("Game.exe"), b"other").unwrap();