feat(hsr): support continue download & apply-archive

This commit is contained in:
tretrauit 2024-01-02 23:16:58 +07:00
parent 6f030e79ce
commit 6db85bc439
3 changed files with 57 additions and 11 deletions

View File

@ -3,7 +3,7 @@ from vollerei.cli import hsr
application = Application()
for command in hsr.commands:
application.add(command)
application.add(command())
def run():

View File

@ -1,21 +1,19 @@
from cleo.commands.command import Command
from cleo.helpers import option
from cleo.helpers import option, argument
from platform import system
from vollerei.hsr.launcher.enums import GameChannel
from vollerei.paths import set_base_path, base_paths
from vollerei.cli import utils
from vollerei.exceptions.game import GameError
from vollerei.hsr import Game, Patcher
from vollerei.exceptions.patcher import PatcherError, PatchUpdateError
from vollerei.hsr.patcher import PatchType
from tqdm import tqdm
import requests
patcher = Patcher()
default_options = [
option("channel", "c", description="Game channel", flag=False, default="overseas"),
option("force", "f", description="Force the command to run"),
option(
"game-path",
"g",
@ -289,12 +287,60 @@ class UpdateCommand(Command):
)
return
progress.finish("<comment>Update applied.</comment>")
self.line("Setting version config... ")
self.set_version_config()
self.line(
f"The game has been updated to version: <comment>{State.game.get_version_str()}</comment>"
)
class ApplyUpdateArchive(Command):
name = "hsr update apply-archive"
description = "Applies the update archive to the local game"
arguments = [argument("path", description="Path to the update archive")]
options = default_options + [
option(
"auto-repair", "R", description="Automatically repair the game if needed"
),
]
def handle(self):
callback(command=self)
auto_repair = self.option("auto-repair")
update_archive = self.argument("path")
if auto_repair:
self.line("<comment>Auto-repair is enabled.</comment>")
progress = utils.ProgressIndicator(self)
progress.start("Applying update package...")
try:
State.game.apply_update_archive(update_archive, auto_repair=auto_repair)
except Exception as e:
progress.finish(
f"<error>Couldn't apply update: {e} ({e.__context__})</error>"
)
return
progress.finish("<comment>Update applied.</comment>")
self.line("Setting version config... ")
try:
State.game.set_version_config()
except Exception as e:
self.line_error(f"<warn>Couldn't set version config: {e}</warn>")
self.line_error(
"This won't affect the overall experience, but if you're using the official launcher"
)
self.line_error(
"you may have to edit the file 'config.ini' manually to reflect the latest version."
)
self.line(
f"The game has been updated to version: <comment>{State.game.get_version_str()}</comment>"
)
commands = [
UpdateCommand(),
PatchTypeCommand(),
UpdatePatchCommand(),
PatchInstallCommand(),
GetVersionCommand(),
ApplyUpdateArchive,
UpdateCommand,
PatchTypeCommand,
UpdatePatchCommand,
PatchInstallCommand,
GetVersionCommand,
]

View File

@ -347,7 +347,6 @@ class Game(GameABC):
archive_file = Path(archive_file)
# Hello hell again, dealing with HDiffPatch and all the things again.
functions.apply_update_archive(self, archive_file, auto_repair=auto_repair)
self.set_version_config()
def install_update(
self, update_info: resource.Diff = None, auto_repair: bool = True
@ -370,3 +369,4 @@ class Game(GameABC):
archive_file = self._cache.joinpath(update_info.name)
download(update_info.path, archive_file)
self.apply_update_archive(archive_file=archive_file, auto_repair=auto_repair)
self.set_version_config()