mirror of
https://github.com/kuhyx/steam-backlog-enforcer.git
synced 2026-11-23 11:26:19 +01:00
The KCD2 run reported success but Steam re-downloaded 90 GB anyway. Two
independent causes, plus a defect that hid both.
force_install_dir sets a Steam *library root*, not an install directory.
Pointing it at the game folder made steamcmd search <game>/steamapps/ for
manifests ("Loaded 0 apps from install folder"), create that stray dir, and
fail the app with "Invalid platform" for lack of depot context. Dropped it;
the app already lives in a registered library. Separately, a Linux steamcmd
needs +@sSteamCmdForcePlatformType windows for a Windows-only title.
Steam then discarded the manifest because it was self-contradictory:
StateFlags=4 while BytesDownloaded (22 GB) != BytesToDownload (92 GB), with
tens of GB still staged under steamapps/downloading/. Across every genuinely
installed manifest the byte counters are equal in pairs, StagingSize is 0 and
staging is empty; DownloadType is kept, not dropped. Settle all of it, and
refuse to call an install real until it holds.
The defect that hid this: steamcmd exited 8 having done nothing and the tool
still wrote StateFlags=4, printed a success line and returned 0. Now gated on
depotdownloader succeeding, every required depot being cached, real game
content on disk, a matching buildid and no running Steam client -- and it
re-reads the manifest after writing.
Also fixes data corruption found in review: vdf.dumps never re-escaped
backslashes, so each parse/dump cycle halved them and silently mangled the
Windows paths in appmanifest_228980.acf's InstallScripts. Manifest writes are
now atomic with a preserved pristine .acf.bak.
Adds per-run logging to ~/.local/state/steam-game-installer (argv, exit codes,
full subprocess output, manifest before/after), teed through a pty so
steamcmd's password prompt still works.
Verified end-to-end on KCD2: Steam logged "Fully Installed, App Running" and
the game launched with no download queued. Coverage 100% statements+branches,
enforced by fail_under.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EK4urCmbTqN4Vrc3nGBcXF
106 lines
4.6 KiB
Markdown
106 lines
4.6 KiB
Markdown
# steam-game-installer
|
|
|
|
Download an owned Steam game with `depotdownloader` (which saturates a link far
|
|
better than the Steam client), then make the Steam client accept the result as
|
|
a real install so **Play** works.
|
|
|
|
```bash
|
|
./install.sh # checks depotdownloader + steamcmd are present
|
|
pip install -e .
|
|
steam-game-installer --appid 1771300 --username <steam-user>
|
|
```
|
|
|
|
**Close the Steam client first.** Steam owns `appmanifest_<appid>.acf` while it
|
|
runs and rewrites it from its own in-memory state, so anything written
|
|
underneath a live client is discarded. The tool refuses to start if it sees one.
|
|
|
|
## Run logs
|
|
|
|
Every run writes a full log:
|
|
|
|
```
|
|
~/.local/state/steam-game-installer/run-<timestamp>-<appid>.log
|
|
~/.local/state/steam-game-installer/latest.log -> most recent
|
|
```
|
|
|
|
The path is printed at the start and end of every run, and on every error path.
|
|
It contains the full argv, exit code and complete output of each subprocess, the
|
|
manifest verbatim before and after every write, the depot cache listing,
|
|
expected-vs-actual depots, and whether Steam was running. Send `latest.log` when
|
|
something goes wrong. `--verbose` mirrors all of it to the console.
|
|
|
|
Subprocess output is teed through a pty rather than captured, because steamcmd
|
|
only prompts for a password / Steam Guard code when it believes it is on a
|
|
terminal — with a plain pipe the prompt never appears and the run looks hung.
|
|
|
|
## How it works
|
|
|
|
1. `depotdownloader` pulls the content (fast path).
|
|
2. `steamcmd app_update <id> validate` reconciles Steam's own bookkeeping.
|
|
3. If that fails or leaves the manifest incomplete, the manifest is finished by
|
|
hand — but only when every precondition below holds.
|
|
|
|
## Fail-closed preconditions
|
|
|
|
The tool refuses to mark an app installed, and exits non-zero, unless:
|
|
|
|
- `depotdownloader` exited 0;
|
|
- every required depot has a cached manifest under `.DepotDownloader/`
|
|
(required = this app's depots for the chosen language and OS, excluding DLC,
|
|
optional and shared depots — KCD2 lists 12 depots but an english/windows
|
|
install only ever fetches 3);
|
|
- the manifest carries a real `buildid` matching the current public build;
|
|
- no Steam client is running;
|
|
- the manifest reads back as a real install *after* being written.
|
|
|
|
This matters: an earlier version wrote `StateFlags=4` and reported success after
|
|
a steamcmd run that had done nothing at all.
|
|
|
|
## Failure modes this encodes
|
|
|
|
Each of these cost a real debugging session; the tests pin them.
|
|
|
|
**`force_install_dir` is a library root, not an install directory.** Pointing it
|
|
at the game folder made steamcmd look for manifests in `<game>/steamapps/`, find
|
|
none (`Loaded 0 apps from install folder`), create that stray directory, and then
|
|
fail the app with `Invalid platform` — it had no depot context for the app.
|
|
Dropped entirely: the app already lives in a registered library.
|
|
|
|
**A Linux steamcmd needs `+@sSteamCmdForcePlatformType windows`** (before
|
|
`+login`) for a Windows-only game, or it resolves depots against the host OS.
|
|
|
|
**Steam rejects an internally inconsistent manifest.** A file that says
|
|
`StateFlags=4` while `BytesDownloaded` (22 GB) still differs from
|
|
`BytesToDownload` (92 GB) is self-contradictory; Steam discards the "installed"
|
|
claim and resumes downloading. Across every genuinely installed manifest the
|
|
counters are equal in pairs and `StagingSize` is `0`. `DownloadType` is *kept* —
|
|
it is present on every real install, so removing it is not the fix.
|
|
|
|
**Staging must be cleared too.** Steam stages chunks in
|
|
`steamapps/downloading/<appid>/`. Declaring the app installed while tens of GB
|
|
sit there pending makes Steam resume the update. Installed apps have an empty
|
|
(4 KB) staging dir.
|
|
|
|
**Shared depots are not installed depots.** `228989` belongs to app 228980
|
|
(Steamworks Common Redistributables); listing it in `InstalledDepots`
|
|
contradicts `SharedDepots`.
|
|
|
|
**`SizeOnDisk` excludes `.DepotDownloader/`** — its cache and staging tree are
|
|
not game content and overstate the total by gigabytes.
|
|
|
|
## Development
|
|
|
|
```bash
|
|
./install.sh # also prepares the test env
|
|
.venv/bin/python -m pytest tests/ -q
|
|
ruff check steam_installer/ tests/
|
|
ruff format --check steam_installer/ tests/
|
|
```
|
|
|
|
Coverage is enforced at **100% of statements and branches**
|
|
(`fail_under = 100`), so an uncovered line fails the suite rather than quietly
|
|
lowering a number. One test runs `python -m steam_installer.cli` in a
|
|
subprocess to prove the `__main__` entry point works; recording coverage from
|
|
a child process needs a `.pth` that calls `coverage.process_startup()`, which
|
|
`install.sh` writes into the venv. Skip `install.sh` and coverage reports 99%.
|