mirror of
https://github.com/kuhyx/steam-backlog-enforcer.git
synced 2026-11-22 23:02:19 +01:00
The installer ships as the steam_installer package beside steam_backlog_enforcer, with its tests, docs and Proton lock. The enforcer's fast install now starts the installer from this checkout. Both appinfo.vdf readers share one key-value decoder (steam_installer.appinfo_kv), and the duplicated test fixtures and helpers are folded into conftest and _cli_helpers so the whole-tree duplicate-code check is clean. check_requirements_sync treats sibling packages as first-party. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WzxdWZCxnNWLtpVwFLVk9w
51 lines
2.0 KiB
Python
51 lines
2.0 KiB
Python
"""Build a binary appinfo.vdf (magic 0x07564429) for tests.
|
|
|
|
The writer mirrors what Steam stores: a header, one entry per app (appid,
|
|
size, 60 header bytes, binary key-values whose keys index a string table),
|
|
a zero appid terminator, then the string table itself.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import struct
|
|
|
|
MAGIC = 0x07564429
|
|
|
|
|
|
def _kv(data: dict, strings: dict[str, int]) -> bytes:
|
|
out = bytearray()
|
|
for key, value in data.items():
|
|
index = strings.setdefault(key, len(strings))
|
|
if isinstance(value, dict):
|
|
out += b"\x00" + struct.pack("<I", index) + _kv(value, strings)
|
|
elif isinstance(value, int):
|
|
out += b"\x02" + struct.pack("<I", index) + struct.pack("<i", value)
|
|
elif isinstance(value, float):
|
|
out += b"\x03" + struct.pack("<I", index) + struct.pack("<f", value)
|
|
elif isinstance(value, tuple):
|
|
kind, raw = value # (7, u64) / (10, i64): the wide integer types
|
|
fmt = "<Q" if kind == 7 else "<q"
|
|
out += bytes([kind]) + struct.pack("<I", index) + struct.pack(fmt, raw)
|
|
else:
|
|
out += b"\x01" + struct.pack("<I", index) + value.encode() + b"\x00"
|
|
return bytes(out) + b"\x08"
|
|
|
|
|
|
def encode(apps: dict[int, dict], change_number: int = 41062472) -> bytes:
|
|
"""Serialize `{appid: appinfo-dict}`; each dict is wrapped in "appinfo"."""
|
|
strings: dict[str, int] = {}
|
|
body = bytearray()
|
|
for appid, data in apps.items():
|
|
kv = _kv({"appinfo": data}, strings)
|
|
header = struct.pack(
|
|
"<IIQ20sI20s", 2, 1795000000, 0, b"\0" * 20, change_number, b"\0" * 20
|
|
)
|
|
payload = header + kv
|
|
body += struct.pack("<II", appid, len(payload)) + payload
|
|
body += struct.pack("<I", 0)
|
|
table_offset = 16 + len(body)
|
|
table = struct.pack("<I", len(strings)) + b"".join(
|
|
key.encode() + b"\x00" for key in strings
|
|
)
|
|
return struct.pack("<IIq", MAGIC, 1, table_offset) + bytes(body) + table
|