"""Read app info from the Steam client's own cache, `appcache/appinfo.vdf`. This replaced `steamcmd +app_info_print`. On 2026-11-22 all 11 compared fields for app 1201270 (name, installdir, build id, change number, depot gids, ...) matched steamcmd's answer exactly. The cache is only as fresh as Steam's last run, which is why callers check its gids against what depotdownloader actually fetched. Layout (magic 0x07564429): u32 magic, u32 universe, i64 offset of a string table; then per app: u32 appid, u32 size, `size` bytes made of a 60-byte header and binary key-values whose keys are u32 indexes into the string table. Appid 0 ends the list. The table is a u32 count followed by NUL-terminated strings. Every scalar comes back as a string, the way `app_info_print` printed it: the rest of the tool compares `== "1"` and `!= str(appid)`, and an int there would silently change which depots count. """ from __future__ import annotations import struct from pathlib import Path from steam_installer.library import find_steam_root MAGIC = 0x07564429 _HEADER = 60 FIX = "start Steam once, let it sync, rerun" # Fixed-width value types: KV type byte -> struct format. _SCALARS = {2: " Path: return find_steam_root() / "appcache" / "appinfo.vdf" def load(path: Path | None = None) -> dict[int, dict]: """Every app in the cache, appid -> its `appinfo` block. Parsed once per file version: four lookups in one run would otherwise parse the ~100 MB file four times. """ path = path or default_path() try: stat = path.stat() except OSError as exc: raise CacheError(f"cannot read Steam's app cache {path}: {FIX}") from exc key = (stat.st_mtime_ns, stat.st_size) cached = _memo.get(path) if cached is not None and cached[0] == key: return cached[1] apps = _parse(path.read_bytes()) _memo[path] = (key, apps) return apps def _parse(buf: bytes) -> dict[int, dict]: magic, _universe, table_offset = struct.unpack_from(" list[str]: (count,) = struct.unpack_from(" tuple[dict, int]: out: dict = {} while True: kind = buf[pos] pos += 1 if kind == 8: return out, pos (index,) = struct.unpack_from("