From 32d6ca18914ab21a590e5bba3af3ad6cf673e372 Mon Sep 17 00:00:00 2001 From: tretrauit Date: Sun, 18 Jun 2023 00:05:02 +0700 Subject: [PATCH] chore: some improvement to cli --- vollerei/cli/__init__.py | 8 +++++++- vollerei/cli/hsr.py | 41 +++++++++++++++++++++++++++++++++------- vollerei/cli/utils.py | 14 ++++++++++++++ 3 files changed, 55 insertions(+), 8 deletions(-) create mode 100644 vollerei/cli/utils.py diff --git a/vollerei/cli/__init__.py b/vollerei/cli/__init__.py index b29ef2b..0ea5d18 100644 --- a/vollerei/cli/__init__.py +++ b/vollerei/cli/__init__.py @@ -2,14 +2,20 @@ from pathlib import Path from vollerei import __version__ from vollerei.cli.hsr import HSR from vollerei.hsr import PatchType +from vollerei.cli import utils class CLI: - def __init__(self, game_path: str = None, patch_type=None) -> None: + def __init__( + self, game_path: str = None, patch_type=None, noconfirm: bool = False + ) -> None: """ Vollerei CLI """ print(f"Vollerei v{__version__}") + if noconfirm: + print("User requested to automatically answer yes to all questions.") + utils.no_confirm = noconfirm if not game_path: game_path = Path.cwd() game_path = Path(game_path) diff --git a/vollerei/cli/hsr.py b/vollerei/cli/hsr.py index 6e45809..24a413b 100644 --- a/vollerei/cli/hsr.py +++ b/vollerei/cli/hsr.py @@ -1,4 +1,6 @@ from traceback import print_exc +from platform import system +from vollerei.cli.utils import ask from vollerei.hsr import Game, Patcher from vollerei.exceptions.patcher import PatcherError, PatchUpdateError from vollerei.hsr.patcher import PatchType @@ -26,7 +28,6 @@ class HSR: except PatchUpdateError as e: print("FAILED") print(f"Patch update failed with following error: {e} ({e.__context__})") - print_exc() return False print("OK") return True @@ -34,11 +35,9 @@ class HSR: def update_patch(self): self.__update_patch() - def patch(self): - if not self.__update_patch(): - return + def __patch_jadeite(self): try: - print("Patching game...", end=" ") + print("Installing patch...", end=" ") jadelte_dir = self._patcher.patch_game(game=self._game) except PatcherError as e: print("FAILED") @@ -48,9 +47,37 @@ class HSR: exe_path = jadelte_dir.joinpath("jadeite.exe") print("Jadelte executable is located at:", exe_path) print( - "Patching succeeded, but note that you need to run the game using Jadeite to use the patch." + "Installation succeeded, but note that you need to run the game using " + + "Jadeite to use the patch." ) print(f'E.g: I_WANT_A_BAN=1 {exe_path} "{self._game.path}"') print( - "And for your own sake, please only use testing accounts, as there is an extremely high risk of getting banned." + "And for your own sake, please only use testing accounts, as there is an " + + "extremely high risk of getting banned." ) + + def __patch_astra(self): + try: + print("Patching game...", end=" ") + self._patcher.patch_game(game=self._game) + except PatcherError as e: + print("FAILED") + print(f"Patching failed with following error: {e}") + return + print("OK") + + def patch(self): + if system() == "Windows": + print( + "Windows is supported officialy by the game, so no patching is needed." + ) + if not ask("Do you still want to patch?"): + print("Patching aborted.") + return + if not self.__update_patch(): + return + match self._patcher.patch_type: + case PatchType.Jadeite: + self.__patch_jadeite() + case PatchType.Astra: + self.__patch_astra() diff --git a/vollerei/cli/utils.py b/vollerei/cli/utils.py new file mode 100644 index 0000000..2ddcfb2 --- /dev/null +++ b/vollerei/cli/utils.py @@ -0,0 +1,14 @@ +no_confirm = False + + +def ask(question: str): + if no_confirm: + print(question + " [Y/n] Y") + return True + while True: + answer = input(question + " [y/n] ") + if answer.lower() in ["y", "yes"]: + return True + # Pacman way, treat all other answers as no + else: + return False