From a9cd982ec866092ce45f0e5b8e93e59a8d678733 Mon Sep 17 00:00:00 2001 From: xXJsonDeruloXx Date: Thu, 1 Oct 2026 18:27:53 -0400 Subject: [PATCH] Let Steam install prerequisites and retire blanket registry seeding --- .../launcher/session/SessionFiles.kt | 2 +- .../usr/local/bin/bannerlator-restore-redists | 86 +++++++++++++++++ .../usr/local/bin/bannerlator-seed-redists | 94 ------------------- .../overlay/usr/local/bin/bannerlator-session | 28 +----- tools/tests/test_restore_redists.py | 90 ++++++++++++++++++ 5 files changed, 182 insertions(+), 118 deletions(-) create mode 100755 tools/linuxfs/overlay/usr/local/bin/bannerlator-restore-redists delete mode 100755 tools/linuxfs/overlay/usr/local/bin/bannerlator-seed-redists create mode 100644 tools/tests/test_restore_redists.py diff --git a/app/src/main/java/com/droiddeck/launcher/session/SessionFiles.kt b/app/src/main/java/com/droiddeck/launcher/session/SessionFiles.kt index f579e6c94e..ef221c0997 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/SessionFiles.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/SessionFiles.kt @@ -35,7 +35,7 @@ object SessionFiles { "usr/local/bin/bannerlator-steam-compat" to "usr/local/bin/bannerlator-steam-compat", "usr/local/bin/bannerlator-steam-install" to "usr/local/bin/bannerlator-steam-install", "usr/local/bin/bannerlator-steam-library" to "usr/local/bin/bannerlator-steam-library", - "usr/local/bin/bannerlator-seed-redists" to "usr/local/bin/bannerlator-seed-redists", + "usr/local/bin/bannerlator-restore-redists" to "usr/local/bin/bannerlator-restore-redists", "usr/local/bin/bannerlator-proton-extra" to "usr/local/bin/bannerlator-proton-extra", "usr/local/bin/bannerlator-netmanager" to "usr/local/bin/bannerlator-netmanager", "usr/local/bin/bannerlator-steam-launch" to "usr/local/bin/bannerlator-steam-launch", diff --git a/tools/linuxfs/overlay/usr/local/bin/bannerlator-restore-redists b/tools/linuxfs/overlay/usr/local/bin/bannerlator-restore-redists new file mode 100755 index 0000000000..ab1a7abe46 --- /dev/null +++ b/tools/linuxfs/overlay/usr/local/bin/bannerlator-restore-redists @@ -0,0 +1,86 @@ +#!/usr/bin/python3 +"""Undo the old blanket HasRunKey seeder before Steam/Wine starts. + +Steam must run native prerequisites and record their real result. Only prefixes carrying +our old seeder stamp are migrated. Proton's intentional .NET/XNA defaults remain intact. +""" +import os +from pathlib import Path +import re +import sys +import tempfile + + +def restore_prefix(prefix): + prefix = Path(prefix) + stamp = prefix / '.bannerlator-redists' + reg = prefix / 'system.reg' + if not stamp.is_file() or stamp.is_symlink() or not reg.is_file() or reg.is_symlink(): + return False + text = reg.read_text(encoding='utf-8') + if not text.startswith('WINE REGISTRY Version 2'): + raise ValueError('not a Wine registry') + out = [] + clear = False + for line in text.splitlines(keepends=True): + match = re.match(r'^\[([^\]]+)\]', line) + if match: + key = match[1].replace('\\\\', '\\').lower() + parts = key.split('\\') + try: + common = parts.index('commonredist') + except ValueError: + clear = False + else: + clear = (parts[:common] in ( + ['software', 'valve', 'steam', 'apps'], + ['software', 'wow6432node', 'valve', 'steam', 'apps']) + and len(parts) > common + 1 + and parts[common + 1] not in ('.net', 'xna')) + if clear and re.fullmatch(r'"[^"\r\n]+"=dword:00000001\s*', line): + continue + out.append(line) + updated = ''.join(out) + if updated != text: + stat = reg.stat() + descriptor, temporary = tempfile.mkstemp(dir=prefix, prefix='.redists-') + try: + with os.fdopen(descriptor, 'w', encoding='utf-8') as f: + f.write(updated) + os.chmod(temporary, stat.st_mode & 0o777) + # Preserve template dates: this migration already covers existing prefixes and + # should not force every game through a Proton prefix upgrade. + os.utime(temporary, ns=(stat.st_atime_ns, stat.st_mtime_ns)) + os.replace(temporary, reg) + finally: + if os.path.exists(temporary): + os.unlink(temporary) + stamp.unlink() + return updated != text + + +def restore(steam_root, libraries=('/mnt/droiddeck-sd',)): + roots = [Path(steam_root), *(Path(p) for p in libraries)] + prefixes = [] + for root in roots: + prefixes.extend(root.glob('steamapps/compatdata/*/pfx')) + prefixes.extend(root.glob('steamapps/common/Proton*/files/share/default_pfx*')) + prefixes.extend(Path(steam_root).glob('compatibilitytools.d/*/files/share/default_pfx*')) + seen = set() + changed = 0 + for prefix in prefixes: + actual = prefix.resolve() + if actual in seen: + continue + seen.add(actual) + try: + if restore_prefix(actual): + changed += 1 + print('bannerlator-restore-redists: restored Steam prerequisite checks in %s' % prefix) + except (OSError, UnicodeError, ValueError) as error: + print('bannerlator-restore-redists: %s: %s' % (prefix, error), file=sys.stderr) + return changed + + +if __name__ == '__main__': + restore(sys.argv[1]) diff --git a/tools/linuxfs/overlay/usr/local/bin/bannerlator-seed-redists b/tools/linuxfs/overlay/usr/local/bin/bannerlator-seed-redists deleted file mode 100755 index ea1d413f54..0000000000 --- a/tools/linuxfs/overlay/usr/local/bin/bannerlator-seed-redists +++ /dev/null @@ -1,94 +0,0 @@ -#!/bin/bash -# Marks Steam's shared redistributables as already run in every Proton prefix, and in the -# template Proton makes new prefixes from. -# -# A game whose depot lists _CommonRedist makes the client run the real installer inside the -# prefix on first launch. Those are x86 bundles, so they run under FEX, and the 2019 one leaves -# a task behind every time: its main thread exits while a helper stays blocked reading a pipe it -# also holds the write end of, so the process never reaps and the client keeps waiting on it. -# -# The client skips a "Run Process" block whose HasRunKey is already set, which is the same escape -# WineUtils.seedVcRedistRegistryIfDllsPresent() takes for the app's own containers. The names and -# versions come out of the install scripts rather than a list kept here, because Valve revises -# them; a prefix already carrying the same set is left alone. -set -u -steam_root=${1:?steam root} - -redist="$steam_root/steamapps/common/Steamworks Shared/_CommonRedist" - -# Every process an install script would run, as the registry key and value the client writes once -# it has run it. Names sit one level inside "Run Process", the key they share a level further in. -pairs=$(find "$redist" -name installscript.vdf -print0 2>/dev/null | sort -z | xargs -0 -r awk ' - FNR == 1 { depth = 0; name = ""; key = "" } - /^[[:space:]]*\{/ { depth++; next } - /^[[:space:]]*\}/ { - if (depth == 3 && name != "" && key != "") - printf "%s\t%s\n", key, name - depth-- - next - } - { - n = split($0, part, "\"") - if (n >= 5 && tolower(part[2]) == "hasrunkey") { key = part[4]; next } - if (n >= 3 && depth == 2) { name = part[2]; key = "" } - } -') -# The client downloads the scripts with the first game that wants them, which is too late for that -# game; until then the set they held when this was written stands in. (WinNative's list.) -[ -n "$pairs" ] || pairs=$(sed 's/^\([^ ]*\) /HKEY_LOCAL_MACHINE\\\\Software\\\\Valve\\\\Steam\\\\Apps\\\\CommonRedist\\\\\1\t/' <<'KNOWN' -DirectX\\Jun2010 dxsetup -.NET\\4.8 4.8 -vcredist\\2008 x86 SP1 -vcredist\\2008 x64 SP1 -vcredist\\2010 x86 -vcredist\\2010 x64 -vcredist\\2013 x86 12.0.30501 -vcredist\\2013 x64 12.0.30501 -vcredist\\2015 x86 Update 3 14.0.24215.0 -vcredist\\2015 x64 Update 3 14.0.24215.0 -vcredist\\2017 x86 14.10.25008.0 -vcredist\\2017 x64 14.10.25008.0 -vcredist\\2019 x86 14.28.29334.0 -vcredist\\2019 x64 14.28.29334.0 -vcredist\\2022 x86 14.51.36247.0 -vcredist\\2022 x64 14.51.36247.0 -KNOWN -) -# The stamp is the set of names, taken before the block below dates its keys: stamped from the -# dated block it never matched, and every prefix had the whole block appended again on every beat. -stamp=$(printf '%s' "$pairs" | cksum) - -block=$(printf '%s\n' "$pairs" | awk -F'\t' -v now="$(date +%s)" ' - { - path = $1 - sub(/^HKEY_LOCAL_MACHINE\\\\/, "", path) - if (path == $1) - next - printf "\n[%s] %d\n\"%s\"=dword:00000001\n", path, now, $2 - # The client writes these from 32-bit steam.exe, so its own copy lands under Wow6432Node; - # both spellings are seeded because the reader picks by its own word size. - sub(/^Software\\\\/, "Software\\\\\\\\Wow6432Node\\\\\\\\", path) - printf "\n[%s] %d\n\"%s\"=dword:00000001\n", path, now, $2 - } -') -[ -n "$block" ] || exit 0 - -# Proton builds a new prefix from its template, and the client runs the install scripts in that -# prefix moments later, so the template carries the markers too. Its date is kept: Proton reads a -# changed one as a new template and upgrades every prefix made from the old. -for reg in "$steam_root"/steamapps/common/Proton*/files/share/default_pfx*/system.reg \ - "$steam_root"/compatibilitytools.d/*/files/share/default_pfx*/system.reg \ - "$steam_root"/steamapps/compatdata/*/pfx/system.reg \ - /mnt/droiddeck-sd/steamapps/compatdata/*/pfx/system.reg; do - [ -f "$reg" ] || continue - seeded=$(dirname "$reg")/.bannerlator-redists - [ "$(cat "$seeded" 2>/dev/null)" = "$stamp" ] && continue - dated=$(mktemp) || continue - touch -r "$reg" "$dated" - if printf '%s\n' "$block" >>"$reg"; then - printf '%s\n' "$stamp" >"$seeded" - echo "== seeded redist markers into $reg" - fi - touch -r "$dated" "$reg" - rm -f "$dated" -done diff --git a/tools/linuxfs/overlay/usr/local/bin/bannerlator-session b/tools/linuxfs/overlay/usr/local/bin/bannerlator-session index cb65953400..3b51ef1b7a 100755 --- a/tools/linuxfs/overlay/usr/local/bin/bannerlator-session +++ b/tools/linuxfs/overlay/usr/local/bin/bannerlator-session @@ -323,9 +323,9 @@ case $mode in step "adding the app's own games to the client's library" bannerlator-steam-shortcuts "$steam_root" "$BL_ADDED_GAMES" || true fi - # Steam runs a game's shared redistributables inside its prefix on first launch; marking - # them as already run keeps those x86 installers from starting under emulation at all. - bannerlator-seed-redists "$steam_root" || true + # Undo earlier blanket success markers while Wine is stopped. Steam now installs its + # prerequisites normally; the Proton wrapper handles the old VC MSI bundles quietly. + bannerlator-restore-redists "$steam_root" || true # The compatibility tool runs Valve's arm64 Proton, which the client fetches like any depot. # Asked for on the command line the first time, so a Windows title has it before it is needed. if [ ! -f "$steam_root/steamapps/appmanifest_4427310.acf" ]; then @@ -397,18 +397,6 @@ case $mode in # titles are installed: a title installed this session gets the client's own per-app Proton # choice, which it cannot start. Refresh the per-app entries every so often; the registrar is # idempotent, so a repeat costs nothing. - # The seeder has the same problem and a worse consequence. It marks the shared redistributables - # as already run in each prefix that exists, and a game's prefix is not created until the - # client launches it - so a title played for the first time this session was never covered, and - # its install scripts run for real. That is exactly the hang the seeder exists to prevent: Need - # for Speed Payback sat on "Running install script" with vcredist_x86.exe blocked in pipe_read, - # holding both ends of a pipe nobody would write to, while the client waited for it to exit. - # Seeding again on the same beat covers a prefix the moment it appears. - # The seeder runs on a shorter beat than the registrar because it is racing something. The - # client creates a prefix when it launches a title and runs that title's install scripts - # moments later, so the seeder has only that gap to mark the redistributables as already run. - # It stamps each prefix it has covered and skips it thereafter, so the extra passes cost - # almost nothing. # The drawer's "Stretch games to fill the screen" works live: the app writes its choice to # ~/.droiddeck-fill, and each change goes to gamescope as GAMESCOPE_FORCE_WINDOWS_FULLSCREEN on # the root window, which it watches. What gamescope was started with is where this begins. @@ -478,13 +466,8 @@ case $mode in esac done ) & - # The library beat. Both helpers are whole programs under proot (the compat one a python - # start and a parse of the client's config), and nearly every beat has nothing new for them. - # The seeder marks Proton's prefix template as well as the prefixes, so a new prefix is born - # marked and every 15 s is soon enough for the rest. The compat pass runs when a directory it - # reads from has changed since its last run - a new manifest, a new depot or tool, the client - # rewriting config.vdf - which [ -nt ] answers without starting anything, and once a minute - # regardless. + # Refresh compatibility registrations when a library or client config changes, and once + # a minute regardless. Prerequisite checks belong to Steam and are not changed on this beat. ( beat=0 compat_stamp=$HOME/.bl-compat-beat @@ -502,7 +485,6 @@ case $mode in nap 5 beat=$((beat + 1)) [ "$((beat % 3))" -eq 0 ] || continue - bannerlator-seed-redists "$steam_root" >/dev/null 2>&1 || true if compat_due; then : > "$compat_stamp" bannerlator-steam-compat "$steam_root" >/dev/null 2>&1 || true diff --git a/tools/tests/test_restore_redists.py b/tools/tests/test_restore_redists.py new file mode 100644 index 0000000000..5f6727270d --- /dev/null +++ b/tools/tests/test_restore_redists.py @@ -0,0 +1,90 @@ +from pathlib import Path +import runpy +import tempfile +import unittest + +RESTORE = runpy.run_path(str(Path(__file__).resolve().parents[1] / + 'linuxfs/overlay/usr/local/bin/bannerlator-restore-redists')) + + +class RestoreRedistsTest(unittest.TestCase): + def setUp(self): + self.tmp = tempfile.TemporaryDirectory() + self.addCleanup(self.tmp.cleanup) + self.root = Path(self.tmp.name) + + def prefix(self, path): + path.mkdir(parents=True) + reg = path / 'system.reg' + reg.write_text('WINE REGISTRY Version 2\n\n' + + '[Software\\\\Wow6432Node\\\\Valve\\\\Steam\\\\Apps\\\\CommonRedist\\\\vcredist\\\\2019] 1\n' + '"x86"=dword:00000001\n"x64"=dword:00000001\n"OtherData"="preserved"\n\n' + '[Software\\\\Valve\\\\Steam\\\\Apps\\\\CommonRedist\\\\DirectX\\\\Jun2010] 1\n' + '"dxsetup"=dword:00000001\n\n' + '[Software\\\\Wow6432Node\\\\Valve\\\\Steam\\\\Apps\\\\CommonRedist\\\\.NET\\\\4.8] 1\n' + '"4.8"=dword:00000001\n\n' + '[Software\\\\Wow6432Node\\\\Valve\\\\Steam\\\\Apps\\\\CommonRedist\\\\XNA\\\\4.0] 1\n' + '"4.0"=dword:00000001\n\n' + '[Software\\\\Valve\\\\Steam\\\\Apps\\\\50620] 1\n' + '"Accessories"=dword:00000001\n\n' + '[Software\\\\Microsoft\\\\Installer\\\\Products\\\\NativeProduct] 1\n' + '"Installed"=dword:00000001\n') + (path / '.bannerlator-redists').write_text('old checksum') + return reg + + def test_migration_preserves_proton_defaults_native_products_and_game_checks(self): + reg = self.prefix(self.root / 'pfx') + stat = reg.stat() + self.assertTrue(RESTORE['restore_prefix'](reg.parent)) + text = reg.read_text() + for flag in ('"x86"', '"x64"', '"dxsetup"'): + self.assertNotIn(flag + '=dword:00000001', text) + for flag in ('"4.8"', '"4.0"', '"Accessories"', '"Installed"'): + self.assertIn(flag + '=dword:00000001', text) + self.assertIn('"OtherData"="preserved"', text) + self.assertEqual(stat.st_mtime_ns, reg.stat().st_mtime_ns) + self.assertEqual(stat.st_mode, reg.stat().st_mode) + # Once Steam has really installed a prerequisite, a later startup keeps its result. + with reg.open('a') as f: + f.write('\n[Software\\\\Valve\\\\Steam\\\\Apps\\\\CommonRedist\\\\vcredist\\\\2022] 2\n' + '"x86"=dword:00000001\n') + installed = reg.read_bytes() + self.assertFalse(RESTORE['restore_prefix'](reg.parent)) + self.assertEqual(installed, reg.read_bytes()) + + def test_unstamped_prefixes_and_registry_symlinks_are_untouched(self): + reg = self.prefix(self.root / 'pfx') + original = reg.read_bytes() + (reg.parent / '.bannerlator-redists').unlink() + self.assertFalse(RESTORE['restore_prefix'](reg.parent)) + self.assertEqual(original, reg.read_bytes()) + (reg.parent / '.bannerlator-redists').touch() + outside = self.root / 'original.reg' + reg.rename(outside) + reg.symlink_to(outside) + self.assertFalse(RESTORE['restore_prefix'](reg.parent)) + self.assertEqual(original, outside.read_bytes()) + + def test_primary_secondary_and_both_template_architectures_are_migrated(self): + steam, secondary = self.root / 'Steam', self.root / 'SD' + paths = [steam / 'steamapps/compatdata/1/pfx', + secondary / 'steamapps/compatdata/2/pfx', + steam / 'steamapps/common/Proton 11/files/share/default_pfx_arm64', + secondary / 'steamapps/common/Proton Experimental/files/share/default_pfx', + steam / 'compatibilitytools.d/GE/files/share/default_pfx_arm64'] + for path in paths: + self.prefix(path) + self.assertEqual(5, RESTORE['restore'](steam, [secondary])) + self.assertEqual(0, RESTORE['restore'](steam, [secondary])) + + def test_invalid_registry_keeps_migration_stamp_for_retry(self): + reg = self.prefix(self.root / 'pfx') + reg.write_text('incomplete registry') + with self.assertRaises(ValueError): + RESTORE['restore_prefix'](reg.parent) + self.assertTrue((reg.parent / '.bannerlator-redists').is_file()) + self.assertEqual('incomplete registry', reg.read_text()) + + +if __name__ == '__main__': + unittest.main()