mirror of
https://github.com/tcsenpai/UWINE.git
synced 2025-06-07 03:55:21 +00:00
ulwgl_dl_util: refactor _get_from_cache
This commit is contained in:
parent
ecde7f642f
commit
83a59dcf1d
@ -190,62 +190,43 @@ def _get_from_cache(
|
|||||||
steam_compat: Path,
|
steam_compat: Path,
|
||||||
cache: Path,
|
cache: Path,
|
||||||
files: List[Tuple[str, str]],
|
files: List[Tuple[str, str]],
|
||||||
latest=True,
|
use_latest=True,
|
||||||
) -> Dict[str, str]:
|
) -> Dict[str, str]:
|
||||||
"""Refer to ULWGL cache directory.
|
"""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
|
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:
|
path: Path = None
|
||||||
tarball: str = files[1][0] # GE-Proton*.tar.gz
|
name: str = ""
|
||||||
proton: str = tarball[: tarball.find(".")] # GE-Proton\d+\-\d\d
|
|
||||||
|
|
||||||
print(tarball + " found in: " + cache.as_posix())
|
for tarball in cache.glob("GE-Proton*.tar.gz"):
|
||||||
|
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:
|
try:
|
||||||
_extract_dir(
|
_extract_dir(path, steam_compat)
|
||||||
Path(Path().home().as_posix() + "/.cache/ULWGL").joinpath(tarball),
|
environ["PROTONPATH"] = steam_compat.joinpath(
|
||||||
steam_compat,
|
name[: name.find(".")]
|
||||||
)
|
).as_posix()
|
||||||
|
|
||||||
# Set PROTONPATH to .local/share/Steam/compatibilitytools.d/GE-Proton*
|
|
||||||
environ["PROTONPATH"] = steam_compat.joinpath(proton).as_posix()
|
|
||||||
env["PROTONPATH"] = environ["PROTONPATH"]
|
env["PROTONPATH"] = environ["PROTONPATH"]
|
||||||
|
|
||||||
return env
|
return env
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
# Exit cleanly
|
proton: str = name[: name.find(".")]
|
||||||
# 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
|
|
||||||
|
|
||||||
print(f"{tarball.name} found in: {cache.as_posix()}")
|
|
||||||
try:
|
|
||||||
_extract_dir(tarball, steam_compat)
|
|
||||||
environ["PROTONPATH"] = steam_compat.joinpath(
|
|
||||||
tarball.name[: tarball.name.find(".")]
|
|
||||||
).as_posix()
|
|
||||||
env["PROTONPATH"] = environ["PROTONPATH"]
|
|
||||||
|
|
||||||
break
|
|
||||||
except KeyboardInterrupt:
|
|
||||||
proton: str = tarball.name[: tarball.name.find(".")]
|
|
||||||
|
|
||||||
if steam_compat.joinpath(proton).is_dir():
|
if steam_compat.joinpath(proton).is_dir():
|
||||||
print(f"Purging {proton} in {steam_compat} ...")
|
print(f"Purging {proton} in {steam_compat} ...")
|
||||||
rmtree(steam_compat.joinpath(proton).as_posix())
|
rmtree(steam_compat.joinpath(proton).as_posix())
|
||||||
raise
|
raise
|
||||||
|
|
||||||
return env
|
return None
|
||||||
|
|
||||||
|
|
||||||
def _get_latest(
|
def _get_latest(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user