From f4e09a7aad04415081faabff48a0228f6f594608 Mon Sep 17 00:00:00 2001 From: tretrauit Date: Wed, 27 Mar 2024 12:20:29 +0700 Subject: [PATCH] fix: handle hdiffpatch downloading for each architecture --- vollerei/cli/hsr.py | 3 +++ vollerei/paths.py | 2 +- vollerei/utils/hdiffpatch/__init__.py | 32 ++++++++++++++++----------- 3 files changed, 23 insertions(+), 14 deletions(-) diff --git a/vollerei/cli/hsr.py b/vollerei/cli/hsr.py index 4d34a6a..cd7584a 100644 --- a/vollerei/cli/hsr.py +++ b/vollerei/cli/hsr.py @@ -8,6 +8,7 @@ from vollerei.exceptions.game import GameError from vollerei.hsr import Game, Patcher from vollerei.exceptions.patcher import PatcherError, PatchUpdateError from vollerei.hsr.patcher import PatchType +from vollerei import paths patcher = Patcher() @@ -49,6 +50,8 @@ def callback( channel = GameChannel[channel.capitalize()] elif isinstance(channel, int): channel = GameChannel(channel) + if temporary_path: + paths.set_base_path(temporary_path) State.game: Game = Game(game_path, temporary_path) if channel: State.game.channel_override = channel diff --git a/vollerei/paths.py b/vollerei/paths.py index d9d3085..2e7afd2 100644 --- a/vollerei/paths.py +++ b/vollerei/paths.py @@ -20,7 +20,7 @@ class Paths: def set_base_path(path: PathLike): path = Path(path) Paths.base_paths = path - Paths.cache_path = Paths.base_paths.joinpath("Cache") + Paths.cache_path = Paths.base_paths.joinpath("cache") Paths.data_path = Paths.base_paths Paths.tools_data_path = Paths.data_path.joinpath("tools") Paths.tools_cache_path = Paths.cache_path.joinpath("tools") diff --git a/vollerei/utils/hdiffpatch/__init__.py b/vollerei/utils/hdiffpatch/__init__.py index 31b9b08..ba66684 100644 --- a/vollerei/utils/hdiffpatch/__init__.py +++ b/vollerei/utils/hdiffpatch/__init__.py @@ -26,22 +26,33 @@ class HDiffPatch: @staticmethod def _get_platform_arch(): + processor = platform.machine() match platform.system(): case "Windows": - match platform.architecture()[0]: - case "32bit": + match processor: + case "i386": return "windows32" - case "64bit": + case "x86_64": return "windows64" + case "arm": + return "windows_arm32" + case "arm64": + return "windows_arm64" case "Linux": - match platform.architecture()[0]: - case "32bit": + match processor: + case "i386": return "linux32" - case "64bit": + case "x86_64": return "linux64" + case "arm": + return "linux_arm32" + case "arm64": + return "linux_arm64" case "Darwin": return "macos" + # TODO: Add support for Android & other architectures + # Rip BSD they need to use Linux compatibility layer to run this # (or use Wine if they prefer that) raise PlatformNotSupportedError( @@ -88,16 +99,11 @@ class HDiffPatch: params={"Headers": "Accept: application/vnd.github.v3+json"}, ) rsp.raise_for_status() + archive_processor = self._get_platform_arch() for asset in rsp.json()["assets"]: if not asset["name"].endswith(".zip"): continue - if "linux" in asset["name"]: - continue - if "windows" in asset["name"]: - continue - if "macos" in asset["name"]: - continue - if "android" in asset["name"]: + if archive_processor not in asset["name"]: continue return asset