Read version from game file (thanks to An Anime Game Launcher project)
Basically I copied their method of doing that and their regex pattern.
This commit is contained in:
parent
2b811d99b9
commit
ad391a551c
@ -1,3 +1,4 @@
|
|||||||
aiohttp==3.8.1
|
aiohttp==3.8.1
|
||||||
appdirs~=1.4.4
|
appdirs~=1.4.4
|
||||||
aiofiles~=0.8.0
|
aiofiles~=0.8.0
|
||||||
|
aiopath~=0.6.10
|
@ -1,16 +1,28 @@
|
|||||||
import asyncio
|
import re
|
||||||
import tarfile
|
|
||||||
import constants
|
|
||||||
import appdirs
|
|
||||||
import aiofiles
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
import shutil
|
|
||||||
import aiohttp
|
|
||||||
from worthless.launcher import Launcher
|
|
||||||
from configparser import ConfigParser
|
from configparser import ConfigParser
|
||||||
|
from worthless.launcher import Launcher
|
||||||
|
|
||||||
|
|
||||||
class Installer:
|
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):
|
def __init__(self, gamedir: str | Path = Path.cwd(), overseas: bool = True):
|
||||||
if isinstance(gamedir, str):
|
if isinstance(gamedir, str):
|
||||||
gamedir = Path(gamedir)
|
gamedir = Path(gamedir)
|
||||||
@ -22,12 +34,6 @@ class Installer:
|
|||||||
self._launcher = Launcher(self._gamedir, self._overseas)
|
self._launcher = Launcher(self._gamedir, self._overseas)
|
||||||
if config_file.exists():
|
if config_file.exists():
|
||||||
self._version = self._read_version_from_config()
|
self._version = self._read_version_from_config()
|
||||||
else: # TODO: Use An Anime Game Launcher method (which is more brutal, but it works)
|
elif gamedir.joinpath("./GenshinImpact_Data/globalgamemanagers").exists():
|
||||||
self._version = "mangosus"
|
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")
|
|
||||||
|
@ -18,7 +18,7 @@ class Patcher:
|
|||||||
self._temp_path = Path(self._appdirs.user_cache_dir)
|
self._temp_path = Path(self._appdirs.user_cache_dir)
|
||||||
else:
|
else:
|
||||||
if not isinstance(data_dir, Path):
|
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._patch_path = data_dir.joinpath("Patch")
|
||||||
self._temp_path = data_dir.joinpath("Temp")
|
self._temp_path = data_dir.joinpath("Temp")
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user