From a7d763d847f1abe2c2f2cf923a075aa5aed4c701 Mon Sep 17 00:00:00 2001 From: tretrauit Date: Tue, 6 Feb 2024 14:24:44 +0700 Subject: [PATCH] feat(hsr): add voicepack related commands --- vollerei/cli/hsr.py | 113 +++++++++++++++++++++++++++++++++- vollerei/hsr/launcher/game.py | 2 +- 2 files changed, 113 insertions(+), 2 deletions(-) diff --git a/vollerei/cli/hsr.py b/vollerei/cli/hsr.py index 6b292cc..311577a 100644 --- a/vollerei/cli/hsr.py +++ b/vollerei/cli/hsr.py @@ -75,6 +75,113 @@ def callback( command.add_style("warn", fg="yellow") +class VoicepackListInstalled(Command): + name = "hsr voicepack list-installed" + description = "Get the installed voicepacks" + options = default_options + + def handle(self): + callback(command=self) + installed_voicepacks_str = [ + f"{str(x.name)}" + for x in State.game.get_installed_voicepacks() + ] + self.line(f"Installed voicepacks: {", ".join(installed_voicepacks_str)}") + + +class VoicepackUpdateAll(Command): + name = "hsr voicepack update-all" + description = "Updates all installed voicepacks" + options = default_options + [ + option( + "auto-repair", "R", description="Automatically repair the game if needed" + ), + option("pre-download", description="Pre-download the game if available"), + option( + "from-version", description="Update from a specific version", flag=False + ), + ] + + def handle(self): + callback(command=self) + auto_repair = self.option("auto-repair") + pre_download = self.option("pre-download") + from_version = self.option("from-version") + if auto_repair: + self.line("Auto-repair is enabled.") + if from_version: + self.line(f"Updating from version: {from_version}") + State.game.version_override = from_version + # Get installed voicepacks + installed_voicepacks = State.game.get_installed_voicepacks() + installed_voicepacks_str = [ + f"{str(x.name)}" for x in installed_voicepacks + ] + self.line(f"Installed voicepacks: {", ".join(installed_voicepacks_str)}") + progress = utils.ProgressIndicator(self) + progress.start("Checking for updates... ") + try: + update_diff = State.game.get_update(pre_download=pre_download) + game_info = State.game.get_remote_game(pre_download=pre_download) + except Exception as e: + progress.finish( + f"Update checking failed with following error: {e} ({e.__context__})" + ) + return + if update_diff is None: + progress.finish("Game is already updated.") + return + progress.finish("Update available.") + self.line( + f"The current version is: {State.game.get_version_str()}" + ) + self.line( + f"The latest version is: {game_info.latest.version}" + ) + if not self.confirm("Do you want to update the game?"): + self.line("Update aborted.") + return + # Voicepack update + for remote_voicepack in update_diff.voice_packs: + if remote_voicepack.language not in installed_voicepacks: + continue + # Voicepack is installed, update it + self.line( + f"Downloading update package for language: {remote_voicepack.language.name}... " + ) + archive_file = State.game.cache.joinpath(remote_voicepack.name) + try: + download_result = utils.download( + remote_voicepack.path, archive_file, file_len=update_diff.size + ) + except Exception as e: + self.line_error(f"Couldn't download update: {e}") + return + if not download_result: + self.line_error("Download failed.") + return + self.line("Download completed.") + progress = utils.ProgressIndicator(self) + progress.start("Applying update package...") + try: + State.game.apply_update_archive( + archive_file=archive_file, auto_repair=auto_repair + ) + except Exception as e: + progress.finish( + f"Couldn't apply update: {e} ({e.__context__})" + ) + return + progress.finish( + f"Update applied for language {remote_voicepack.language.name}." + ) + self.line("Setting version config... ") + State.game.set_version_config() + self.line( + f"The game has been updated to version: {State.game.get_version_str()}" + ) + + class PatchTypeCommand(Command): name = "hsr patch type" description = "Get the patch type of the game" @@ -285,7 +392,9 @@ class UpdateCommand(Command): "auto-repair", "R", description="Automatically repair the game if needed" ), option("pre-download", description="Pre-download the game if available"), - option("from-version", description="Update from a specific version"), + option( + "from-version", description="Update from a specific version", flag=False + ), ] def handle(self): @@ -436,4 +545,6 @@ commands = [ PatchTypeCommand, UpdatePatchCommand, UpdateCommand, + VoicepackListInstalled, + VoicepackUpdateAll, ] diff --git a/vollerei/hsr/launcher/game.py b/vollerei/hsr/launcher/game.py index 8b9dd32..9a414fa 100644 --- a/vollerei/hsr/launcher/game.py +++ b/vollerei/hsr/launcher/game.py @@ -300,7 +300,7 @@ class Game(GameABC): ): if child.is_dir(): try: - voicepacks.append(VoicePackLanguage(child.name)) + voicepacks.append(VoicePackLanguage[child.name]) except ValueError: pass return voicepacks