import re from pathlib import Path 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) self._gamedir = gamedir config_file = self._gamedir.joinpath("config.ini") self._config_file = config_file.resolve() self._version = None self._overseas = overseas self._launcher = Launcher(self._gamedir, self._overseas) if config_file.exists(): self._version = self._read_version_from_config() elif gamedir.joinpath("./GenshinImpact_Data/globalgamemanagers").exists(): self._version = self._read_version_from_game_file()