From c866bb90dbafe27dd27d9f4fd615856385bb8ac8 Mon Sep 17 00:00:00 2001 From: maxjivi05 Date: Sat, 24 Oct 2026 16:00:41 -0400 Subject: [PATCH] Share installed games between the arm64 and x86-64 Steam clients --- .../droiddeck/launcher/frontend/Library.kt | 16 +- .../launcher/session/SessionFiles.kt | 1 + .../launcher/frontend/LibraryArchTest.kt | 14 + docs/development/x86-64-steam-client.md | 37 ++- .../overlay/usr/local/bin/droiddeck-session | 1 + .../usr/local/bin/droiddeck-steam-share | 266 ++++++++++++++++++ .../overlay/usr/local/bin/droiddeck-steam-x64 | 16 +- tools/tests/test_steam_share.py | 149 ++++++++++ 8 files changed, 486 insertions(+), 14 deletions(-) create mode 100755 tools/linuxfs/overlay/usr/local/bin/droiddeck-steam-share create mode 100644 tools/tests/test_steam_share.py diff --git a/app/src/main/java/com/droiddeck/launcher/frontend/Library.kt b/app/src/main/java/com/droiddeck/launcher/frontend/Library.kt index 3e1a0e85eb..59cf850617 100644 --- a/app/src/main/java/com/droiddeck/launcher/frontend/Library.kt +++ b/app/src/main/java/com/droiddeck/launcher/frontend/Library.kt @@ -106,7 +106,10 @@ object Library { .firstOrNull { it.isDirectory } } - fun steamGames(context: Context, strictRead: Boolean = false, arch: String = SessionPrefs.activeSteamClientArch(context)): List { + fun steamGames( + context: Context, strictRead: Boolean = false, arch: String = SessionPrefs.activeSteamClientArch(context), + withShared: Boolean = true, + ): List { val root = SessionPrefs.steamRoot(context, arch) val cache = File(root, "appcache/librarycache") val libraries = steamLibraries(context, arch) @@ -139,9 +142,20 @@ object Library { )) } } + if (withShared) { + val other = if (arch == "x86_64") "arm64" else "x86_64" + val shared = sharedApps(context, arch) - out.keys + if (shared.isNotEmpty()) runCatching { steamGames(context, arch = other, withShared = false) }.getOrDefault(emptyList()) + .filter { it.appId in shared }.forEach { out[it.appId] = it } + } return out.values.toList() } + internal fun sharedApps(context: Context, arch: String): Set { + val view = File(LinuxRuntime.rootDir(context), "root/.droiddeck-x64/shared/${if (arch == "x86_64") "arm64" else "x86-64"}/steamapps") + return view.list().orEmpty().mapNotNull { Regex("appmanifest_(\\d+)\\.acf").matchEntire(it)?.groupValues?.get(1)?.toIntOrNull() }.toSet() + } + fun steamLibraryArt(context: Context): List> { val root = SessionPrefs.activeSteamRoot(context) val cache = File(root, "appcache/librarycache") 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 8cd846513d..38d6c6fd08 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/SessionFiles.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/SessionFiles.kt @@ -61,6 +61,7 @@ object SessionFiles { "usr/local/bin/droiddeck-steam-shaders" to "usr/local/bin/droiddeck-steam-shaders", "usr/local/bin/droiddeck-steam-desktop-ui" to "usr/local/bin/droiddeck-steam-desktop-ui", "usr/local/bin/droiddeck-steam-library" to "usr/local/bin/droiddeck-steam-library", + "usr/local/bin/droiddeck-steam-share" to "usr/local/bin/droiddeck-steam-share", "usr/local/bin/droiddeck-seed-redists" to "usr/local/bin/droiddeck-seed-redists", "usr/local/bin/droiddeck-launcher-cores" to "usr/local/bin/droiddeck-launcher-cores", "usr/local/bin/droiddeck-proton-extra" to "usr/local/bin/droiddeck-proton-extra", diff --git a/app/src/test/java/com/droiddeck/launcher/frontend/LibraryArchTest.kt b/app/src/test/java/com/droiddeck/launcher/frontend/LibraryArchTest.kt index 8ecd411b0c..0b05b0e842 100644 --- a/app/src/test/java/com/droiddeck/launcher/frontend/LibraryArchTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/frontend/LibraryArchTest.kt @@ -23,6 +23,20 @@ class LibraryArchTest { assertEquals(emptyList(), Library.launchableGames(app, added = emptyList(), arch = "arm64").map { it.name }) } + @Test fun aGameTheOtherClientSharesIsListedFromItsFiles() { + SessionPrefs.setGameStorage(app, SessionPrefs.GAME_STORAGE_OFF, "") + val apps = File(SessionPrefs.steamRoot(app, "x86_64"), "steamapps").apply { mkdirs() } + File(apps, "common/Team Fortress 2").mkdirs() + val manifest = "\"AppState\"\n{\n\t\"appid\"\t\t\"440\"\n\t\"name\"\t\t\"Team Fortress 2\"\n\t\"StateFlags\"\t\t\"4\"\n\t\"installdir\"\t\t\"Team Fortress 2\"\n}\n" + File(apps, "appmanifest_440.acf").writeText(manifest) + val view = File(com.droiddeck.launcher.runtime.LinuxRuntime.rootDir(app), "root/.droiddeck-x64/shared/x86-64/steamapps").apply { mkdirs() } + File(view, "appmanifest_440.acf").writeText(manifest) + val shared = Library.steamGames(app, arch = "arm64").single() + assertEquals("Team Fortress 2", shared.name) + assertEquals(File(apps, "common/Team Fortress 2"), shared.gameFiles) + assertEquals(listOf("Team Fortress 2"), Library.steamGames(app, arch = "x86_64").map { it.name }) + } + @Test fun anAddedGameSteamAlreadyListsFromItsFolderIsShownOnce() { SessionPrefs.setGameStorage(app, SessionPrefs.GAME_STORAGE_OFF, "") val folder = File(app.filesDir, "games/Example").apply { mkdirs() } diff --git a/docs/development/x86-64-steam-client.md b/docs/development/x86-64-steam-client.md index 3e0d867a26..8d57b9ce23 100644 --- a/docs/development/x86-64-steam-client.md +++ b/docs/development/x86-64-steam-client.md @@ -291,13 +291,28 @@ alone would then read as an installed client. ## Libraries, SD card and sharing between clients -- **Separate libraries.** With folders shared, each client could update, verify or switch the - other's games. A title with a Linux build runs as that in the x86 client and as the Windows build in - the arm64 one, so opening it in the other client switched the files and the first client downloaded - its version again (Left 4 Dead 2, 8.6 GB). Hard links do not help: switching platform makes Steam - download depot 551 anyway. A game wanted in both clients is installed in both. Folders an earlier - version shared are taken out of the x86 client's lists (written only while no x86 client runs); the - games stay in the arm64 library. +- **Shared games.** Before either client starts, `droiddeck-steam-share` gives it a view of the games + the other client installed: `~/.droiddeck-x64/shared/arm64` for the x86 client ("ARM64 client + games") and `shared/x86-64` for the arm64 one ("x86-64 client games"). A view holds a copy of each + finished game's manifest and links to its `common` folder and `compatdata`, so the game shows as + installed in both clients, runs from the same files and keeps one prefix and one set of saves. + Runtimes, Proton and FEX are not shared. Device: the x86 client listed the 14 arm64 games as + installed (13 ready to launch, Valheim fetching its shader cache) and started Stardew Valley from the + arm64 files with no game data downloaded; the arm64 client listed Spacewar installed only in the x86 + client. +- **Same build in both.** A title with a Linux build ran as that in the x86 client and as the Windows + build in the arm64 one, so opening it in the other client switched the files and the first client + downloaded its version again (Left 4 Dead 2, 8.6 GB; hard links do not help, switching platform makes + Steam download depot 551 anyway). A shared game gets the tool its own client uses: `droiddeck-fex` + there becomes `droiddeck-direct` here and the other way round, a Proton build keeps its Proton. Only + automatic choices are replaced; a tool the user picked stays. +- **Updates and uninstall.** The newer manifest wins: an update made through a view is written back to + the client that owns the game. Uninstalling a shared game removes it from that client only; its files + stay with the client that installed it (Steam does not delete through the link) and it stays hidden + there until that client updates or reinstalls it. A game installed in both clients is each client's + own and is not shared. A view with nothing in it is not offered as an install location. Views are + written only while no client runs. Shader pre-caching stays each client's own: the x86 client may + fetch a shared game's shader cache into its own folder (Valheim, 1.8 GB). - **SD card.** The x86 client's card library is a folder inside the arm64 one (`/mnt/droiddeck-sd/x86-64`, `GameStorage.X64_CARD_DIR`, passed as `BL_X64_STEAM_LIBRARIES`), so the install dialog offers Internal Storage and SD card. compatdata, shadercache and runtime tools stay private, as in the arm64 card @@ -334,9 +349,11 @@ alone would then read as an installed client. redactor learns account names from both clients. The startup movie is staged into the x86 client's config only once its first start has created it; `--prepare` links the arm64 `config/uioverrides` and copies the `StartupMovie` choice. -- **Storage page.** It lists both clients' games, the x86 ones labelled; a game can be installed in - both and an id left over in several libraries. `steam://uninstall` reaches only the session's client, - so the other client's copy is uninstalled after switching clients. Tools in the x86 client's +- **Storage page.** It lists both clients' games, the x86 ones labelled, each where its files are, so a + shared game is counted once; a game can be installed in both and an id left over in several + libraries. The Games page of each client lists the games shared with it. `steam://uninstall` + reaches only the session's client, so the other client's own copy is uninstalled after switching + clients. Tools in the x86 client's libraries are shown as required (it runs its Linux games with Valve's runtimes). Proton tool files live only in the arm64 root; the x86 client has wrappers. An x86 client without `config.vdf` has never mapped a game. diff --git a/tools/linuxfs/overlay/usr/local/bin/droiddeck-session b/tools/linuxfs/overlay/usr/local/bin/droiddeck-session index e1db4272df..e95a7a940a 100755 --- a/tools/linuxfs/overlay/usr/local/bin/droiddeck-session +++ b/tools/linuxfs/overlay/usr/local/bin/droiddeck-session @@ -396,6 +396,7 @@ case $mode in steam_root=$XDG_DATA_HOME/Steam if [ -f "${BL_X64_HOME:-$HOME/.droiddeck-x64}/.local/share/Steam/local.vdf" ]; then droiddeck-steam-x64 --sync-login || true + droiddeck-steam-x64 --share || true fi steam_client=("$steam_root/steamrtarm64/steam") _bl_srt_shim=$HOME/.droiddeck-steamrt-shim diff --git a/tools/linuxfs/overlay/usr/local/bin/droiddeck-steam-share b/tools/linuxfs/overlay/usr/local/bin/droiddeck-steam-share new file mode 100755 index 0000000000..fd6380c653 --- /dev/null +++ b/tools/linuxfs/overlay/usr/local/bin/droiddeck-steam-share @@ -0,0 +1,266 @@ +#!/usr/bin/python3 +import json +import os +import re +import runpy +import sys + +NOT_GAMES = frozenset(( + "228980", "1070560", "1391110", "1628350", "1493710", "3127680", + "4183110", "4185400", "4427310", "4628740", +)) +TOOL_DIR = re.compile(r"(steam ?linux ?runtime.*|proton.*|steamworks shared|fex|steamvr)", re.I) +AUTOMATIC = ("", "droiddeck-direct", "droiddeck-fex", "droiddeck-proton-arm64", "droiddeck-proton-11-arm64") +STATE = ".droiddeck-shared.json" +LABELS = {"arm64": "ARM64 client games", "x86-64": "x86-64 client games"} + + +def say(message): + print("droiddeck-steam-share: " + message) + + +def read(path): + try: + with open(path, encoding="utf-8", errors="surrogateescape") as f: + return f.read() + except OSError: + return None + + +def write(path, text): + staged = path + ".droiddeck-new" + with open(staged, "w", encoding="utf-8", errors="surrogateescape") as f: + f.write(text) + os.replace(staged, path) + + +def field(text, key): + m = re.search(r'"%s"\s+"([^"]*)"' % re.escape(key), text or "", re.I) + return m.group(1) if m else None + + +def number(text, key): + value = field(text, key) + return int(value) if value and value.isdigit() else 0 + + +def same(a, b): + return os.path.realpath(a) == os.path.realpath(b) + + +def libraries(root, skip): + found = [root] + [p.replace("\\\\", "\\") for p in + re.findall(r'"path"\s+"((?:[^"\\]|\\.)*)"', read(os.path.join(root, "steamapps", "libraryfolders.vdf")) or "")] + return [p for p in dict.fromkeys(found) if not any(same(p, s) for s in skip)] + + +def installs(libs): + games = {} + for library in libs: + steamapps = os.path.join(library, "steamapps") + try: + names = sorted(os.listdir(steamapps)) + except OSError: + continue + for name in names: + m = re.fullmatch(r"appmanifest_(\d+)\.acf", name) + if not m or m.group(1) in NOT_GAMES or m.group(1) in games: + continue + text = read(os.path.join(steamapps, name)) + folder = field(text, "installdir") + if (not folder or folder in (".", "..") or "/" in folder or TOOL_DIR.fullmatch(folder) + or not number(text, "StateFlags") & 4 + or not os.path.isdir(os.path.join(steamapps, "common", folder))): + continue + games[m.group(1)] = (steamapps, text, folder) + return games + + +def link(path, target): + if os.path.islink(path): + if os.readlink(path) == target: + return True + os.unlink(path) + elif os.path.lexists(path): + return False + os.symlink(target, path) + return True + + +def unlink(path): + if os.path.islink(path): + os.unlink(path) + + +def emptied(src, folder): + path = os.path.join(src, "common", folder) + return not os.path.isdir(path) or not os.listdir(path) + + +def sync(view, source, own): + steamapps = os.path.join(view, "steamapps") + for sub in ("common", "compatdata"): + os.makedirs(os.path.join(steamapps, sub), exist_ok=True) + state = {} + try: + state = json.loads(read(os.path.join(view, STATE)) or "{}") + except ValueError: + pass + managed = {app: tuple(v) for app, v in state.get("shared", {}).items() if isinstance(v, list) and len(v) == 2} + hidden = state.get("hidden", {}) + shared, back = {}, [] + for app, (src, folder) in managed.items(): + if app in source and app not in own: + continue + manifest = os.path.join(steamapps, "appmanifest_%s.acf" % app) + if app not in own and not os.path.isfile(manifest) and emptied(src, folder) and os.path.isfile(os.path.join(src, "appmanifest_%s.acf" % app)): + os.unlink(os.path.join(src, "appmanifest_%s.acf" % app)) + unlink(os.path.join(steamapps, "common", folder)) + unlink(os.path.join(steamapps, "compatdata", app)) + if os.path.isfile(manifest): + os.unlink(manifest) + for app, (src, text, folder) in sorted(source.items(), key=lambda item: int(item[0])): + if app in own: + continue + stamp = number(text, "LastUpdated") + if hidden.get(app) == stamp: + continue + hidden.pop(app, None) + manifest = os.path.join(steamapps, "appmanifest_%s.acf" % app) + mine = read(manifest) + if app in managed and mine is None: + unlink(os.path.join(steamapps, "common", folder)) + unlink(os.path.join(steamapps, "compatdata", app)) + if emptied(src, folder): + os.unlink(os.path.join(src, "appmanifest_%s.acf" % app)) + else: + hidden[app] = stamp + continue + if not link(os.path.join(steamapps, "common", folder), os.path.join(src, "common", folder)): + continue + if os.path.isdir(os.path.join(src, "compatdata", app)): + link(os.path.join(steamapps, "compatdata", app), os.path.join(src, "compatdata", app)) + if mine is not None and number(mine, "LastUpdated") > stamp: + write(os.path.join(src, "appmanifest_%s.acf" % app), mine) + back.append(app) + elif mine != text: + write(manifest, text) + shared[app] = [src, folder] + state = {"shared": shared, "hidden": hidden} + write(os.path.join(view, STATE), json.dumps(state, indent=1, sort_keys=True) + "\n") + return shared, back + + +def tools(root): + names = set() + folder = os.path.join(root, "compatibilitytools.d") + try: + entries = os.listdir(folder) + except OSError: + return names + for entry in entries: + text = read(os.path.join(folder, entry, "compatibilitytool.vdf")) or "" + m = re.search(r'"compat_tools"\s*\{\s*"([^"]+)"', text) + if m: + names.add(m.group(1)) + return names + + +def mapping_block(text): + m = re.search(r'"CompatToolMapping"\s*\{', text) + if not m: + return None + depth, k = 1, m.end() + while depth and k < len(text): + depth += {"{": 1, "}": -1}.get(text[k], 0) + k += 1 + return m.end(), k - 1 + + +def entries(text): + span = mapping_block(text) + found = {} + if not span: + return found + inner = text[span[0]:span[1]] + for m in re.finditer(r'"(\d+)"\s*\{([^{}]*)\}', inner): + name = re.search(r'"name"\s*"([^"]*)"', m.group(2)) + found.setdefault(m.group(1), name.group(1) if name else "") + return found + + +def set_tools(config, wanted): + text = read(config) + if text is None or not wanted: + return [] + span = mapping_block(text) + if not span: + return [] + inner = text[span[0]:span[1]] + changed = [] + for app, tool in sorted(wanted.items(), key=lambda item: int(item[0])): + m = re.search(r'"%s"\s*\{([^{}]*)\}' % app, inner) + if m: + name = re.search(r'"name"\s*"([^"]*)"', m.group(1)) + name = name.group(1) if name else "" + if name == tool or not (name in AUTOMATIC or name.startswith("proton_")): + continue + inner = inner[:m.start()] + inner[m.end():] + inner = ('\n\t\t\t\t\t"%s"\n\t\t\t\t\t{\n\t\t\t\t\t\t"name"\t\t"%s"\n\t\t\t\t\t\t"config"\t\t""\n' + '\t\t\t\t\t\t"priority"\t\t"250"\n\t\t\t\t\t}' % (app, tool)) + inner + changed.append(app) + if changed: + write(config, text[:span[0]] + inner + text[span[1]:]) + return changed + + +def translate(name, here, available): + if name == "droiddeck-fex" and here == "x86-64": + return "droiddeck-direct" + if name == "droiddeck-direct" and here == "arm64": + return "droiddeck-fex" + return name if name in available else None + + +def library_helper(): + sibling = os.path.join(os.path.dirname(os.path.realpath(__file__)), "droiddeck-steam-library") + return runpy.run_path(sibling if os.path.isfile(sibling) else "/usr/local/bin/droiddeck-steam-library") + + +def main(argv): + if len(argv) != 5 or argv[0] not in LABELS: + say("usage: droiddeck-steam-share arm64|x86-64 ARM_STEAM X64_STEAM X64_CARD SHARED_DIR") + return 2 + here, arm, x64, x64_card, shared_dir = argv + views = {name: os.path.join(shared_dir, name) for name in LABELS} + roots = {"arm64": arm, "x86-64": x64} + other = "x86-64" if here == "arm64" else "arm64" + skip = list(views.values()) + [x64, x64_card] + arm_libs = libraries(arm, skip) + x64_libs = [x64] + [p for p in libraries(x64, list(views.values()) + [arm]) if not same(p, x64)] + games = {"arm64": installs(arm_libs), "x86-64": installs(x64_libs)} + view = views[other] + shared, back = sync(view, games[other], games[here]) + helper = library_helper() + if not any(re.fullmatch(r"appmanifest_\d+\.acf", n) for n in os.listdir(os.path.join(view, "steamapps"))): + helper["forget"](roots[here], view) + return 0 + helper["register"](roots[here], view, LABELS[other]) + helper["relabel"](roots[here], view, LABELS[other]) + picks = entries(read(os.path.join(roots[other], "config", "config.vdf")) or "") + available = tools(roots[here]) | {"droiddeck-direct" if here == "x86-64" else "droiddeck-fex"} + wanted = {} + for app in shared: + tool = translate(picks.get(app) or picks.get("0", ""), here, available) + if tool: + wanted[app] = tool + changed = set_tools(os.path.join(roots[here], "config", "config.vdf"), wanted) + say("%d game(s) from the %s client%s%s" % ( + len(shared), other, + "; tools set for %s" % " ".join(changed) if changed else "", + "; manifests sent back for %s" % " ".join(back) if back else "")) + return 0 + + +if __name__ == "__main__": + sys.exit(main(sys.argv[1:])) diff --git a/tools/linuxfs/overlay/usr/local/bin/droiddeck-steam-x64 b/tools/linuxfs/overlay/usr/local/bin/droiddeck-steam-x64 index f6f11d1873..8461fdf8a6 100755 --- a/tools/linuxfs/overlay/usr/local/bin/droiddeck-steam-x64 +++ b/tools/linuxfs/overlay/usr/local/bin/droiddeck-steam-x64 @@ -87,7 +87,7 @@ x64_map_direct() { [ -f "$STEAM_X64/config/config.vdf" ] || return 0 if [ "$mode" = write ] && pgrep -f 'steamrt64/steam( |$)' >/dev/null 2>&1; then return 0; fi python3 - "$mode" "$STEAM_X64/config/config.vdf" "$STEAM_X64/appcache/appinfo.vdf" "$X64_HOME/direct-auto.json" \ - "$X64_HOME/direct-sniper" "$STEAM_X64/steamapps:/mnt/droiddeck-sd/x86-64/steamapps" "$(x64_default_tool)" \ + "$X64_HOME/direct-sniper" "$STEAM_X64/steamapps:/mnt/droiddeck-sd/x86-64/steamapps:$X64_HOME/shared/arm64/steamapps" "$(x64_default_tool)" \ "$REAL_HOME/.bl-compat-pending" ${BL_X64_DIRECT_APPS:-550} \ <<'PY' || { [ "$mode" = live ] || step "could not map titles to DroidDeck direct"; } # Steam does not swap an installed build when the tool changes: a title installed for Windows stays on Proton. @@ -610,6 +610,7 @@ RUN printf '"InstallConfigStore"\n{\n\t"Software"\n\t{\n\t\t"Valve"\n\t\t{\n\t\t\t"Steam"\n\t\t\t{\n\t\t\t\t"CompatToolMapping"\n\t\t\t\t{\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n}\n' \ > "$STEAM_X64/config/config.vdf" fi + x64_share x86-64 x64_map_direct # Each wrapper execs droiddeck-x64-arm-proton through an arm64 binary, which FEX hands straight to the CPU. arm_tools=$ARM_STEAM/compatibilitytools.d @@ -659,9 +660,9 @@ VDF # Each client keeps its own libraries; written only while no x86 client runs, as it rewrites these on exit. if ! pgrep -f 'steamrt64/steam( |$)' >/dev/null 2>&1; then listing_ok=0 - if python3 - "$STEAM_X64" "${BL_X64_STEAM_LIBRARIES:-}" "$STEAM_X64/config/libraryfolders.vdf" "$STEAM_X64/steamapps/libraryfolders.vdf" <<'PY'; then + if BL_X64_SHARED=$X64_HOME/shared/arm64 python3 - "$STEAM_X64" "${BL_X64_STEAM_LIBRARIES:-}" "$STEAM_X64/config/libraryfolders.vdf" "$STEAM_X64/steamapps/libraryfolders.vdf" <<'PY'; then import json, os, re, sys -keep = {os.path.realpath(sys.argv[1])} +keep = {os.path.realpath(sys.argv[1]), os.path.realpath(os.environ["BL_X64_SHARED"])} # Without the session's list nothing is known about the card: leave the folders as they are. if not sys.argv[2]: sys.exit(3) @@ -911,6 +912,14 @@ x64_exec() { exec "${BL_FEX:-/usr/local/bin/FEX}" "$STEAM_X64/steamrt64/steam" "$@" } +x64_share() { + pgrep -f 'steamrt64/steam( |$)' >/dev/null 2>&1 && return 0 + pgrep -f 'steamrtarm64/steam( |$)' >/dev/null 2>&1 && return 0 + [ -d "$STEAM_X64/steamapps" ] && [ -d "$ARM_STEAM/steamapps" ] || return 0 + droiddeck-steam-share "$1" "$ARM_STEAM" "$STEAM_X64" /mnt/droiddeck-sd/x86-64 "$X64_HOME/shared" || + step "could not share the games between the clients" +} + # Steam renews its token every few days and refuses old copies: copy the newest every start, never while a client runs. x64_sync_login() { pgrep -f 'steamrt64/steam( |$)' >/dev/null 2>&1 && return 0 @@ -1027,6 +1036,7 @@ PY case "${1:-}" in --sync-login) x64_sync_login; exit 0 ;; + --share) x64_share arm64; exit 0 ;; --prepare) x64_prepare; exit 0 ;; --exec) shift; x64_exec "$@" ;; --gpu) x64_gpu; exit $? ;; diff --git a/tools/tests/test_steam_share.py b/tools/tests/test_steam_share.py new file mode 100644 index 0000000000..c1b269713f --- /dev/null +++ b/tools/tests/test_steam_share.py @@ -0,0 +1,149 @@ +from pathlib import Path +import contextlib +import io +import json +import os +import runpy +import tempfile +import unittest + + +SCRIPT = Path(__file__).resolve().parents[1] / 'linuxfs/overlay/usr/local/bin/droiddeck-steam-share' +SHARE = runpy.run_path(str(SCRIPT)) + +CONFIG = ('"InstallConfigStore"\n{\n\t"Software"\n\t{\n\t\t"Valve"\n\t\t{\n\t\t\t"Steam"\n\t\t\t{\n' + '\t\t\t\t"CompatToolMapping"\n\t\t\t\t{\n%s\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n}\n') + + +def mapping(**tools): + return ''.join('\t\t\t\t\t"%s"\n\t\t\t\t\t{\n\t\t\t\t\t\t"name"\t\t"%s"\n\t\t\t\t\t\t"config"\t\t""\n' + '\t\t\t\t\t\t"priority"\t\t"250"\n\t\t\t\t\t}\n' % (app.lstrip('_'), name) + for app, name in tools.items()) + + +def manifest(app, folder, updated=100, flags=4): + return ('"AppState"\n{\n\t"appid"\t\t"%s"\n\t"name"\t\t"%s"\n\t"StateFlags"\t\t"%d"\n' + '\t"installdir"\t\t"%s"\n\t"LastUpdated"\t\t"%d"\n}\n' % (app, folder, flags, folder, updated)) + + +class SteamShareTest(unittest.TestCase): + def setUp(self): + self.temp = tempfile.TemporaryDirectory() + self.addCleanup(self.temp.cleanup) + home = Path(self.temp.name) + self.arm = home / 'arm/Steam' + self.x64 = home / 'x64/Steam' + self.card = home / 'card' + self.shared = home / 'x64/shared' + for root in (self.arm, self.x64): + (root / 'steamapps/common').mkdir(parents=True) + (root / 'config').mkdir() + (root / 'compatibilitytools.d/proton').mkdir(parents=True) + (root / 'compatibilitytools.d/proton/compatibilitytool.vdf').write_text( + '"compatibilitytools"\n{\n\t"compat_tools"\n\t{\n\t\t"droiddeck-proton-arm64"\n\t\t{\n\t\t}\n\t}\n}\n') + (self.arm / 'config/config.vdf').write_text(CONFIG % mapping(_0='droiddeck-proton-arm64', _413150='droiddeck-fex')) + (self.x64 / 'config/config.vdf').write_text(CONFIG % '') + self.install(self.arm, '413150', 'Stardew Valley') + self.install(self.arm, '13210', 'Unreal Tournament 3') + self.install(self.arm, '1493710', 'Proton - Experimental') + + def install(self, root, app, folder, updated=100): + (root / 'steamapps/common' / folder).mkdir(parents=True, exist_ok=True) + (root / 'steamapps/common' / folder / 'game.bin').write_text('x') + (root / ('steamapps/appmanifest_%s.acf' % app)).write_text(manifest(app, folder, updated)) + + def run_share(self, here): + with contextlib.redirect_stdout(io.StringIO()): + return SHARE['main']([here, str(self.arm), str(self.x64), str(self.card), str(self.shared)]) + + def view(self, *parts): + return self.shared.joinpath('arm64', 'steamapps', *parts) + + def test_x64_client_sees_arm64_games_in_place(self): + self.assertEqual(self.run_share('x86-64'), 0) + self.assertEqual(os.readlink(self.view('common/Stardew Valley')), str(self.arm / 'steamapps/common/Stardew Valley')) + self.assertTrue(self.view('appmanifest_413150.acf').is_file()) + self.assertTrue(self.view('appmanifest_13210.acf').is_file()) + self.assertFalse(self.view('appmanifest_1493710.acf').exists()) + folders = (self.x64 / 'steamapps/libraryfolders.vdf').read_text() + self.assertIn(str(self.shared / 'arm64'), folders) + self.assertIn('ARM64 client games', folders) + + def test_tools_follow_the_other_client(self): + self.run_share('x86-64') + tools = SHARE['entries']((self.x64 / 'config/config.vdf').read_text()) + self.assertEqual(tools['413150'], 'droiddeck-direct') + self.assertEqual(tools['13210'], 'droiddeck-proton-arm64') + + def test_a_tool_the_user_chose_is_kept(self): + (self.x64 / 'config/config.vdf').write_text(CONFIG % mapping(_13210='my-proton')) + self.run_share('x86-64') + self.assertEqual(SHARE['entries']((self.x64 / 'config/config.vdf').read_text())['13210'], 'my-proton') + + def test_own_install_wins(self): + self.install(self.x64, '413150', 'Stardew Valley') + self.run_share('x86-64') + self.assertFalse(self.view('appmanifest_413150.acf').exists()) + self.assertFalse(os.path.lexists(self.view('common/Stardew Valley'))) + + def test_newer_update_goes_back_to_the_source(self): + self.run_share('x86-64') + self.view('appmanifest_413150.acf').write_text(manifest('413150', 'Stardew Valley', 200)) + self.run_share('x86-64') + self.assertIn('"LastUpdated"\t\t"200"', (self.arm / 'steamapps/appmanifest_413150.acf').read_text()) + + def test_uninstall_from_the_view_hides_until_reinstalled(self): + self.run_share('x86-64') + self.view('appmanifest_13210.acf').unlink() + self.run_share('x86-64') + self.assertFalse(os.path.lexists(self.view('common/Unreal Tournament 3'))) + self.assertTrue((self.arm / 'steamapps/common/Unreal Tournament 3/game.bin').is_file()) + self.run_share('x86-64') + self.assertFalse(self.view('appmanifest_13210.acf').exists()) + self.install(self.arm, '13210', 'Unreal Tournament 3', 300) + self.run_share('x86-64') + self.assertTrue(self.view('appmanifest_13210.acf').is_file()) + + def test_files_deleted_through_the_view_drop_the_source_manifest(self): + self.run_share('x86-64') + (self.arm / 'steamapps/common/Unreal Tournament 3/game.bin').unlink() + self.view('appmanifest_13210.acf').unlink() + self.run_share('x86-64') + self.assertFalse((self.arm / 'steamapps/appmanifest_13210.acf').exists()) + + def test_removed_source_leaves_the_view(self): + self.run_share('x86-64') + (self.arm / 'steamapps/appmanifest_413150.acf').unlink() + self.run_share('x86-64') + self.assertFalse(self.view('appmanifest_413150.acf').exists()) + self.assertFalse(os.path.lexists(self.view('common/Stardew Valley'))) + state = json.loads((self.shared / 'arm64/.droiddeck-shared.json').read_text()) + self.assertNotIn('413150', state['shared']) + + def test_arm64_client_sees_x64_games(self): + self.install(self.x64, '550', 'Left 4 Dead 2') + (self.x64 / 'config/config.vdf').write_text(CONFIG % mapping(_550='droiddeck-direct')) + self.run_share('arm64') + self.assertTrue(self.shared.joinpath('x86-64/steamapps/appmanifest_550.acf').is_file()) + self.assertEqual(SHARE['entries']((self.arm / 'config/config.vdf').read_text())['550'], 'droiddeck-fex') + self.assertIn('x86-64 client games', (self.arm / 'steamapps/libraryfolders.vdf').read_text()) + + def test_an_empty_view_is_not_offered(self): + self.run_share('x86-64') + for app in ('413150', '13210', '1493710'): + (self.arm / ('steamapps/appmanifest_%s.acf' % app)).unlink() + self.run_share('x86-64') + self.assertNotIn(str(self.shared / 'arm64'), (self.x64 / 'steamapps/libraryfolders.vdf').read_text()) + + def test_unfinished_installs_are_not_shared(self): + (self.arm / 'steamapps/appmanifest_413150.acf').write_text(manifest('413150', 'Stardew Valley', flags=1026)) + self.run_share('x86-64') + self.assertFalse(self.view('appmanifest_413150.acf').exists()) + + def test_bad_arguments(self): + with contextlib.redirect_stdout(io.StringIO()): + self.assertEqual(SHARE['main'](['mips']), 2) + + +if __name__ == '__main__': + unittest.main()