steam-backlog-enforcer/_installer_import/steam_installer/compat_apply.py
Krzysztof kuhy Rudnicki c1b6fdd16f Map safe games to a FOSS Proton
Install the pinned proton-cachyos-native build (signature and
sha256 checked, .INSTALL never run), decide per game whether it
is safe, write the CompatToolMapping as text, add --map-installed
and --valve-proton, and drop steamcmd from install.sh.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 14:57:48 +01:00

75 lines
2.7 KiB
Python

"""Run the per-game decision and, when it says so, write the mapping.
Shared by the install flow (right after the manifest is finished, while Steam
is still closed) and by `--map-installed`. The decision rules live in
:mod:`compat_decide`, the config.vdf edit in :mod:`compat_map`.
"""
from __future__ import annotations
import logging
from pathlib import Path
from steam_installer import anticheat, appinfo, compat_decide, compat_map, proton_pkg
VALVE_PROTON = "--valve-proton"
TOOL_DIR = "compatibilitytools.d/proton-cachyos-native"
class Context:
"""What every decision in one run shares: fetched once, not per game."""
def __init__(self, steam_root: Path, extra_overrides: dict[str, str] | None = None):
self.steam_root = steam_root
self.config = compat_map.config_path(steam_root)
self.anticheat = anticheat.steam_ids()
self.overrides = {**compat_decide.load_overrides(), **(extra_overrides or {})}
self.tool_ready = compat_decide.tool_ready(
steam_root / TOOL_DIR, proton_pkg.read_lock().version
)
def decide(self, appid: int, block: dict, owned_dlc: bool) -> compat_decide.Decision:
return compat_decide.decide(
appid,
block,
anticheat=self.anticheat,
overrides=self.overrides,
owned_dlc=owned_dlc,
tool_ready=self.tool_ready,
)
def after_install(
steam_root: Path,
appid: int,
owned_dlc: bool,
valve_proton: bool,
logger: logging.Logger,
) -> None:
"""Map a freshly installed game, or say why it keeps Valve's default.
Never fails the install: a game left unmapped still runs on Valve's
Proton, exactly as before this tool knew about compat tools.
"""
extra = {str(appid): VALVE_PROTON} if valve_proton else {}
try:
context = Context(steam_root, extra)
decision = context.decide(appid, appinfo._fetch_app_block(appid), owned_dlc)
if not decision.map:
logger.info("Compat tool: %s", decision.describe())
return
outcome = compat_map.map_app(context.config, appid)
except (appinfo.AppInfoError, compat_map.CompatMapError, OSError, ValueError) as exc:
logger.warning("Compat tool not set (%s); the game stays on Valve's default.", exc)
return
report(logger, appid, outcome)
def report(logger: logging.Logger, appid: int, outcome: compat_map.Outcome) -> None:
if outcome.action == "kept":
logger.info("Compat tool for %s kept: %s", appid, outcome.detail)
elif outcome.action == "already":
logger.info("Compat tool for %s: already mapped to %s.", appid, compat_map.TOOL)
else:
logger.info("Compat tool for %s: mapped to %s.", appid, compat_map.TOOL)