ulwgl_dl_util: prefer creating a var for the Proton dir

- Referencing the tuple element within the array for the tarball name then parsing it was becoming highly error prone/unreadable.
This commit is contained in:
R1kaB3rN 2024-02-17 12:18:43 -08:00
parent 71eaff0ca5
commit 9f2de76c5a
No known key found for this signature in database

View File

@ -111,6 +111,9 @@ def _fetch_proton(
"""Download the latest ULWGL-Proton and set it as PROTONPATH.""" """Download the latest ULWGL-Proton and set it as PROTONPATH."""
hash, hash_url = files[0] hash, hash_url = files[0]
proton, proton_url = files[1] proton, proton_url = files[1]
proton_dir: str = proton[
: proton.find(".tar.gz")
] # Proton dir without suffixes/dashes
# TODO: Parallelize this # TODO: Parallelize this
print(f"Downloading {hash} ...") print(f"Downloading {hash} ...")
@ -130,7 +133,7 @@ def _fetch_proton(
print(f"{proton}: SHA512 is OK") print(f"{proton}: SHA512 is OK")
_extract_dir(cache.joinpath(proton), steam_compat) _extract_dir(cache.joinpath(proton), steam_compat)
environ["PROTONPATH"] = steam_compat.joinpath(proton[: proton.find(".")]).as_posix() environ["PROTONPATH"] = steam_compat.joinpath(proton_dir).as_posix()
env["PROTONPATH"] = environ["PROTONPATH"] env["PROTONPATH"] = environ["PROTONPATH"]
return env return env
@ -163,7 +166,12 @@ def _get_from_steamcompat(
env: Dict[str, str], steam_compat: Path, cache: Path, files: List[Tuple[str, str]] env: Dict[str, str], steam_compat: Path, cache: Path, files: List[Tuple[str, str]]
) -> Dict[str, str]: ) -> Dict[str, str]:
"""Refer to Steam compat folder for any existing Proton directories.""" """Refer to Steam compat folder for any existing Proton directories."""
for proton in steam_compat.glob("GE-Proton*"): proton_dir: str = "" # Latest Proton
if len(files) == 2:
proton_dir: str = files[1][0][
: files[1][0].find(".tar.gz")
] # Proton dir without suffixes/dashes
for proton in steam_compat.glob("ULWGL-Proton*"): for proton in steam_compat.glob("ULWGL-Proton*"):
print(f"{proton.name} found in: {steam_compat.as_posix()}") print(f"{proton.name} found in: {steam_compat.as_posix()}")
@ -171,7 +179,7 @@ def _get_from_steamcompat(
env["PROTONPATH"] = environ["PROTONPATH"] env["PROTONPATH"] = environ["PROTONPATH"]
# Notify the user that they're not using the latest # Notify the user that they're not using the latest
if len(files) == 2 and proton.name != files[1][0][: files[1][0].find(".")]: if proton_dir and proton.name != proton_dir:
print( print(
"ULWGL-Proton is outdated.\nFor latest release, please download " "ULWGL-Proton is outdated.\nFor latest release, please download "
+ files[1][1] + files[1][1]
@ -207,20 +215,20 @@ def _get_from_cache(
break break
if path: if path:
proton_dir: str = name[
: name.find(".tar.gz")
] # Proton dir without suffixes/dashes
try: try:
_extract_dir(path, steam_compat) _extract_dir(path, steam_compat)
environ["PROTONPATH"] = steam_compat.joinpath( environ["PROTONPATH"] = steam_compat.joinpath(proton_dir).as_posix()
name[: name.find(".")]
).as_posix()
env["PROTONPATH"] = environ["PROTONPATH"] env["PROTONPATH"] = environ["PROTONPATH"]
return env return env
except KeyboardInterrupt: except KeyboardInterrupt:
proton: str = name[: name.find(".")] if steam_compat.joinpath(proton_dir).is_dir():
print(f"Purging {proton_dir} in {steam_compat} ...")
if steam_compat.joinpath(proton).is_dir(): rmtree(steam_compat.joinpath(proton_dir).as_posix())
print(f"Purging {proton} in {steam_compat} ...")
rmtree(steam_compat.joinpath(proton).as_posix())
raise raise
return None return None
@ -244,11 +252,14 @@ def _get_latest(
return None return None
except KeyboardInterrupt: except KeyboardInterrupt:
tarball: str = files[1][0] tarball: str = files[1][0]
proton_dir: str = tarball[
: tarball.find(".tar.gz")
] # Proton dir without suffixes/dashes
# Exit cleanly # Exit cleanly
# Clean up extracted data and cache to prevent corruption/errors # Clean up extracted data and cache to prevent corruption/errors
# Refer to the cache for old version next # Refer to the cache for old version next
_cleanup(tarball, tarball[: tarball.find(".")], cache, steam_compat) _cleanup(tarball, proton_dir, cache, steam_compat)
return None return None
return env return env