From e3563cb8f330410feac9316531d70ca71c70ce3b Mon Sep 17 00:00:00 2001 From: R1kaB3rN <100738684+R1kaB3rN@users.noreply.github.com> Date: Fri, 16 Feb 2024 11:37:00 -0800 Subject: [PATCH] ulwgl_dl_util: move cache to func - Code block in which the digest mismatched, user interrupt or failure to download/no internet. --- ulwgl_dl_util.py | 52 ++++++++++++++++++++++++++++-------------------- 1 file changed, 30 insertions(+), 22 deletions(-) diff --git a/ulwgl_dl_util.py b/ulwgl_dl_util.py index aa88356..0bdfb85 100644 --- a/ulwgl_dl_util.py +++ b/ulwgl_dl_util.py @@ -59,28 +59,10 @@ def get_ulwgl_proton(env: Dict[str, str]) -> Union[Dict[str, str], None]: ) # Cache - # This point is reached when digests somehow mismatched or user interrupts the extraction process - 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"] - - return env - except KeyboardInterrupt: - proton: str = tarball.name[: tarball.name.find(".")] - - 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 + if _get_from_cache(env, steam_compat, cache, files, False): + return env # No internet and cache/compat tool is empty, just return and raise an exception from the caller return env @@ -252,3 +234,29 @@ def _get_from_cache( 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(): + print(f"Purging {proton} in {steam_compat} ...") + rmtree(steam_compat.joinpath(proton).as_posix()) + raise + + return env