Files
DroidDeck/tools
Kurt HimebauchandTimmyCraft a5d8abeab4 feat(xbox): install legacy EAppx titles through Windows Update (on main) (#2825)
* feat(xbox): install legacy EAppx titles through Windows Update

A legacy Store title does not ship as MSIXVC. It ships as an encrypted
EAppx bundle, which streaming rejects, so the store could list the game
and never install it.

Accept EAPPX and EAPPXBUNDLE beside MSIXVC, carry the format through the
catalogue, the install record and the cached library, and dispatch
legacy-install for those formats.

Two backend patches do the work:

- droiddeck-legacy-packages.patch lets the plan, license and extract
  verbs handle a legacy package, and expands a bundle in place (nesting
  bounded at three), decrypting each inner EAppx with the same keys.
- droiddeck-legacy-install.patch adds legacy-install: resolve,
  license, download, extract, hoist AppxManifest.xml to the game root.
  Resolution asks the Xbox content service first and Windows Update
  second, because some legacy products return no files from the content
  service at all. The WU endpoint needs no Xbox credential but chains to
  Microsoft's ECC Product Root CA 2018, which Android's CA bundle does
  not carry, so that one public root is pinned for those requests.

The manifest reader accepts AppxManifest.xml as well as
MicrosoftGame.config, since a legacy package carries only the former.

Running it against a real title exposed four things that only show up at
full size:

- A licence names a key by its 16-byte content id, while a bundle header
  names it as a (content id, package id) pair. Reading the 16-byte id
  yields a different pair, so a complete key file reported every key
  missing and no bundle could be opened. Keys are now aligned against
  the header's own ids before the header is judged.
- Windows Update answers with several updates whose PackageContentId
  differs from the bundle's own. Licensing used to take the first and
  fail with content-http 400; every candidate is now tried in order,
  preferring the one the container is named after.
- A container already in .xodus-container is reused rather than fetched
  again, so a failed run does not cost another download of tens of
  gigabytes. The space preflight no longer counts a container twice for
  the same reason.
- A bundle that carries add-on packages unpacks each into its own
  folder, leaving the manifest one level down. Hoisting lifts the
  largest folder that holds a manifest, so the game still lands at the
  root beside its add-ons.

Unpacking now reports bytes written, so the install bubble fills while a
package is decrypted instead of holding a single unchanging word.

* fix(xbox): unpack a legacy package across cores and report the bytes

Unpacking one title ran as a single thread on a saturated core at about
40 MB/s. Files sit at independent offsets, so each worker now opens its own
handle and takes every Nth file, with a 1 MiB read buffer in place of the
8 KiB default that turned one 64 KiB block into eight reads. Measured on the
Forza Horizon 4 bundle, writes went from 40 MB/s to about 200 MB/s.

Two things the first full-size run exposed:

- The container was deleted only after the whole nested tree was unpacked,
  so a title that holds its package as one member held the archive and the
  decrypted copy at once. On this device that runs out of space partway
  through the second stage. The container is now deleted once its members
  are on disk, which frees the archive before they are decrypted.
- A bundle member is written as a single file, so a counter that advances
  when a file finishes stays at zero for the whole of the longest stage.
  The reported figure now also follows the growth of the destination while
  that is the case, and never moves backwards when the container is freed.

Progress is exact during the per-file stage: each file's declared length is
added as it lands, instead of walking the whole destination every tick.

* docs(xbox): record the completed legacy install

The evidence section said a finished legacy install and its decrypted
contents were unverified, because the first run was still unpacking when it
was written. That install has now completed on the same device: the
85,219,173,025-byte container produced 79.3 GB at the game root with
AppxManifest.xml and the package DLLs directly beneath it, and the launcher
lists the title as installed.

It also records what unpacking costs, since that decided the change: one
thread held a core at 100% for about 40 MB/s and four reach about 200 MB/s,
and releasing each container once its members are on disk is what keeps the
peak footprint at one package rather than the archive plus its contents.

The launch is not part of this evidence, and the entry says so.

* fix(xbox): place the 64-bit framework beside a legacy title

A Windows Update framework category lists one package per architecture under
identifier-only names. The first package was unpacked, which on this device was
the x86 build, so a 64-bit title got 32-bit DLLs and every load failed with
STATUS_INVALID_IMAGE_FORMAT. Candidates are unpacked now and only the one whose
manifest declares ProcessorArchitecture="x64" is kept.

The framework folder was also never created, so a finished download failed at the
move with "no such file or directory".

unzip.rs belongs to this patch: legacy-install calls it and the recipe left it out,
so a rebuild from the pinned source could not compile.

* feat(xbox): report a UWP entry point at launch

An unpacked package can name a COM class as its entry point instead of
Windows.FullTrustApplication. That class is a UWP application, which expects the
app model to activate a view; Wine has no host for it, so the launch died inside
the loader with no explanation. The launch now reads the entry point and reports
uwp-entry-point, and full-trust packages are unaffected.

Forza Horizon 4 is such a package: its manifest names Forza.App. Its frameworks
are installed and the loader is clean before that point.

* fix(xbox): report why a launch was refused

A failed prepare replaced the backend message with a fixed sign-in hint, so a title
that was not installed or a runtime that refused all read as a bad account. The
reason is kept, with paths and URLs dropped, and written to the store log.

* fix(adb): dismiss the keyboard on Search and Go

Search and Go were terminal IME actions but were not handled, so focus stayed in
the field and the keyboard covered the results it had just fetched.

* fix(xbox): keep a cache row without a legacy format plain

Decoding added a format key with an empty value to every cached title, so a
library restored from storage no longer matched the one that was saved.

* test(ui): match the manifest message a legacy package reports

The message covers both a MicrosoftGame.config and an AppxManifest, so the
assertion follows the text the content dialog now prints.

* fix(xbox): refuse to start a title that needs the Windows app model

A legacy package that names an entry point other than
Windows.FullTrustApplication is a UWP application. Wine has no app-model
host, so starting its executable crashes inside the loader and the launch
looks like nothing happened. Read the entry point from the manifest the
installer already parses and stop the Play action with a message instead.

Forza Horizon 4 names Forza.App, so it installs and reports as installed
but cannot be started here yet.

* fix(xbox): dispatch on the container format of the chosen package

The catalogue records the format of the first installable desktop package, and
the picker only replaced the content id. An offer that lists MSIXVC and a legacy
container would then hand the legacy id to streaming, or the streamed id to
legacy-install, and the install failed after resolution had succeeded.

The choice now carries its own format and the catalogue value only fills a gap.

* fix(xbox): keep an extraction reason that the sanitizer rewrote

The extraction sanitizer replaces anything outside letters, digits, space, dot,
underscore and dash with a question mark, so a reason such as "(os error 28)"
arrived as "?os error 28?" and the allowlist dropped the line. The failure then
showed only the stage code, with no cause.

Add that replacement character to the class the allowlist accepts.

* fix(xbox): print the reason a launch was refused

The account channel sends a reason with a refusal, and the guest replaced it
with a fixed sign-in message, so a title that was never installed still read as
a bad account. The guest now shows the reason it was given, and a token holding
a path is dropped whole instead of having its slashes removed and its directory
names kept.

* build(xbox): leave RUST_TEST_THREADS unset when the host has no value

The recipe always passed the variable, empty when the host had none, and the
pinned test harness rejects an empty count. On an ARM64 host that runs cargo
test, so the default local build failed before compiling.

* fix(xbox): rebuild the backend patches from the tree that ran

The two patches in this branch were not the ones the verified install ran, and
one of them did not compile. `unzip.rs` inflates deflated entries but the
dependency that provides the inflater was never added, so `prepare.py` produced
a tree that failed at `flate2::read::DeflateDecoder`. Anything else missing fell
into the same gap: the install stage reported no bytes, so the bar held one
value for the whole unpack, and a container a stopped run had finished was
downloaded again.

Rebuilt from the patched source, and fixed the defects a review of the patch
found:

- Unpacking reports bytes again: the workers count each file's declared length,
  and for the single-file bundle member the folder's growth stands in, which is
  what the device run showed.
- A finished container is reused, so a retry after a failure past the download
  does not spend hours fetching it again. The space preflight counts it as
  reclaimable, since the retry truncates it first.
- An install over a folder that already has a manifest replaces the old files
  instead of leaving the new package nested and reporting success. A first
  install still refuses to merge into an existing target.
- The manifest search looks at the depth a nested bundle writes, not only one
  level down.
- `withdraw_libraries` removes only the DLLs `copy_libraries` recorded copying,
  so a framework replacement cannot delete a library the title owns.
- ZIP64 sizes and offsets stay `u64`; truncating them to `u32` read the wrong
  local header past 4 GiB.
- The extraction checks the blockmap length against the footer's before writing,
  which the crate only does when asked.
- The container being unpacked is never treated as a nested member, so
  `extract-eappx title.eappx .` no longer re-enters and deletes its own input.
- `flate2` is declared and the lock is updated.

`prepare.py` reproduces this from a pristine checkout and `cargo test` passes on
it.

* fix(xbox): apply the legacy install patch over the Nexus 0.2.15 backend

* fix(xbox): install only the newest x64 build of a legacy title and size the space check at its real peak

* fix(xbox): install a store package that is a plain archive instead of an XVD

* fix(xbox): refuse a package entry that ends before its recorded size

* fix(xbox): credit only complete staged containers toward the free space a legacy install needs

* fix(xbox): bound each package entry to its data and check ZIP64 decoded sizes

* fix(xbox): refuse duplicate package names and clear an unfinished download before measuring space

* fix(xbox): bound package entries by the next header and stage a plain package until it validates

* fix(xbox): hold the install folder lock through a legacy install

* fix(xbox): fall back to an older build when Microsoft refuses the newest one a license

* fix(xbox): keep the registered device across sign-out

* feat(xbox): explain device-limit and license refusals, with a link to manage devices

* fix(xbox): locate each build only once licensed, roll back a failed package swap, report the final license answer

* fix(xbox): skip trial and preorder packages, read runtime behavior, keep licensing timeouts

* fix(xbox): keep a failed package swap recoverable, size bundles up front, report key-write and framework errors cleanly

* fix(xbox): drop a pending manifest check on any newer launch, keep committed backups out of restores, match the app-model order

* fix(xbox): cancel pending launch checks on a new intent, remember entries a rollback could not remove

* fix(xbox): clear the removal list before a restore moves old files back

---------

Co-authored-by: TimmyCraft <46533729+TimmyTurner51@users.noreply.github.com>
2026-11-18 14:14:26 -05:00
..