2023-12-02 16:45:16 +00:00
|
|
|
from typing import Optional
|
|
|
|
from pathlib import Path
|
|
|
|
|
|
|
|
import vdf
|
|
|
|
|
|
|
|
STEAM_PATHS = [
|
|
|
|
Path.home() / ".var/app/com.valvesoftware.Steam/data/Steam",
|
|
|
|
]
|
|
|
|
|
2023-12-02 16:46:48 +00:00
|
|
|
|
2023-12-02 16:45:16 +00:00
|
|
|
def find_library_folder_for_game(appid: str) -> Optional[Path]:
|
|
|
|
for steam_path in STEAM_PATHS:
|
|
|
|
if not steam_path.exists():
|
|
|
|
continue
|
|
|
|
|
|
|
|
library_folders_vdf = steam_path / "steamapps/libraryfolders.vdf"
|
|
|
|
if not library_folders_vdf.exists():
|
|
|
|
continue
|
|
|
|
|
|
|
|
with open(library_folders_vdf, "r") as f:
|
|
|
|
content = vdf.load(f)
|
2023-12-02 16:46:48 +00:00
|
|
|
|
2023-12-02 16:45:16 +00:00
|
|
|
for index in content["libraryfolders"]:
|
|
|
|
library = content["libraryfolders"][index]
|
|
|
|
|
|
|
|
if not Path(library["path"]).exists():
|
|
|
|
continue
|
|
|
|
|
|
|
|
if appid in library["apps"]:
|
|
|
|
return Path(library["path"])
|
|
|
|
|
2023-12-02 16:46:48 +00:00
|
|
|
return None
|