Support downloading game & voicepacks and install, bump to 1.1.0

In CLI too, also optimized code & added test for voiceover functions.
This commit is contained in:
2022-02-18 11:11:55 +07:00
parent 07ba17b576
commit bb37e4554d
5 changed files with 194 additions and 26 deletions

View File

@ -1,6 +1,8 @@
#!/usr/bin/python3
import argparse
import asyncio
import appdirs
from pathlib import Path
from worthless.launcher import Launcher
@ -17,8 +19,11 @@ class UI:
self._installer = Installer(gamedir, data_dir=tempdir)
self._patcher = Patcher(gamedir)
@staticmethod
def _ask(question):
def _ask(self, question):
if self._noconfirm:
# Fake dialog
print(question + " (y/n): y")
return True
answer = ""
while answer.lower() not in ['y', 'n']:
if answer != "":
@ -76,16 +81,76 @@ class UI:
self._install_from_archive(filepath)
print("Game installed successfully.")
def install_game(self):
# TODO
raise NotImplementedError("Install game is not implemented.")
def install_game(self, forced: bool = False):
res_info = asyncio.run(self._launcher.get_resource_info())
print("Latest game version: {}".format(res_info.game.latest.version))
if not self._ask("Do you want to install the game?"):
print("Aborting game installation process.")
return
print("Downloading full game (This will take a long time)...")
asyncio.run(self._installer.download_full_game())
print("Installing game...")
self._install_from_archive(self._installer.temp_path.joinpath(res_info.game.latest.name))
def install_voiceover(self, languages: str):
res_info = asyncio.run(self._launcher.get_resource_info())
print("Latest game version: {}".format(res_info.game.latest.version))
for lng in languages.split(" "):
for vo in res_info.game.latest.voice_packs:
if not self._installer.voiceover_lang_translate(lng) == vo.language:
continue
if not self._ask("Do you want to install this voiceover pack? ({})".format(lng)):
print("Aborting voiceover installation process.")
return
print("Downloading voiceover pack (This will take a long time)...")
asyncio.run(self._installer.download_full_voiceover(lng))
print("Installing voiceover pack...")
self._apply_voiceover_from_archive(self._installer.temp_path.joinpath(res_info.game.latest.name))
break
def update_game(self):
print("Checking for current game version...")
# Call check_game_version()
print("Updating game...")
# Call update_game(fromver)
raise NotImplementedError("Update game is not implemented.")
game_ver = self._installer.get_game_version()
if not game_ver:
self.install_game()
return
print("Current game installation detected. ({})".format(game_ver))
diff_archive = asyncio.run(self._installer.get_game_diff_archive())
res_info = asyncio.run(self._launcher.get_resource_info())
if not diff_archive:
print("No game updates available.")
return
print("Latest game version: {}".format(res_info.game.latest.version))
if not self._ask("Do you want to update the game?"):
print("Aborting game update process.")
return
print("Downloading game update (This will take a long time)...")
asyncio.run(self._installer.download_game_update())
print("Installing game update...")
self.install_from_file(self._installer.temp_path.joinpath(res_info.game.latest.name))
def update_voiceover(self, languages: str):
game_ver = self._installer.get_game_version()
if not game_ver:
self.install_voiceover(languages)
return
print("Current game installation detected. ({})".format(game_ver))
for lng in languages.split(" "):
diff_archive = asyncio.run(self._installer.get_voiceover_diff_archive(lng))
# res_info = asyncio.run(self._launcher.get_resource_info())
if not diff_archive:
print("No voiceover updates available for {}.".format(lng))
continue
if not self._ask("Do you want to update this voiceover? ({})".format(lng)):
print("Aborting this voiceover language update process.")
continue
print("Downloading voiceover update (This may takes some time)...")
asyncio.run(self._installer.download_voiceover_update(lng))
print("Installing voiceover update for {}...".format(lng))
self._apply_voiceover_from_archive(self._installer.temp_path.joinpath(diff_archive.name))
def update_game_voiceover(self, languages: str):
self.update_game()
self.update_voiceover(languages)
def interactive_ui(self):
raise NotImplementedError()
@ -109,9 +174,9 @@ def main():
else update from archive)")
parser.add_argument("-Sp", "--patch", action="store_true",
help="Patch the game (if not already patched, else do nothing)")
parser.add_argument("-Sy", "--update", action="store_true",
parser.add_argument("-Sy", "--update", action="store", type=str,
help="Update the game and specified voiceover pack only (or install if not found)")
parser.add_argument("-Sv", "--update-voiceover", action="store_true",
parser.add_argument("-Sv", "--update-voiceover", action="store", type=str,
help="Update the voiceover pack only (or install if not found)")
parser.add_argument("-Syu", "--update-all", action="store_true",
help="Update the game and all installed voiceover packs (or install if not found)")
@ -125,7 +190,7 @@ def main():
args = parser.parse_args()
interactive_mode = not args.install and not args.install_from_file and not args.patch and not args.update and not \
args.remove and not args.remove_patch and not args.remove_voiceover and not args.get_game_version and not \
args.install_voiceover_from_file
args.install_voiceover_from_file and not args.update_voiceover
if args.temporary_dir:
args.temporary_dir.mkdir(parents=True, exist_ok=True)
@ -150,7 +215,10 @@ def main():
ui.install_game()
if args.update:
ui.update_game()
ui.update_game_voiceover(args.update)
if args.update_voiceover:
ui.update_voiceover(args.update_voiceover)
if args.install_from_file:
ui.install_from_file(args.install_from_file)