add Config.locate_bin_from_steam_config method
This commit is contained in:
parent
f2a5ada697
commit
83684128f6
|
@ -3,6 +3,7 @@ import shutil
|
|||
import subprocess
|
||||
import sys
|
||||
import tarfile
|
||||
import vdf
|
||||
|
||||
from pathlib import Path
|
||||
from os import environ
|
||||
|
@ -21,6 +22,19 @@ DOTNET_REG = """
|
|||
"""
|
||||
|
||||
|
||||
def get_path(path: str | Path) -> Path:
|
||||
"""
|
||||
Resolve a path
|
||||
|
||||
:param path: Path to process
|
||||
"""
|
||||
|
||||
if not isinstance(path, Path):
|
||||
path = Path(path)
|
||||
|
||||
return path.expanduser().resolve()
|
||||
|
||||
|
||||
class Config:
|
||||
"Base class for managing a WINE prefix for Project Torque"
|
||||
|
||||
|
@ -37,10 +51,10 @@ class Config:
|
|||
:param winetricks: Path to the ``winetricks`` script
|
||||
"""
|
||||
|
||||
self.path = Path(Config.path).expanduser().resolve()
|
||||
self.binpath = Path(binpath or Config.binpath).expanduser().resolve()
|
||||
self.prefix = Path(prefix or Config.prefix).expanduser().resolve()
|
||||
self.winetricks = Path(winetricks or Config.winetricks).expanduser().resolve()
|
||||
self.path = get_path(Config.path)
|
||||
self.binpath = get_path(binpath or Config.binpath)
|
||||
self.prefix = get_path(prefix or Config.prefix)
|
||||
self.winetricks = get_path(winetricks or Config.winetricks)
|
||||
|
||||
|
||||
def fetch_dxvk(self, version: str):
|
||||
|
@ -89,7 +103,7 @@ class Config:
|
|||
data = json.load(fd)
|
||||
|
||||
for param in ("binpath", "prefix", "winetricks"):
|
||||
path = Path(data.get(param, getattr(Config, param))).expanduser().resolve()
|
||||
path = get_path(data.get(param, getattr(Config, param)))
|
||||
setattr(self, param, path)
|
||||
|
||||
|
||||
|
@ -102,7 +116,7 @@ class Config:
|
|||
:raises FileNotFoundError: If the game binary cannot be found
|
||||
"""
|
||||
|
||||
path = Path(directory or "~/.steam").expanduser().resolve()
|
||||
path = get_path(directory or "~/.steam")
|
||||
|
||||
for item in path.rglob("*.exe"):
|
||||
if item.name.lower() == "projecttorque.exe":
|
||||
|
@ -112,6 +126,41 @@ class Config:
|
|||
raise FileNotFoundError("Cannot find 'ProjectTorque.exe'")
|
||||
|
||||
|
||||
def locate_bin_from_steam_config(self):
|
||||
"""
|
||||
Find the path to the Project Torque binary from the Steam config
|
||||
|
||||
:raises FileNotFoundError: If the steam config path or the game bin could not be found
|
||||
"""
|
||||
|
||||
paths = []
|
||||
steam_cfg_paths = [
|
||||
get_path("~/.steam/steam/config/libraryfolders.vdf"),
|
||||
get_path("~/.local/share/steam/config/libraryfolders.vdf")
|
||||
]
|
||||
|
||||
for cfg_path in steam_cfg_paths:
|
||||
if not cfg_path.exists():
|
||||
continue
|
||||
|
||||
with cfg_path.open("r", encoding = "UTF-8") as fd:
|
||||
cfg = vdf.load(fd, mapper = vdf.VDFDict)
|
||||
paths = list(item["path"] for item in cfg["libraryfolders"].values())
|
||||
|
||||
if not paths:
|
||||
raise FileNotFoundError("Could not locate Steam library paths")
|
||||
|
||||
for path in paths:
|
||||
try:
|
||||
self.locate_bin(path)
|
||||
return
|
||||
|
||||
except FileNotFoundError:
|
||||
pass
|
||||
|
||||
raise FileNotFoundError("Could not locate Project Torque from Steam config")
|
||||
|
||||
|
||||
def nuke_prefix(self):
|
||||
"Remove the WINE prefix"
|
||||
|
||||
|
@ -258,7 +307,7 @@ def main(): # pylint: disable=missing-function-docstring
|
|||
config.save()
|
||||
|
||||
if sys.argv[-1].endswith("ProjectTorque.exe"):
|
||||
config.binpath = Path(sys.argv[-1]).expanduser().resolve()
|
||||
config.binpath = get_path(sys.argv[-1])
|
||||
|
||||
config.setup()
|
||||
|
||||
|
|
Loading…
Reference in a new issue