mirror of
https://github.com/kuhyx/steam-backlog-enforcer.git
synced 2026-11-23 11:46:18 +01:00
Wraps depotdownloader for the bulk content pull (bypasses Steam's own capped download speed) and steamcmd's app_update --validate to make Steam recognize the result, with a manual-manifest fallback for the confirmed steamcmd install-script segfault bug when no fix is available. Name search via store.steampowered.com is best-effort since that endpoint TLS-rejects scripted clients on this network; --appid plus steamcmd's own app_info_print is the reliable primary path. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
77 lines
2.3 KiB
Python
77 lines
2.3 KiB
Python
"""Steam library discovery: find install roots and where a given app lives."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from dataclasses import dataclass
|
|
from pathlib import Path
|
|
|
|
from steam_installer import vdf
|
|
|
|
DEFAULT_STEAM_ROOT = Path.home() / ".local/share/Steam"
|
|
|
|
|
|
@dataclass
|
|
class SteamLibrary:
|
|
path: Path
|
|
|
|
@property
|
|
def common(self) -> Path:
|
|
return self.path / "steamapps" / "common"
|
|
|
|
@property
|
|
def steamapps(self) -> Path:
|
|
return self.path / "steamapps"
|
|
|
|
|
|
def find_steam_root() -> Path:
|
|
"""Locate the Steam installation. Raises if none of the usual paths exist."""
|
|
for candidate in (DEFAULT_STEAM_ROOT, Path.home() / ".steam/steam"):
|
|
if (candidate / "steamapps").is_dir():
|
|
return candidate
|
|
raise FileNotFoundError(
|
|
"No Steam installation found at ~/.local/share/Steam or ~/.steam/steam"
|
|
)
|
|
|
|
|
|
def list_libraries(steam_root: Path) -> list[SteamLibrary]:
|
|
"""Every Steam library folder, parsed from libraryfolders.vdf (plus steam_root itself)."""
|
|
libraries = [SteamLibrary(steam_root)]
|
|
vdf_path = steam_root / "steamapps" / "libraryfolders.vdf"
|
|
if not vdf_path.is_file():
|
|
return libraries
|
|
data = vdf.parse(vdf_path.read_text())
|
|
folders = data.get("libraryfolders", {})
|
|
if not isinstance(folders, dict):
|
|
return libraries
|
|
seen = {steam_root.resolve()}
|
|
for entry in folders.values():
|
|
if not isinstance(entry, dict):
|
|
continue
|
|
raw_path = entry.get("path")
|
|
if not raw_path:
|
|
continue
|
|
path = Path(raw_path).resolve()
|
|
if path not in seen:
|
|
seen.add(path)
|
|
libraries.append(SteamLibrary(path))
|
|
return libraries
|
|
|
|
|
|
def find_existing_install(
|
|
libraries: list[SteamLibrary], installdir: str
|
|
) -> Path | None:
|
|
"""Return the install path if `installdir` already exists in any library."""
|
|
for library in libraries:
|
|
candidate = library.common / installdir
|
|
if candidate.is_dir():
|
|
return candidate
|
|
return None
|
|
|
|
|
|
def pick_install_target(libraries: list[SteamLibrary], installdir: str) -> Path:
|
|
"""Where to install: an existing partial install if one exists, else the primary library."""
|
|
existing = find_existing_install(libraries, installdir)
|
|
if existing is not None:
|
|
return existing
|
|
return libraries[0].common / installdir
|