mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-18 20:36:04 +00:00
Merge branch 'main' into stretch-to-panel
This commit is contained in:
commit
d659a03467
118 files changed
+5493
-1028
No files matched your search
@@ -11,7 +11,7 @@ import sys
|
||||
|
||||
HOME = os.environ.get("HOME", "/root")
|
||||
STEAM_ROOT = sys.argv[1] if len(sys.argv) > 1 else os.path.join(HOME, ".local/share/Steam")
|
||||
LIBRARIES = ((STEAM_ROOT, "Steam Games"), ("/mnt/bannerlator-sd", "SD Games"))
|
||||
LIBRARIES = ((STEAM_ROOT, "Steam Games"), ("/mnt/droiddeck-sd", "SD Games"))
|
||||
# The client's own tools and runtimes live in steamapps beside the games; they are not titles.
|
||||
NOT_GAMES = {228980, 1493710, 3127680, 4183110, 4427310, 4185400}
|
||||
APPS_DIR = os.path.join(HOME, ".local/share/applications")
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#!/bin/bash
|
||||
# Marks Steam's shared redistributables as already run in every Proton prefix.
|
||||
# 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
|
||||
@@ -14,27 +15,15 @@ set -u
|
||||
steam_root=${1:?steam root}
|
||||
|
||||
redist="$steam_root/steamapps/common/Steamworks Shared/_CommonRedist"
|
||||
[ -d "$redist" ] || exit 0
|
||||
|
||||
# Every process an install script would run becomes the registry value the client writes once it
|
||||
# has run it. Names sit one level inside "Run Process", the key they share a level further in.
|
||||
block=$(find "$redist" -name installscript.vdf -print0 2>/dev/null | sort -z | xargs -0 -r awk -v now="$(date +%s)" '
|
||||
function emit(key, name, path) {
|
||||
path = key
|
||||
sub(/^HKEY_LOCAL_MACHINE\\\\/, "", path)
|
||||
if (path == key)
|
||||
return
|
||||
printf "\n[%s] %d\n\"%s\"=dword:00000001\n", path, now, name
|
||||
# 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, name
|
||||
}
|
||||
# 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 != "")
|
||||
emit(key, name)
|
||||
printf "%s\t%s\n", key, name
|
||||
depth--
|
||||
next
|
||||
}
|
||||
@@ -44,15 +33,62 @@ block=$(find "$redist" -name installscript.vdf -print0 2>/dev/null | sort -z | x
|
||||
if (n >= 3 && depth == 2) { name = part[2]; key = "" }
|
||||
}
|
||||
')
|
||||
[ -n "$block" ] || exit 0
|
||||
stamp=$(printf '%s' "$block" | cksum)
|
||||
# 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)
|
||||
|
||||
for reg in "$steam_root"/steamapps/compatdata/*/pfx/system.reg \
|
||||
/mnt/bannerlator-sd/steamapps/compatdata/*/pfx/system.reg; do
|
||||
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
|
||||
printf '%s\n' "$block" >>"$reg" || continue
|
||||
printf '%s\n' "$stamp" >"$seeded"
|
||||
echo "== seeded redist markers into $reg"
|
||||
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
|
||||
@@ -159,6 +159,11 @@ if [ -z "${BL_INSIDE:-}" ]; then
|
||||
args+=(-r "$BL_REFRESH")
|
||||
fi
|
||||
[ "$mode" = steam ] && args+=(-e)
|
||||
# Touch passes through to the client as touch until the client says otherwise, as SteamOS's
|
||||
# gamescope-session starts it (TOUCH_MODE=4). The client sets the mode itself (STEAM_TOUCH_CLICK_MODE)
|
||||
# only once it has a controller; until then gamescope's own default made a finger a left-click
|
||||
# mouse, so the Steam interface took taps but would not scroll on a phone with no pad attached.
|
||||
[ "$mode" = steam ] && args+=(--default-touch-mode 4)
|
||||
# A game that resizes its own window when it loses focus (the Steam menu opening over it) comes
|
||||
# back smaller, and gamescope draws a window that is not flagged fullscreen at its own size in
|
||||
# the top-left corner. Forcing every window to the output's size keeps it filling the screen.
|
||||
@@ -243,7 +248,7 @@ case $mode in
|
||||
bannerlator-steam-install || exit $?
|
||||
step "Steam client ready"
|
||||
steam_root=$XDG_DATA_HOME/Steam
|
||||
# Register the card library (bound at /mnt/bannerlator-sd) with the client - internal storage is
|
||||
# Register the card library (bound at /mnt/droiddeck-sd) with the client - internal storage is
|
||||
# its main library already - and the ARM64 Proton that lets it launch the Windows ones.
|
||||
# A request left in ~/.bl-proton-extra installs a third-party Proton before the client starts,
|
||||
# so it is in the Compatibility dropdown the first time the user looks. One per line, each the
|
||||
@@ -282,13 +287,24 @@ case $mode in
|
||||
# device it took 5 of 8, leaving out both little cores and the fastest one - which is a
|
||||
# reasonable thing to do while a game is running and the wrong thing when the client is all
|
||||
# there is. BL_CLIENT_CPUS overrides it. Re-applied on a beat because steamwebhelper spawns
|
||||
# children continuously and each one inherits Steam's choice, not ours.
|
||||
# children continuously and each one inherits Steam's choice, not ours. The beat reads /proc
|
||||
# itself instead of running pgrep, and only runs taskset for a process that is new or has
|
||||
# grown threads since it was last pinned: every fork is a round of traced syscalls, and a
|
||||
# beat that forked a taskset per process every 5 s did that for an hour. taskset -a, because
|
||||
# without it only a process's main thread moves and the renderer's workers stay where they were.
|
||||
if [ -n "${BL_CLIENT_CPUS:-}" ]; then
|
||||
step "client cores: $BL_CLIENT_CPUS"
|
||||
(
|
||||
for _ in $(seq 1 720); do
|
||||
for _p in $(pgrep -f 'steamwebhelper|steamrtarm64/steam|gamescope' 2>/dev/null); do
|
||||
taskset -cp "$BL_CLIENT_CPUS" "$_p" >/dev/null 2>&1 || true
|
||||
declare -A _bl_pinned=()
|
||||
for ((_i = 0; _i < 720; _i++)); do
|
||||
for _d in /proc/[0-9]*; do
|
||||
IFS= read -r -d '' _c < "$_d/cmdline" 2>/dev/null || continue
|
||||
case $_c in *steamwebhelper*|*steamrtarm64/steam|*gamescope*) ;; *) continue ;; esac
|
||||
_t=("$_d"/task/*)
|
||||
_p=${_d#/proc/}
|
||||
[ "${_bl_pinned[$_p]:-}" = "${#_t[@]}" ] && continue
|
||||
taskset -a -cp "$BL_CLIENT_CPUS" "$_p" >/dev/null 2>&1 || true
|
||||
_bl_pinned[$_p]=${#_t[@]}
|
||||
done
|
||||
nap 5
|
||||
done
|
||||
@@ -429,13 +445,64 @@ case $mode in
|
||||
prev=$app
|
||||
done
|
||||
) &
|
||||
# Evidence for touch reports: the touch mode the client asks gamescope for (STEAM_TOUCH_CLICK_MODE,
|
||||
# set once it has a controller, per focused app) and which app has focus, logged as they change.
|
||||
# A finger that clicks but won't scroll, or touch that stops once a pad is used, shows here as
|
||||
# the mode in force at that moment. 4 is touch passed through, 1 a left-click mouse.
|
||||
[ -z "${BL_DESKTOP:-}" ] && (
|
||||
# What follows "=" in an xprop line, or $2 for a property that is missing or has no value
|
||||
# yet ("NAME(CARDINAL) =", which read leaves with nothing after the "=").
|
||||
xprop_value() {
|
||||
case $1 in *'not found'*|*=) echo "$2"; return ;; esac
|
||||
local v=${1#*=}
|
||||
v=${v# }
|
||||
echo "${v:-$2}"
|
||||
}
|
||||
tmode= app=
|
||||
xprop -spy -root STEAM_TOUCH_CLICK_MODE GAMESCOPE_FOCUSED_APP 2>/dev/null | while read -r line; do
|
||||
case $line in
|
||||
STEAM_TOUCH_CLICK_MODE*)
|
||||
v=$(xprop_value "$line" unset)
|
||||
[ "$v" = "$tmode" ] && continue
|
||||
tmode=$v
|
||||
echo "== touch mode: $tmode (focused app ${app:-?}) at $(date +%T)"
|
||||
;;
|
||||
GAMESCOPE_FOCUSED_APP*)
|
||||
v=$(xprop_value "$line" none)
|
||||
[ "$v" = "$app" ] && continue
|
||||
app=$v
|
||||
echo "== focused app: $app (touch mode ${tmode:-unset}) at $(date +%T)"
|
||||
;;
|
||||
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.
|
||||
(
|
||||
beat=0
|
||||
for _ in $(seq 1 720); do
|
||||
compat_stamp=$HOME/.bl-compat-beat
|
||||
rm -f "$compat_stamp"
|
||||
compat_due() {
|
||||
local d
|
||||
[ -e "$compat_stamp" ] && [ "$((beat % 12))" -ne 0 ] || return 0
|
||||
for d in "$steam_root/steamapps" "$steam_root/steamapps/common" "$steam_root/config" \
|
||||
"$steam_root/compatibilitytools.d" /mnt/droiddeck-sd/steamapps; do
|
||||
[ "$d" -nt "$compat_stamp" ] && return 0
|
||||
done
|
||||
return 1
|
||||
}
|
||||
for ((_i = 0; _i < 720; _i++)); do
|
||||
nap 5
|
||||
bannerlator-seed-redists "$steam_root" >/dev/null 2>&1 || true
|
||||
beat=$((beat + 1))
|
||||
if [ "$((beat % 3))" -eq 0 ]; then
|
||||
[ "$((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
|
||||
fi
|
||||
done
|
||||
@@ -587,6 +654,24 @@ BUSCONF
|
||||
bannerlator-steam-games watch "$steam_root" "$BL_ADDED_GAMES" &
|
||||
games_watcher=$!
|
||||
fi
|
||||
# Lossless Scaling (Steam app 993090): whether this account owns it, asked of the signed-in
|
||||
# client once a session until the answer is yes. From then on the app offers importing
|
||||
# Lossless.dll and passes BL_LOSSLESS_OWNED=1, so the question is never asked again.
|
||||
if [ "${BL_LOSSLESS_OWNED:-0}" != 1 ]; then
|
||||
(
|
||||
owned=$HOME/.config/droiddeck/lossless-owned
|
||||
for ((_i = 0; _i < 60; _i++)); do
|
||||
nap 30
|
||||
[ -e "$owned" ] && exit 0
|
||||
answer=$(bannerlator-steam-games probe "$steam_root" 993090 2>/dev/null) || continue
|
||||
case $answer in
|
||||
*'"993090": true'*) mkdir -p "${owned%/*}" && : > "$owned" && echo "== Lossless Scaling: owned" ;;
|
||||
*) echo "== Lossless Scaling: not owned by this account" ;;
|
||||
esac
|
||||
exit 0
|
||||
done
|
||||
) &
|
||||
fi
|
||||
echo "== steam args: ${_bl_ui[*]} -clientbeta $steam_channel -no-cef-sandbox -cef-force-gpu -cef-ozone-platform=x11 -cef-use-gl=angle -cef-use-angle=vulkan $*"
|
||||
# An update that cannot install asks for a restart (rc=42) every time; the count is capped so a
|
||||
# session can never again loop in silence, which reads as a menu opening and closing by itself.
|
||||
|
||||
@@ -152,6 +152,9 @@ bl_game_cpus() {
|
||||
# container that path never reaches Proton either. (WinNative's winnative-proton-launch.)
|
||||
BL_LIBPATH_SETUP = """
|
||||
bl_libpath() {
|
||||
# A Proton built to prefer PipeWire (CachyOS's among the adopted ones) hung its audio thread
|
||||
# here, where only PulseAudio answers. (WinNative, winnative-proton-launch.)
|
||||
export PROTON_USE_PIPEWIRE=${PROTON_USE_PIPEWIRE:-0}
|
||||
[ -n "${LD_LIBRARY_PATH:-}" ] || return 0
|
||||
local kept= dir old_ifs=$IFS
|
||||
IFS=:
|
||||
@@ -246,17 +249,29 @@ if [ -f "$fake" ]; then
|
||||
*) LD_PRELOAD="$fake${LD_PRELOAD:+:$LD_PRELOAD}"; export LD_PRELOAD ;;
|
||||
esac
|
||||
fi
|
||||
# The newest of the ARM64 depots the client has, by the build number that opens each one's version
|
||||
# file: taking the first one found ran a stale Experimental over a newer 11.0. (WinNative.)
|
||||
depot=
|
||||
best=0
|
||||
for name in %s; do
|
||||
depot="$steam_root/steamapps/common/$name"
|
||||
if [ -d "$depot/files/bin-arm64" ] && [ -x "$depot/proton" ]; then
|
||||
bl_components "$depot"
|
||||
bl_directaudio "$depot"
|
||||
bl_game_cpus
|
||||
bl_idtech3 "$@"
|
||||
bl_libpath
|
||||
exec ${BL_TASKSET:-} /usr/local/bin/bannerlator-game-env "$depot/proton" "$verb" "$@" "${BL_EXTRA_ARGS[@]}"
|
||||
candidate="$steam_root/steamapps/common/$name"
|
||||
[ -d "$candidate/files/bin-arm64" ] && [ -x "$candidate/proton" ] || continue
|
||||
build=0
|
||||
read -r build _ 2>/dev/null < "$candidate/version"
|
||||
case $build in "" | *[!0-9]*) build=0 ;; esac
|
||||
if [ -z "$depot" ] || [ "$build" -gt "$best" ]; then
|
||||
depot=$candidate
|
||||
best=$build
|
||||
fi
|
||||
done
|
||||
if [ -n "$depot" ]; then
|
||||
bl_components "$depot"
|
||||
bl_directaudio "$depot"
|
||||
bl_game_cpus
|
||||
bl_idtech3 "$@"
|
||||
bl_libpath
|
||||
exec ${BL_TASKSET:-} /usr/local/bin/bannerlator-game-env "$depot/proton" "$verb" "$@" "${BL_EXTRA_ARGS[@]}"
|
||||
fi
|
||||
echo "bannerlator-proton: no ARM64 Proton depot yet - the client downloads one as this tool's dependency; retry the launch once it has" >&2
|
||||
exit 1
|
||||
""" % " ".join('"%s"' % n for n in SOURCES)
|
||||
@@ -568,15 +583,23 @@ def register_default(config_path, apps=(), name=None, protect=()):
|
||||
write_changed(config_path, text)
|
||||
|
||||
|
||||
def depot_build(depot):
|
||||
"""The build number a depot's version file starts with; 0 when there is none."""
|
||||
try:
|
||||
with open(os.path.join(depot, "version"), encoding="utf-8", errors="replace") as f:
|
||||
first = f.read().split(None, 1)
|
||||
except OSError:
|
||||
return 0
|
||||
return int(first[0]) if first and first[0].isdigit() else 0
|
||||
|
||||
|
||||
def find_source(steam_root):
|
||||
"""The ARM64 Proton depot the client has downloaded, or None."""
|
||||
"""The newest ARM64 Proton depot the client has downloaded (the one the launcher runs), or None."""
|
||||
common = os.path.join(steam_root, "steamapps", "common")
|
||||
for name in SOURCES:
|
||||
depot = os.path.join(common, name)
|
||||
# bin-arm64 is what makes it the native build rather than the x86_64 one.
|
||||
if os.path.isdir(os.path.join(depot, "files", "bin-arm64")):
|
||||
return depot
|
||||
return None
|
||||
# bin-arm64 is what makes it the native build rather than the x86_64 one.
|
||||
found = [os.path.join(common, name) for name in SOURCES
|
||||
if os.path.isdir(os.path.join(common, name, "files", "bin-arm64"))]
|
||||
return max(found, key=depot_build) if found else None
|
||||
|
||||
|
||||
def build_tool(tool_dir):
|
||||
|
||||
@@ -13,6 +13,9 @@ import urllib.parse
|
||||
import urllib.request
|
||||
|
||||
STATE = ".droiddeck-games.json"
|
||||
WINNATIVE = ".winnative-steam/steamapps"
|
||||
LIBRARY = "/mnt/droiddeck-sd"
|
||||
LEGACY_LIBRARY = "/mnt/bannerlator-sd"
|
||||
BASE_ID = 76561197960265728
|
||||
|
||||
|
||||
@@ -40,6 +43,11 @@ def edition_key(name):
|
||||
return title_key(name)
|
||||
|
||||
|
||||
def legacy_path(path):
|
||||
path = str(path)
|
||||
return LEGACY_LIBRARY + path[len(LIBRARY):] if path == LIBRARY or path.startswith(LIBRARY + "/") else path
|
||||
|
||||
|
||||
def source_stamp(game):
|
||||
try:
|
||||
exe = Path(game["exe"])
|
||||
@@ -53,19 +61,23 @@ def source_stamp(game):
|
||||
return None
|
||||
|
||||
|
||||
def manifest_ids(steamapps, name):
|
||||
matches = []
|
||||
for manifest in Path(steamapps).glob("appmanifest_*.acf"):
|
||||
try:
|
||||
install = re.search(r'"installdir"\s*"([^"\\]*)"', manifest.read_text(), re.I)
|
||||
if install and install[1] == name:
|
||||
matches.append(int(manifest.stem.removeprefix("appmanifest_")))
|
||||
except (OSError, ValueError):
|
||||
pass
|
||||
return matches
|
||||
|
||||
|
||||
def identify(game):
|
||||
folder = Path(game["folder"])
|
||||
steamapps = folder.parent.parent
|
||||
if folder.parent.name == "common" and steamapps.name == "steamapps":
|
||||
matches = []
|
||||
for manifest in steamapps.glob("appmanifest_*.acf"):
|
||||
try:
|
||||
text = manifest.read_text()
|
||||
install = re.search(r'"installdir"\s*"([^"\\]*)"', text, re.I)
|
||||
if install and install[1] == folder.name:
|
||||
matches.append(int(manifest.stem.removeprefix("appmanifest_")))
|
||||
except (OSError, ValueError):
|
||||
pass
|
||||
for library in ([steamapps] if folder.parent.name == "common" and steamapps.name == "steamapps" else []) + [folder.parent / WINNATIVE]:
|
||||
matches = manifest_ids(library, folder.name)
|
||||
if matches:
|
||||
return matches[0] if len(matches) == 1 else None
|
||||
ids = set()
|
||||
@@ -128,6 +140,43 @@ def probe(steam_root, ids):
|
||||
method(client, 1, C.c_bool, C.c_int)(client, pipe)
|
||||
|
||||
|
||||
def game_running():
|
||||
"""Whether a Proton game is up: a wineserver is there for as long as any prefix is in use."""
|
||||
try:
|
||||
pids = [p for p in os.listdir("/proc") if p.isdigit()]
|
||||
except OSError:
|
||||
return False
|
||||
for pid in pids:
|
||||
try:
|
||||
with open("/proc/%s/comm" % pid) as f:
|
||||
if f.read().strip() == "wineserver":
|
||||
return True
|
||||
except OSError:
|
||||
pass
|
||||
return False
|
||||
|
||||
|
||||
def downloads_idle(steam_root):
|
||||
try:
|
||||
return not any(Path(steam_root, "steamapps/downloading").iterdir())
|
||||
except OSError:
|
||||
return True
|
||||
|
||||
|
||||
def request_restart(steam_root):
|
||||
"""The client reads manifests and shortcuts only at start, so an import needs one restart;
|
||||
the session's loop runs the importer between the exit and the next start."""
|
||||
Path(os.environ.get("HOME", "/root"), ".bl-restart-once").touch()
|
||||
subprocess.run([str(Path(steam_root) / "steamrtarm64/steam"), "-shutdown"],
|
||||
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, timeout=30)
|
||||
|
||||
|
||||
def unimported(steam_root, snapshot, candidates):
|
||||
routes = read_json(Path(steam_root) / "userdata" / snapshot["account"] / "config/.droiddeck-routes.json", {})
|
||||
routed = set(routes.values()) if isinstance(routes, dict) else set()
|
||||
return sorted({appid for appid in candidates.values() if snapshot["owned"].get(str(appid)) is True} - routed)
|
||||
|
||||
|
||||
def watch(steam_root, listing):
|
||||
games = read_json(listing, [])
|
||||
if os.environ.get("BL_STEAM_OFFLINE") == "1" or not games:
|
||||
@@ -138,7 +187,11 @@ def watch(steam_root, listing):
|
||||
# The probe is a fresh python that loads steamclient.so, seconds of CPU under proot. Ownership
|
||||
# only moves with a purchase or a new match, so it runs when the matches or their sources
|
||||
# change, after a failed probe, and otherwise every five minutes - not on every 30 s beat.
|
||||
probed, next_probe = None, 0
|
||||
# A failed probe is retried on a doubling delay up to those five minutes rather than on every
|
||||
# beat (a client that is not logged on fails it for as long as it stays that way), and none
|
||||
# starts while a game is running: the answer can wait, the game's cores cannot.
|
||||
probed, next_probe, failures = None, 0, 0
|
||||
pending, requested = [], []
|
||||
while True:
|
||||
now = time.monotonic()
|
||||
for game in games:
|
||||
@@ -155,7 +208,9 @@ def watch(steam_root, listing):
|
||||
next_lookup = now + 300
|
||||
status = "waiting for a matching Steam title"
|
||||
key = (dict(candidates), dict(sources))
|
||||
if candidates and (key != probed or now >= next_probe):
|
||||
if candidates and (key != probed or now >= next_probe) and game_running():
|
||||
status = last_status
|
||||
elif candidates and (key != probed or now >= next_probe):
|
||||
probed, next_probe = key, now + 300
|
||||
try:
|
||||
result = subprocess.run([sys.executable, __file__, "probe", steam_root,
|
||||
@@ -163,8 +218,10 @@ def watch(steam_root, listing):
|
||||
capture_output=True, text=True, timeout=15)
|
||||
if result.returncode != 0:
|
||||
status = "ownership probe failed: " + (result.stderr.strip()[-300:] or str(result.returncode))
|
||||
probed = None
|
||||
failures += 1
|
||||
next_probe = now + min(300, 30 * 2 ** failures)
|
||||
else:
|
||||
failures = 0
|
||||
line = next(line for line in result.stdout.splitlines() if line.startswith("DROIDDECK_OWNERSHIP="))
|
||||
snapshot = json.loads(line.removeprefix("DROIDDECK_OWNERSHIP="))
|
||||
if not snapshot["account"].isdigit() or int(snapshot["account"]) <= 0:
|
||||
@@ -172,18 +229,59 @@ def watch(steam_root, listing):
|
||||
snapshot["candidates"] = candidates
|
||||
snapshot["sources"] = sources
|
||||
save_json(Path(steam_root) / "userdata" / snapshot["account"] / "config" / STATE, snapshot)
|
||||
pending = unimported(steam_root, snapshot, candidates)
|
||||
status = "matched %d/%d games; %d owned" % (len(candidates), len(games), sum(snapshot["owned"].values()))
|
||||
except (OSError, ValueError, KeyError, StopIteration, subprocess.TimeoutExpired) as error:
|
||||
status = "ownership check unavailable: " + str(error)
|
||||
probed = None
|
||||
failures += 1
|
||||
next_probe = now + min(300, 30 * 2 ** failures)
|
||||
elif candidates:
|
||||
status = last_status
|
||||
if pending and pending != requested and not game_running() and downloads_idle(steam_root):
|
||||
requested = pending
|
||||
print("bannerlator-steam-games: restarting the client once to import %s" % pending, flush=True)
|
||||
try:
|
||||
request_restart(steam_root)
|
||||
except (OSError, subprocess.TimeoutExpired) as error:
|
||||
print("bannerlator-steam-games: restart unavailable: %s" % error, flush=True)
|
||||
if status != last_status:
|
||||
print("bannerlator-steam-games: " + status, flush=True)
|
||||
last_status = status
|
||||
time.sleep(30)
|
||||
|
||||
|
||||
def installed_build(folder, appid, installdir):
|
||||
"""The build another Steam client recorded for these files, so Steam updates from it
|
||||
instead of verifying every file."""
|
||||
try:
|
||||
text = (folder.parent / WINNATIVE / f"appmanifest_{appid}.acf").read_text()
|
||||
install = re.search(r'("installdir"\s*")([^"\\]*)(")', text, re.I)
|
||||
flags = re.search(r'"StateFlags"\s*"(\d+)"', text)
|
||||
if (install and install[2] == folder.name and flags and flags[1] == "4"
|
||||
and re.search(rf'"appid"\s*"{appid}"', text) and '"InstalledDepots"' in text):
|
||||
return text[:install.start(2)] + installdir + text[install.end(2):]
|
||||
except OSError:
|
||||
pass
|
||||
if not (folder / ".download_complete").is_file():
|
||||
return None
|
||||
try:
|
||||
ids = json.loads((folder / ".DepotDownloader/depot.config").read_text())["installedManifestIDs"]
|
||||
depots = sorted((int(depot), int(gid)) for depot, gid in ids.items())
|
||||
except (OSError, ValueError, KeyError, TypeError, AttributeError):
|
||||
return None
|
||||
if not depots or not all(0 < depot < 0x80000000 and 0 < gid < 0x7FFFFFFFFFFFFFFF for depot, gid in depots):
|
||||
return None
|
||||
return "".join(f' "{depot}"\n {{\n "manifest" "{gid}"\n }}\n' for depot, gid in depots)
|
||||
|
||||
|
||||
def update_not_started(text, steamapps, appid, installdir):
|
||||
fields = dict(re.findall(r'^\s*"(\w+)"\s*"([^"]*)"', text, re.M))
|
||||
return (fields.get("installdir") == installdir and fields.get("buildid", "0") == "0"
|
||||
and fields.get("BytesDownloaded", "0") == "0" and fields.get("BytesStaged", "0") == "0"
|
||||
and re.search(r'"InstalledDepots"\s*\{\s*\}', text) is not None
|
||||
and not (steamapps / "downloading" / str(appid)).exists())
|
||||
|
||||
|
||||
def seed_install(steam_root, game, appid):
|
||||
steamapps = Path(steam_root) / "steamapps"
|
||||
common = steamapps / "common"
|
||||
@@ -191,16 +289,30 @@ def seed_install(steam_root, game, appid):
|
||||
target = common / name
|
||||
source = Path(game["folder"])
|
||||
title = game["name"].replace("\\", "\\\\").replace('"', '\\"').replace("\n", " ").replace("\r", " ")
|
||||
content = ('"AppState"\n{\n' + f' "appid" "{appid}"\n "Universe" "1"\n "name" "{title}"\n'
|
||||
minimal = ('"AppState"\n{\n' + f' "appid" "{appid}"\n "Universe" "1"\n "name" "{title}"\n'
|
||||
+ f' "StateFlags" "4"\n "installdir" "{name}"\n' + '}\n')
|
||||
legacy = content.replace(' "Universe" "1"\n', '')
|
||||
legacy = minimal.replace(' "Universe" "1"\n', '')
|
||||
build = installed_build(source, appid, name)
|
||||
if build is None:
|
||||
content = minimal
|
||||
elif build.lstrip().startswith('"AppState"'):
|
||||
content = build
|
||||
else:
|
||||
content = minimal[:-2] + ' "InstalledDepots"\n {\n' + build + ' }\n}\n'
|
||||
manifest = steamapps / f"appmanifest_{appid}.acf"
|
||||
for root in [Path(steam_root), Path("/mnt/bannerlator-sd")]:
|
||||
if target.is_symlink() and os.readlink(target) != str(source) and os.readlink(target) == legacy_path(source):
|
||||
relink = target.with_name(name + ".droiddeck")
|
||||
relink.unlink(missing_ok=True)
|
||||
relink.symlink_to(source, target_is_directory=True)
|
||||
os.replace(relink, target)
|
||||
for root in [Path(steam_root), Path(LIBRARY)]:
|
||||
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() in (legacy, legacy.replace('"StateFlags" "4"', '"StateFlags" "2"'))):
|
||||
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)))):
|
||||
temp = manifest.with_suffix(".droiddeck")
|
||||
temp.write_text(content)
|
||||
os.replace(temp, manifest)
|
||||
@@ -232,11 +344,13 @@ def route(steam_root, acct, games):
|
||||
owned, candidates, sources = {}, {}, {}
|
||||
shortcuts, routes = [], {}
|
||||
for game in games:
|
||||
appid = candidates.get(game.get("folder"))
|
||||
folder = game.get("folder", "")
|
||||
appid = candidates.get(folder, candidates.get(legacy_path(folder)))
|
||||
stamp = source_stamp(game)
|
||||
recorded = sources.get(folder, sources.get(legacy_path(folder)))
|
||||
confirmed = (isinstance(appid, int) and 0 < appid < 0x80000000
|
||||
and owned.get(str(appid)) is True and stamp is not None
|
||||
and sources.get(game.get("folder")) == stamp)
|
||||
and recorded in (stamp, [stamp[0], legacy_path(stamp[1])] + stamp[2:]))
|
||||
if confirmed:
|
||||
try:
|
||||
if seed_install(steam_root, game, appid):
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#!/usr/bin/python3
|
||||
# Registers the card the app installs to (bound at /mnt/bannerlator-sd) as a library folder of the
|
||||
# Registers the card the app installs to (bound at /mnt/droiddeck-sd) as a library folder of the
|
||||
# native Steam client, so they show as installed there instead of being downloaded a second time.
|
||||
#
|
||||
# bannerlator-steam-library <steam root>
|
||||
@@ -14,7 +14,7 @@ import sys
|
||||
# The app binds the storage the user chose (Steam cog -> Game storage) at this path and names it
|
||||
# in BL_LIBRARY_LABEL; nothing bound = internal only, and the entry is removed so the client does
|
||||
# not keep offering a place that is not there.
|
||||
LIBRARIES = (("/mnt/bannerlator-sd", os.environ.get("BL_LIBRARY_LABEL", "SD Card")),)
|
||||
LIBRARIES = (("/mnt/droiddeck-sd", os.environ.get("BL_LIBRARY_LABEL", "SD Card")),)
|
||||
# The client calls its own library "Local Drive (/)", which says nothing about where that is.
|
||||
# It is the phone's internal storage, so say so.
|
||||
MAIN_LABEL = "Internal Storage"
|
||||
@@ -66,6 +66,26 @@ def register(steam_root, library, label):
|
||||
|
||||
|
||||
RETIRED = ("/mnt/bannerlator",)
|
||||
RENAMED = (("/mnt/bannerlator-sd", "/mnt/droiddeck-sd"),)
|
||||
|
||||
|
||||
def rename(steam_root, old, new):
|
||||
"""Moves a library registered under an earlier mount point to the current one, keeping its
|
||||
entry (content id, app sizes) rather than registering it anew."""
|
||||
path = os.path.join(steam_root, "steamapps", "libraryfolders.vdf")
|
||||
if not os.path.isfile(path):
|
||||
return
|
||||
with open(path, encoding="utf-8", errors="replace") as f:
|
||||
text = f.read()
|
||||
old_path = re.compile(r'("path"\s+")%s(")' % re.escape(old))
|
||||
if not old_path.search(text):
|
||||
return
|
||||
if re.search(r'"path"\s+"%s"' % re.escape(new), text):
|
||||
forget(steam_root, old)
|
||||
return
|
||||
with open(path, "w", encoding="utf-8") as f:
|
||||
f.write(old_path.sub(lambda m: m.group(1) + new + m.group(2), text))
|
||||
print("bannerlator-steam-library: moved %s to %s" % (old, new))
|
||||
|
||||
|
||||
def forget(steam_root, library):
|
||||
@@ -152,6 +172,8 @@ def main():
|
||||
steam_root = sys.argv[1]
|
||||
for library in RETIRED:
|
||||
forget(steam_root, library)
|
||||
for old, new in RENAMED:
|
||||
rename(steam_root, old, new)
|
||||
relabel(steam_root, steam_root, MAIN_LABEL)
|
||||
for library, label in LIBRARIES:
|
||||
if os.path.isdir(os.path.join(library, "steamapps")):
|
||||
|
||||
@@ -97,7 +97,7 @@ def write(obj):
|
||||
return bytes(out)
|
||||
|
||||
|
||||
def shortcut(game):
|
||||
def shortcut(game, launch_options=""):
|
||||
appid = int(game["appid"]) & 0xFFFFFFFF
|
||||
return {
|
||||
"appid": struct.unpack("<i", struct.pack("<I", appid))[0],
|
||||
@@ -106,7 +106,7 @@ def shortcut(game):
|
||||
"StartDir": '"%s"' % game["dir"],
|
||||
"icon": (game.get("art") or {}).get("icon", "") or "",
|
||||
"ShortcutPath": "",
|
||||
"LaunchOptions": "",
|
||||
"LaunchOptions": launch_options,
|
||||
"IsHidden": 0,
|
||||
"AllowDesktopConfig": 1,
|
||||
"AllowOverlay": 1,
|
||||
@@ -208,8 +208,22 @@ def main():
|
||||
routing = importlib.util.module_from_spec(spec)
|
||||
loader.exec_module(routing)
|
||||
games, routes = routing.route(steam_root, acct, games)
|
||||
# Steam saves Big Picture's per-shortcut launch options in shortcuts.vdf. Keep them when
|
||||
# refreshing our entries, keyed by the appid that stays stable across session starts.
|
||||
managed = {
|
||||
v.get("appid"): v for v in existing.values()
|
||||
if isinstance(v, dict) and TAG in (v.get("tags") or {}).values()
|
||||
}
|
||||
kept = [v for v in existing.values() if isinstance(v, dict) and TAG not in (v.get("tags") or {}).values()]
|
||||
ours = [shortcut(g) for g in games if g.get("exe") and g.get("name")]
|
||||
ours = []
|
||||
for game in games:
|
||||
if not game.get("exe") or not game.get("name"):
|
||||
continue
|
||||
entry = shortcut(game)
|
||||
previous = managed.get(entry["appid"])
|
||||
if previous and isinstance(previous.get("LaunchOptions"), str):
|
||||
entry["LaunchOptions"] = previous["LaunchOptions"]
|
||||
ours.append(entry)
|
||||
entries = {str(i): v for i, v in enumerate(kept + ours)}
|
||||
tmp = path + ".bannerlator"
|
||||
with open(tmp, "wb") as f:
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Adreno revisions the runtime's Turnip does not know, reported as the revision it does.
|
||||
*
|
||||
* Retail SM8850 phones report their A840 as chip_id 0x44050A21 (KGSL gpu_model "Adreno840v2").
|
||||
* Mesa only lists 0x44050A31, so the runtime's glibc Turnip refuses the device outright
|
||||
* ("device (chip_id = 44050A21, gpu_id = 6860) is unsupported") and gamescope exits before Steam
|
||||
* starts. Banners-Turnip fixes its own builds by registering the v2 id on the same A840 GPU info
|
||||
* (patches/a840v2.py); answering KGSL's device-info query with the known id has the same effect
|
||||
* on any Turnip in the session, including the one the runtime was built with. A driver that
|
||||
* already knows the v2 id resolves the rewritten one to the same entry.
|
||||
*
|
||||
* Only the KGSL device-info property is touched. Its layout is the kernel's uapi (msm_kgsl.h).
|
||||
*/
|
||||
#define _GNU_SOURCE 1
|
||||
#include <stddef.h>
|
||||
#include <sys/ioctl.h>
|
||||
|
||||
struct kgsl_devinfo {
|
||||
unsigned int device_id;
|
||||
unsigned int chip_id;
|
||||
unsigned int mmu_enabled;
|
||||
unsigned long gmem_gpubaseaddr;
|
||||
unsigned int gpu_id;
|
||||
size_t gmem_sizebytes;
|
||||
};
|
||||
|
||||
struct kgsl_device_getproperty {
|
||||
unsigned int type;
|
||||
void *value;
|
||||
size_t sizebytes;
|
||||
};
|
||||
|
||||
#define KGSL_IOC_TYPE 0x09
|
||||
#define IOCTL_KGSL_DEVICE_GETPROPERTY _IOWR(KGSL_IOC_TYPE, 0x2, struct kgsl_device_getproperty)
|
||||
#define KGSL_PROP_DEVICE_INFO 0x1
|
||||
|
||||
static const struct {
|
||||
unsigned int reported;
|
||||
unsigned int known;
|
||||
} CHIP_IDS[] = {
|
||||
{0x44050A21, 0x44050A31}, /* Adreno 840v2 -> Adreno 840 */
|
||||
};
|
||||
|
||||
void bl_kgsl_chip_id_fixup(unsigned long request, void *arg, int rc) {
|
||||
if (rc != 0 || request != IOCTL_KGSL_DEVICE_GETPROPERTY || arg == NULL) return;
|
||||
struct kgsl_device_getproperty *prop = arg;
|
||||
if (prop->type != KGSL_PROP_DEVICE_INFO || prop->value == NULL
|
||||
|| prop->sizebytes < sizeof(struct kgsl_devinfo)) {
|
||||
return;
|
||||
}
|
||||
struct kgsl_devinfo *info = prop->value;
|
||||
for (size_t i = 0; i < sizeof(CHIP_IDS) / sizeof(CHIP_IDS[0]); i++) {
|
||||
if (info->chip_id == CHIP_IDS[i].reported) {
|
||||
info->chip_id = CHIP_IDS[i].known;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
* A zero-timeout KGSL timestamp wait answered as the poll it was meant to be.
|
||||
*
|
||||
* Turnip's KGSL backend emulates timeline semaphores with timestamps, and asks "has this one
|
||||
* retired yet?" by waiting on it with IOCTL_KGSL_DEVICE_WAITTIMESTAMP_CTXTID and a timeout of 0.
|
||||
* KGSL reads a timeout of 0 as no timeout at all, so the poll blocks until the GPU gets there.
|
||||
* Mesa's timeline bookkeeping polls like that under a lock on every signalling submit, which put
|
||||
* vkd3d-proton, DXVK, gamescope and Zink in lock-step with the GPU: one frame queued, never two.
|
||||
* Found and measured by Bannerlator (PROGRESS_LOG 2026-09-29: a D3D12 demo went from 614 to
|
||||
* 4335 fps with the same answer given in its Vulkan adapter); the driver-side fix is on
|
||||
* Banners-Turnip, and this covers the drivers that do not carry it yet.
|
||||
*
|
||||
* The answer comes from the context's retired timestamp, compared the way KGSL compares them
|
||||
* (with wrap-around). Anything the read does not answer - an unknown context, a device that is not
|
||||
* KGSL - goes to the kernel as before. BL_NO_KGSL_POLL_FIX=1 turns it off.
|
||||
*/
|
||||
#define _GNU_SOURCE
|
||||
#include <errno.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/ioctl.h>
|
||||
|
||||
#define KGSL_IOC_TYPE 0x09
|
||||
#define KGSL_TIMESTAMP_RETIRED 0x00000002
|
||||
|
||||
struct kgsl_device_waittimestamp_ctxtid {
|
||||
unsigned int context_id;
|
||||
unsigned int timestamp;
|
||||
unsigned int timeout;
|
||||
};
|
||||
|
||||
struct kgsl_cmdstream_readtimestamp_ctxtid {
|
||||
unsigned int context_id;
|
||||
unsigned int type;
|
||||
unsigned int timestamp;
|
||||
};
|
||||
|
||||
#define IOCTL_KGSL_DEVICE_WAITTIMESTAMP_CTXTID \
|
||||
_IOW(KGSL_IOC_TYPE, 0x7, struct kgsl_device_waittimestamp_ctxtid)
|
||||
#define IOCTL_KGSL_CMDSTREAM_READTIMESTAMP_CTXTID \
|
||||
_IOWR(KGSL_IOC_TYPE, 0x16, struct kgsl_cmdstream_readtimestamp_ctxtid)
|
||||
|
||||
static int enabled(void) {
|
||||
static int cached = -1;
|
||||
const char *off;
|
||||
|
||||
if (cached >= 0) return cached;
|
||||
off = getenv("BL_NO_KGSL_POLL_FIX");
|
||||
cached = !(off != NULL && off[0] == '1');
|
||||
return cached;
|
||||
}
|
||||
|
||||
/* True when the call was answered here, with its result in *rc (and errno set on failure). */
|
||||
__attribute__((visibility("hidden"))) int bl_kgsl_poll(int (*real)(int, unsigned long, void *),
|
||||
int fd, unsigned long request, void *arg,
|
||||
int *rc) {
|
||||
const struct kgsl_device_waittimestamp_ctxtid *wait = arg;
|
||||
struct kgsl_cmdstream_readtimestamp_ctxtid read;
|
||||
int saved = errno;
|
||||
|
||||
if (request != IOCTL_KGSL_DEVICE_WAITTIMESTAMP_CTXTID || arg == NULL || wait->timeout != 0 ||
|
||||
!enabled())
|
||||
return 0;
|
||||
read.context_id = wait->context_id;
|
||||
read.type = KGSL_TIMESTAMP_RETIRED;
|
||||
read.timestamp = 0;
|
||||
if (real(fd, IOCTL_KGSL_CMDSTREAM_READTIMESTAMP_CTXTID, &read) != 0) {
|
||||
errno = saved;
|
||||
return 0;
|
||||
}
|
||||
if ((int32_t)(read.timestamp - wait->timestamp) >= 0) {
|
||||
errno = saved;
|
||||
*rc = 0;
|
||||
} else {
|
||||
errno = ETIMEDOUT;
|
||||
*rc = -1;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
@@ -349,6 +349,10 @@ static int is_link_query(unsigned long request) {
|
||||
|| request == SIOCGIFBRDADDR;
|
||||
}
|
||||
|
||||
void bl_kgsl_chip_id_fixup(unsigned long request, void *arg, int rc); /* kgslid.c */
|
||||
int bl_kgsl_poll(int (*real)(int, unsigned long, void *), int fd, unsigned long request,
|
||||
void *arg, int *rc) __attribute__((visibility("hidden")));
|
||||
|
||||
/* Every DRM and evdev call comes through here, so the lookup is done once. Two threads racing
|
||||
* to store it store the same pointer. */
|
||||
int ioctl(int fd, unsigned long request, ...) {
|
||||
@@ -360,7 +364,9 @@ int ioctl(int fd, unsigned long request, ...) {
|
||||
va_end(ap);
|
||||
|
||||
if (real == NULL) real = (ioctl_fn) dlsym(RTLD_NEXT, "ioctl");
|
||||
int rc = real(fd, request, arg);
|
||||
int rc;
|
||||
if (!bl_kgsl_poll(real, fd, request, arg, &rc)) rc = real(fd, request, arg);
|
||||
bl_kgsl_chip_id_fixup(request, arg, rc);
|
||||
if (arg == NULL || !is_link_query(request)) return rc;
|
||||
int saved = errno;
|
||||
if (answer_ifreq(request, (struct ifreq *) arg, rc)) return 0;
|
||||
|
||||
Executable
+419
@@ -0,0 +1,419 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Build and publish the one-file update catalog consumed by DroidDeck.
|
||||
|
||||
The catalog is derived from GitHub releases, but the Android app never has to infer
|
||||
channels, parse release notes, dereference tags, or spend unauthenticated API quota.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import base64
|
||||
import datetime as dt
|
||||
import json
|
||||
import os
|
||||
import re
|
||||
import time
|
||||
import urllib.error
|
||||
import urllib.parse
|
||||
import urllib.request
|
||||
|
||||
API = "https://api.github.com"
|
||||
SHA256 = re.compile(r"^[0-9a-f]{64}$")
|
||||
PR_TAG = re.compile(r"^pr-([1-9][0-9]*)$")
|
||||
MAIN_TAG = re.compile(r"^main-([0-9a-f]{7,40})$")
|
||||
|
||||
|
||||
class ApiError(RuntimeError):
|
||||
def __init__(self, status: int, message: str):
|
||||
super().__init__(f"GitHub API {status}: {message}")
|
||||
self.status = status
|
||||
|
||||
|
||||
class GitHub:
|
||||
def __init__(self, token: str):
|
||||
self.token = token
|
||||
|
||||
def request(self, method: str, path: str, body=None):
|
||||
data = None
|
||||
headers = {
|
||||
"Accept": "application/vnd.github+json",
|
||||
"User-Agent": "DroidDeck-update-catalog",
|
||||
"X-GitHub-Api-Version": "2022-11-28",
|
||||
}
|
||||
if self.token:
|
||||
headers["Authorization"] = f"Bearer {self.token}"
|
||||
if body is not None:
|
||||
data = json.dumps(body).encode()
|
||||
headers["Content-Type"] = "application/json"
|
||||
req = urllib.request.Request(API + path, data=data, headers=headers, method=method)
|
||||
try:
|
||||
with urllib.request.urlopen(req, timeout=30) as response:
|
||||
raw = response.read()
|
||||
return json.loads(raw) if raw else None
|
||||
except urllib.error.HTTPError as e:
|
||||
raw = e.read().decode(errors="replace")
|
||||
raise ApiError(e.code, raw[:500]) from e
|
||||
|
||||
def get(self, path: str):
|
||||
return self.request("GET", path)
|
||||
|
||||
def put(self, path: str, body):
|
||||
return self.request("PUT", path, body)
|
||||
|
||||
|
||||
def q(value: str) -> str:
|
||||
return urllib.parse.quote(value, safe="")
|
||||
|
||||
|
||||
def repo_file(gh: GitHub, repo: str, path: str, ref: str) -> str:
|
||||
obj = gh.get(f"/repos/{repo}/contents/{q(path)}?ref={q(ref)}")
|
||||
if obj.get("encoding") != "base64":
|
||||
raise RuntimeError(f"{repo}:{ref}:{path} was not base64 content")
|
||||
return base64.b64decode(obj["content"]).decode()
|
||||
|
||||
|
||||
def resolve_tag(gh: GitHub, repo: str, tag: str) -> str:
|
||||
obj = gh.get(f"/repos/{repo}/git/ref/tags/{q(tag)}")["object"]
|
||||
while obj["type"] == "tag":
|
||||
obj = gh.get(f"/repos/{repo}/git/tags/{q(obj['sha'])}")["object"]
|
||||
if obj["type"] != "commit":
|
||||
raise RuntimeError(f"{repo} tag {tag} points to {obj['type']}, not a commit")
|
||||
return obj["sha"]
|
||||
|
||||
|
||||
def parse_gradle(text: str) -> tuple[int, str | None]:
|
||||
code = re.search(r"(?m)^\s*versionCode\s+(\d+)\s*$", text)
|
||||
name = re.search(r'(?m)^\s*versionName\s+"([^"]+)"\s*$', text)
|
||||
if not code:
|
||||
raise RuntimeError("app/build.gradle has no numeric versionCode")
|
||||
return int(code.group(1)), name.group(1) if name else None
|
||||
|
||||
|
||||
def parse_variants(text: str) -> list[tuple[str, str]]:
|
||||
out = []
|
||||
for raw in text.splitlines():
|
||||
line = raw.strip()
|
||||
if not line or line.startswith("#"):
|
||||
continue
|
||||
fields = line.split()
|
||||
if len(fields) < 3:
|
||||
raise RuntimeError(f"bad variants.txt row: {raw!r}")
|
||||
out.append((fields[1], "" if fields[2] == "-" else fields[2]))
|
||||
if not out:
|
||||
raise RuntimeError("variants.txt has no packages")
|
||||
return out
|
||||
|
||||
|
||||
def published_millis(release: dict, prefer_updated: bool = False) -> int:
|
||||
value = (
|
||||
release.get("updated_at") if prefer_updated else None
|
||||
) or release.get("published_at") or release.get("created_at")
|
||||
if not value:
|
||||
return 0
|
||||
return int(dt.datetime.fromisoformat(value.replace("Z", "+00:00")).timestamp() * 1000)
|
||||
|
||||
|
||||
def paragraphs(markdown: str) -> list[str]:
|
||||
return [p.strip() for p in re.split(r"\n\s*\n", markdown.replace("\r", "")) if p.strip()]
|
||||
|
||||
|
||||
def plain(markdown: str) -> str:
|
||||
text = re.sub(r"!\[[^]]*]\([^)]*\)", "", markdown)
|
||||
text = re.sub(r"\[([^]]*)]\([^)]*\)", r"\1", text)
|
||||
text = re.sub(r"[*_`]{1,3}", "", text)
|
||||
return re.sub(r"\s+", " ", text).strip()
|
||||
|
||||
|
||||
def prose_lines(markdown: str) -> str:
|
||||
lines = []
|
||||
for raw in markdown.splitlines():
|
||||
match = re.match(r"^\s*[-*]\s+", raw)
|
||||
value = ("• " + plain(raw[match.end():])) if match else plain(raw)
|
||||
if value:
|
||||
lines.append(value)
|
||||
return "\n".join(lines)
|
||||
|
||||
|
||||
def ci_description(release: dict) -> tuple[str, str]:
|
||||
ps = paragraphs(release.get("body") or "")
|
||||
head = ps[0] if ps else ""
|
||||
title = ""
|
||||
if "): " in head:
|
||||
title = head.split("): ", 1)[1]
|
||||
title = re.sub(r" \(merged[^)]*\)$", "", title)
|
||||
title = plain(title or head or release.get("name") or release["tag_name"])
|
||||
summary = ps[1] if len(ps) > 1 else ""
|
||||
if summary.startswith("Signed build") or summary.startswith("Source:"):
|
||||
summary = ""
|
||||
return title, prose_lines(summary)
|
||||
|
||||
|
||||
def stable_description(release: dict) -> tuple[str, str]:
|
||||
name = release.get("name") or release["tag_name"]
|
||||
summary = ""
|
||||
for p in paragraphs(release.get("body") or ""):
|
||||
if not (p.startswith("#") or p.startswith("![") or p.startswith("<")):
|
||||
summary = prose_lines(p)
|
||||
break
|
||||
return name, summary
|
||||
|
||||
|
||||
def source_meta(source: GitHub, repo: str, ref: str):
|
||||
gradle = repo_file(source, repo, "app/build.gradle", ref)
|
||||
code, version = parse_gradle(gradle)
|
||||
variants = parse_variants(repo_file(source, repo, "tools/release/variants.txt", ref))
|
||||
signer = repo_file(source, repo, "keystore/release-signer.sha256", ref).strip().lower()
|
||||
if not SHA256.fullmatch(signer):
|
||||
raise RuntimeError(f"{repo}:{ref} has an invalid release signer digest")
|
||||
return code, version, variants, signer
|
||||
|
||||
|
||||
def asset_for_suffix(assets: list[dict], suffix: str, all_suffixes: list[str]):
|
||||
others = [s for s in all_suffixes if s and s != suffix]
|
||||
for asset in assets:
|
||||
name = asset.get("name", "")
|
||||
if not name.endswith(f"{suffix}.apk"):
|
||||
continue
|
||||
if any(name.endswith(f"{other}.apk") for other in others):
|
||||
continue
|
||||
digest = (asset.get("digest") or "").lower()
|
||||
if not digest.startswith("sha256:") or not SHA256.fullmatch(digest[7:]):
|
||||
continue
|
||||
return {
|
||||
"name": name,
|
||||
"url": asset["browser_download_url"],
|
||||
"size": int(asset.get("size") or 0),
|
||||
"sha256": digest[7:],
|
||||
}
|
||||
return None
|
||||
|
||||
|
||||
def release_entry(
|
||||
release: dict,
|
||||
commit: str,
|
||||
pr: int,
|
||||
version: str | None,
|
||||
version_code: int,
|
||||
variants: list[tuple[str, str]],
|
||||
signer: str,
|
||||
title: str,
|
||||
summary: str,
|
||||
prefer_updated: bool = False,
|
||||
):
|
||||
suffixes = [suffix for _, suffix in variants]
|
||||
apks = {}
|
||||
for package, suffix in variants:
|
||||
asset = asset_for_suffix(release.get("assets") or [], suffix, suffixes)
|
||||
if not asset:
|
||||
continue
|
||||
asset.update(
|
||||
{
|
||||
"packageName": package,
|
||||
"versionCode": version_code,
|
||||
"signerSha256": signer,
|
||||
}
|
||||
)
|
||||
apks[package] = asset
|
||||
return {
|
||||
"tag": release["tag_name"],
|
||||
"title": title,
|
||||
"summary": summary,
|
||||
"commit": commit,
|
||||
"pr": pr,
|
||||
"version": version,
|
||||
"versionCode": version_code,
|
||||
"publishedAt": published_millis(release, prefer_updated),
|
||||
"url": release.get("html_url") or "",
|
||||
"apks": apks,
|
||||
}
|
||||
|
||||
|
||||
def release_body_value(body: str, key: str):
|
||||
match = re.search(rf"(?mi)^\s*{re.escape(key)}:\s*`?([^\s`]+)", body or "")
|
||||
return match.group(1) if match else None
|
||||
|
||||
|
||||
def main_commit(release: dict) -> str | None:
|
||||
body = release.get("body") or ""
|
||||
explicit = release_body_value(body, "Commit")
|
||||
if explicit and re.fullmatch(r"[0-9a-f]{7,40}", explicit):
|
||||
return explicit
|
||||
match = re.search(r"/commit/([0-9a-f]{40})", body)
|
||||
return match.group(1) if match else None
|
||||
|
||||
|
||||
def build_catalog(source: GitHub, ci: GitHub, source_repo: str, ci_repo: str) -> dict:
|
||||
try:
|
||||
stable_release = source.get(f"/repos/{source_repo}/releases/latest")
|
||||
except ApiError as e:
|
||||
if e.status != 404:
|
||||
raise
|
||||
stable_release = None
|
||||
|
||||
stable = None
|
||||
if stable_release:
|
||||
stable_commit = resolve_tag(source, source_repo, stable_release["tag_name"])
|
||||
code, version_name, variants, signer = source_meta(source, source_repo, stable_commit)
|
||||
title, summary = stable_description(stable_release)
|
||||
stable = release_entry(
|
||||
stable_release,
|
||||
stable_commit,
|
||||
0,
|
||||
version_name or stable_release["tag_name"].removeprefix("v"),
|
||||
code,
|
||||
variants,
|
||||
signer,
|
||||
title,
|
||||
summary,
|
||||
)
|
||||
|
||||
releases = ci.get(f"/repos/{ci_repo}/releases?per_page=100")
|
||||
previews = []
|
||||
tests = []
|
||||
for release in releases:
|
||||
if release.get("draft"):
|
||||
continue
|
||||
tag = release.get("tag_name") or ""
|
||||
main_match = MAIN_TAG.fullmatch(tag)
|
||||
if main_match:
|
||||
commit = main_commit(release)
|
||||
if not commit:
|
||||
continue
|
||||
try:
|
||||
code, _, variants, signer = source_meta(source, source_repo, commit)
|
||||
except ApiError:
|
||||
continue
|
||||
title, summary = ci_description(release)
|
||||
previews.append(
|
||||
release_entry(release, commit, 0, None, code, variants, signer, title, summary)
|
||||
)
|
||||
continue
|
||||
|
||||
pr_match = PR_TAG.fullmatch(tag)
|
||||
if not pr_match:
|
||||
continue
|
||||
pr = int(pr_match.group(1))
|
||||
body = release.get("body") or ""
|
||||
if f"github.com/{source_repo}/pull/{pr}" not in body:
|
||||
continue
|
||||
try:
|
||||
pull = source.get(f"/repos/{source_repo}/pulls/{pr}")
|
||||
except ApiError:
|
||||
continue
|
||||
if pull.get("state") != "open" or pull.get("draft") or pull.get("base", {}).get("ref") != "main":
|
||||
continue
|
||||
commit = release_body_value(body, "Commit")
|
||||
if not commit or not re.fullmatch(r"[0-9a-f]{7,40}", commit):
|
||||
continue
|
||||
base_ref = release_body_value(body, "Base") or pull["base"]["sha"]
|
||||
try:
|
||||
base_code, _, variants, signer = source_meta(source, source_repo, base_ref)
|
||||
except ApiError:
|
||||
continue
|
||||
version_code_text = release_body_value(body, "VersionCode")
|
||||
if version_code_text and version_code_text.isdigit():
|
||||
version_code = int(version_code_text)
|
||||
else:
|
||||
# Legacy test releases did not record it. If the PR did not change build.gradle,
|
||||
# the base value is exact; otherwise use the PR head's value.
|
||||
version_code = base_code
|
||||
try:
|
||||
changed = source.get(f"/repos/{source_repo}/pulls/{pr}/files?per_page=100")
|
||||
if any(item.get("filename") == "app/build.gradle" for item in changed):
|
||||
head_repo = pull["head"]["repo"]["full_name"]
|
||||
version_code = parse_gradle(repo_file(source, head_repo, "app/build.gradle", pull["head"]["sha"]))[0]
|
||||
except (ApiError, KeyError):
|
||||
pass
|
||||
title, summary = ci_description(release)
|
||||
tests.append(
|
||||
release_entry(
|
||||
release,
|
||||
commit,
|
||||
pr,
|
||||
None,
|
||||
version_code,
|
||||
variants,
|
||||
signer,
|
||||
title,
|
||||
summary,
|
||||
prefer_updated=True,
|
||||
)
|
||||
)
|
||||
|
||||
previews.sort(key=lambda r: r["publishedAt"], reverse=True)
|
||||
tests.sort(key=lambda r: r["publishedAt"], reverse=True)
|
||||
return {
|
||||
"schema": 1,
|
||||
"sourceRepo": source_repo,
|
||||
"ciRepo": ci_repo,
|
||||
"generatedAt": int(time.time() * 1000),
|
||||
"stable": stable,
|
||||
"preview": previews[0] if previews else None,
|
||||
"tests": tests,
|
||||
}
|
||||
|
||||
|
||||
def current_file(ci: GitHub, repo: str, path: str):
|
||||
try:
|
||||
return ci.get(f"/repos/{repo}/contents/{q(path)}?ref=main")
|
||||
except ApiError as e:
|
||||
if e.status == 404:
|
||||
return None
|
||||
raise
|
||||
|
||||
|
||||
def publish_catalog(source: GitHub, ci: GitHub, source_repo: str, ci_repo: str, path: str):
|
||||
for attempt in range(4):
|
||||
catalog = build_catalog(source, ci, source_repo, ci_repo)
|
||||
content = (json.dumps(catalog, indent=2, sort_keys=False) + "\n").encode()
|
||||
old = current_file(ci, ci_repo, path)
|
||||
body = {
|
||||
"message": "ci: refresh DroidDeck update catalog",
|
||||
"content": base64.b64encode(content).decode(),
|
||||
"branch": "main",
|
||||
}
|
||||
if old:
|
||||
body["sha"] = old["sha"]
|
||||
try:
|
||||
old_bytes = base64.b64decode(old["content"])
|
||||
old_json = json.loads(old_bytes)
|
||||
old_json.pop("generatedAt", None)
|
||||
new_json = dict(catalog)
|
||||
new_json.pop("generatedAt", None)
|
||||
if old_json == new_json:
|
||||
print("catalog contents are already current")
|
||||
return catalog
|
||||
except Exception:
|
||||
pass
|
||||
try:
|
||||
ci.put(f"/repos/{ci_repo}/contents/{q(path)}", body)
|
||||
print(f"published https://raw.githubusercontent.com/{ci_repo}/main/{path}")
|
||||
return catalog
|
||||
except ApiError as e:
|
||||
if e.status not in (409, 422) or attempt == 3:
|
||||
raise
|
||||
time.sleep(1 + attempt)
|
||||
raise RuntimeError("catalog publish retry loop exhausted")
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("--source-repo", default="Droid-Deck/DroidDeck")
|
||||
parser.add_argument("--ci-repo", default="Droid-Deck/DroidDeck-CI")
|
||||
parser.add_argument("--path", default="catalog.json")
|
||||
parser.add_argument("--dry-run", action="store_true")
|
||||
args = parser.parse_args()
|
||||
|
||||
source = GitHub(os.environ.get("SOURCE_GITHUB_TOKEN", ""))
|
||||
ci = GitHub(os.environ.get("CI_GITHUB_TOKEN", os.environ.get("SOURCE_GITHUB_TOKEN", "")))
|
||||
if args.dry_run:
|
||||
print(json.dumps(build_catalog(source, ci, args.source_repo, args.ci_repo), indent=2))
|
||||
else:
|
||||
if not os.environ.get("CI_GITHUB_TOKEN"):
|
||||
raise SystemExit("CI_GITHUB_TOKEN is required to publish")
|
||||
publish_catalog(source, ci, args.source_repo, args.ci_repo, args.path)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -20,6 +20,7 @@ def load(name):
|
||||
|
||||
imports = load('bannerlator-steam-games')
|
||||
shortcuts = load('bannerlator-steam-shortcuts')
|
||||
library = load('bannerlator-steam-library')
|
||||
|
||||
|
||||
class ImportsTest(unittest.TestCase):
|
||||
@@ -73,6 +74,7 @@ class ImportsTest(unittest.TestCase):
|
||||
from unittest.mock import Mock
|
||||
result = Mock(returncode=0, stdout='DROIDDECK_OWNERSHIP=' + json.dumps(dict(account='123', owned={'42': True})))
|
||||
with patch.object(imports, 'identify', side_effect=[None, 42]) as identify, \
|
||||
patch.object(imports, 'request_restart'), \
|
||||
patch.object(imports.time, 'monotonic', side_effect=[0, 301]), \
|
||||
patch.object(imports.time, 'sleep', side_effect=[None, RuntimeError('stop')]), \
|
||||
patch.object(imports.subprocess, 'run', return_value=result), \
|
||||
@@ -83,6 +85,35 @@ class ImportsTest(unittest.TestCase):
|
||||
snapshot = imports.read_json(self.acct / 'config' / imports.STATE, {})
|
||||
self.assertTrue(snapshot['owned']['42'])
|
||||
|
||||
def run_watch(self, beats, routes=None, busy=False):
|
||||
listing = self.root / 'games.json'
|
||||
listing.write_text(json.dumps([self.game]))
|
||||
if routes is not None:
|
||||
imports.save_json(self.acct / 'config/.droiddeck-routes.json', routes)
|
||||
if busy:
|
||||
(self.steam / 'steamapps/downloading/7').mkdir(parents=True)
|
||||
from unittest.mock import Mock
|
||||
result = Mock(returncode=0, stdout='DROIDDECK_OWNERSHIP=' + json.dumps(dict(account='123', owned={'42': True})))
|
||||
with patch.object(imports, 'identify', return_value=42), \
|
||||
patch.object(imports, 'game_running', return_value=False), \
|
||||
patch.object(imports, 'request_restart') as restart, \
|
||||
patch.object(imports.time, 'monotonic', side_effect=list(range(0, 30 * beats, 30))), \
|
||||
patch.object(imports.time, 'sleep', side_effect=[None] * (beats - 1) + [RuntimeError('stop')]), \
|
||||
patch.object(imports.subprocess, 'run', return_value=result), \
|
||||
patch('builtins.print'):
|
||||
with self.assertRaisesRegex(RuntimeError, 'stop'):
|
||||
imports.watch(self.steam, listing)
|
||||
return restart
|
||||
|
||||
def test_newly_owned_game_restarts_the_client_once(self):
|
||||
self.assertEqual(1, self.run_watch(3).call_count)
|
||||
|
||||
def test_imported_game_does_not_restart_the_client(self):
|
||||
self.assertEqual(0, self.run_watch(2, routes={'1': 42}).call_count)
|
||||
|
||||
def test_restart_waits_for_downloads(self):
|
||||
self.assertEqual(0, self.run_watch(2, busy=True).call_count)
|
||||
|
||||
def test_unowned_unknown_and_different_account_stay_shortcuts(self):
|
||||
for owned, account in [(False, '123'), (True, '456')]:
|
||||
self.snapshot(owned, account)
|
||||
@@ -91,6 +122,93 @@ class ImportsTest(unittest.TestCase):
|
||||
self.assertEqual(([self.game], {}), imports.route(self.steam, self.acct, [self.game]))
|
||||
self.assertFalse((self.steam / 'steamapps').exists())
|
||||
|
||||
def winnative_manifest(self, flags='4', installdir='Example'):
|
||||
path = self.folder.parent / imports.WINNATIVE / 'appmanifest_42.acf'
|
||||
path.parent.mkdir(parents=True, exist_ok=True)
|
||||
path.write_text('"AppState"\n{\n\t"appid"\t\t"42"\n\t"StateFlags"\t\t"%s"\n\t"installdir"\t\t"%s"\n'
|
||||
'\t"buildid"\t\t"7"\n\t"InstalledDepots"\n\t{\n\t\t"43"\n\t\t{\n\t\t\t"manifest"\t\t"99"\n'
|
||||
'\t\t\t"size"\t\t"4"\n\t\t}\n\t}\n}\n' % (flags, installdir))
|
||||
return path
|
||||
|
||||
def test_winnative_manifest_carries_installed_build(self):
|
||||
source = self.winnative_manifest()
|
||||
self.snapshot()
|
||||
imports.route(self.steam, self.acct, [self.game])
|
||||
text = (self.steam / 'steamapps/appmanifest_42.acf').read_text()
|
||||
self.assertEqual(source.read_text().replace('"Example"', '"DroidDeck-42"'), text)
|
||||
|
||||
def test_winnative_manifest_identifies_folder(self):
|
||||
self.winnative_manifest()
|
||||
with patch.object(imports.urllib.request, 'urlopen', side_effect=AssertionError):
|
||||
self.assertEqual(42, imports.identify(self.game))
|
||||
|
||||
def test_incomplete_winnative_manifest_is_ignored(self):
|
||||
for flags, installdir in [('1026', 'Example'), ('4', 'Other')]:
|
||||
self.winnative_manifest(flags, installdir)
|
||||
self.assertIsNone(imports.installed_build(self.folder, 42, 'DroidDeck-42'))
|
||||
|
||||
def test_depot_config_records_installed_depots(self):
|
||||
config = self.folder / '.DepotDownloader/depot.config'
|
||||
config.parent.mkdir()
|
||||
config.write_text(json.dumps({'installedManifestIDs': {'43': 99}}))
|
||||
self.assertIsNone(imports.installed_build(self.folder, 42, 'DroidDeck-42'))
|
||||
(self.folder / '.download_complete').touch()
|
||||
self.snapshot()
|
||||
imports.route(self.steam, self.acct, [self.game])
|
||||
text = (self.steam / 'steamapps/appmanifest_42.acf').read_text()
|
||||
self.assertIn('"InstalledDepots"\n {\n "43"\n {\n "manifest" "99"', text)
|
||||
self.assertTrue(text.endswith(' }\n}\n'))
|
||||
config.write_text(json.dumps({'installedManifestIDs': {'43': 0x7FFFFFFFFFFFFFFF}}))
|
||||
self.assertIsNone(imports.installed_build(self.folder, 42, 'DroidDeck-42'))
|
||||
|
||||
def test_bare_import_manifest_gains_installed_build(self):
|
||||
self.snapshot()
|
||||
imports.route(self.steam, self.acct, [self.game])
|
||||
self.winnative_manifest()
|
||||
imports.route(self.steam, self.acct, [self.game])
|
||||
self.assertIn('"buildid"\t\t"7"', (self.steam / 'steamapps/appmanifest_42.acf').read_text())
|
||||
|
||||
def steam_fresh_install(self, downloaded='0'):
|
||||
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"BytesDownloaded"\t\t"%s"\n\t"BytesStaged"\t\t"0"\n'
|
||||
'\t"InstalledDepots"\n\t{\n\t}\n}\n' % downloaded)
|
||||
self.winnative_manifest()
|
||||
return path
|
||||
|
||||
def test_queued_fresh_install_takes_installed_build(self):
|
||||
path = self.steam_fresh_install()
|
||||
imports.route(self.steam, self.acct, [self.game])
|
||||
self.assertIn('"buildid"\t\t"7"', 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)
|
||||
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_links_and_snapshots_from_the_old_mount_carry_over(self):
|
||||
old = self.root / 'old-mount'
|
||||
with patch.object(imports, 'LIBRARY', str(self.root / 'Games')), \
|
||||
patch.object(imports, 'LEGACY_LIBRARY', str(old)):
|
||||
legacy_game = dict(self.game, folder=str(old / 'Example'), exe=str(old / 'Example/Example.exe'))
|
||||
stamp = imports.source_stamp(self.game)
|
||||
imports.save_json(self.acct / 'config' / imports.STATE,
|
||||
dict(account='123', owned={'42': True}, candidates={legacy_game['folder']: 42},
|
||||
sources={legacy_game['folder']: [stamp[0], legacy_game['exe']] + stamp[2:]}))
|
||||
link = self.steam / 'steamapps/common/DroidDeck-42'
|
||||
link.parent.mkdir(parents=True)
|
||||
link.symlink_to(legacy_game['folder'], target_is_directory=True)
|
||||
games, routes = imports.route(self.steam, self.acct, [self.game])
|
||||
self.assertEqual([], games)
|
||||
self.assertEqual({str(self.game['appid']): 42}, routes)
|
||||
self.assertEqual(str(self.folder), imports.os.readlink(link))
|
||||
|
||||
def test_existing_manifest_is_never_overwritten(self):
|
||||
manifest = self.steam / 'steamapps/appmanifest_42.acf'
|
||||
manifest.parent.mkdir(parents=True)
|
||||
@@ -188,6 +306,34 @@ class ImportsTest(unittest.TestCase):
|
||||
self.assertEqual({str(self.game['appid']): 42}, json.loads((path.parent / '.droiddeck-routes.json').read_text()))
|
||||
|
||||
|
||||
class LibraryRenameTest(unittest.TestCase):
|
||||
def setUp(self):
|
||||
temp = tempfile.TemporaryDirectory()
|
||||
self.addCleanup(temp.cleanup)
|
||||
self.steam = Path(temp.name)
|
||||
self.vdf = self.steam / 'steamapps/libraryfolders.vdf'
|
||||
self.vdf.parent.mkdir()
|
||||
|
||||
def entry(self, index, path):
|
||||
return '\t"%d"\n\t{\n\t\t"path"\t\t"%s"\n\t\t"contentid"\t\t"%d"\n\t}\n' % (index, path, 7 + index)
|
||||
|
||||
def test_old_mount_keeps_its_entry_under_the_new_path(self):
|
||||
self.vdf.write_text('"libraryfolders"\n{\n' + self.entry(0, '/root') + self.entry(1, '/mnt/bannerlator-sd') + '}\n')
|
||||
with patch('builtins.print'):
|
||||
library.rename(str(self.steam), '/mnt/bannerlator-sd', '/mnt/droiddeck-sd')
|
||||
text = self.vdf.read_text()
|
||||
self.assertIn('"path"\t\t"/mnt/droiddeck-sd"\n\t\t"contentid"\t\t"8"', text)
|
||||
self.assertNotIn('bannerlator-sd', text)
|
||||
|
||||
def test_old_mount_is_dropped_when_new_path_is_registered(self):
|
||||
self.vdf.write_text('"libraryfolders"\n{\n' + self.entry(0, '/mnt/droiddeck-sd') + self.entry(1, '/mnt/bannerlator-sd') + '}\n')
|
||||
with patch('builtins.print'):
|
||||
library.rename(str(self.steam), '/mnt/bannerlator-sd', '/mnt/droiddeck-sd')
|
||||
text = self.vdf.read_text()
|
||||
self.assertEqual(1, text.count('"path"'))
|
||||
self.assertIn('/mnt/droiddeck-sd', text)
|
||||
|
||||
|
||||
class SteamProbeTest(unittest.TestCase):
|
||||
def test_probe_reads_account_and_licenses_and_releases_handles(self):
|
||||
import ctypes as C
|
||||
|
||||
@@ -0,0 +1,91 @@
|
||||
import unittest
|
||||
|
||||
from tools.release.update_catalog import (
|
||||
asset_for_suffix,
|
||||
ci_description,
|
||||
parse_gradle,
|
||||
parse_variants,
|
||||
published_millis,
|
||||
release_body_value,
|
||||
)
|
||||
|
||||
|
||||
class UpdateCatalogTest(unittest.TestCase):
|
||||
def test_gradle_metadata(self):
|
||||
code, name = parse_gradle("""android {
|
||||
defaultConfig {
|
||||
versionCode 12
|
||||
versionName "0.3.1"
|
||||
}
|
||||
}
|
||||
""")
|
||||
self.assertEqual(12, code)
|
||||
self.assertEqual("0.3.1", name)
|
||||
|
||||
def test_variants(self):
|
||||
rows = parse_variants("""
|
||||
# name package suffix
|
||||
standard com.droiddeck.launcher -
|
||||
pubg com.tencent.ig -pubg
|
||||
""")
|
||||
self.assertEqual(
|
||||
[("com.droiddeck.launcher", ""), ("com.tencent.ig", "-pubg")],
|
||||
rows,
|
||||
)
|
||||
|
||||
def test_standard_asset_does_not_take_a_variant(self):
|
||||
assets = [
|
||||
{
|
||||
"name": "DroidDeck-main-deadbee-pubg.apk",
|
||||
"size": 10,
|
||||
"digest": "sha256:" + "a" * 64,
|
||||
"browser_download_url": "https://example/pubg",
|
||||
},
|
||||
{
|
||||
"name": "DroidDeck-main-deadbee.apk",
|
||||
"size": 11,
|
||||
"digest": "sha256:" + "b" * 64,
|
||||
"browser_download_url": "https://example/standard",
|
||||
},
|
||||
]
|
||||
standard = asset_for_suffix(assets, "", ["", "-pubg"])
|
||||
pubg = asset_for_suffix(assets, "-pubg", ["", "-pubg"])
|
||||
self.assertEqual("DroidDeck-main-deadbee.apk", standard["name"])
|
||||
self.assertEqual("DroidDeck-main-deadbee-pubg.apk", pubg["name"])
|
||||
|
||||
def test_ci_description(self):
|
||||
title, summary = ci_description(
|
||||
{
|
||||
"tag_name": "main-deadbee",
|
||||
"name": "main deadbee",
|
||||
"body": (
|
||||
"**Merged to main** - [PR #9](https://github.com/Droid-Deck/DroidDeck/pull/9): "
|
||||
"fix: keep Steam alive (merged 2026-09-30)\n\n"
|
||||
"Steam no longer **exits** on resume.\n\n"
|
||||
"Signed build of https://example"
|
||||
),
|
||||
}
|
||||
)
|
||||
self.assertEqual("fix: keep Steam alive", title)
|
||||
self.assertEqual("Steam no longer exits on resume.", summary)
|
||||
|
||||
def test_release_body_metadata(self):
|
||||
tick = chr(96)
|
||||
body = f"Commit: {tick}abcdef1234567{tick}\nBase: 1234567\nVersionCode: 42\n"
|
||||
self.assertEqual("abcdef1234567", release_body_value(body, "Commit"))
|
||||
self.assertEqual("1234567", release_body_value(body, "Base"))
|
||||
self.assertEqual("42", release_body_value(body, "VersionCode"))
|
||||
|
||||
def test_republished_pr_uses_updated_time_but_other_channels_use_publish_time(self):
|
||||
release = {
|
||||
"published_at": "2026-09-30T10:00:00Z",
|
||||
"updated_at": "2026-09-30T12:00:00Z",
|
||||
}
|
||||
self.assertLess(
|
||||
published_millis(release),
|
||||
published_millis(release, prefer_updated=True),
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user