From 1ec1c20be13be56ce22df981748d54b6dc2ee617 Mon Sep 17 00:00:00 2001 From: K11MCH1 <81425424+K11MCH1@users.noreply.github.com> Date: Wed, 4 Nov 2026 00:11:10 +0900 Subject: [PATCH] Steam: imported games with no known build update only when launched An added game the account owns is linked into Steam as DroidDeck-. When the folder carries no Steam build, Steam marks it Update Required and checks every file before updating. That check reads the whole game, and an interrupted one starts over, so on an SD card it ran again in every session and kept the card busy: Lords of the Fallen (33 GB) restarted 51 times in a day on an AYANEO Pocket FIT Elite. The manifest for such an import now asks Steam to update the game when it is launched. Imports that Steam already rewrote, but whose update has not started, switch from "always keep updated" to "update when launched"; a priority of 2, an update in progress, or an import with a recorded build is left alone. --- .../usr/local/bin/droiddeck-steam-games | 29 ++++++++--- tools/tests/test_steam_games.py | 48 ++++++++++++++++++- 2 files changed, 69 insertions(+), 8 deletions(-) diff --git a/tools/linuxfs/overlay/usr/local/bin/droiddeck-steam-games b/tools/linuxfs/overlay/usr/local/bin/droiddeck-steam-games index f8d3ef027c..2997444f9d 100755 --- a/tools/linuxfs/overlay/usr/local/bin/droiddeck-steam-games +++ b/tools/linuxfs/overlay/usr/local/bin/droiddeck-steam-games @@ -380,6 +380,13 @@ def update_not_started(text, steamapps, appid, installdir): and not (steamapps / "downloading" / str(appid)).exists()) +def update_on_launch(text): + if re.search(r'^\s*"AutoUpdateBehavior"', text, re.M): + return re.sub(r'^(\s*"AutoUpdateBehavior"\s*")0(")', r"\g<1>1\2", text, count=1, flags=re.M) + end = text.rstrip().rfind("}") + return text[:end] + '\t"AutoUpdateBehavior"\t\t"1"\n' + text[end:] + + def libraries(steam_root): try: text = (Path(steam_root) / "steamapps/libraryfolders.vdf").read_text(errors="replace") @@ -436,9 +443,11 @@ def seed_install(steam_root, game, appid): minimal = ('"AppState"\n{\n' + f' "appid" "{appid}"\n "Universe" "1"\n "name" "{title}"\n' + f' "StateFlags" "4"\n "installdir" "{name}"\n' + '}\n') legacy = minimal.replace(' "Universe" "1"\n', '') + # Steam checks every file of an import with no build before updating it, from scratch each time it is interrupted. + bare = minimal[:-2] + ' "AutoUpdateBehavior" "1"\n}\n' build = installed_build(source, appid, name) if build is None: - content = minimal + content = bare elif build.lstrip().startswith('"AppState"'): content = build else: @@ -452,13 +461,19 @@ def seed_install(steam_root, game, appid): for root in libraries(steam_root): existing = root / "steamapps" / manifest.name if existing.is_file(): - if (existing == manifest and source.is_dir() and target.is_symlink() - and os.readlink(target) == str(source) - and existing.read_text() != content - and (existing.read_text() in (minimal, legacy, legacy.replace('"StateFlags" "4"', '"StateFlags" "2"')) - or (build is not None and update_not_started(existing.read_text(), steamapps, appid, name)))): + text = existing.read_text() + linked = (existing == manifest and source.is_dir() and target.is_symlink() + and os.readlink(target) == str(source)) + if linked and build is None and update_not_started(text, steamapps, appid, name): + wanted = update_on_launch(text) + elif linked and (text in (minimal, bare, legacy, legacy.replace('"StateFlags" "4"', '"StateFlags" "2"')) + or (build is not None and update_not_started(text, steamapps, appid, name))): + wanted = content + else: + wanted = text + if wanted != text: temp = manifest.with_suffix(".droiddeck") - temp.write_text(content) + temp.write_text(wanted) os.replace(temp, manifest) return True if not source.is_dir(): diff --git a/tools/tests/test_steam_games.py b/tools/tests/test_steam_games.py index 142898a172..ae9e1d5699 100644 --- a/tools/tests/test_steam_games.py +++ b/tools/tests/test_steam_games.py @@ -101,7 +101,8 @@ class ImportsTest(unittest.TestCase): imports.route(self.steam, self.acct, [self.game]) path = self.steam / 'steamapps/appmanifest_42.acf' current = path.read_text() - legacy = current.replace(' "Universe" "1"\n', '').replace('"StateFlags" "4"', '"StateFlags" "2"') + legacy = (current.replace(' "AutoUpdateBehavior" "1"\n', '').replace(' "Universe" "1"\n', '') + .replace('"StateFlags" "4"', '"StateFlags" "2"')) path.write_text(legacy) imports.route(self.steam, self.acct, [self.game]) self.assertEqual(current, path.read_text()) @@ -300,6 +301,51 @@ class ImportsTest(unittest.TestCase): imports.route(self.steam, self.acct, [self.game]) self.assertIn('"buildid"\t\t"7"', path.read_text()) + def test_import_without_a_build_updates_only_when_launched(self): + self.snapshot() + imports.route(self.steam, self.acct, [self.game]) + path = self.steam / 'steamapps/appmanifest_42.acf' + current = path.read_text() + self.assertIn(' "AutoUpdateBehavior" "1"\n', current) + path.write_text(current.replace(' "AutoUpdateBehavior" "1"\n', '')) + imports.route(self.steam, self.acct, [self.game]) + self.assertEqual(current, path.read_text()) + + def queued_bare_install(self, extra): + self.snapshot() + imports.route(self.steam, self.acct, [self.game]) + path = self.steam / 'steamapps/appmanifest_42.acf' + path.write_text('"AppState"\n{\n\t"appid"\t\t"42"\n\t"StateFlags"\t\t"6"\n\t"installdir"\t\t"DroidDeck-42"\n' + '\t"buildid"\t\t"0"\n\t"TargetBuildID"\t\t"9"\n%s\t"InstalledDepots"\n\t{\n\t}\n' + '\t"UserConfig"\n\t{\n\t}\n}\n' % extra) + return path + + def test_queued_import_without_a_build_waits_for_a_launch(self): + path = self.queued_bare_install('\t"AutoUpdateBehavior"\t\t"0"\n') + before = path.read_text() + imports.route(self.steam, self.acct, [self.game]) + self.assertEqual(before.replace('"AutoUpdateBehavior"\t\t"0"', '"AutoUpdateBehavior"\t\t"1"'), path.read_text()) + path = self.queued_bare_install('') + before = path.read_text() + imports.route(self.steam, self.acct, [self.game]) + self.assertEqual(before[:-2] + '\t"AutoUpdateBehavior"\t\t"1"\n}\n', path.read_text()) + + def test_queued_import_keeps_a_chosen_update_priority(self): + path = self.queued_bare_install('\t"AutoUpdateBehavior"\t\t"2"\n') + before = path.read_text() + imports.route(self.steam, self.acct, [self.game]) + self.assertEqual(before, path.read_text()) + + def test_started_import_without_a_build_is_left_to_steam(self): + for extra, staging in [('\t"BytesDownloaded"\t\t"5"\n\t"AutoUpdateBehavior"\t\t"0"\n', False), + ('\t"AutoUpdateBehavior"\t\t"0"\n', True)]: + path = self.queued_bare_install(extra) + if staging: + (self.steam / 'steamapps/downloading/42').mkdir(parents=True) + before = path.read_text() + imports.route(self.steam, self.acct, [self.game]) + self.assertEqual(before, path.read_text()) + def test_started_fresh_install_is_left_to_steam(self): for downloaded, staging in [('5', False), ('0', True)]: path = self.steam_fresh_install(downloaded)