diff --git a/app/src/main/java/com/droiddeck/launcher/stores/xbox/XboxManifest.kt b/app/src/main/java/com/droiddeck/launcher/stores/xbox/XboxManifest.kt
index bb8bc0408d..d966dea1e8 100644
--- a/app/src/main/java/com/droiddeck/launcher/stores/xbox/XboxManifest.kt
+++ b/app/src/main/java/com/droiddeck/launcher/stores/xbox/XboxManifest.kt
@@ -102,8 +102,29 @@ internal object XboxManifest {
file = matches.single()
}
require(file.canonicalPath.startsWith(folder.canonicalPath + File.separator))
- if (file.isFile) return file.relativeTo(folder).invariantSeparatorsPath
+ if (file.isFile) return forwarded(folder, file) ?: file.relativeTo(folder).invariantSeparatorsPath
}
error("The Xbox package has no supported PC launch executable.")
}
+
+ private fun forwarded(folder: File, launcher: File): String? = try {
+ val arguments = File(launcher.parentFile, launcher.nameWithoutExtension + "LaunchArguments.txt")
+ if (!arguments.isFile || arguments.length() > 65_536) null
+ else arguments.readLines().firstNotNullOfOrNull { line ->
+ line.trim().takeIf { it.startsWith("exe=", ignoreCase = true) }?.substring(4)?.trim()
+ }?.takeIf { it.isNotEmpty() && !it.contains(':') }?.let { target -> located(folder.canonicalFile, launcher.parentFile.canonicalFile, target) }
+ } catch (_: java.io.IOException) {
+ null
+ }
+
+ private fun located(root: File, start: File, target: String): String? {
+ var file = start
+ for (part in target.split('/', '\\').filter { it.isNotEmpty() && it != "." }) {
+ file = if (part == "..") file.parentFile ?: return null
+ else file.listFiles().orEmpty().filter { it.name.equals(part, true) }.singleOrNull() ?: return null
+ }
+ val resolved = file.canonicalFile
+ if (!resolved.isFile || !resolved.path.startsWith(root.path + File.separator) || !resolved.extension.equals("exe", true)) return null
+ return resolved.relativeTo(root).invariantSeparatorsPath
+ }
}
diff --git a/app/src/test/java/com/droiddeck/launcher/stores/xbox/XboxManifestTest.kt b/app/src/test/java/com/droiddeck/launcher/stores/xbox/XboxManifestTest.kt
index d2396db935..d23072471a 100644
--- a/app/src/test/java/com/droiddeck/launcher/stores/xbox/XboxManifestTest.kt
+++ b/app/src/test/java/com/droiddeck/launcher/stores/xbox/XboxManifestTest.kt
@@ -16,6 +16,46 @@ class XboxManifestTest {
java.io.File(root, "MicrosoftGame.Config").writeText("")
assertEquals("Bin/Game.exe", XboxInstaller.executable(root))
}
+ @Test fun aLauncherMenuIsSkippedForTheProgramItNames() {
+ val root = temporary.newFolder()
+ java.io.File(root, "EmuMenu").mkdir()
+ java.io.File(root, "EmuMenu/EmuMenu.exe").writeText("menu")
+ java.io.File(root, "Emu.exe").writeText("emulator")
+ java.io.File(root, "MicrosoftGame.config").writeText("")
+ java.io.File(root, "EmuMenu/EmuMenuLaunchArguments.txt").writeText("exe=..\\Emu.exe\r\ntitlename=Game\r\n")
+ assertEquals("Emu.exe", XboxInstaller.executable(root))
+ java.io.File(root, "EmuMenu/EmuMenuLaunchArguments.txt").writeText("exe=..\\..\\outside.exe\r\n")
+ assertEquals("EmuMenu/EmuMenu.exe", XboxInstaller.executable(root))
+ java.io.File(root, "EmuMenu/EmuMenuLaunchArguments.txt").writeText("titlename=Game\r\n")
+ assertEquals("EmuMenu/EmuMenu.exe", XboxInstaller.executable(root))
+ java.io.File(root, "EmuMenu/EmuMenuLaunchArguments.txt").writeText("exe=..\\EMU.EXE\r\n")
+ assertEquals("Emu.exe", XboxInstaller.executable(root))
+ java.io.File(root, "emu.exe").writeText("other")
+ if (root.listFiles().orEmpty().count { it.name.equals("emu.exe", true) } == 2)
+ assertEquals("EmuMenu/EmuMenu.exe", XboxInstaller.executable(root))
+ }
+ @Test fun anUnreadableForwardingFileFallsBackToTheDeclaredProgram() {
+ val root = temporary.newFolder()
+ java.io.File(root, "EmuMenu").mkdir()
+ java.io.File(root, "EmuMenu/EmuMenu.exe").writeText("menu")
+ java.io.File(root, "Emu.exe").writeText("emulator")
+ java.io.File(root, "MicrosoftGame.config").writeText("")
+ val arguments = java.io.File(root, "EmuMenu/EmuMenuLaunchArguments.txt").apply { writeText("exe=..\\Emu.exe\r\n") }
+ org.junit.Assume.assumeTrue(arguments.setReadable(false, false) && !arguments.canRead())
+ try { assertEquals("EmuMenu/EmuMenu.exe", XboxInstaller.executable(root)) } finally { arguments.setReadable(true, false) }
+ }
+ @Test fun aForwardedProgramStaysRelativeWhenTheFolderIsReachedThroughALink() {
+ val real = temporary.newFolder()
+ java.io.File(real, "EmuMenu").mkdir()
+ java.io.File(real, "EmuMenu/EmuMenu.exe").writeText("menu")
+ java.io.File(real, "Emu.exe").writeText("emulator")
+ java.io.File(real, "MicrosoftGame.config").writeText("")
+ java.io.File(real, "EmuMenu/EmuMenuLaunchArguments.txt").writeText("exe=..\\Emu.exe\r\n")
+ val link = java.io.File(temporary.root, "linked")
+ val linked = runCatching { java.nio.file.Files.createSymbolicLink(link.toPath(), real.toPath()) }.isSuccess
+ org.junit.Assume.assumeTrue(linked)
+ assertEquals("Emu.exe", XboxInstaller.executable(link))
+ }
@Test fun rejectsTraversalAndExternalEntities() {
for (xml in listOf("",
"]>&external;",
diff --git a/tools/linuxfs/overlay/usr/local/bin/droiddeck-xbox b/tools/linuxfs/overlay/usr/local/bin/droiddeck-xbox
index f15e0b694a..ca7032cdc9 100755
--- a/tools/linuxfs/overlay/usr/local/bin/droiddeck-xbox
+++ b/tools/linuxfs/overlay/usr/local/bin/droiddeck-xbox
@@ -1,4 +1,5 @@
#!/usr/bin/python3
+import hashlib
import hmac
import json
import os
@@ -11,6 +12,7 @@ import subprocess
import sys
import tempfile
import threading
+import xml.etree.ElementTree as ElementTree
BIN = Path(__file__).resolve().parent
RUNTIME = Path('/usr/local/lib/droiddeck-xbox')
@@ -137,6 +139,117 @@ def register_classes(proton, prefix, env):
print('droiddeck-xbox: Windows Runtime class registration failed; launching without it', file=sys.stderr)
+def game_config(exe):
+ path = Path(exe)
+ if not path.is_absolute():
+ return None
+ for folder in list(path.parents)[:4]:
+ config = folder / 'MicrosoftGame.config'
+ if config.is_file():
+ return config
+ return None
+
+
+def windows_arguments(text):
+ arguments, current, quoted, started, at = [], [], False, False, 0
+ while at < len(text):
+ char = text[at]
+ if char == '\\':
+ run = len(text) - at - len(text[at:].lstrip('\\'))
+ at += run
+ if at < len(text) and text[at] == '"':
+ current.append('\\' * (run // 2))
+ if run % 2:
+ current.append('"')
+ at += 1
+ else:
+ current.append('\\' * run)
+ started = True
+ continue
+ if char == '"':
+ if quoted and text[at + 1:at + 2] == '"':
+ current.append('"')
+ at += 2
+ continue
+ quoted = not quoted
+ started = True
+ elif char in ' \t' and not quoted:
+ if started:
+ arguments.append(''.join(current))
+ current, started = [], False
+ else:
+ current.append(char)
+ started = True
+ at += 1
+ if started:
+ arguments.append(''.join(current))
+ return arguments
+
+
+def install_actions(config):
+ try:
+ root = ElementTree.fromstring(config.read_bytes())
+ except (OSError, ElementTree.ParseError):
+ return []
+ actions = []
+ for registration in root.iter():
+ if registration.tag.rsplit('}', 1)[-1] != 'CustomInstallActions':
+ continue
+ folder = next((node.text or '' for node in registration if node.tag.rsplit('}', 1)[-1] == 'Folder'), '')
+ for node in registration.iter():
+ if node.tag.rsplit('}', 1)[-1] != 'InstallAction':
+ continue
+ name, file = node.get('Name', ''), node.get('File', '')
+ parts = [part for part in (folder.strip() + '\\' + file).replace('/', '\\').split('\\') if part]
+ if not name or not file or any(part in ('.', '..') or ':' in part for part in parts):
+ continue
+ target = config.parent.joinpath(*parts)
+ try:
+ inside = target.resolve().is_relative_to(config.parent.resolve())
+ except OSError:
+ inside = False
+ if inside and target.is_file() and target.suffix.lower() in ('.msi', '.exe'):
+ actions.append((name, target, windows_arguments(node.get('Arguments', ''))))
+ return actions
+
+
+def run_install_actions(proton, prefix, exe, env):
+ config = game_config(exe)
+ if config is None:
+ return
+ done = prefix / 'drive_c' / 'ProgramData' / 'DroidDeck' / 'install-actions'
+ for name, target, arguments in install_actions(config):
+ try:
+ content = hashlib.sha256()
+ with target.open('rb') as source:
+ for block in iter(lambda: source.read(1 << 20), b''):
+ content.update(block)
+ identity = hashlib.sha256(name.encode('utf-8') + b'\0' + content.digest()).hexdigest()[:24]
+ marker = done / ('%s-%s' % (''.join(c for c in name if c.isalnum() or c in '-_')[:64], identity))
+ if marker.exists():
+ continue
+ except OSError as error:
+ print('droiddeck-xbox: install action %s could not be read (%s); launching without it' % (name, error), file=sys.stderr)
+ continue
+ windows = 'Z:' + str(target).replace('/', '\\')
+ if target.suffix.lower() == '.msi':
+ command = [proton, 'run', 'msiexec', '/i', windows, *arguments]
+ else:
+ command = [proton, 'run', windows, *arguments]
+ try:
+ code = subprocess.run(command, stdout=sys.stderr, env=env, timeout=600).returncode
+ except (OSError, subprocess.TimeoutExpired):
+ code = None
+ if code != 0:
+ print('droiddeck-xbox: install action %s did not finish; launching without it' % name, file=sys.stderr)
+ continue
+ try:
+ done.mkdir(parents=True, exist_ok=True)
+ marker.touch()
+ except OSError as error:
+ print('droiddeck-xbox: install action %s finished but could not be recorded (%s)' % (name, error), file=sys.stderr)
+
+
def view_drive(prefix, exe):
path = Path(exe)
view = next((parent for parent in path.parents if parent.name.startswith('droiddeck-xbox-')), None)
@@ -184,6 +297,7 @@ def wine(argv, source_env=None):
target.unlink()
shutil.copyfile(RUNTIME / 'windows' / name, target)
register_classes(command[0], prefix, env)
+ run_install_actions(command[0], prefix, argv[0], env)
overrides = ';'.join(name[:-4] + '=n' for name in DLLS if name != 'libnghttp2.dll')
env['WINEDLLOVERRIDES'] = overrides + ';' + env.get('WINEDLLOVERRIDES', '')
exe, drive = view_drive(prefix, argv[0])
diff --git a/tools/tests/test_xbox_launch.py b/tools/tests/test_xbox_launch.py
index f082ba9a91..be2851fd31 100644
--- a/tools/tests/test_xbox_launch.py
+++ b/tools/tests/test_xbox_launch.py
@@ -178,6 +178,101 @@ class XboxLaunchTest(unittest.TestCase):
self.assertEqual(sorted(p.name for p in devices.iterdir()), ['v:', 'w:', 'x:'])
self.assertEqual(xbox['view_drive'](root / 'pfx', '/games/Game.exe'), ('/games/Game.exe', None))
+ def test_package_install_actions_run_once_and_stay_inside_the_game(self):
+ with tempfile.TemporaryDirectory() as root:
+ game, prefix = Path(root) / 'game', Path(root) / 'pfx'
+ (game / 'Installers').mkdir(parents=True)
+ (game / 'Installers' / 'GameInputRedist.msi').write_bytes(b'msi')
+ (game / 'Emu.exe').write_bytes(b'exe')
+ (Path(root) / 'outside.msi').write_bytes(b'msi')
+ (game / 'MicrosoftGame.config').write_text(
+ 'Installers'
+ ''
+ ''
+ '')
+ with patch('subprocess.run', return_value=subprocess.CompletedProcess([], 0)) as child:
+ xbox['run_install_actions']('/selected/proton', prefix, str(game / 'Emu.exe'), {'A': '1'})
+ xbox['run_install_actions']('/selected/proton', prefix, str(game / 'Emu.exe'), {'A': '1'})
+ self.assertEqual(child.call_count, 1)
+ command = child.call_args.args[0]
+ self.assertEqual(command[:4], ['/selected/proton', 'run', 'msiexec', '/i'])
+ self.assertTrue(command[4].startswith('Z:') and command[4].endswith('GameInputRedist.msi'))
+ self.assertEqual(command[5:], ['/quiet'])
+
+ def test_a_failed_install_action_is_retried_on_the_next_launch(self):
+ with tempfile.TemporaryDirectory() as root:
+ game, prefix = Path(root) / 'game', Path(root) / 'pfx'
+ game.mkdir()
+ (game / 'setup.exe').write_bytes(b'exe')
+ (game / 'MicrosoftGame.config').write_text(
+ ''
+ '')
+ with patch('subprocess.run', return_value=subprocess.CompletedProcess([], 1)) as child:
+ xbox['run_install_actions']('/p', prefix, str(game / 'setup.exe'), {})
+ xbox['run_install_actions']('/p', prefix, str(game / 'setup.exe'), {})
+ self.assertEqual(child.call_count, 2)
+ self.assertEqual(child.call_args.args[0][:2], ['/p', 'run'])
+
+ def test_install_action_arguments_follow_windows_command_line_rules(self):
+ parse = xbox['windows_arguments']
+ self.assertEqual(parse('/quiet /log "C:\\ProgramData\\Game Setup\\install.log"'),
+ ['/quiet', '/log', 'C:\\ProgramData\\Game Setup\\install.log'])
+ self.assertEqual(parse('a\\\\b "x\\"y" "\\\\" "" c""d "e""f"'), ['a\\\\b', 'x"y', '\\', '', 'cd', 'e"f'])
+ self.assertEqual(parse(' '), [])
+ with tempfile.TemporaryDirectory() as root:
+ game, prefix = Path(root) / 'game', Path(root) / 'pfx'
+ game.mkdir()
+ (game / 'setup.msi').write_bytes(b'msi')
+ (game / 'MicrosoftGame.config').write_text(
+ ''
+ '')
+ with patch('subprocess.run', return_value=subprocess.CompletedProcess([], 0)) as child:
+ xbox['run_install_actions']('/p', prefix, str(game / 'setup.msi'), {})
+ self.assertEqual(child.call_args.args[0][5:], ['/quiet', '/log', 'C:\\ProgramData\\Game Setup\\install.log'])
+
+ def test_actions_whose_names_differ_only_in_punctuation_each_run(self):
+ with tempfile.TemporaryDirectory() as root:
+ game, prefix = Path(root) / 'game', Path(root) / 'pfx'
+ game.mkdir()
+ (game / 'setup.exe').write_bytes(b'exe')
+ (game / 'MicrosoftGame.config').write_text(
+ ''
+ ''
+ ''
+ '')
+ with patch('subprocess.run', return_value=subprocess.CompletedProcess([], 0)) as child:
+ xbox['run_install_actions']('/p', prefix, str(game / 'setup.exe'), {})
+ xbox['run_install_actions']('/p', prefix, str(game / 'setup.exe'), {})
+ self.assertEqual([call.args[0][-1] for call in child.call_args_list], ['/a', '/b'])
+
+ def test_an_install_action_error_never_stops_the_launch(self):
+ with tempfile.TemporaryDirectory() as root:
+ game, prefix = Path(root) / 'game', Path(root) / 'pfx'
+ game.mkdir()
+ (game / 'first.exe').write_bytes(b'exe')
+ (game / 'second.exe').write_bytes(b'exe')
+ (game / 'MicrosoftGame.config').write_text(
+ ''
+ ''
+ '')
+ real_open = Path.open
+ def unreadable(path, *args, **kwargs):
+ if path.name == 'first.exe':
+ raise PermissionError('denied')
+ return real_open(path, *args, **kwargs)
+ with patch.object(Path, 'open', unreadable), \
+ patch('subprocess.run', return_value=subprocess.CompletedProcess([], 0)) as child:
+ xbox['run_install_actions']('/p', prefix, str(game / 'first.exe'), {})
+ self.assertEqual(child.call_count, 1)
+ self.assertTrue(child.call_args.args[0][2].endswith('second.exe'))
+ with patch('subprocess.run', side_effect=OSError('no proton')):
+ xbox['run_install_actions']('/p', prefix, str(game / 'first.exe'), {})
+ with patch.object(Path, 'touch', side_effect=OSError('read-only')), \
+ patch('subprocess.run', return_value=subprocess.CompletedProcess([], 0)) as child:
+ xbox['run_install_actions']('/p', prefix / 'other', str(game / 'first.exe'), {})
+ self.assertEqual(child.call_count, 2)
+
def test_missing_runtime_classes_are_registered_once(self):
with tempfile.TemporaryDirectory() as root:
prefix = Path(root)
diff --git a/tools/xbox/README.md b/tools/xbox/README.md
index fb8705b166..c0a6636aba 100644
--- a/tools/xbox/README.md
+++ b/tools/xbox/README.md
@@ -125,6 +125,15 @@ download plus two copies of the largest container, and each container is deleted
The download has no control channel: cancelling kills it and the next attempt starts that
container from zero.
+`droiddeck-msixvc2.patch` installs MSIXVC2 packages, the format Xbox 360 backward-compatible
+titles ship in. The package Windows Update serves is only an index (`XboxPackage.cbor`, chunk and
+file tables); the files are encrypted, Brotli-compressed segments inside `.box` blobs on the Xbox
+content hosts. `streaming` unpacks the index, licenses its content id, derives the package key from
+the content key (SP800-108 HMAC-SHA256, label `MSIXVC2:PackageData:AES_256_CBC`), unwraps each
+segment key with AES-256-CBC, fetches adjacent segments in one ranged request, and checks the
+SHA-384 of every stored segment, decompressed segment and finished file before it is renamed into
+place. Files already complete are skipped on a retry.
+
Cloud saves and in-game identity use the reused XGameRuntime/service interfaces;
those are game-dependent. Entitlements distinguish purchases from Game Pass
access, and the backend performs a fresh license check for downloads and launch.
diff --git a/tools/xbox/droiddeck-legacy-install.patch b/tools/xbox/droiddeck-legacy-install.patch
index bf2013fa8e..2d34e91679 100644
--- a/tools/xbox/droiddeck-legacy-install.patch
+++ b/tools/xbox/droiddeck-legacy-install.patch
@@ -2026,7 +2026,7 @@ index 0000000..7fec6e5
+ }
+}
diff --git a/crates/xodus-cli/src/commands/streaming.rs b/crates/xodus-cli/src/commands/streaming.rs
-index a0136f8..8637cab 100644
+index a0136f8..8e9d0e0 100644
--- a/crates/xodus-cli/src/commands/streaming.rs
+++ b/crates/xodus-cli/src/commands/streaming.rs
@@ -9,7 +9,7 @@ use indicatif::{MultiProgress, ProgressBar, ProgressStyle};
@@ -2054,7 +2054,7 @@ index a0136f8..8637cab 100644
let remote_xvd = match XvdFile::parse(&mut remote_file).await {
Ok(xvd) => xvd,
Err(error) => { failure::report_metadata(error.as_ref()); return ExitCode::FAILURE; }
-@@ -692,3 +701,337 @@ where
+@@ -692,3 +701,369 @@ where
}
ExitCode::SUCCESS
}
@@ -2095,11 +2095,7 @@ index a0136f8..8637cab 100644
+ Ok::<(), String>(())
+ })();
+ match result {
-+ Ok(()) => {
-+ std::fs::remove_file(previous.join(PENDING)).ok();
-+ std::fs::remove_dir_all(&previous).ok();
-+ Ok(())
-+ }
++ Ok(()) => release(&previous),
+ Err(error) => {
+ let stuck: Vec = placed
+ .iter()
@@ -2125,7 +2121,22 @@ index a0136f8..8637cab 100644
+
+/// Moves every entry kept in `previous` back into `out`, then removes `previous`.
+/// On any failure `previous` stays, holding what has not been put back.
++fn release(previous: &Path) -> Result<(), String> {
++ std::fs::remove_file(previous.join(PENDING))
++ .map_err(|error| format!("the replacement finished but its backup could not be released: {error}"))?;
++ std::fs::remove_dir_all(previous).ok();
++ Ok(())
++}
++
+fn restore(previous: &Path, out: &Path) -> Result<(), String> {
++ restore_with(previous, out, &mut |from, to| std::fs::rename(from, to))
++}
++
++fn restore_with(
++ previous: &Path,
++ out: &Path,
++ move_entry: &mut dyn FnMut(&Path, &Path) -> std::io::Result<()>,
++) -> Result<(), String> {
+ let placed = std::fs::read_to_string(previous.join(PENDING)).map_err(|error| error.to_string())?;
+ for name in placed.lines().filter(|name| !name.is_empty() && !name.contains(['/', '\\']) && *name != "." && *name != "..") {
+ let target = out.join(name);
@@ -2146,7 +2157,7 @@ index a0136f8..8637cab 100644
+ if std::fs::symlink_metadata(&target).is_ok() {
+ remove(&target).map_err(|error| format!("could not clear {}: {error}", target.display()))?;
+ }
-+ std::fs::rename(entry.path(), &target).map_err(|error| format!("could not restore {}: {error}", target.display()))?;
++ move_entry(&entry.path(), &target).map_err(|error| format!("could not restore {}: {error}", target.display()))?;
+ }
+ std::fs::remove_file(previous.join(PENDING)).map_err(|error| error.to_string())?;
+ std::fs::remove_dir(previous).map_err(|error| error.to_string())
@@ -2312,21 +2323,42 @@ index a0136f8..8637cab 100644
+ #[test]
+ fn a_restore_interrupted_after_its_removals_never_deletes_what_it_put_back() {
+ let root = tempfile::tempdir().unwrap();
-+ let (staging, out) = (root.path().join("staging"), root.path().join("out"));
++ let out = root.path().join("out");
+ let previous = out.join(".xodus-plain-previous");
-+ std::fs::create_dir_all(&staging).unwrap();
+ std::fs::create_dir_all(&previous).unwrap();
-+ std::fs::write(previous.join(".pending"), "a").unwrap();
-+ std::fs::write(previous.join("a"), b"old").unwrap();
-+ std::fs::write(out.join("a"), b"stray").unwrap();
-+ super::restore(&previous, &out).unwrap();
-+ assert_eq!(std::fs::read(out.join("a")).unwrap(), b"old");
-+ std::fs::create_dir_all(&previous).unwrap();
-+ std::fs::write(previous.join(".pending"), "").unwrap();
++ std::fs::write(previous.join(".pending"), "a
++b").unwrap();
++ std::fs::write(previous.join("a"), b"old-a").unwrap();
+ std::fs::write(previous.join("b"), b"old-b").unwrap();
-+ super::publish(&staging, &out).unwrap();
-+ assert_eq!(std::fs::read(out.join("a")).unwrap(), b"old");
++ std::fs::write(out.join("a"), b"new-a").unwrap();
++ std::fs::write(out.join("b"), b"new-b").unwrap();
++ let mut moves = 0;
++ let interrupted = super::restore_with(&previous, &out, &mut |from, to| {
++ moves += 1;
++ if moves == 2 { return Err(std::io::Error::other("interrupted")) }
++ std::fs::rename(from, to)
++ });
++ assert!(interrupted.is_err());
++ let restored = ["a", "b"].into_iter().find(|name| out.join(name).exists()).unwrap();
++ super::restore(&previous, &out).unwrap();
++ assert_eq!(std::fs::read(out.join(restored)).unwrap(), format!("old-{restored}").as_bytes());
++ assert_eq!(std::fs::read(out.join("a")).unwrap(), b"old-a");
+ assert_eq!(std::fs::read(out.join("b")).unwrap(), b"old-b");
++ assert!(!previous.exists());
++ }
++
++ #[test]
++ fn a_backup_whose_marker_cannot_be_removed_is_kept_and_reported() {
++ let root = tempfile::tempdir().unwrap();
++ let previous = root.path().join(".xodus-plain-previous");
++ std::fs::create_dir_all(previous.join(".pending").join("held")).unwrap();
++ std::fs::write(previous.join("kept"), b"old").unwrap();
++ assert!(super::release(&previous).is_err());
++ assert!(previous.join("kept").exists());
++ std::fs::remove_dir_all(previous.join(".pending")).unwrap();
++ std::fs::write(previous.join(".pending"), b"").unwrap();
++ super::release(&previous).unwrap();
++ assert!(!previous.exists());
+ }
+
+ #[test]
diff --git a/tools/xbox/droiddeck-msixvc2.patch b/tools/xbox/droiddeck-msixvc2.patch
new file mode 100644
index 0000000000..b02ec68bbb
--- /dev/null
+++ b/tools/xbox/droiddeck-msixvc2.patch
@@ -0,0 +1,1131 @@
+diff --git a/Cargo.lock b/Cargo.lock
+index 5dfc09a..15198af 100644
+--- a/Cargo.lock
++++ b/Cargo.lock
+@@ -83,6 +83,21 @@ dependencies = [
+ "memchr",
+ ]
+
++[[package]]
++name = "alloc-no-stdlib"
++version = "2.0.4"
++source = "registry+https://github.com/rust-lang/crates.io-index"
++checksum = "cc7bb162ec39d46ab1ca8c77bf72e890535becd1751bb45f64c597edb4c8c6b3"
++
++[[package]]
++name = "alloc-stdlib"
++version = "0.2.4"
++source = "registry+https://github.com/rust-lang/crates.io-index"
++checksum = "0e76a019e91224d279006ff972f1e984179a6e9feb050adba6ce8274aef23195"
++dependencies = [
++ "alloc-no-stdlib",
++]
++
+ [[package]]
+ name = "android_system_properties"
+ version = "0.1.6"
+@@ -586,6 +601,16 @@ dependencies = [
+ "objc2",
+ ]
+
++[[package]]
++name = "brotli-decompressor"
++version = "5.0.3"
++source = "registry+https://github.com/rust-lang/crates.io-index"
++checksum = "3a32acac15fe1967bc3986b2a6347dffc965602354ea6f450ad07e8bfd253583"
++dependencies = [
++ "alloc-no-stdlib",
++ "alloc-stdlib",
++]
++
+ [[package]]
+ name = "bstr"
+ version = "1.13.1"
+@@ -728,6 +753,33 @@ dependencies = [
+ "windows-link 0.2.1",
+ ]
+
++[[package]]
++name = "ciborium"
++version = "0.2.2"
++source = "registry+https://github.com/rust-lang/crates.io-index"
++checksum = "42e69ffd6f0917f5c029256a24d0161db17cea3997d185db0d35926308770f0e"
++dependencies = [
++ "ciborium-io",
++ "ciborium-ll",
++ "serde",
++]
++
++[[package]]
++name = "ciborium-io"
++version = "0.2.2"
++source = "registry+https://github.com/rust-lang/crates.io-index"
++checksum = "05afea1e0a06c9be33d539b876f1ce3692f4afea2cb41f740e7743225ed1c757"
++
++[[package]]
++name = "ciborium-ll"
++version = "0.2.2"
++source = "registry+https://github.com/rust-lang/crates.io-index"
++checksum = "57663b653d948a338bfb3eeba9bb2fd5fcfaecb9e199e87e1eda4d9e8b240fd9"
++dependencies = [
++ "ciborium-io",
++ "half",
++]
++
+ [[package]]
+ name = "cipher"
+ version = "0.4.4"
+@@ -1055,6 +1107,12 @@ dependencies = [
+ "winapi",
+ ]
+
++[[package]]
++name = "crunchy"
++version = "0.2.4"
++source = "registry+https://github.com/rust-lang/crates.io-index"
++checksum = "460fbee9c2c2f33933d720630a6a0bac33ba7053db5344fac858d4b8952d77d5"
++
+ [[package]]
+ name = "crypto-bigint"
+ version = "0.5.5"
+@@ -2370,6 +2428,17 @@ dependencies = [
+ "tracing",
+ ]
+
++[[package]]
++name = "half"
++version = "2.7.1"
++source = "registry+https://github.com/rust-lang/crates.io-index"
++checksum = "6ea2d84b969582b4b1864a92dc5d27cd2b77b622a8d79306834f1be5ba20d84b"
++dependencies = [
++ "cfg-if",
++ "crunchy",
++ "zerocopy",
++]
++
+ [[package]]
+ name = "hash2curve"
+ version = "0.14.0"
+@@ -7178,9 +7247,13 @@ dependencies = [
+ name = "xodus-cli"
+ version = "0.1.0"
+ dependencies = [
++ "aes 0.9.3",
+ "async-trait",
+ "base64 0.23.1",
++ "brotli-decompressor",
++ "cbc 0.2.1",
+ "chrono",
++ "ciborium",
+ "clap",
+ "console-subscriber",
+ "ctrlc",
+@@ -7188,6 +7261,7 @@ dependencies = [
+ "flate2",
+ "fs2",
+ "futures-util",
++ "hmac 0.13.0",
+ "indicatif",
+ "inquire",
+ "msixvc",
+@@ -7196,6 +7270,7 @@ dependencies = [
+ "reqwest 0.13.4",
+ "rustix",
+ "serde_json",
++ "sha2 0.11.0",
+ "tao",
+ "tempfile",
+ "tokio",
+diff --git a/crates/xodus-cli/Cargo.toml b/crates/xodus-cli/Cargo.toml
+index f49470b..3579838 100644
+--- a/crates/xodus-cli/Cargo.toml
++++ b/crates/xodus-cli/Cargo.toml
+@@ -31,6 +31,12 @@ tempfile = "3.27.0"
+ rustix = "1.1.4"
+ ctrlc = "3.5.2"
+ nix = "0.31.3"
++aes = "0.9.2"
++cbc = "0.2.1"
++hmac = "0.13.0"
++sha2 = "0.11.0"
++ciborium = "0.2.2"
++brotli-decompressor = "5.0.0"
+
+ [features]
+ default = ["native-webview"]
+diff --git a/crates/xodus-cli/src/commands.rs b/crates/xodus-cli/src/commands.rs
+index 825c24e..c23f637 100644
+--- a/crates/xodus-cli/src/commands.rs
++++ b/crates/xodus-cli/src/commands.rs
+@@ -20,6 +20,7 @@ pub mod library;
+ #[cfg(unix)]
+ pub mod run;
+ pub mod splicense;
++pub mod msixvc2;
+ pub mod streaming;
+
+ pub mod native_social;
+diff --git a/crates/xodus-cli/src/commands/msixvc2.rs b/crates/xodus-cli/src/commands/msixvc2.rs
+new file mode 100644
+index 0000000..5caab57
+--- /dev/null
++++ b/crates/xodus-cli/src/commands/msixvc2.rs
+@@ -0,0 +1,820 @@
++use std::collections::HashMap;
++use std::io::{ErrorKind, Read, Seek, SeekFrom, Write};
++use std::path::{Component, Path, PathBuf};
++
++use aes::cipher::{BlockModeDecrypt, KeyIvInit, block_padding::NoPadding};
++use ciborium::Value;
++use futures_util::{StreamExt, stream};
++use hmac::{Hmac, Mac};
++use sha2::{Digest, Sha256, Sha384};
++
++const HOSTS: [&str; 4] = ["assets1.xboxlive.com", "assets2.xboxlive.com", "xvcf1.xboxlive.com", "xvcf2.xboxlive.com"];
++const KDF_LABEL: &[u8] = b"MSIXVC2:PackageData:AES_256_CBC";
++const MAX_REQUEST: u64 = 16 * 1024 * 1024;
++const PARALLEL: usize = 6;
++const BROTLI: u64 = 2;
++const DEFLATE: u64 = 1;
++const STATE: &str = ".droiddeck-install";
++const PARTIAL: &str = "partial";
++const VERIFIED: &str = "verified";
++
++pub fn is_package(folder: &Path) -> bool {
++ folder.join("XboxPackage.cbor").is_file()
++}
++
++pub fn content_id(folder: &Path) -> Result {
++ let package = read_cbor(&folder.join("XboxPackage.cbor"))?;
++ text(&package, 260).map(str::to_owned).ok_or_else(|| "The package names no content id".to_string())
++}
++
++#[derive(Clone)]
++pub struct Segment {
++ hash: Vec,
++ length: u64,
++ compression: u64,
++ stored: u64,
++ key: Option>,
++ wrapped: Option>,
++ wrap_iv: [u8; 16],
++ box_hash: Option>,
++ box_index: usize,
++ offset: u64,
++ span: u64,
++}
++
++pub struct Entry {
++ pub path: PathBuf,
++ size: u64,
++ hash: Option>,
++ segments: Vec,
++}
++
++pub struct Plan {
++ pub entries: Vec,
++ boxes: Vec,
++ package_key: [u8; 32],
++}
++
++impl Plan {
++ pub fn total(&self) -> u64 {
++ self.entries.iter().map(|entry| entry.size).sum()
++ }
++
++ pub fn remaining(&self, out: &Path) -> u64 {
++ let root = out.canonicalize().unwrap_or_else(|_| out.to_path_buf());
++ let verified = verified(&root);
++ self.entries.iter().filter(|entry| !complete(&root, entry, &verified)).map(|entry| entry.size).sum()
++ }
++}
++
++fn identity(entry: &Entry) -> String {
++ let mut digest = Sha384::new();
++ digest.update(entry.path.to_string_lossy().as_bytes());
++ digest.update([0]);
++ digest.update(entry.size.to_be_bytes());
++ match &entry.hash {
++ Some(hash) => digest.update(hash),
++ None => entry.segments.iter().for_each(|segment| digest.update(&segment.hash)),
++ }
++ digest.finalize().iter().map(|byte| format!("{byte:02x}")).collect()
++}
++
++fn key(path: &Path) -> String {
++ Sha256::digest(path.to_string_lossy().as_bytes()).iter().map(|byte| format!("{byte:02x}")).collect()
++}
++
++fn verified(root: &Path) -> HashMap {
++ let record = root.join(STATE).join(VERIFIED);
++ if !std::fs::symlink_metadata(&record).is_ok_and(|meta| meta.is_file()) {
++ return HashMap::new();
++ }
++ let text = std::fs::read_to_string(record).unwrap_or_default();
++ text[..text.rfind('\n').map_or(0, |end| end + 1)]
++ .lines()
++ .filter_map(|line| line.split_once(' '))
++ .map(|(path, identity)| (path.to_owned(), identity.to_owned()))
++ .collect()
++}
++
++fn complete(root: &Path, entry: &Entry, verified: &HashMap) -> bool {
++ verified.get(&key(&entry.path)) == Some(&identity(entry))
++ && std::fs::symlink_metadata(root.join(&entry.path)).is_ok_and(|meta| meta.is_file() && meta.len() == entry.size)
++}
++
++fn note(record: &Path, path: &Path, identity: &str) -> Result<(), String> {
++ std::fs::OpenOptions::new()
++ .create(true)
++ .read(true)
++ .append(true)
++ .open(record)
++ .and_then(|mut file| {
++ let length = file.metadata()?.len();
++ let mut last = [0u8; 1];
++ if length > 0 {
++ file.seek(SeekFrom::Start(length - 1))?;
++ file.read_exact(&mut last)?;
++ }
++ if length > 0 && last[0] != b'\n' {
++ let mut end = length;
++ let mut keep = 0;
++ let mut chunk = vec![0u8; 4096];
++ while end > 0 {
++ let start = end.saturating_sub(chunk.len() as u64);
++ let part = &mut chunk[..(end - start) as usize];
++ file.seek(SeekFrom::Start(start))?;
++ file.read_exact(part)?;
++ if let Some(at) = part.iter().rposition(|byte| *byte == b'\n') {
++ keep = start + at as u64 + 1;
++ break;
++ }
++ end = start;
++ }
++ file.set_len(keep)?;
++ }
++ writeln!(file, "{} {identity}", key(path))?;
++ file.sync_all()
++ })
++ .map_err(|error| format!("Could not record a finished game file: {error}"))
++}
++
++fn folder(root: &Path, relative: &Path) -> Result {
++ let mut at = root.to_path_buf();
++ for part in relative.components() {
++ at.push(part);
++ match std::fs::symlink_metadata(&at) {
++ Ok(meta) if meta.is_dir() => {}
++ Ok(_) => return Err("The game folder holds a link or file where a folder belongs".into()),
++ Err(error) if error.kind() == ErrorKind::NotFound => match std::fs::create_dir(&at) {
++ Ok(()) => {}
++ Err(error) if error.kind() == ErrorKind::AlreadyExists && std::fs::symlink_metadata(&at).is_ok_and(|meta| meta.is_dir()) => {}
++ Err(error) => return Err(format!("Could not create a game folder: {error}")),
++ },
++ Err(error) => return Err(format!("Could not read the game folder: {error}")),
++ }
++ }
++ Ok(at)
++}
++
++fn place(root: &Path, relative: &Path) -> Result {
++ let parent = folder(root, relative.parent().unwrap_or(Path::new("")))?;
++ let target = parent.join(relative.file_name().ok_or("The package names an unusable file path")?);
++ match std::fs::symlink_metadata(&target) {
++ Ok(meta) if !meta.is_file() => Err("The game folder holds a link or folder where a file belongs".into()),
++ _ => Ok(target),
++ }
++}
++
++pub fn reclaim(out: &Path) -> Result<(), String> {
++ let root = out.canonicalize().map_err(|error| format!("Could not open the game folder: {error}"))?;
++ let state = root.join(STATE);
++ match std::fs::symlink_metadata(&state) {
++ Ok(meta) if meta.is_dir() => {}
++ Ok(_) => return Err("The game folder holds a link or file where the install state belongs".into()),
++ Err(_) => return Ok(()),
++ }
++ let partial = state.join(PARTIAL);
++ match std::fs::symlink_metadata(&partial) {
++ Ok(meta) if meta.is_dir() => std::fs::remove_dir_all(&partial),
++ Ok(_) => std::fs::remove_file(&partial),
++ Err(_) => Ok(()),
++ }
++ .map_err(|error| format!("Could not clear an unfinished download: {error}"))
++}
++
++pub async fn plan(client: &reqwest::Client, folder: &Path, content_keys: &HashMap<[u8; 16], [u8; 32]>) -> Result {
++ let package = read_cbor(&folder.join("XboxPackage.cbor"))?;
++ let boxes: Vec = list(&package, 264)
++ .ok_or("The package lists no content boxes")?
++ .iter()
++ .map(|item| text(item, 25).map(str::to_owned).ok_or("A content box has no location".to_string()))
++ .collect::>()?;
++ for location in &boxes {
++ if !location.starts_with('/') || location.contains("..") || location.contains("://") {
++ return Err("The package lists an unusable box location".into());
++ }
++ }
++ let package_key = package_key(&package, content_keys)?;
++ let initial = iv(&package, 27).unwrap_or([0; 16]);
++ let chunks = list(&package, 265).ok_or("The package lists no chunks")?;
++ let mut entries = Vec::new();
++ for chunk in chunks {
++ let id = int(chunk, 24).ok_or("A chunk has no id")?;
++ let secret = get(chunk, 26).ok_or("A chunk has no details")?;
++ let details = secret_details(client, &boxes, secret, initial, &package_key, chunks.len()).await?;
++ let names: Vec = list(&details, 28)
++ .ok_or("A chunk's details list no files")?
++ .iter()
++ .map(|item| text(item, 25).map(str::to_owned).ok_or("A file has no name".to_string()))
++ .collect::>()?;
++ let layout = read_cbor(&folder.join("Chunks").join(format!("{id}.cbor")))?;
++ let files = list(&layout, 28).ok_or("A chunk lists no files")?;
++ if files.len() != names.len() {
++ return Err("A chunk's names and files disagree".into());
++ }
++ let mut rolling = iv(&layout, 27).unwrap_or([0; 16]);
++ for (file, name) in files.iter().zip(names) {
++ let size = int(file, 2).ok_or("A file has no size")?;
++ let hash = hash(file, 1);
++ let segments = match list(file, 29) {
++ Some(items) => segments(items, &mut rolling)?,
++ None => {
++ let file_id = int(file, 24).ok_or("A file has no id")?;
++ let detail = read_cbor(&folder.join("Files").join(format!("{file_id}.cbor")))?;
++ let mut own = iv(&detail, 27).unwrap_or([0; 16]);
++ segments(list(&detail, 29).ok_or("A file lists no segments")?, &mut own)?
++ }
++ };
++ if segments.iter().map(|segment| segment.length).sum::() != size {
++ return Err("A file's segments do not add up to its size".into());
++ }
++ entries.push(Entry { path: relative(&name)?, size, hash, segments });
++ }
++ }
++ Ok(Plan { entries, boxes, package_key })
++}
++
++pub async fn install(client: &reqwest::Client, plan: &Plan, out: &Path, progress: &(dyn Fn(u64) + Sync)) -> Result<(), String> {
++ let root = out.canonicalize().map_err(|error| format!("Could not open the game folder: {error}"))?;
++ let verified = verified(&root);
++ let record = place(&root, &Path::new(STATE).join(VERIFIED))?;
++ for (index, entry) in plan.entries.iter().enumerate() {
++ if complete(&root, entry, &verified) {
++ progress(entry.size);
++ continue;
++ }
++ let target = place(&root, &entry.path)?;
++ let partial = folder(&root, &Path::new(STATE).join(PARTIAL))?.join(index.to_string());
++ match std::fs::remove_file(&partial) {
++ Err(error) if error.kind() != ErrorKind::NotFound => return Err(format!("Could not clear an unfinished download: {error}")),
++ _ => {}
++ }
++ let mut file = std::fs::OpenOptions::new()
++ .write(true)
++ .create_new(true)
++ .open(&partial)
++ .map_err(|error| format!("Could not write a game file: {error}"))?;
++ let mut digest = Sha384::new();
++ let mut results = stream::iter(requests(&entry.segments))
++ .map(|request| fetch_request(client, plan, request))
++ .buffered(PARALLEL);
++ while let Some(result) = results.next().await {
++ for plain in result? {
++ digest.update(&plain);
++ file.write_all(&plain).map_err(|error| format!("Could not write a game file: {error}"))?;
++ progress(plain.len() as u64);
++ }
++ }
++ file.sync_all().map_err(|error| format!("Could not write a game file: {error}"))?;
++ drop(file);
++ if let Some(expected) = &entry.hash
++ && digest.finalize().as_slice() != expected.as_slice()
++ {
++ std::fs::remove_file(&partial).ok();
++ return Err("A downloaded game file failed verification".into());
++ }
++ if place(&root, &entry.path)? != target {
++ return Err("The game folder changed during the install".into());
++ }
++ note(&record, &entry.path, "-")?;
++ std::fs::rename(&partial, &target).map_err(|error| format!("Could not finish a game file: {error}"))?;
++ note(&record, &entry.path, &identity(entry))?;
++ }
++ reclaim(&root)
++}
++
++struct Request<'a> {
++ box_index: usize,
++ offset: u64,
++ length: u64,
++ segments: &'a [Segment],
++}
++
++fn requests(segments: &[Segment]) -> Vec> {
++ let mut found: Vec> = Vec::new();
++ let mut start = 0;
++ while start < segments.len() {
++ let first = &segments[start];
++ let mut end = start + 1;
++ let mut length = first.span;
++ while end < segments.len() {
++ let next = &segments[end];
++ if next.box_index != first.box_index || next.offset != first.offset + length || length + next.span > MAX_REQUEST {
++ break;
++ }
++ length += next.span;
++ end += 1;
++ }
++ found.push(Request { box_index: first.box_index, offset: first.offset, length, segments: &segments[start..end] });
++ start = end;
++ }
++ found
++}
++
++async fn fetch_request(client: &reqwest::Client, plan: &Plan, request: Request<'_>) -> Result>, String> {
++ let bytes = fetch(client, &plan.boxes[request.box_index], request.offset, request.length).await?;
++ let mut at = 0usize;
++ let mut plain = Vec::with_capacity(request.segments.len());
++ for segment in request.segments {
++ let stored = &bytes[at..at + segment.span as usize];
++ at += segment.span as usize;
++ plain.push(open(segment, stored, &plan.package_key)?);
++ }
++ Ok(plain)
++}
++
++async fn fetch(client: &reqwest::Client, location: &str, offset: u64, length: u64) -> Result, String> {
++ let mut last = String::new();
++ for attempt in 0..HOSTS.len() * 2 {
++ let host = HOSTS[attempt % HOSTS.len()];
++ let response = client
++ .get(format!("http://{host}{location}"))
++ .header("Range", format!("bytes={}-{}", offset, offset + length - 1))
++ .send()
++ .await;
++ match response {
++ Ok(response) if response.status().as_u16() == 206 => match response.bytes().await {
++ Ok(body) if body.len() as u64 == length => return Ok(body.to_vec()),
++ Ok(_) => last = "the content host sent a short range".into(),
++ Err(error) => last = error.to_string(),
++ },
++ Ok(response) => last = format!("the content host answered HTTP {}", response.status().as_u16()),
++ Err(error) => last = error.to_string(),
++ }
++ tokio::time::sleep(std::time::Duration::from_millis(500 * (attempt as u64 + 1))).await;
++ }
++ Err(format!("Could not download game data: {last}"))
++}
++
++fn open(segment: &Segment, stored: &[u8], package_key: &[u8; 32]) -> Result, String> {
++ if let Some(expected) = &segment.box_hash
++ && Sha384::digest(stored).as_slice() != expected.as_slice()
++ {
++ return Err("Downloaded game data failed verification".into());
++ }
++ let key = match (&segment.key, &segment.wrapped) {
++ (Some(key), _) => Some(key32(key)?),
++ (None, Some(wrapped)) => Some(key32(&cbc(package_key, &segment.wrap_iv, wrapped)?)?),
++ (None, None) => None,
++ };
++ let decrypted = match key {
++ Some(key) => {
++ let mut iv = [0u8; 16];
++ iv.copy_from_slice(segment.hash.get(..16).ok_or("A segment hash is too short")?);
++ cbc(&key, &iv, stored)?
++ }
++ None => stored.to_vec(),
++ };
++ let body = decrypted.get(..segment.stored as usize).ok_or("A segment is shorter than its stored size")?;
++ let plain = match segment.compression {
++ 0 => body.to_vec(),
++ BROTLI => {
++ let mut out = Vec::with_capacity(segment.length as usize);
++ brotli_decompressor::Decompressor::new(body, 4096)
++ .take(segment.length + 1)
++ .read_to_end(&mut out)
++ .map_err(|_| "A segment could not be decompressed".to_string())?;
++ out
++ }
++ DEFLATE => {
++ let mut out = Vec::with_capacity(segment.length as usize);
++ flate2::read::DeflateDecoder::new(body)
++ .take(segment.length + 1)
++ .read_to_end(&mut out)
++ .map_err(|_| "A segment could not be decompressed".to_string())?;
++ out
++ }
++ _ => return Err("A segment uses an unsupported compression".into()),
++ };
++ if plain.len() as u64 != segment.length || Sha384::digest(&plain).as_slice() != segment.hash.as_slice() {
++ return Err("A game data segment failed verification".into());
++ }
++ Ok(plain)
++}
++
++async fn secret_details(
++ client: &reqwest::Client,
++ boxes: &[String],
++ secret: &Value,
++ initial: [u8; 16],
++ package_key: &[u8; 32],
++ chunks: usize,
++) -> Result {
++ let mut base = initial;
++ let segment = segment(secret, &mut base)?;
++ let stored = fetch(client, boxes.get(segment.box_index).ok_or("A chunk refers to a missing box")?, segment.offset, segment.span).await?;
++ for step in 0..=chunks as u128 {
++ let mut candidate = segment.clone();
++ if get(secret, 7).is_none() {
++ candidate.wrap_iv = (u128::from_be_bytes(initial).wrapping_add(step)).to_be_bytes();
++ }
++ if let Ok(plain) = open(&candidate, &stored, package_key) {
++ return ciborium::de::from_reader::(plain.as_slice())
++ .map(untag)
++ .map_err(|_| "A chunk's details are not readable".to_string());
++ }
++ if candidate.wrapped.is_none() {
++ break;
++ }
++ }
++ Err("Could not decrypt a chunk's details with this license".into())
++}
++
++fn package_key(package: &Value, content_keys: &HashMap<[u8; 16], [u8; 32]>) -> Result<[u8; 32], String> {
++ let groups = list(package, 262).ok_or("The package lists no keys")?;
++ for group in groups {
++ let sources = match group {
++ Value::Array(items) => items.as_slice(),
++ _ => continue,
++ };
++ for source in sources {
++ let Some(id) = text(source, 288).and_then(|id| hex(id).ok()) else { continue };
++ let Some(short) = id.get(..16).and_then(|bytes| <[u8; 16]>::try_from(bytes).ok()) else { continue };
++ let Some(master) = content_keys.get(&short) else { continue };
++ let context = bytes(source, 286).ok_or("A package key has no derivation context")?;
++ let wrap_iv = iv(source, 7).ok_or("A package key has no wrapping IV")?;
++ let wrapped = bytes(source, 6).ok_or("A package key is missing")?;
++ let kek = derive(master, context);
++ return key32(&cbc(&kek, &wrap_iv, wrapped)?);
++ }
++ }
++ Err("The license holds no key for this package".into())
++}
++
++fn derive(master: &[u8; 32], context: &[u8]) -> [u8; 32] {
++ let mut message = Vec::with_capacity(4 + KDF_LABEL.len() + 1 + context.len() + 4);
++ message.extend_from_slice(&1u32.to_be_bytes());
++ message.extend_from_slice(KDF_LABEL);
++ message.push(0);
++ message.extend_from_slice(context);
++ message.extend_from_slice(&256u32.to_be_bytes());
++ let mut mac = as hmac::KeyInit>::new_from_slice(master).expect("HMAC takes any key length");
++ mac.update(&message);
++ mac.finalize().into_bytes().into()
++}
++
++fn cbc(key: &[u8; 32], iv: &[u8; 16], data: &[u8]) -> Result, String> {
++ if data.len() % 16 != 0 {
++ return Err("Encrypted game data is not block aligned".into());
++ }
++ let mut out = data.to_vec();
++ cbc::Decryptor::::new(key.into(), iv.into())
++ .decrypt_padded::(&mut out)
++ .map_err(|_| "Game data could not be decrypted".to_string())?;
++ Ok(out)
++}
++
++fn segments(items: &[Value], rolling: &mut [u8; 16]) -> Result, String> {
++ items.iter().map(|item| segment(item, rolling)).collect()
++}
++
++fn segment(item: &Value, rolling: &mut [u8; 16]) -> Result {
++ let length = int(item, 2).ok_or("A segment has no length")?;
++ let segment = Segment {
++ hash: hash(item, 1).ok_or("A segment has no hash")?,
++ length,
++ compression: int(item, 3).unwrap_or(0),
++ stored: int(item, 4).unwrap_or(length),
++ key: bytes(item, 5).map(<[u8]>::to_vec),
++ wrapped: bytes(item, 6).map(<[u8]>::to_vec),
++ wrap_iv: iv(item, 7).unwrap_or(*rolling),
++ box_hash: hash(item, 8),
++ box_index: int(item, 9).unwrap_or(0) as usize,
++ offset: int(item, 10).unwrap_or(0),
++ span: int(item, 11).unwrap_or(length),
++ };
++ if segment.stored > segment.span {
++ return Err("A segment is larger than its stored range".into());
++ }
++ *rolling = u128::from_be_bytes(*rolling).wrapping_add(1).to_be_bytes();
++ Ok(segment)
++}
++
++fn relative(name: &str) -> Result {
++ let path = PathBuf::from(name.replace('\\', "/"));
++ if name.is_empty()
++ || name.contains(':')
++ || !path.components().all(|part| matches!(part, Component::Normal(_)))
++ || path.components().next().is_some_and(|part| part.as_os_str().to_string_lossy().eq_ignore_ascii_case(STATE))
++ {
++ return Err("The package names an unusable file path".into());
++ }
++ Ok(path)
++}
++
++fn read_cbor(path: &Path) -> Result {
++ let file = std::fs::File::open(path).map_err(|_| "The package index is incomplete".to_string())?;
++ ciborium::de::from_reader::(std::io::BufReader::new(file))
++ .map(untag)
++ .map_err(|_| "The package index is not readable".to_string())
++}
++
++fn untag(value: Value) -> Value {
++ match value {
++ Value::Tag(_, inner) => untag(*inner),
++ other => other,
++ }
++}
++
++fn get(value: &Value, key: u64) -> Option<&Value> {
++ let Value::Map(entries) = value else { return None };
++ entries.iter().find_map(|(k, v)| match k {
++ Value::Integer(number) if u64::try_from(*number).ok() == Some(key) => Some(v),
++ _ => None,
++ })
++}
++
++fn int(value: &Value, key: u64) -> Option {
++ match get(value, key)? {
++ Value::Integer(number) => u64::try_from(*number).ok(),
++ _ => None,
++ }
++}
++
++fn text(value: &Value, key: u64) -> Option<&str> {
++ match get(value, key)? {
++ Value::Text(text) => Some(text),
++ _ => None,
++ }
++}
++
++fn bytes(value: &Value, key: u64) -> Option<&[u8]> {
++ match get(value, key)? {
++ Value::Bytes(bytes) => Some(bytes),
++ Value::Tag(_, inner) => match inner.as_ref() {
++ Value::Bytes(bytes) => Some(bytes),
++ _ => None,
++ },
++ _ => None,
++ }
++}
++
++fn hash(value: &Value, key: u64) -> Option> {
++ bytes(value, key).filter(|bytes| bytes.len() == 48).map(<[u8]>::to_vec)
++}
++
++fn iv(value: &Value, key: u64) -> Option<[u8; 16]> {
++ bytes(value, key).and_then(|bytes| <[u8; 16]>::try_from(bytes).ok())
++}
++
++fn list(value: &Value, key: u64) -> Option<&[Value]> {
++ match get(value, key)? {
++ Value::Array(items) => Some(items),
++ _ => None,
++ }
++}
++
++fn key32(bytes: &[u8]) -> Result<[u8; 32], String> {
++ <[u8; 32]>::try_from(bytes.get(..32).ok_or("A key is too short")?).map_err(|_| "A key is too short".to_string())
++}
++
++fn hex(text: &str) -> Result, ()> {
++ if text.len() % 2 != 0 {
++ return Err(());
++ }
++ (0..text.len()).step_by(2).map(|at| u8::from_str_radix(&text[at..at + 2], 16).map_err(|_| ())).collect()
++}
++
++#[cfg(test)]
++mod tests {
++ use super::*;
++ use aes::cipher::BlockModeEncrypt;
++
++ fn encrypt(key: &[u8; 32], iv: &[u8; 16], data: &[u8]) -> Vec {
++ let mut out = data.to_vec();
++ cbc::Encryptor::::new(key.into(), iv.into()).encrypt_padded::(&mut out, data.len()).unwrap();
++ out
++ }
++
++ fn sealed(plain: &[u8], segment_key: &[u8; 32]) -> (Segment, Vec) {
++ let hash = Sha384::digest(plain).to_vec();
++ let mut padded = plain.to_vec();
++ padded.resize(plain.len().div_ceil(16) * 16, 0);
++ let mut iv = [0u8; 16];
++ iv.copy_from_slice(&hash[..16]);
++ let stored = encrypt(segment_key, &iv, &padded);
++ let segment = Segment {
++ hash,
++ length: plain.len() as u64,
++ compression: 0,
++ stored: plain.len() as u64,
++ key: Some(segment_key.to_vec()),
++ wrapped: None,
++ wrap_iv: [0; 16],
++ box_hash: Some(Sha384::digest(&stored).to_vec()),
++ box_index: 0,
++ offset: 0,
++ span: stored.len() as u64,
++ };
++ (segment, stored)
++ }
++
++ #[test]
++ fn a_segment_opens_only_with_its_key_and_hashes() {
++ let (segment, stored) = sealed(b"game data that is not block aligned", &[7; 32]);
++ assert_eq!(open(&segment, &stored, &[0; 32]).unwrap(), b"game data that is not block aligned");
++ let mut tampered = stored.clone();
++ tampered[3] ^= 1;
++ assert!(open(&segment, &tampered, &[0; 32]).is_err());
++ let wrong = Segment { key: Some(vec![8; 32]), box_hash: None, ..segment };
++ assert!(open(&wrong, &stored, &[0; 32]).is_err());
++ }
++
++ #[test]
++ fn a_wrapped_segment_key_is_unwrapped_with_the_package_key() {
++ let package_key = [3u8; 32];
++ let segment_key = [9u8; 32];
++ let wrap_iv = [5u8; 16];
++ let (segment, stored) = sealed(b"wrapped", &segment_key);
++ let wrapped = Segment { key: None, wrapped: Some(encrypt(&package_key, &wrap_iv, &segment_key)), wrap_iv, ..segment };
++ assert_eq!(open(&wrapped, &stored, &package_key).unwrap(), b"wrapped");
++ }
++
++ #[test]
++ fn adjacent_segments_in_one_box_share_a_request() {
++ let (segment, _) = sealed(b"x", &[1; 32]);
++ let at = |box_index: usize, offset: u64| Segment { box_index, offset, span: 16, ..segment.clone() };
++ let parts = [at(0, 0), at(0, 16), at(0, 48), at(1, 64)];
++ let shape: Vec<(usize, u64, u64, usize)> =
++ requests(&parts).iter().map(|r| (r.box_index, r.offset, r.length, r.segments.len())).collect();
++ assert_eq!(shape, [(0, 0, 32, 2), (0, 48, 16, 1), (1, 64, 16, 1)]);
++ }
++
++ #[test]
++ fn the_rolling_wrap_iv_advances_per_segment_and_an_explicit_one_wins() {
++ let item = |explicit: bool| {
++ let mut map = vec![
++ (Value::Integer(1.into()), Value::Bytes(vec![0; 48])),
++ (Value::Integer(2.into()), Value::Integer(4.into())),
++ ];
++ if explicit {
++ map.push((Value::Integer(7.into()), Value::Bytes(vec![0xee; 16])));
++ }
++ Value::Map(map)
++ };
++ let mut rolling = [0u8; 16];
++ rolling[15] = 0xff;
++ let found = segments(&[item(false), item(true), item(false)], &mut rolling).unwrap();
++ assert_eq!(found[0].wrap_iv[14..], [0x00, 0xff]);
++ assert_eq!(found[1].wrap_iv, [0xee; 16]);
++ assert_eq!(found[2].wrap_iv[14..], [0x01, 0x01]);
++ }
++
++ fn empty(path: &str) -> Entry {
++ Entry { path: PathBuf::from(path), size: 0, hash: Some(Sha384::digest(b"").to_vec()), segments: vec![] }
++ }
++
++ fn plan_of(entries: Vec) -> Plan {
++ Plan { entries, boxes: vec![], package_key: [0; 32] }
++ }
++
++ async fn run(plan: &Plan, out: &Path) -> Result<(), String> {
++ install(&reqwest::Client::new(), plan, out, &|_| {}).await
++ }
++
++ #[test]
++ fn only_files_verified_by_an_install_count_as_complete() {
++ let root = tempfile::tempdir().unwrap();
++ let (segment, _) = sealed(b"x", &[1; 32]);
++ let entry = |path: &str, size: u64| Entry { path: PathBuf::from(path), size, hash: None, segments: vec![segment.clone()] };
++ let plan = plan_of(vec![entry("done.bin", 4), entry("partial.bin", 10), entry("missing.bin", 7)]);
++ std::fs::write(root.path().join("done.bin"), b"abcd").unwrap();
++ std::fs::write(root.path().join("partial.bin"), b"abc").unwrap();
++ assert_eq!(plan.total(), 21);
++ assert_eq!(plan.remaining(root.path()), 21);
++ std::fs::create_dir(root.path().join(STATE)).unwrap();
++ let record = root.path().join(STATE).join(VERIFIED);
++ note(&record, Path::new("done.bin"), &identity(&plan.entries[0])).unwrap();
++ assert_eq!(plan.remaining(root.path()), 17);
++ std::fs::write(root.path().join("done.bin"), b"abcde").unwrap();
++ assert_eq!(plan.remaining(root.path()), 21);
++ }
++
++ #[test]
++ fn an_interrupted_record_never_swallows_the_next_one() {
++ let root = tempfile::tempdir().unwrap();
++ let (older, _) = sealed(b"old", &[1; 32]);
++ let (newer, _) = sealed(b"new", &[1; 32]);
++ let entry = |segment: &Segment| Entry { path: PathBuf::from("game.bin"), size: 3, hash: None, segments: vec![segment.clone()] };
++ let (old, new) = (plan_of(vec![entry(&older)]), plan_of(vec![entry(&newer)]));
++ let (kept, _) = sealed(b"keep", &[1; 32]);
++ let other = plan_of(vec![Entry { path: PathBuf::from("other.bin"), size: 4, hash: None, segments: vec![kept] }]);
++ std::fs::write(root.path().join("game.bin"), b"new").unwrap();
++ std::fs::write(root.path().join("other.bin"), b"keep").unwrap();
++ std::fs::create_dir(root.path().join(STATE)).unwrap();
++ let record = root.path().join(STATE).join(VERIFIED);
++ note(&record, Path::new("other.bin"), &identity(&other.entries[0])).unwrap();
++ note(&record, Path::new("game.bin"), &identity(&old.entries[0])).unwrap();
++ let mut torn = std::fs::read(&record).unwrap();
++ torn.extend_from_slice(&key(Path::new("game.bin")).as_bytes()[..20]);
++ std::fs::write(&record, &torn).unwrap();
++ assert_eq!(old.remaining(root.path()), 0);
++ note(&record, Path::new("game.bin"), "-").unwrap();
++ assert_eq!(old.remaining(root.path()), 3);
++ assert_eq!(new.remaining(root.path()), 3);
++ assert_eq!(other.remaining(root.path()), 0);
++ assert!(std::fs::read(&record).unwrap().ends_with(b"\n"));
++ }
++
++ #[test]
++ fn only_the_latest_record_for_a_path_describes_its_file() {
++ let root = tempfile::tempdir().unwrap();
++ let (older, _) = sealed(b"old", &[1; 32]);
++ let (newer, _) = sealed(b"new", &[1; 32]);
++ let entry = |segment: &Segment| Entry { path: PathBuf::from("game.bin"), size: 3, hash: None, segments: vec![segment.clone()] };
++ let (old, new) = (plan_of(vec![entry(&older)]), plan_of(vec![entry(&newer)]));
++ std::fs::write(root.path().join("game.bin"), b"new").unwrap();
++ std::fs::create_dir(root.path().join(STATE)).unwrap();
++ let record = root.path().join(STATE).join(VERIFIED);
++ note(&record, Path::new("game.bin"), &identity(&old.entries[0])).unwrap();
++ note(&record, Path::new("game.bin"), "-").unwrap();
++ assert_eq!(old.remaining(root.path()), 3);
++ note(&record, Path::new("game.bin"), &identity(&new.entries[0])).unwrap();
++ assert_eq!(new.remaining(root.path()), 0);
++ assert_eq!(old.remaining(root.path()), 3);
++ }
++
++ #[tokio::test]
++ async fn a_planned_name_never_serves_as_another_files_partial() {
++ let root = tempfile::tempdir().unwrap();
++ let plan = plan_of(vec![empty("data.bin.part"), empty("data.bin")]);
++ run(&plan, root.path()).await.unwrap();
++ assert!(root.path().join("data.bin.part").is_file());
++ assert!(root.path().join("data.bin").is_file());
++ assert_eq!(plan.remaining(root.path()), 0);
++ assert!(!root.path().join(STATE).join(PARTIAL).exists());
++ }
++
++ #[cfg(unix)]
++ #[tokio::test]
++ async fn a_linked_folder_inside_the_install_is_refused_and_a_linked_root_is_followed() {
++ let root = tempfile::tempdir().unwrap();
++ let outside = tempfile::tempdir().unwrap();
++ std::os::unix::fs::symlink(outside.path(), root.path().join("Data")).unwrap();
++ assert!(run(&plan_of(vec![empty("Data/game.bin")]), root.path()).await.is_err());
++ assert_eq!(std::fs::read_dir(outside.path()).unwrap().count(), 0);
++ std::fs::create_dir_all(root.path().join(STATE).join(PARTIAL)).unwrap();
++ std::fs::write(outside.path().join("victim"), b"keep").unwrap();
++ std::os::unix::fs::symlink(outside.path().join("victim"), root.path().join(STATE).join(PARTIAL).join("0")).unwrap();
++ run(&plan_of(vec![empty("game.bin")]), root.path()).await.unwrap();
++ assert_eq!(std::fs::read(outside.path().join("victim")).unwrap(), b"keep");
++ let real = tempfile::tempdir().unwrap();
++ let link = root.path().join("linked-root");
++ std::os::unix::fs::symlink(real.path(), &link).unwrap();
++ run(&plan_of(vec![empty("Bin/game.bin")]), &link).await.unwrap();
++ assert!(real.path().join("Bin/game.bin").is_file());
++ }
++
++ #[test]
++ fn reclaiming_clears_only_unfinished_downloads() {
++ let root = tempfile::tempdir().unwrap();
++ std::fs::create_dir_all(root.path().join(STATE).join(PARTIAL)).unwrap();
++ std::fs::write(root.path().join(STATE).join(PARTIAL).join("0"), vec![0; 4096]).unwrap();
++ std::fs::write(root.path().join(STATE).join(VERIFIED), b"x y\n").unwrap();
++ std::fs::write(root.path().join("game.bin"), b"done").unwrap();
++ reclaim(root.path()).unwrap();
++ assert!(!root.path().join(STATE).join(PARTIAL).exists());
++ assert!(root.path().join(STATE).join(VERIFIED).is_file());
++ assert!(root.path().join("game.bin").is_file());
++ reclaim(root.path()).unwrap();
++ }
++
++ #[cfg(unix)]
++ #[test]
++ fn reclaiming_never_follows_a_linked_state_folder() {
++ let root = tempfile::tempdir().unwrap();
++ let outside = tempfile::tempdir().unwrap();
++ std::fs::create_dir(outside.path().join(PARTIAL)).unwrap();
++ std::fs::write(outside.path().join(PARTIAL).join("keep"), b"keep").unwrap();
++ std::os::unix::fs::symlink(outside.path(), root.path().join(STATE)).unwrap();
++ assert!(reclaim(root.path()).is_err());
++ assert!(outside.path().join(PARTIAL).join("keep").is_file());
++ let linked_root = tempfile::tempdir().unwrap();
++ let real = tempfile::tempdir().unwrap();
++ std::fs::create_dir_all(real.path().join(STATE).join(PARTIAL)).unwrap();
++ let link = linked_root.path().join("game");
++ std::os::unix::fs::symlink(real.path(), &link).unwrap();
++ reclaim(&link).unwrap();
++ assert!(!real.path().join(STATE).join(PARTIAL).exists());
++ }
++
++ #[test]
++ fn package_paths_stay_inside_the_install_folder() {
++ assert_eq!(relative("EmuMenu\\EmuMenu.exe").unwrap(), PathBuf::from("EmuMenu/EmuMenu.exe"));
++ for bad in ["", "..\\x", "/abs", "a\\..\\..\\b", "C:\\x", ".DroidDeck-Install\\verified"] {
++ assert!(relative(bad).is_err(), "{bad}");
++ }
++ }
++
++ #[test]
++ fn the_key_derivation_matches_sp800_108_counter_mode() {
++ let derived = derive(&[0x42; 32], b"ctx");
++ let mut message = 1u32.to_be_bytes().to_vec();
++ message.extend_from_slice(KDF_LABEL);
++ message.push(0);
++ message.extend_from_slice(b"ctx");
++ message.extend_from_slice(&256u32.to_be_bytes());
++ let mut mac = as hmac::KeyInit>::new_from_slice(&[0x42; 32]).unwrap();
++ mac.update(&message);
++ assert_eq!(derived.as_slice(), mac.finalize().into_bytes().as_slice());
++ }
++}
+diff --git a/crates/xodus-cli/src/commands/store_delivery.rs b/crates/xodus-cli/src/commands/store_delivery.rs
+index 7fec6e5..d34b402 100644
+--- a/crates/xodus-cli/src/commands/store_delivery.rs
++++ b/crates/xodus-cli/src/commands/store_delivery.rs
+@@ -363,16 +363,6 @@ async fn download_url(
+ Err(format!("No download location was issued for {}", revision.name))
+ }
+
+-/// Resolves the legacy packages of a Store product through Windows Update.
+-pub async fn resolve(
+- client: &reqwest::Client,
+- product: &str,
+- market: &str,
+-) -> Result {
+- let category = category(client, product, market).await?;
+- resolve_category(client, &category).await
+-}
+-
+ /// Every build of a Store product Windows Update lists, newest first. Each build
+ /// has its own content id, and Microsoft can refuse keys for one but not another.
+ pub struct Builds {
+@@ -438,16 +428,6 @@ fn builds_newest_first(revisions: Vec) -> Vec> {
+ groups.into_iter().filter(|group| !group.is_empty()).collect()
+ }
+
+-/// The packages a Windows Update category lists, in the containers a title is
+-/// packed in.
+-pub async fn resolve_category(client: &reqwest::Client, category: &str) -> Result {
+- resolve_wanted(client, category, true, |name| {
+- let lower = name.to_ascii_lowercase();
+- lower.ends_with(".eappx") || lower.ends_with(".eappxbundle")
+- })
+- .await
+-}
+-
+ /// The plain `.appx` packages a category lists, which is how a framework ships.
+ pub async fn resolve_frameworks(client: &reqwest::Client, category: &str) -> Result {
+ resolve_wanted(client, category, false, |name| name.to_ascii_lowercase().ends_with(".appx")).await
+diff --git a/crates/xodus-cli/src/commands/streaming.rs b/crates/xodus-cli/src/commands/streaming.rs
+index 8e9d0e0..426de96 100644
+--- a/crates/xodus-cli/src/commands/streaming.rs
++++ b/crates/xodus-cli/src/commands/streaming.rs
+@@ -361,7 +361,11 @@ where
+ return ExitCode::FAILURE;
+ }
+ if plain {
+- return plain_package(remote_file, l, out).await;
++ let code = plain_package(remote_file, l, out).await;
++ if code != ExitCode::SUCCESS || !crate::commands::msixvc2::is_package(out) {
++ return code;
++ }
++ return boxed_package(client, tokens, out, market, tx).await;
+ }
+ let remote_xvd = match XvdFile::parse(&mut remote_file).await {
+ Ok(xvd) => xvd,
+@@ -853,6 +857,82 @@ async fn plain_package(mut remote: R, length: u64, out: &P
+ }
+ }
+
++async fn boxed_package(
++ client: &reqwest::Client,
++ tokens: &TokenManager,
++ out: &Path,
++ market: Option,
++ tx: &Sender,
++) -> ExitCode {
++ let fail = |message: &str| {
++ eprintln!("NEXUS_TRANSFER_DIAGNOSTIC_V1 boxed-package-failed 0");
++ eprintln!("{message}");
++ ExitCode::FAILURE
++ };
++ let content_id = match crate::commands::msixvc2::content_id(out) {
++ Ok(id) => id,
++ Err(error) => return fail(&error),
++ };
++ let (device_key, license) = match get_license(client, tokens, content_id, market.unwrap_or("neutral".to_string()), None, false).await {
++ Ok(found) => found,
++ Err(error) => {
++ eprintln!("{error}");
++ return ExitCode::FAILURE;
++ }
++ };
++ let mut keys = HashMap::new();
++ for (id, packed) in license.content_keys {
++ let Ok(key) = packed.unpack(&device_key) else {
++ return fail("The content key could not be authenticated. Retry the installation or sign in again.");
++ };
++ if let Ok(key) = <[u8; 32]>::try_from(&key[..]) {
++ keys.insert(id.to_bytes_le(), key);
++ }
++ }
++ tx.send(ProgressEvent::UpdateStatus { name: "Preparing".to_owned() }).await.ok();
++ let plan = match crate::commands::msixvc2::plan(client, out, &keys).await {
++ Ok(plan) => plan,
++ Err(error) => return fail(&error),
++ };
++ if let Err(error) = crate::commands::msixvc2::reclaim(out) {
++ return fail(&error);
++ }
++ let total = plan.total();
++ let needed = plan.remaining(out);
++ if let Ok(free) = available_space(out)
++ && free < needed
++ {
++ eprintln!("NEXUS_LEGACY_INSTALL_DIAGNOSTIC_V1 insufficient-space");
++ eprintln!(
++ "NEXUS_LEGACY_INSTALL_DETAIL_V1 an install this size needs about {} GB free, and {} GB is available",
++ needed.div_ceil(1_000_000_000),
++ free / 1_000_000_000
++ );
++ return ExitCode::FAILURE;
++ }
++ tx.send(ProgressEvent::UpdateRemaining { name: "Downloading".to_owned(), total }).await.ok();
++ tx.send(ProgressEvent::Started { id: 0, name: "Game files".to_owned(), total }).await.ok();
++ let pending = std::sync::atomic::AtomicU64::new(0);
++ let report = |written: u64| {
++ let delta = pending.fetch_add(written, std::sync::atomic::Ordering::Relaxed) + written;
++ if tx.try_send(ProgressEvent::Advanced { id: 0, delta }).is_ok() {
++ pending.fetch_sub(delta, std::sync::atomic::Ordering::Relaxed);
++ }
++ };
++ let installed = crate::commands::msixvc2::install(client, &plan, out, &report).await;
++ let rest = pending.swap(0, std::sync::atomic::Ordering::Relaxed);
++ if rest > 0 {
++ tx.send(ProgressEvent::Advanced { id: 0, delta: rest }).await.ok();
++ }
++ match installed {
++ Ok(()) => {
++ tx.send(ProgressEvent::Finished { id: 0 }).await.ok();
++ ExitCode::SUCCESS
++ }
++ Err(error) => fail(&error),
++ }
++}
++
+ #[cfg(test)]
+ mod plain_tests {
+ fn stored_zip(name: &str, data: &[u8]) -> Vec {
diff --git a/tools/xbox/prepare.py b/tools/xbox/prepare.py
index cb243221b2..5ff45b9c64 100755
--- a/tools/xbox/prepare.py
+++ b/tools/xbox/prepare.py
@@ -11,7 +11,8 @@ lock = json.loads((recipe / 'backend.lock.json').read_text())
local_patches = ['droiddeck-credentials.patch', 'droiddeck-launch-view.patch', 'droiddeck-library-subscriptions.patch',
'droiddeck-credential-fallback.patch', 'droiddeck-credential-diagnostics.patch', 'droiddeck-cloud-token.patch',
'droiddeck-licensing-device-ticket.patch', 'droiddeck-dlc-mount.patch',
- 'droiddeck-legacy-packages.patch', 'droiddeck-legacy-install.patch', 'droiddeck-legacy-run.patch']
+ 'droiddeck-legacy-packages.patch', 'droiddeck-legacy-install.patch', 'droiddeck-legacy-run.patch',
+ 'droiddeck-msixvc2.patch']
identity = hashlib.sha256((recipe / 'backend.lock.json').read_bytes() + b''.join((recipe / name).read_bytes() for name in local_patches)).hexdigest()
source = cache / ('source-' + identity[:16])
if not (source / '.prepared').is_file():