diff --git a/vollerei/cli/hsr.py b/vollerei/cli/hsr.py index e8bfd1c..661c355 100644 --- a/vollerei/cli/hsr.py +++ b/vollerei/cli/hsr.py @@ -86,7 +86,7 @@ class VoicepackListInstalled(Command): f"{x.name}" for x in State.game.get_installed_voicepacks() ] - self.line(f"Installed voicepacks: {", ".join(installed_voicepacks_str)}") + self.line(f"Installed voicepacks: {', '.join(installed_voicepacks_str)}") class VoicepackList(Command): @@ -104,7 +104,7 @@ class VoicepackList(Command): f"{x.language.name} ({x.language.value})" for x in remote_game.latest.voice_packs ] - self.line(f"Available voicepacks: {", ".join(available_voicepacks_str)}") + self.line(f"Available voicepacks: {', '.join(available_voicepacks_str)}") class VoicepackUpdateAll(Command): @@ -135,7 +135,7 @@ class VoicepackUpdateAll(Command): installed_voicepacks_str = [ f"{str(x.name)}" for x in installed_voicepacks ] - self.line(f"Installed voicepacks: {", ".join(installed_voicepacks_str)}") + self.line(f"Installed voicepacks: {', '.join(installed_voicepacks_str)}") progress = utils.ProgressIndicator(self) progress.start("Checking for updates... ") try: @@ -512,6 +512,87 @@ class UpdateCommand(Command): ) +class UpdateDownloadCommand(Command): + name = "hsr update download" + description = "Download the update for the local game if available" + 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 + 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 download the update?"): + self.line("Download aborted.") + return + self.line("Downloading update package...") + out_path = State.game.cache.joinpath(update_diff.name) + try: + download_result = utils.download( + update_diff.path, out_path, 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.") + # Get installed voicepacks + installed_voicepacks = State.game.get_installed_voicepacks() + # Voicepack update + for remote_voicepack in update_diff.voice_packs: + if remote_voicepack.language not in installed_voicepacks: + continue + # Voicepack is installed, update it + archive_file = State.game.cache.joinpath(remote_voicepack.name) + try: + download_result = utils.download( + update_diff.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.") + + class ApplyUpdateArchive(Command): name = "hsr update apply-archive" description = "Applies the update archive to the local game" @@ -563,6 +644,7 @@ commands = [ PatchTypeCommand, UpdatePatchCommand, UpdateCommand, + UpdateDownloadCommand, VoicepackList, VoicepackListInstalled, VoicepackUpdateAll, diff --git a/vollerei/common/api/resource.py b/vollerei/common/api/resource.py index 733dfd2..e323eda 100644 --- a/vollerei/common/api/resource.py +++ b/vollerei/common/api/resource.py @@ -2,7 +2,6 @@ Class wrapper for API endpoint /resource """ - from vollerei.common.enums import VoicePackLanguage @@ -31,9 +30,11 @@ class Segment: return Segment( data["path"], data["md5"], - int(data["package_size"]) - if data["package_size"] and data["package_size"] != "0" - else None, + ( + int(data["package_size"]) + if data["package_size"] and data["package_size"] != "0" + else None + ), ) @@ -397,9 +398,11 @@ class Resource: LauncherPlugin.from_dict(json["plugin"]), json["web_url"], json["force_update"], - Game.from_dict(json["pre_download_game"]) - if json["pre_download_game"] - else None, + ( + Game.from_dict(json["pre_download_game"]) + if json["pre_download_game"] + else None + ), [DeprecatedPackage.from_dict(x) for x in json["deprecated_packages"]], json["sdk"], [DeprecatedFile.from_dict(x) for x in json["deprecated_files"]],