"""Entry point: resolve -> confirm -> fast download -> make Steam recognize it.""" from __future__ import annotations import argparse import shutil import sys import time from steam_installer import appinfo, depotdl, recognize, resolve from steam_installer.library import find_steam_root, list_libraries, pick_install_target def _require_tool(name: str, install_hint: str) -> None: if shutil.which(name) is None: print(f"error: `{name}` not found on PATH. {install_hint}", file=sys.stderr) sys.exit(1) def _resolve_appid(args: argparse.Namespace) -> int: """Prefer an explicit --appid; fall back to search, which is best-effort (store.steampowered.com is known to reject scripted clients on some networks -- see resolve.py). Either way, the final confirmation uses the real name from steamcmd's own app info, not whatever the search returned. """ if args.appid is not None: return args.appid try: results = resolve.search(args.name) except resolve.SearchUnavailable as exc: print(f"Store search unavailable ({exc}).", file=sys.stderr) print( "Find the numeric AppID yourself (e.g. from the store URL) and pass --appid.", file=sys.stderr, ) sys.exit(1) chosen = resolve.prompt_confirm(results) return chosen.appid def main(argv: list[str] | None = None) -> int: parser = argparse.ArgumentParser( description="Download an owned Steam game fast, then make Steam recognize it." ) parser.add_argument("name", nargs="?", default=None, help="Game name to search for") parser.add_argument( "--appid", type=int, default=None, help="Steam AppID (skips search)" ) parser.add_argument("--username", required=True, help="Steam account username") parser.add_argument( "--language", default=None, help="Language depot to fetch (default: prompts)" ) parser.add_argument( "--max-downloads", type=int, default=depotdl.DEFAULT_MAX_DOWNLOADS ) parser.add_argument( "--skip-steamcmd", action="store_true", help=( "Finish the manifest directly from depotdownloader's own cached data " "instead of running steamcmd's app_update. Steamcmd's install-script " "step has shown two separate failure modes (a confirmed segfault, " "and a silent no-op run); this is the same direct-write approach " "already confirmed to work." ), ) args = parser.parse_args(argv) if args.appid is None and args.name is None: parser.error("provide a game name to search for, or --appid directly") _require_tool("depotdownloader", "See ~/depotdownloader.") if not args.skip_steamcmd: _require_tool("steamcmd", "Run: yay -S steamcmd") appid = _resolve_appid(args) metadata = appinfo.get_metadata(appid) print(f"Confirmed: {metadata.name} (appid {metadata.appid})") answer = input("Proceed? [y/N]: ").strip().lower() if answer != "y": print("Cancelled.") return 1 steam_root = find_steam_root() libraries = list_libraries(steam_root) target = pick_install_target(libraries, metadata.installdir) print(f"Install target: {target}") language = args.language if language is None: language = input("Language [english]: ").strip() or "english" print("Downloading via depotdownloader (fast path)...") depotdl.download( appid=metadata.appid, install_dir=target, username=args.username, language=language, max_downloads=args.max_downloads, ) library = next(lib for lib in libraries if lib.common == target.parent) recognize.ensure_installdir_correct(library, metadata.appid, target) if not args.skip_steamcmd: print("Reconciling with steamcmd (validate)...") result = recognize.run_steamcmd_validate(metadata.appid, target, args.username) # Never trust steamcmd's exit code alone -- verify the manifest actually # reflects a real install before believing it. A "clean" exit has # produced a manifest steamcmd itself hadn't finished updating before. if ( not result.crashed_on_install_script and recognize.manifest_reflects_real_install( library, metadata.appid, target ) ): print("steamcmd finished cleanly -- Steam should show Play.") return 0 if result.crashed_on_install_script: print( "steamcmd hit the known install-script crash; finishing the manifest manually..." ) else: print( f"steamcmd exited {result.returncode} but the manifest doesn't reflect a " "real install; finishing it manually..." ) manifest_path = recognize.finish_manifest_manually( library=library, appid=metadata.appid, install_dir=target, now_unix=int(time.time()), ) print(f"Wrote {manifest_path} -- launch Steam and confirm Play works.") return 0 if __name__ == "__main__": raise SystemExit(main())