diff --git a/requirements.txt b/requirements.txt index ff2bf94..2057569 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ aiohttp==3.8.1 appdirs~=1.4.4 -aiofiles~=0.8.0 \ No newline at end of file +aiofiles~=0.8.0 +aiopath~=0.6.10 \ No newline at end of file diff --git a/worthless/installer.py b/worthless/installer.py index a571090..02d70b6 100644 --- a/worthless/installer.py +++ b/worthless/installer.py @@ -1,16 +1,28 @@ -import asyncio -import tarfile -import constants -import appdirs -import aiofiles +import re from pathlib import Path -import shutil -import aiohttp -from worthless.launcher import Launcher from configparser import ConfigParser +from worthless.launcher import Launcher class Installer: + def _read_version_from_config(self): + if self._config_file.exists(): + raise FileNotFoundError(f"Config file {self._config_file} not found") + cfg = ConfigParser() + cfg.read(str(self._config_file)) + return cfg.get("miHoYo", "game_version") + + # https://gitlab.com/KRypt0n_/an-anime-game-launcher/-/blob/main/src/ts/Game.ts#L26 + def _read_version_from_game_file(self): + globalgamemanagers = self._gamedir.joinpath("./GenshinImpact_Data/globalgamemanagers") + if globalgamemanagers.exists(): + with globalgamemanagers.open("rb") as f: + data = f.read().decode("ascii") + result = re.search(r"([1-9]+\.[0-9]+\.[0-9]+)_[\d]+_[\d]+", data) + if not result: + raise ValueError("Could not find version in game file") + return result.group(1) + def __init__(self, gamedir: str | Path = Path.cwd(), overseas: bool = True): if isinstance(gamedir, str): gamedir = Path(gamedir) @@ -22,12 +34,6 @@ class Installer: self._launcher = Launcher(self._gamedir, self._overseas) if config_file.exists(): self._version = self._read_version_from_config() - else: # TODO: Use An Anime Game Launcher method (which is more brutal, but it works) - self._version = "mangosus" + elif gamedir.joinpath("./GenshinImpact_Data/globalgamemanagers").exists(): + self._version = self._read_version_from_game_file() - def _read_version_from_config(self): - if self._config_file.exists(): - raise FileNotFoundError(f"Config file {self._config_file} not found") - cfg = ConfigParser() - cfg.read(str(self._config_file)) - return cfg.get("miHoYo", "game_version") diff --git a/worthless/patcher.py b/worthless/patcher.py index ae21055..fb3d2e4 100644 --- a/worthless/patcher.py +++ b/worthless/patcher.py @@ -18,7 +18,7 @@ class Patcher: self._temp_path = Path(self._appdirs.user_cache_dir) else: if not isinstance(data_dir, Path): - override_data_dir = Path(data_dir) + data_dir = Path(data_dir) self._patch_path = data_dir.joinpath("Patch") self._temp_path = data_dir.joinpath("Temp")