Skip to content

Commit

Permalink
ulwgl_dl_util: refactor _get_from_cache
Browse files Browse the repository at this point in the history
  • Loading branch information
R1kaB3rN committed Feb 17, 2024
1 parent ecde7f6 commit 83a59dc
Showing 1 changed file with 17 additions and 36 deletions.
53 changes: 17 additions & 36 deletions ulwgl_dl_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,62 +190,43 @@ def _get_from_cache(
steam_compat: Path,
cache: Path,
files: List[Tuple[str, str]],
latest=True,
use_latest=True,
) -> Dict[str, str]:
"""Refer to ULWGL cache directory.
Use the latest in the cache when present. Older Proton versions are only referred to when: digests mismatch, user interrupt, or download failure/no internet
"""
if files and latest:
tarball: str = files[1][0] # GE-Proton*.tar.gz
proton: str = tarball[: tarball.find(".")] # GE-Proton\d+\-\d\d
path: Path = None
name: str = ""

print(tarball + " found in: " + cache.as_posix())
try:
_extract_dir(
Path(Path().home().as_posix() + "/.cache/ULWGL").joinpath(tarball),
steam_compat,
)

# Set PROTONPATH to .local/share/Steam/compatibilitytools.d/GE-Proton*
environ["PROTONPATH"] = steam_compat.joinpath(proton).as_posix()
env["PROTONPATH"] = environ["PROTONPATH"]

return env
except KeyboardInterrupt:
# Exit cleanly
# Clean up only the extracted data
if steam_compat.joinpath(proton).is_dir():
print(f"Purging {proton} in {steam_compat} ...")
rmtree(steam_compat.joinpath(proton).as_posix())

raise

# Refer to an old version previously installed
# Reached on digest mismatch, user interrupt or download failure/no internet
for tarball in cache.glob("GE-Proton*.tar.gz"):
# Ignore the mismatched file
if files and tarball == cache.joinpath(files[1][0]):
continue

if files and tarball == cache.joinpath(files[1][0]) and use_latest:
path = tarball
name = tarball.name
elif not use_latest:
path = tarball
name = tarball.name
print(f"{tarball.name} found in: {cache.as_posix()}")
break

if path:
try:
_extract_dir(tarball, steam_compat)
_extract_dir(path, steam_compat)
environ["PROTONPATH"] = steam_compat.joinpath(
tarball.name[: tarball.name.find(".")]
name[: name.find(".")]
).as_posix()
env["PROTONPATH"] = environ["PROTONPATH"]

break
return env
except KeyboardInterrupt:
proton: str = tarball.name[: tarball.name.find(".")]
proton: str = name[: name.find(".")]

if steam_compat.joinpath(proton).is_dir():
print(f"Purging {proton} in {steam_compat} ...")
rmtree(steam_compat.joinpath(proton).as_posix())
raise

return env
return None


def _get_latest(
Expand Down

0 comments on commit 83a59dc

Please sign in to comment.