Skip to content

Repair install state for games that are already on disk - #116

Closed
Code-Leafy wants to merge 1 commit into
madoiscool:mainfrom
Code-Leafy:fix/adopt-install-on-disk
Closed

Code-Leafy wants to merge 1 commit into
madoiscool:mainfrom
Code-Leafy:fix/adopt-install-on-disk

Conversation

@Code-Leafy

Copy link
Copy Markdown

Two games of mine had their files fully on disk and Steam wanted to pull both of them again. 3024040 had no appmanifest at all, so it was just invisible. 361420 had one blanked to StateFlags 1538 with SizeOnDisk 0 and an empty InstalledDepots, and Steam staged 3211445310 bytes into steamapps\downloading\361420 while the complete 3215764300 byte install sat in common:

AppID 361420 update canceled : Failed building depot dependency (Invalid content configuration)
AppID 361420 state changed : Update Required,Update Paused,Update Started,

Steam decides "installed" purely on the appmanifest existing, and GetInstallDir can only mirror that: it builds the path out of the appmanifest and bails when it is missing (if (!File.Exists(acf)) continue;). Nothing in the app writes one back, so the state is reported and never repaired. Renaming the folder to match installdir does not get you out of it either, I tried that first — it only ever works through the appmanifest, so with no appmanifest there is nothing to match against.

What this does

The folder is located from appinfo (config.installdir plus the launch exe), matched on the normalized name and required to contain that exe, then the appmanifest is written against it under the name it already has. Renaming is therefore optional, not a prerequisite. Depot ids, gids and sizes come from the pinned lua, including the commented setManifestid lines; a depot with no gid is left out rather than invented.

Things that would otherwise bite, and what is done about them:

  • an app that already carries FullyInstalled is skipped, so this is idempotent
  • a manifest that exists but is not FullyInstalled is backed up (<acf>.bak-<utc>) before being replaced, which is the broken shape being repaired
  • an orphaned downloading\<appid> folder is cleared, otherwise Steam resumes a dead staging directory instead of reconfiguring
  • a shared depot the lua references is registered on the app that owns it. Without that, BuildDepotDependency aborts with Invalid content configuration and the entry never leaves "update"
  • AutoUpdateBehavior 1 (update on launch only), because the lua describes one build and the scheduler would otherwise chase another the moment the entry appears

Steam is stopped for the write and restarted after, the same as LaunchOptionsService does for appinfo edits. GetInstallDir gains the fallback too, so the fix flow, SteamlessService and the manifest job factory stop reporting a game that is plainly on disk as missing.

Where it runs

FixesViewModel.OpenGame, once, when the resolved folder is null. A toast says it happened and the rows stop saying "not installed". Worth arguing about: that is a write nobody explicitly asked for. The alternative is a button, which needs a view change and more strings; say the word and I will move it.

Notes

  • SteamLibraryService.GetLibraryRoots became public to reuse it. The rest is new surface: InstallDirMatcher (pure, no IO) and InstallStateRepairService.
  • 21 tests: the matcher's refusals (Steamworks Shared, right name but no exe, nothing to match), the manifest fields and escaping, and a round trip against a temp Steam install covering the backup, the skip, the staging clear, the shared depot and the library index entry.
  • The two new strings are English-only and listed in PENDING_TRANSLATION. check-i18n.py passes; happy to do the 29 translations in this PR if you would rather not carry them.
  • Not covered: a libraryfolders.vdf with no entry for the library at all, and anything about DLC depots listed without a key.
  • Ran it against my own library with both games already repaired, so the real path here was exercised end to end but the already-installed skip is what my own installs hit; the actual adoption only ran in tests.

dotnet build and dotnet test both clean (316 passing), Windows 11, Steam 1794424036.

Steam treats a game as installed purely on the appmanifest being there. When it is missing, or present but blanked to StateFlags 1538 with an empty InstalledDepots, the payload is unreachable: the library entry is dead and Install re-downloads everything over files that are already complete. GetInstallDir could only report that state back, because it resolves the folder from the appmanifest and nothing ever writes one.

The folder is found from appinfo instead (installdir + launch exe, matched on the normalized name and required to contain that exe), and the appmanifest is written against it under whatever name it actually has, so a renamed or unpacked folder does not have to be renamed back first.

Guards for the ways this could otherwise bite: the app is skipped when a manifest already carries FullyInstalled, an existing manifest is backed up before being replaced, and an orphaned staging folder is cleared so Steam reconfigures instead of resuming a dead download. A shared depot the lua references is registered on the app that owns it, since a missing one aborts the depot dependency build with Invalid content configuration.

Steam is stopped for the write and restarted after, the same way appinfo edits are applied.

Two new strings are English-only for now and listed in PENDING_TRANSLATION.
@Code-Leafy

Copy link
Copy Markdown
Author

Test build for anyone who wants to poke at this without building it: https://github.com/Code-Leafy/LuaTools/releases/tag/test-adopt-install

Commit bbe8f3c, dotnet publish -c Release, framework-dependent, unsigned, marked prerelease. It does not ship a Velopack update path, so it will not touch an installed copy. Unzip it anywhere; TESTING.txt inside has the steps and how to undo them (it writes a real appmanifest to a real library, plus a .bak of anything it replaces).

If you would rather build it yourself, the branch is fix/adopt-install-on-disk and dotnet publish -c Release is all it needs. I will re-tag and re-upload if the branch moves.

@Code-Leafy

Copy link
Copy Markdown
Author

Closing in favour of #117, which carries this as an issue instead of a PR.

@Code-Leafy Code-Leafy closed this Nov 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant