31 lines
824 B
Python
31 lines
824 B
Python
|
from typing import Optional
|
||
|
from pathlib import Path
|
||
|
|
||
|
import vdf
|
||
|
|
||
|
STEAM_PATHS = [
|
||
|
Path.home() / ".var/app/com.valvesoftware.Steam/data/Steam",
|
||
|
]
|
||
|
|
||
|
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)
|
||
|
|
||
|
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"])
|
||
|
|
||
|
return None
|