left4me/l4d2host/steam_install.py

40 lines
1.3 KiB
Python

from pathlib import Path
from typing import Callable
from l4d2host.paths import get_left4me_root
from l4d2host.process import run_command
class SteamInstaller:
def __init__(self, install_dir: Path | None = None, steamcmd: str = "steamcmd"):
self.install_dir = get_left4me_root() / "installation" if install_dir is None else Path(install_dir)
self.steamcmd = steamcmd
def install_or_update(
self,
*,
on_stdout: Callable[[str], None] | None = None,
on_stderr: Callable[[str], None] | None = None,
passthrough: bool = False,
should_cancel: Callable[[], bool] | None = None,
) -> None:
for platform in ("windows", "linux"):
run_command(
[
self.steamcmd,
"+force_install_dir",
str(self.install_dir),
"+login",
"anonymous",
"+@sSteamCmdForcePlatformType",
platform,
"+app_update",
"222860",
"validate",
"+quit",
],
on_stdout=on_stdout,
on_stderr=on_stderr,
passthrough=passthrough,
should_cancel=should_cancel,
)