Support chinese variant game version detection (not tested)

Also some minor improvements for preparation of installation features.
This commit is contained in:
tretrauit 2022-02-16 02:55:19 +07:00
parent ad391a551c
commit 140e508dbf
Signed by: tretrauit
GPG Key ID: 862760FF1903319E
3 changed files with 25 additions and 6 deletions

View File

@ -1,7 +1,9 @@
#!/usr/bin/python3
import argparse
import appdirs
from pathlib import Path
import constants
class UI:
@ -28,9 +30,13 @@ class UI:
def main():
default_dirs = appdirs.AppDirs(constants.APP_NAME, constants.APP_AUTHOR)
parser = argparse.ArgumentParser(prog="worthless", description="A worthless launcher written in Python.")
parser.add_argument("-D", "-d", "--dir", action="store", type=Path, default=Path.cwd(),
parser.add_argument("-D", "--dir", action="store", type=Path, default=Path.cwd(),
help="Specify the game directory (default current working directory)")
parser.add_argument("-W", "--temporary-dir", action="store", type=Path, default=None,
help="Specify the temporary directory (default {} and {})".format(default_dirs.user_data_dir,
default_dirs.user_cache_dir))
parser.add_argument("-S", "--install", action="store_true",
help="Install the game (if not already installed, else do nothing)")
parser.add_argument("-U", "--install-from-file", action="store_true",
@ -40,7 +46,7 @@ def main():
help="Patch the game (if not already patched, else do nothing)")
parser.add_argument("-Sy", "--update", action="store_true",
help="Update the game and specified voiceover pack only (or install if not found)")
parser.add_argument("-Syu", "--update", action="store_true",
parser.add_argument("-Syu", "--update-all", action="store_true",
help="Update the game and all installed voiceover packs (or install if not found)")
parser.add_argument("-Rs", "--remove", action="store_true", help="Remove the game (if installed)")
parser.add_argument("-Rp", "--remove-patch", action="store_true", help="Revert the game patch (if patched)")

View File

@ -1,6 +1,9 @@
import re
import appdirs
from pathlib import Path
from configparser import ConfigParser
from worthless import constants
from worthless.launcher import Launcher
@ -14,7 +17,10 @@ class Installer:
# 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 self._overseas:
globalgamemanagers = self._gamedir.joinpath("./GenshinImpact_Data/globalgamemanagers")
else:
globalgamemanagers = self._gamedir.joinpath("./YuanShen_Data/globalgamemanagers")
if globalgamemanagers.exists():
with globalgamemanagers.open("rb") as f:
data = f.read().decode("ascii")
@ -23,10 +29,17 @@ class Installer:
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, data_dir: str | Path = None):
if isinstance(gamedir, str):
gamedir = Path(gamedir)
self._gamedir = gamedir
if not data_dir:
self._appdirs = appdirs.AppDirs(constants.APP_NAME, constants.APP_AUTHOR)
self._temp_path = Path(self._appdirs.user_cache_dir).joinpath("Installer")
else:
if not isinstance(data_dir, Path):
data_dir = Path(data_dir)
self._temp_path = data_dir.joinpath("Temp/Installer/")
config_file = self._gamedir.joinpath("config.ini")
self._config_file = config_file.resolve()
self._version = None

View File

@ -15,12 +15,12 @@ class Patcher:
if not data_dir:
self._appdirs = appdirs.AppDirs(constants.APP_NAME, constants.APP_AUTHOR)
self._patch_path = Path(self._appdirs.user_data_dir).joinpath("Patch")
self._temp_path = Path(self._appdirs.user_cache_dir)
self._temp_path = Path(self._appdirs.user_cache_dir).joinpath("Patcher")
else:
if not isinstance(data_dir, Path):
data_dir = Path(data_dir)
self._patch_path = data_dir.joinpath("Patch")
self._temp_path = data_dir.joinpath("Temp")
self._temp_path = data_dir.joinpath("Temp/Patcher")
@staticmethod
async def _get(url, **kwargs) -> aiohttp.ClientResponse: