Stores: GOG, Epic Games and Amazon Games libraries, installs and cloud saves (#476)

A Stores section (rail, under Games; Setup › Stores gate) with each store's sign-in,
library, storefront shelves and a download queue. Each store has two tabs, Store and
Library, and Library filters to All or Installed; libraries open from a saved copy
and refresh in the background, with install sizes on every card. Games install to internal storage,
or a card chosen at Install time, and are registered in the Steam client as non-Steam
games, so they launch through Steam and droiddeck-proton from either the front end or
the client.

- Downloads: GOG, Epic and Amazon engines in Rust (app/src/main/rust/stores, built by
  cargo-ndk, nothing compiled in the tree). One adaptive fetch core with a latency
  brake, stalled-host handoff and every CDN a store offers. Per-stage progress,
  pause/resume, two-step cancel that deletes, failed downloads kept for retry, a
  foreground service with Wi-Fi and wake locks and notification controls.
- Games tab: store source chips (Steam, GOG, Epic, Amazon, Custom) and store art.
- Epic: per-launch exchange code from the app and from Steam's Play button,
  "Epic sign-in (EOS)", "Launch offline", and a game's web links opened in Android's
  browser for EOS consent. The EOS overlay crashed games and is left out.
- Cloud saves (GOG, Epic): pulled before launch, pushed after the game or the session
  ends, no upload before a first download, conflicts never overwritten, backups both
  ways.
- Logs: every store line redacted; the engine log goes to daily files.
This commit is contained in:
The412Banner authored and GitHub committed 2026-10-09 11:08:17 -04:00
1 parent fe71084f23
commit e99d5f9505
141 files changed
+25539 -73

No files matched your search

+22 -1
View File
@@ -321,8 +321,29 @@ tar -cf - -C "${bundle_dir}" . | zstd -19 -T0 -c > "${staging_dir}/pulseaudio.tz
bundle_replaced=1
mv "${staging_dir}/pulseaudio.tzst" "${bundle_asset}"
# The GOG / Epic / Amazon download engines are Rust (app/src/main/rust/stores); Gradle's
# buildRustStores task cross-compiles them with cargo-ndk, which needs the Android target and the
# cargo-ndk binary installed once. DROIDDECK_SKIP_RUST=1 builds an apk without the engines (the
# stores then report themselves unavailable) for a machine without a Rust toolchain.
gradle_rust_arg=""
if [[ "${DROIDDECK_SKIP_RUST:-0}" == 1 ]]; then
gradle_rust_arg="-PskipRust=true"
else
export PATH="${HOME}/.cargo/bin:${PATH}"
for tool in rustup cargo; do
if ! command -v "${tool}" >/dev/null 2>&1; then
echo "${tool} is required for the store engines (https://rustup.rs); set DROIDDECK_SKIP_RUST=1 to build without them." >&2
exit 1
fi
done
rustup target add aarch64-linux-android
if ! command -v cargo-ndk >/dev/null 2>&1; then
cargo install cargo-ndk --locked
fi
fi
cd "${repo_root}"
./gradlew "${gradle_task}" --console=plain -PndkVersion="${ndk_version}"
./gradlew "${gradle_task}" --console=plain -PndkVersion="${ndk_version}" ${gradle_rust_arg}
python3 tools/release/check_session_assets.py "app/build/outputs/apk/${build_variant}/app-${build_variant}.apk"
cp -p "${bundle_backup}" "${bundle_asset}"
bundle_replaced=0
+61
View File
@@ -0,0 +1,61 @@
#!/usr/bin/python3
"""A game's web links to Android: Wine's winebrowser starts this (named as the browser in the
prefix's HKCU\\Software\\Wine\\WineBrowser, and as xdg-open first on a game's PATH), and an
http(s) address goes to the app, which opens it in Android's browser - so an EOS sign-in step or a
store page can be finished on the phone. Anything else goes on to the system's own xdg-open.
The session channel is $BL_LAUNCH_DIR/stores; Wine may not pass that variable on to what it
starts, so droiddeck-proton also leaves it in LAUNCH_DIR_FILE."""
import json
import os
LAUNCH_DIR_FILE = "/tmp/droiddeck-browser/launch-dir"
import sys
import time
from pathlib import Path
def hand_over(url, launch_dir):
req = Path(launch_dir) / "stores" / "req"
req.mkdir(parents=True, exist_ok=True)
rid = "url-%d-%d" % (os.getpid(), int(time.time() * 1000))
tmp = req / (rid + ".json.tmp")
tmp.write_text(json.dumps({"op": "open-url", "url": url}))
os.rename(tmp, req / (rid + ".json"))
def where(url):
"""scheme://host only, for the log: no path, no query."""
from urllib.parse import urlsplit
try:
u = urlsplit(url)
return "%s://%s" % (u.scheme, u.hostname or "")
except ValueError:
return "?"
def main(argv):
url = argv[0] if argv else ""
# The Steam client's own form (steam://openurl/<address>), in case a launcher passes it on.
if url.startswith("steam://openurl/"):
url = url[len("steam://openurl/"):]
launch_dir = os.environ.get("BL_LAUNCH_DIR", "")
if not launch_dir:
try:
launch_dir = open(LAUNCH_DIR_FILE).read().strip()
except OSError:
launch_dir = ""
print("droiddeck xdg-open: %s" % where(url), file=sys.stderr, flush=True)
if url.startswith(("https://", "http://")) and launch_dir:
hand_over(url, launch_dir)
return 0
here = os.path.dirname(os.path.realpath(sys.argv[0]))
for d in os.environ.get("PATH", "").split(os.pathsep):
candidate = os.path.join(d, "xdg-open")
if os.access(candidate, os.X_OK) and os.path.realpath(candidate) != os.path.realpath(__file__) and os.path.abspath(d) != here:
os.execv(candidate, [candidate] + argv)
return 1
if __name__ == "__main__":
sys.exit(main(sys.argv[1:]))
@@ -606,6 +606,34 @@ case $mode in
fi
done
) &
# A game the app asked to launch on a cold start is not put on the client's command line: the
# client takes it before its interface is up, its launch stops at "waiting for user response to
# ShowInterstitials" with nobody to answer, and the game page reads Launching for ever (device,
# 2026-10-09, and 2026-10-08 before it). It is handed over once the interface has focus
# (gamescope's focused app 769) and has had a moment, through the same steam-game request an
# in-session launch uses; after two minutes it goes anyway.
if [ -n "${BL_LAUNCH_DIR:-}" ] && [ -z "${BL_DESKTOP:-}" ]; then
_bl_held=
_bl_rest=()
for _bl_arg in "$@"; do
case $_bl_arg in
steam://rungameid/*) _bl_held=${_bl_arg#steam://rungameid/} ;;
*) _bl_rest+=("$_bl_arg") ;;
esac
done
if [ -n "$_bl_held" ]; then
set -- "${_bl_rest[@]}"
(
_bl_end=$((SECONDS + 120))
until [ "$(xprop -root GAMESCOPE_FOCUSED_APP 2>/dev/null | sed -n 's/.*= *//p')" = 769 ] || [ "$SECONDS" -ge "$_bl_end" ]; do
sleep 1
done
sleep 4
echo "== steam: interface up; launching the requested game $_bl_held"
printf '%s\n' "$_bl_held" > "$BL_LAUNCH_DIR/steam-game.tmp" && mv -f "$BL_LAUNCH_DIR/steam-game.tmp" "$BL_LAUNCH_DIR/steam-game"
) &
fi
fi
# Debug aid while the runtime is being brought up: an app id dropped in ~/.bl-autolaunch is
# handed to the client as a rungameid URL, so a launch can be reproduced without touching the
# screen. Removed once the runtime is stable.
+317
View File
@@ -0,0 +1,317 @@
#!/usr/bin/python3
r"""Before Proton starts a store game, asks the app for what that store needs at launch.
Run by droiddeck-proton / droiddeck-proton-wrap (steam-compatibility) for every real game launch,
whoever started it: the Games tab, a pinned shortcut, or the Steam client's own Play button. It
looks for the store launcher DroidDeck wrote (.droiddeck-launch.bat) among the arguments; beside it
.droiddeck-store.json says which store and game it is.
For an Epic game the game needs a fresh exchange code to sign in, which only the app can mint. The
request goes through files under $BL_LAUNCH_DIR/stores (the session root, the same path on both
sides):
req/<id>.json {"op": "epic-code", "store": "epic", "id": "<app name>"} (tmp + rename)
resp/<id>.json {"ok": true, "code": true|false, "reason": "..."}
The app writes .droiddeck-epic-code into the game's folder itself - the code never passes through
here - and the launcher .bat reads and deletes it. No answer within TIMEOUT seconds: the game starts
with its offline identity. A code file older than STALE_SECONDS is removed first, so a code left by
an earlier launch is never used.
The game's prefix gets Wine's browser set to droiddeck-open-url, which hands web addresses to
Android: an EOS sign-in step that falls back to a browser (a consent Epic asks for once per product)
is finished there. An EOS overlay pointer (HKCU\Software\Epic Games\EOS "OverlayPath") an earlier
build wrote is removed - with it the game exited while loading.
droiddeck-store-launch <the arguments Steam gave the compat tool>
"""
import json
import os
import sys
import time
from pathlib import Path
LAUNCHER = ".droiddeck-launch.bat"
SIDECAR = ".droiddeck-store.json"
EPIC_CODE = ".droiddeck-epic-code"
TIMEOUT = 5.0
STALE_SECONDS = 300
SERVER_WAIT = 8.0
BROWSER = "/usr/local/bin/droiddeck-open-url"
EOS_KEY = "[Software\\\\Epic Games\\\\EOS]"
BROWSER_KEY = "[Software\\\\Wine\\\\WineBrowser]"
def log(line):
print("droiddeck-store-launch: " + line, file=sys.stderr, flush=True)
MAX_DEPTH = 6
def sidecar_at(folder):
try:
sidecar = json.loads((folder / SIDECAR).read_text())
except (OSError, ValueError):
return None
if not isinstance(sidecar, dict) or not sidecar.get("store") or not sidecar.get("id"):
return None
return sidecar
def find_store_game(argv):
"""
The (folder, sidecar) of a store game among [argv], or None when this is not one. Steam passes
the shortcut's target: the launcher .bat when the game has one (Epic, Amazon, a GOG game with
arguments), else the game's exe itself (most GOG games), which may sit in a subfolder - so the
folders above it are looked through too, up to MAX_DEPTH, for the sidecar.
"""
for raw in argv:
arg = raw.strip().strip('"').strip("'").replace("\\", "/")
low = arg.lower()
if not (low.endswith(LAUNCHER) or low.endswith(".exe") or low.endswith(".bat")) or "/" not in arg:
continue
folder = Path(arg).parent
for _ in range(MAX_DEPTH):
sidecar = sidecar_at(folder)
if sidecar is not None:
return folder, sidecar
if folder.parent == folder:
break
folder = folder.parent
return None
def drop_stale(folder, now=None):
"""Removes a code file older than STALE_SECONDS; True when one was removed."""
code = folder / EPIC_CODE
try:
if (now if now is not None else time.time()) - code.stat().st_mtime > STALE_SECONDS:
code.unlink()
return True
except OSError:
pass
return False
def ask(channel, request, timeout=TIMEOUT):
"""Writes [request] under channel/req and waits for channel/resp; the answer, or None on timeout."""
req_dir, resp_dir = channel / "req", channel / "resp"
req_dir.mkdir(parents=True, exist_ok=True)
resp_dir.mkdir(parents=True, exist_ok=True)
rid = "%d-%d" % (os.getpid(), int(time.time() * 1000))
tmp = req_dir / (rid + ".json.tmp")
tmp.write_text(json.dumps(request))
os.rename(tmp, req_dir / (rid + ".json"))
answer = resp_dir / (rid + ".json")
deadline = time.monotonic() + timeout
while time.monotonic() < deadline:
try:
value = json.loads(answer.read_text())
answer.unlink()
return value
except (OSError, ValueError):
time.sleep(0.05)
# Not answered: the request is withdrawn so a late app does not mint a code nobody reads.
try:
(req_dir / (rid + ".json")).unlink()
except OSError:
pass
return None
def windows_path(unix):
"""A guest path as Wine names it through Z: (the whole filesystem)."""
return "Z:" + unix.replace("/", "\\")
def reg_escape(value):
return value.replace("\\", "\\\\").replace('"', '\\"')
def set_value(reg, key, name, value, now=None):
"""
Appends `key` with `"name"="value"` to a prefix's user.reg unless the last word on it already
says so. Appended rather than edited in place, as DirectAudio's key is: Wine reads later sections
over earlier ones, and nothing of the file is rewritten under a wineserver that might hold it.
False when there is no user.reg yet (Proton creates the prefix after this; the next launch has it).
"""
if not reg.is_file():
return False
line = '"%s"="%s"' % (name, reg_escape(value))
inside, last = False, None
for row in reg.read_text(errors="replace").splitlines():
if row.startswith("["):
inside = row.startswith(key + " ") or row == key
elif inside and row.startswith('"%s"=' % name):
last = row
if last == line:
return True
with open(reg, "a") as out:
out.write("\n%s %d\n%s\n" % (key, int(now if now is not None else time.time()), line))
return True
def remove_value(reg, key, name):
"""Drops every `"name"=` line under `key` in user.reg; True when one was there."""
if not reg.is_file():
return False
rows, inside, dropped = [], False, False
for row in reg.read_text(errors="replace").splitlines(keepends=True):
if row.startswith("["):
inside = row.startswith(key + " ") or row.rstrip("\n") == key
elif inside and row.startswith('"%s"=' % name):
dropped = True
continue
rows.append(row)
if dropped:
tmp = reg.with_name(reg.name + ".dd-new")
tmp.write_text("".join(rows))
os.replace(tmp, reg)
return dropped
def options(sidecar):
"""An Epic game's launch choices from its sidecar, as the Games tab's Epic card sets them."""
e = sidecar.get("epic") if isinstance(sidecar.get("epic"), dict) else {}
return {"eos": e.get("eos", True) is not False, "offline": e.get("offline", False) is True}
def server_socket(pfx):
"""The wineserver socket for prefix [pfx], as Wine names it (server-<dev>-<inode> under /tmp/.wine-<uid>)."""
try:
st = os.stat(pfx)
except OSError:
return None
base = os.environ.get("BL_WINE_SERVER_BASE") or "/tmp/.wine-%d" % os.getuid()
return Path(base) / ("server-%x-%x" % (st.st_dev, st.st_ino)) / "socket"
def wait_for_server(pfx, timeout=SERVER_WAIT):
"""
Waits for a wineserver still holding this prefix (an earlier verb's, or the last launch's) to
exit: it rewrites user.reg from its own memory when it does, which drops a line appended
meanwhile. True when none is left.
"""
sock = server_socket(pfx)
if sock is None:
return True
deadline = time.monotonic() + timeout
while sock.exists() and time.monotonic() < deadline:
time.sleep(0.1)
return not sock.exists()
def has_value(reg, key, name, value=None):
"""Whether the last word on `key` in user.reg sets "name" (to [value], when given)."""
if not reg.is_file():
return False
inside, last = False, None
for row in reg.read_text(errors="replace").splitlines():
if row.startswith("["):
inside = row.startswith(key + " ") or row == key
elif inside and row.startswith('"%s"=' % name):
last = row
if last is None:
return False
return value is None or last == '"%s"="%s"' % (name, reg_escape(value))
def provision_prefix(compat_data, wait=SERVER_WAIT):
"""Wine's browser set to the hand-off, and an earlier build's EOS overlay pointer removed."""
if not compat_data:
return "no-prefix"
pfx = Path(compat_data) / "pfx"
reg = pfx / "user.reg"
if not reg.is_file():
return "prefix-not-created"
# A wineserver still up for this prefix would write its own copy of user.reg over these lines.
busy = not wait_for_server(pfx, wait)
# winebrowser starts the first entry it can; an absolute path does not depend on the PATH Wine
# hands it.
set_value(reg, BROWSER_KEY, "Browsers", BROWSER + ",xdg-open")
removed = remove_value(reg, EOS_KEY, "OverlayPath")
state = "browser-set" if has_value(reg, BROWSER_KEY, "Browsers", BROWSER + ",xdg-open") else "browser-not-written"
if removed:
state += " old-overlay-removed"
return state + (" server-running" if busy else "")
CLOUD_TIMEOUT = 15.0
CLOUD_STORES = ("gog", "epic")
# Exit status that tells droiddeck-proton this was a store game with cloud saves: it then waits for
# Proton instead of exec'ing it, and runs `droiddeck-store-launch --exited` after.
STORE_GAME = 10
def cloud_on(sidecar):
"""Cloud saves for this game (the game card's switch; on unless turned off)."""
return str(sidecar.get("store")) in CLOUD_STORES and sidecar.get("cloud", True) is not False
def exited(argv):
"""After the game: ask the app to upload what changed, without waiting for it."""
found = find_store_game(argv)
launch_dir = os.environ.get("BL_LAUNCH_DIR", "")
if found is None or not launch_dir or not cloud_on(found[1]):
return 0
store, game = str(found[1].get("store")), str(found[1].get("id"))
ask(Path(launch_dir) / "stores", {"op": "cloud-up", "store": store, "id": game}, timeout=1.0)
log("cloud %s %s up requested" % (store, game))
return 0
def main(argv):
if argv and argv[0] == "--exited":
return exited(argv[1:])
found = find_store_game(argv)
if found is None:
return 0
folder, sidecar = found
store, game = str(sidecar.get("store")), str(sidecar.get("id"))
compat_data = os.environ.get("STEAM_COMPAT_DATA_PATH", "").rstrip("/")
prefix_id = os.path.basename(compat_data) if compat_data else ""
launch_dir = os.environ.get("BL_LAUNCH_DIR", "")
if store == "epic":
drop_stale(folder)
choice = options(sidecar)
if not (choice["eos"] and not choice["offline"]):
# Sign-in off, or offline: no code, and none left over from before.
try:
(folder / EPIC_CODE).unlink()
except OSError:
pass
log("epic launch id=%s code=no reason=%s" % (game, "offline" if choice["offline"] else "eos-off"))
elif not launch_dir:
log("epic launch id=%s code=no reason=no-channel" % game)
else:
answer = ask(Path(launch_dir) / "stores", {"op": "epic-code", "store": store, "id": game, "prefix": prefix_id})
if answer is None:
log("epic launch id=%s code=no reason=timeout" % game)
else:
got = bool(answer.get("code"))
log("epic launch id=%s code=%s reason=%s" % (game, "yes" if got else "no", answer.get("reason", "")))
log("epic prefix=%s %s" % (prefix_id or "?", provision_prefix(compat_data)))
if not cloud_on(sidecar):
if store in CLOUD_STORES:
log("cloud %s %s down result=skipped reason=off" % (store, game))
return 0
if launch_dir:
# The cloud copy where it is newer, before the game reads its saves; bounded, then on regardless.
answer = ask(Path(launch_dir) / "stores", {"op": "cloud-down", "store": store, "id": game}, timeout=CLOUD_TIMEOUT)
if answer is None:
log("cloud %s %s down result=timeout" % (store, game))
else:
log("cloud %s %s down result=%s files=%s reason=%s" % (store, game, answer.get("result", "?"), answer.get("files", 0), answer.get("reason", "")))
else:
log("cloud %s %s down result=skipped reason=no-channel" % (store, game))
return STORE_GAME
if __name__ == "__main__":
try:
sys.exit(main(sys.argv[1:]))
except Exception as e: # never in the way of the launch
log("skipped: %s" % type(e).__name__)
sys.exit(0)
@@ -96,6 +96,46 @@ TOOL_MANIFEST_VDF = """"manifest"
# each package in use. A file that no longer matches - whatever changed it - is put back before
# Proton starts. Only for the Proton build the choice was made for: after a Steam update the build
# differs and the Proton's own new files are left alone until the user chooses again.
# A store game (GOG, Epic, Amazon) is started through the launcher .bat DroidDeck wrote beside it.
# An Epic game needs a fresh sign-in code, which only the app can mint: droiddeck-store-launch asks
# for it and the app writes it into the game's folder, so a launch from the client's own Play
# button signs in just as one from the app does. A real launch only; never in the way of it.
BL_STORE_SETUP = """
bl_store_launch() {
[ "${verb:-}" = waitforexitandrun ] || return 0
# A web address the game opens (Wine's winebrowser runs xdg-open) goes to Android's browser:
# droiddeck-open-url as xdg-open, first on the game's PATH, with the session channel left in a
# file in case Wine does not pass BL_LAUNCH_DIR on. (The prefix also names it as Wine's browser.)
if [ -x /usr/local/bin/droiddeck-open-url ]; then
mkdir -p /tmp/droiddeck-browser
ln -sfn /usr/local/bin/droiddeck-open-url /tmp/droiddeck-browser/xdg-open
[ -n "${BL_LAUNCH_DIR:-}" ] && printf '%s\n' "$BL_LAUNCH_DIR" > /tmp/droiddeck-browser/launch-dir
PATH="/tmp/droiddeck-browser:$PATH"; export PATH
fi
# BL_DEBUG_BROWSER=1 (droiddeck-env): Wine traces how the game opens a web address.
if [ "${BL_DEBUG_BROWSER:-}" = 1 ]; then
WINEDEBUG="${WINEDEBUG:+$WINEDEBUG,}+shell,+winebrowser"; export WINEDEBUG
fi
[ -x /usr/local/bin/droiddeck-store-launch ] || return 0
/usr/local/bin/droiddeck-store-launch "$@"
# 10: a store game with cloud saves - the launch waits for Proton and uploads after (bl_run).
[ $? -eq 10 ] && BL_STORE_EXIT=1
return 0
}
# Runs Proton: exec'd as always, except for a store game with cloud saves, where the wrapper stays
# to tell the app the game has exited so it can upload what changed.
bl_run() {
if [ -n "${BL_STORE_EXIT:-}" ]; then
"$@"
rc=$?
/usr/local/bin/droiddeck-store-launch --exited "${BL_STORE_ARGS[@]}" || true
exit $rc
fi
exec "$@"
}
"""
BL_COMPONENTS_SETUP = """
bl_components() {
base=$1
@@ -332,7 +372,9 @@ if [ -n "$depot" ]; then
bl_game_cpus
bl_idtech3 "$@"
bl_libpath
exec ${BL_TASKSET:-} /usr/local/bin/droiddeck-game-env "$depot/proton" "$verb" "$@" "${BL_EXTRA_ARGS[@]}"
bl_store_launch "$@"
BL_STORE_ARGS=("$@")
bl_run ${BL_TASKSET:-} /usr/local/bin/droiddeck-game-env "$depot/proton" "$verb" "$@" "${BL_EXTRA_ARGS[@]}"
fi
echo "droiddeck-proton: no ARM64 Proton depot yet - the client downloads one as this tool's dependency; retry the launch once it has" >&2
exit 1
@@ -346,7 +388,7 @@ def launcher_sh(sources=SOURCES):
# something else.
return (LAUNCHER_TEMPLATE % " ".join('"%s"' % n for n in sources)).replace(
"verb=$1; shift", "verb=$1; shift\n" + BL_DIRECTAUDIO_SETUP + BL_GAME_CPUS_SETUP + BL_IDTECH3_SETUP
+ BL_COMPONENTS_SETUP + BL_LIBPATH_SETUP, 1)
+ BL_COMPONENTS_SETUP + BL_LIBPATH_SETUP + BL_STORE_SETUP, 1)
LAUNCHER_SH = launcher_sh()
@@ -390,9 +432,11 @@ bl_directaudio "$here"
bl_game_cpus
bl_idtech3 "$@"
bl_libpath
bl_store_launch "$@"
BL_STORE_ARGS=("$@")
# Proton takes its base directory from dirname(sys.argv[0]) without resolving it, so it has to be
# started from its own tree.
exec ${BL_TASKSET:-} /usr/local/bin/droiddeck-game-env "$here/%s" "$verb" "$@" "${BL_EXTRA_ARGS[@]}"
bl_run ${BL_TASKSET:-} /usr/local/bin/droiddeck-game-env "$here/%s" "$verb" "$@" "${BL_EXTRA_ARGS[@]}"
"""
EXTRA_COMPAT_TOOL_VDF = """"compatibilitytools"
{
@@ -619,7 +663,7 @@ def adopt_extras(tools):
body = (EXTRA_WRAPPER_SH % entry_point).replace(
'here=$(dirname "$0")',
'here=$(dirname "$0")\n' + BL_DIRECTAUDIO_SETUP + BL_GAME_CPUS_SETUP + BL_IDTECH3_SETUP
+ BL_COMPONENTS_SETUP + BL_LIBPATH_SETUP, 1)
+ BL_COMPONENTS_SETUP + BL_LIBPATH_SETUP + BL_STORE_SETUP, 1)
write_changed(wrapper, body, 0o755)
write_changed(manifest, EXTRA_MANIFEST_VDF)
write_changed(compat_vdf, EXTRA_COMPAT_TOOL_VDF % (name, display_name(entry)))
+3 -1
View File
@@ -260,7 +260,9 @@ class GameEnvironmentTest(unittest.TestCase):
def test_both_proton_wrappers_call_environment_launcher(self):
for script in (COMPAT["LAUNCHER_SH"], COMPAT["EXTRA_WRAPPER_SH"] % "proton"):
subprocess.run(["bash", "-n"], input=script, text=True, check=True)
self.assertIn('exec ${BL_TASKSET:-} /usr/local/bin/droiddeck-game-env', script)
# Started through bl_run, which execs it - or, for a store game with cloud saves, waits
# for it so droiddeck-store-launch --exited can follow (test_store_launch.CloudHooks).
self.assertIn('bl_run ${BL_TASKSET:-} /usr/local/bin/droiddeck-game-env', script)
def test_wrappers_preload_the_session_library_before_the_input_shim(self):
overlay = "/root/.local/share/Steam/ubuntu12_64/gameoverlayrenderer.so"
+262
View File
@@ -0,0 +1,262 @@
"""droiddeck-store-launch: a launch from anywhere - the Steam client's own Play button included -
asks the app for an Epic game's sign-in code before Proton starts. These pin how it recognises a
store game, how it asks, and that both Proton launchers call it."""
import importlib.machinery
import importlib.util
import json
import os
from pathlib import Path
import tempfile
import threading
import time
import unittest
BIN = Path(__file__).resolve().parents[1] / 'linuxfs/overlay/usr/local/bin'
def load(name):
loader = importlib.machinery.SourceFileLoader(name.replace('-', '_'), str(BIN / name))
spec = importlib.util.spec_from_loader(loader.name, loader)
module = importlib.util.module_from_spec(spec)
loader.exec_module(module)
return module
store = load('droiddeck-store-launch')
def load_path(path, name):
loader = importlib.machinery.SourceFileLoader(name, str(path))
spec = importlib.util.spec_from_loader(name, loader)
module = importlib.util.module_from_spec(spec)
loader.exec_module(module)
return module
compat = load('steam-compatibility')
def game(root, store_id='epic', ident='8b6a0e14'):
folder = Path(root) / 'Games/Stores/Epic/Metalstorm'
folder.mkdir(parents=True)
(folder / '.droiddeck-store.json').write_text(json.dumps({'store': store_id, 'id': ident, 'title': 'Metalstorm', 'exe': 'Metalstorm.exe'}))
(folder / '.droiddeck-launch.bat').write_text('@echo off\r\n')
return folder
class Detection(unittest.TestCase):
def test_the_launcher_among_steams_arguments_names_the_game(self):
with tempfile.TemporaryDirectory() as root:
folder = game(root)
found = store.find_store_game(['/usr/bin/steam-runtime', '"%s/.droiddeck-launch.bat"' % folder, '-flag'])
self.assertIsNotNone(found)
self.assertEqual(folder, found[0])
self.assertEqual('epic', found[1]['store'])
self.assertEqual('8b6a0e14', found[1]['id'])
def test_anything_else_is_left_alone(self):
with tempfile.TemporaryDirectory() as root:
folder = game(root)
# The exe of a store game is one too (a GOG game without a launcher); a stray file is not.
self.assertEqual(folder, store.find_store_game([str(folder / 'Metalstorm.exe')])[0])
self.assertIsNone(store.find_store_game([str(Path(root) / 'elsewhere/readme.txt')]))
(folder / '.droiddeck-store.json').unlink()
self.assertIsNone(store.find_store_game([str(folder / '.droiddeck-launch.bat')]))
def test_only_epic_asks_for_a_code(self):
with tempfile.TemporaryDirectory() as root:
folder = game(root, store_id='gog')
# Cloud saves off: nothing else to ask for either.
sc = json.loads((folder / '.droiddeck-store.json').read_text()); sc['cloud'] = False
(folder / '.droiddeck-store.json').write_text(json.dumps(sc))
os.environ['BL_LAUNCH_DIR'] = str(Path(root) / 'session')
try:
self.assertEqual(0, store.main([str(folder / '.droiddeck-launch.bat')]))
finally:
del os.environ['BL_LAUNCH_DIR']
self.assertFalse((Path(root) / 'session/stores').exists())
class Asking(unittest.TestCase):
def test_a_request_is_answered_through_the_resp_folder(self):
with tempfile.TemporaryDirectory() as root:
channel = Path(root) / 'stores'
def app():
req = channel / 'req'
for _ in range(100):
names = [p for p in req.glob('*.json')] if req.exists() else []
if names:
request = json.loads(names[0].read_text())
self.assertEqual({'op': 'epic-code', 'store': 'epic', 'id': 'x'}, request)
names[0].unlink()
tmp = channel / 'resp' / (names[0].name + '.tmp')
tmp.write_text(json.dumps({'ok': True, 'code': True, 'reason': 'ok'}))
os.rename(tmp, channel / 'resp' / names[0].name)
return
time.sleep(0.02)
t = threading.Thread(target=app)
t.start()
answer = store.ask(channel, {'op': 'epic-code', 'store': 'epic', 'id': 'x'}, timeout=3)
t.join()
self.assertEqual({'ok': True, 'code': True, 'reason': 'ok'}, answer)
def test_no_answer_withdraws_the_request(self):
with tempfile.TemporaryDirectory() as root:
channel = Path(root) / 'stores'
self.assertIsNone(store.ask(channel, {'op': 'epic-code'}, timeout=0.2))
self.assertEqual([], list((channel / 'req').iterdir()))
def test_a_stale_code_is_dropped_before_asking(self):
with tempfile.TemporaryDirectory() as root:
folder = game(root)
code = folder / '.droiddeck-epic-code'
code.write_text('old')
self.assertFalse(store.drop_stale(folder, now=code.stat().st_mtime + 60))
self.assertTrue(store.drop_stale(folder, now=code.stat().st_mtime + store.STALE_SECONDS + 1))
self.assertFalse(code.exists())
class Prefix(unittest.TestCase):
def setUp(self):
self.tmp = tempfile.TemporaryDirectory()
root = Path(self.tmp.name)
self.compat = root / 'compatdata/3785150007'
(self.compat / 'pfx').mkdir(parents=True)
self.reg = self.compat / 'pfx/user.reg'
self.reg.write_text('WINE REGISTRY Version 2\n\n[Software\\\\Wine] 1\n"Version"="win10"\n')
def tearDown(self):
self.tmp.cleanup()
def test_wines_browser_is_the_hand_off_by_its_path(self):
self.assertEqual('browser-set', store.provision_prefix(str(self.compat)))
text = self.reg.read_text()
self.assertIn('[Software\\\\Wine\\\\WineBrowser] ', text)
self.assertIn('"Browsers"="/usr/local/bin/droiddeck-open-url,xdg-open"', text)
# A second launch adds nothing: the last word already says so.
store.provision_prefix(str(self.compat))
self.assertEqual(text, self.reg.read_text())
def test_an_earlier_builds_overlay_pointer_is_removed(self):
self.reg.write_text(self.reg.read_text() + '\n[Software\\\\Epic Games\\\\EOS] 2\n"OverlayPath"="Z:\\\\x"\n"Other"="kept"\n')
self.assertEqual('browser-set old-overlay-removed', store.provision_prefix(str(self.compat)))
text = self.reg.read_text()
self.assertNotIn('OverlayPath', text)
self.assertIn('"Other"="kept"', text)
def test_no_prefix_yet(self):
self.assertEqual('prefix-not-created', store.provision_prefix(self.tmp.name + '/compatdata/1'))
self.assertEqual('no-prefix', store.provision_prefix(''))
class Choices(unittest.TestCase):
def test_the_sidecars_epic_choices_are_honoured(self):
with tempfile.TemporaryDirectory() as root:
folder = game(root)
sidecar = json.loads((folder / '.droiddeck-store.json').read_text())
self.assertEqual({'eos': True, 'offline': False}, store.options(sidecar))
# An earlier build's overlay field is read past.
self.assertEqual({'eos': True, 'offline': False}, store.options({'epic': {'v': 2, 'overlay': True}}))
sidecar['epic'] = {'eos': True, 'offline': True}
sidecar['cloud'] = False
(folder / '.droiddeck-store.json').write_text(json.dumps(sidecar))
(folder / '.droiddeck-epic-code').write_text('left over')
compat = Path(root) / 'compatdata/1'
(compat / 'pfx').mkdir(parents=True)
reg = compat / 'pfx/user.reg'
reg.write_text('WINE REGISTRY Version 2\n\n[Software\\\\Epic Games\\\\EOS] 1\n"OverlayPath"="Z:\\\\x"\n"Other"="kept"\n')
os.environ['BL_LAUNCH_DIR'] = str(Path(root) / 'session')
os.environ['STEAM_COMPAT_DATA_PATH'] = str(compat)
try:
self.assertEqual(0, store.main([str(folder / '.droiddeck-launch.bat')]))
finally:
del os.environ['BL_LAUNCH_DIR']
del os.environ['STEAM_COMPAT_DATA_PATH']
# Offline: no request was made and no code is left; the old overlay pointer is gone.
self.assertFalse((Path(root) / 'session/stores/req').exists())
self.assertFalse((folder / '.droiddeck-epic-code').exists())
text = reg.read_text()
self.assertNotIn('OverlayPath', text)
self.assertIn('"Other"="kept"', text)
class Browser(unittest.TestCase):
def test_a_web_address_is_handed_to_the_app(self):
xdg = load_path(BIN / 'droiddeck-open-url', 'open_url')
with tempfile.TemporaryDirectory() as root:
os.environ['BL_LAUNCH_DIR'] = root
try:
self.assertEqual(0, xdg.main(['https://www.epicgames.com/activate']))
finally:
del os.environ['BL_LAUNCH_DIR']
reqs = list((Path(root) / 'stores/req').glob('*.json'))
self.assertEqual(1, len(reqs))
self.assertEqual({'op': 'open-url', 'url': 'https://www.epicgames.com/activate'}, json.loads(reqs[0].read_text()))
self.assertEqual('https://www.epicgames.com', xdg.where('https://www.epicgames.com/activate?code=SECRET'))
class ExeTarget(unittest.TestCase):
def test_a_game_started_by_its_exe_is_found_from_a_subfolder(self):
# Most GOG games have no launcher .bat: Steam runs the exe, which may sit in a subfolder.
with tempfile.TemporaryDirectory() as root:
folder = game(root, store_id='gog', ident='1207664643')
(folder / 'bin/x64').mkdir(parents=True)
exe = folder / 'bin/x64/ELDERBORN.exe'
exe.write_text('MZ')
found = store.find_store_game(['"%s"' % exe])
self.assertEqual(folder, found[0])
self.assertEqual('gog', found[1]['store'])
self.assertIsNone(store.find_store_game(['/root/Games/Other/x.exe']))
class CloudHooks(unittest.TestCase):
def test_a_store_game_with_cloud_saves_asks_before_and_after(self):
with tempfile.TemporaryDirectory() as root:
folder = game(root, store_id='gog', ident='1207664643')
bat = str(folder / '.droiddeck-launch.bat')
os.environ['BL_LAUNCH_DIR'] = str(Path(root) / 'session')
try:
original = store.ask
asked = []
store.ask = lambda channel, request, timeout=5.0: asked.append((request, timeout)) or {'ok': True, 'files': 2, 'reason': 'ok'}
# 10: the launcher waits for Proton and calls --exited afterwards.
self.assertEqual(store.STORE_GAME, store.main([bat]))
self.assertEqual(0, store.main(['--exited', bat]))
finally:
store.ask = original
del os.environ['BL_LAUNCH_DIR']
self.assertEqual({'op': 'cloud-down', 'store': 'gog', 'id': '1207664643'}, asked[0][0])
self.assertEqual(store.CLOUD_TIMEOUT, asked[0][1])
self.assertEqual('cloud-up', asked[1][0]['op'])
def test_cloud_off_or_amazon_runs_proton_as_before(self):
with tempfile.TemporaryDirectory() as root:
folder = game(root, store_id='gog', ident='1')
sidecar = json.loads((folder / '.droiddeck-store.json').read_text())
sidecar['cloud'] = False
(folder / '.droiddeck-store.json').write_text(json.dumps(sidecar))
self.assertEqual(0, store.main([str(folder / '.droiddeck-launch.bat')]))
self.assertFalse(store.cloud_on({'store': 'amazon', 'id': 'x'}))
self.assertTrue(store.cloud_on({'store': 'epic', 'id': 'x'}))
def test_both_launchers_wait_for_proton_only_for_a_store_game(self):
for sh in (compat.LAUNCHER_SH, compat.EXTRA_WRAPPER_SH):
self.assertIn('bl_run ${BL_TASKSET:-} /usr/local/bin/droiddeck-game-env', sh)
self.assertNotIn('exec ${BL_TASKSET:-} /usr/local/bin/droiddeck-game-env', sh)
self.assertIn('[ $? -eq 10 ] && BL_STORE_EXIT=1', compat.BL_STORE_SETUP)
self.assertIn('droiddeck-store-launch --exited "${BL_STORE_ARGS[@]}"', compat.BL_STORE_SETUP)
self.assertIn('exec "$@"', compat.BL_STORE_SETUP)
class Launchers(unittest.TestCase):
def test_both_proton_launchers_ask_before_proton_starts(self):
sh = compat.LAUNCHER_SH
self.assertIn('bl_store_launch() {', sh)
self.assertLess(sh.index('bl_store_launch "$@"'), sh.index('droiddeck-game-env "$depot/proton"'))
self.assertIn('bl_store_launch "$@"', compat.EXTRA_WRAPPER_SH)
self.assertIn('bl_store_launch() {', compat.BL_STORE_SETUP)
self.assertIn('waitforexitandrun', compat.BL_STORE_SETUP)
if __name__ == '__main__':
unittest.main()
+74
View File
@@ -0,0 +1,74 @@
"""The shortcuts writer and a store install: the app registers a game GOG, Epic or Amazon
installed through the same listing as an added folder, pointing the shortcut at the game's
launcher .bat when it has one. These pin the parts of the writer that contract relies on."""
import importlib.machinery
import importlib.util
import json
from pathlib import Path
import subprocess
import tempfile
import unittest
import zlib
BIN = Path(__file__).resolve().parents[1] / 'linuxfs/overlay/usr/local/bin'
def load(name):
loader = importlib.machinery.SourceFileLoader(name, str(BIN / name))
spec = importlib.util.spec_from_loader(name, loader)
module = importlib.util.module_from_spec(spec)
loader.exec_module(module)
return module
shortcuts = load('droiddeck-steam-shortcuts')
FOLDER = '/root/Games/Stores/Epic/Celeste'
LAUNCHER = FOLDER + '/.droiddeck-launch.bat'
def app_id(exe, name):
"""The appid the app computes for a shortcut (AddedGames.scanGame): CRC32 of the quoted exe
and the name, high bit set - what Steam itself derives for a shortcut it is given."""
return (zlib.crc32(('"%s"' % exe + name).encode()) | 0x80000000) & 0xFFFFFFFF
class StoreShortcutsTest(unittest.TestCase):
def setUp(self):
self.temp = tempfile.TemporaryDirectory()
self.addCleanup(self.temp.cleanup)
self.root = Path(self.temp.name)
self.steam = self.root / 'Steam'
self.config = self.steam / 'userdata/123/config'
self.config.mkdir(parents=True)
self.listing = self.root / 'added-games.json'
def write(self, *games):
self.listing.write_text(json.dumps(list(games)))
subprocess.run(['python3', str(BIN / 'droiddeck-steam-shortcuts'), str(self.steam), str(self.listing)],
check=True, capture_output=True)
return shortcuts.parse((self.config / 'shortcuts.vdf').read_bytes())['shortcuts']
def test_a_launcher_bat_is_the_shortcuts_exe_and_the_folder_its_start_dir(self):
game = dict(name='Celeste', exe=LAUNCHER, folder=FOLDER, dir=FOLDER, appid=app_id(LAUNCHER, 'Celeste'), seen=0)
entries = self.write(game)
entry = next(iter(entries.values()))
self.assertEqual('"%s"' % LAUNCHER, entry['Exe'])
self.assertEqual('"%s"' % FOLDER, entry['StartDir'])
self.assertEqual('Celeste', entry['AppName'])
self.assertIn('droiddeck-app', entry['tags'].values())
def test_the_appid_the_app_computes_is_the_one_written(self):
appid = app_id(LAUNCHER, 'Celeste')
entries = self.write(dict(name='Celeste', exe=LAUNCHER, folder=FOLDER, dir=FOLDER, appid=appid, seen=0))
entry = next(iter(entries.values()))
self.assertEqual(appid, entry['appid'] & 0xFFFFFFFF)
def test_an_uninstalled_game_leaves_the_listing_and_the_shortcut_goes_with_it(self):
game = dict(name='Celeste', exe=LAUNCHER, folder=FOLDER, dir=FOLDER, appid=app_id(LAUNCHER, 'Celeste'), seen=0)
self.assertEqual(1, len(self.write(game)))
self.assertEqual(0, len(self.write()))
if __name__ == '__main__':
unittest.main()