From 94889f5b30365dc88e08c7ec72d708d2c14cf906 Mon Sep 17 00:00:00 2001 From: misyaguziya Date: Mon, 7 Oct 2024 10:37:45 +0900 Subject: [PATCH] =?UTF-8?q?=F0=9F=91=8D=EF=B8=8F[Update]=20Controller=20:?= =?UTF-8?q?=20software=20update=20=E3=81=AE=E5=87=A6=E7=90=86=E3=82=92?= =?UTF-8?q?=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src-python/model.py | 68 ++++++++-------------------------- src-python/webui_controller.py | 45 +++++++++------------- src-python/webui_mainloop.py | 10 ++--- 3 files changed, 37 insertions(+), 86 deletions(-) diff --git a/src-python/model.py b/src-python/model.py index 1b7aec33..52ac1475 100644 --- a/src-python/model.py +++ b/src-python/model.py @@ -351,61 +351,25 @@ class Model: return update_flag @staticmethod - def updateSoftware(restart:bool=True, download=None, update=None): - def updateSoftwareTask(): - filename = 'VRCT.zip' - program_name = 'VRCT.exe' - folder_name = '_internal' - tmp_directory_name = 'tmp' - batch_name = 'update.bat' + def updateSoftware(): + try: + program_name = "updater.exe" + release_url = "https://api.github.com/repos/misyaguziya/VRCT_updater/releases/latest" current_directory = config.PATH_LOCAL + res = requests_get(release_url) + assets = res.json()['assets'] + url = [i["browser_download_url"] for i in assets if i["name"] == program_name][0] - try: - res = requests_get(config.GITHUB_URL) - assets = res.json()['assets'] - url = [i["browser_download_url"] for i in assets if i["name"] == filename][0] - with tempfile.TemporaryDirectory() as tmp_path: - res = requests_get(url, stream=True) - file_size = int(res.headers.get('content-length', 0)) - total_chunk = 0 - with open(os_path.join(tmp_path, filename), 'wb') as file: - for chunk in res.iter_content(chunk_size=1024*5): - file.write(chunk) - total_chunk += len(chunk) - if isinstance(download, Callable): - download(total_chunk/file_size) - print(f"downloaded {total_chunk}/{file_size}") + res = requests_get(url, stream=True) + with open(os_path.join(current_directory, program_name), 'wb') as file: + for chunk in res.iter_content(chunk_size=1024*5): + file.write(chunk) + except Exception: + import traceback + with open('error.log', 'a') as f: + traceback.print_exc(file=f) - with ZipFile(os_path.join(tmp_path, filename)) as zf: - total_files = len(zf.infolist()) - extracted_files = 0 - for file_info in zf.infolist(): - extracted_files += 1 - zf.extract(file_info, os_path.join(current_directory, tmp_directory_name)) - if isinstance(update, Callable): - update(extracted_files/total_files) - print(f"extracted {extracted_files}/{total_files}") - - copyfile(os_path.join(current_directory, folder_name, "batch", batch_name), os_path.join(current_directory, batch_name)) - command = [os_path.join(current_directory, batch_name), program_name, folder_name, tmp_directory_name, str(restart)] - Popen(command, cwd=current_directory) - except Exception: - import traceback - with open('error.log', 'a') as f: - traceback.print_exc(file=f) - webbrowser.open(config.BOOTH_URL, new=2, autoraise=True) - th_update_software = Thread(target=updateSoftwareTask) - th_update_software.daemon = True - th_update_software.start() - - @staticmethod - def reStartSoftware(): - program_name = 'VRCT.exe' - folder_name = '_internal' - batch_name = 'restart.bat' - current_directory = config.PATH_LOCAL - copyfile(os_path.join(current_directory, folder_name, "batch", batch_name), os_path.join(current_directory, batch_name)) - command = [os_path.join(current_directory, batch_name), program_name] + command = [current_directory, program_name] Popen(command, cwd=current_directory) def getListMicHost(self): diff --git a/src-python/webui_controller.py b/src-python/webui_controller.py index 12f42d1d..387d34c8 100644 --- a/src-python/webui_controller.py +++ b/src-python/webui_controller.py @@ -21,20 +21,6 @@ class Controller: self.run = run # response functions - def downloadSoftwareProgressBar(self, progress) -> None: - self.run( - 200, - self.run_mapping["download_software"], - progress, - ) - - def updateSoftwareProgressBar(self, progress) -> None: - self.run( - 200, - self.run_mapping["update_software"], - progress, - ) - def updateMicHostList(self) -> None: self.run( 200, @@ -332,6 +318,14 @@ class Controller: def getVersion(*args, **kwargs) -> dict: return {"status":200, "result":config.VERSION} + def checkSoftwareUpdated(self) -> dict: + update_flag = model.checkSoftwareUpdated() + self.run( + 200, + self.run_mapping["update_software_flag"], + update_flag, + ) + @staticmethod def getTransparencyRange(*args, **kwargs) -> dict: return {"status":200, "result":config.TRANSPARENCY_RANGE} @@ -1289,16 +1283,6 @@ class Controller: config.ENABLE_CHECK_ENERGY_SEND = False return {"status":200, "result":config.ENABLE_CHECK_ENERGY_SEND} - # def updateSoftware(*args, **kwargs) -> dict: - # printLog("Update callbackUpdateSoftware") - # model.updateSoftware(restart=True, download=self.downloadSoftwareProgressBar, update=self.updateSoftwareProgressBar) - # return {"status":200, "result":True} - - # def restartSoftware(*args, **kwargs) -> dict: - # printLog("Restart callbackRestartSoftware") - # model.reStartSoftware() - # return {"status":200, "result":True} - @staticmethod def openFilepathLogs(*args, **kwargs) -> dict: Popen(['explorer', config.PATH_LOGS.replace('/', '\\')], shell=True) @@ -1368,13 +1352,19 @@ class Controller: } } + def updateSoftware(self, *args, **kwargs) -> dict: + th_start_update_software = Thread(target=model.updateSoftware) + th_start_update_software.daemon = True + th_start_update_software.start() + return {"status":200, "result":True} + def downloadCtranslate2Weight(self, *args, **kwargs) -> dict: self.startThreadingDownloadCtranslate2Weight(self.downloadCTranslate2ProgressBar) - return {"status":200} + return {"status":200, "result":True} def downloadWhisperWeight(self, *args, **kwargs) -> dict: self.startThreadingDownloadWhisperWeight(self.downloadWhisperProgressBar) - return {"status":200} + return {"status":200, "result":True} @staticmethod def messageFormatter(format_type:str, translation:list, message:list) -> str: @@ -1583,8 +1573,7 @@ class Controller: # check Software Updated printLog("Check Software Updated") - if model.checkSoftwareUpdated() is True: - pass + self.checkSoftwareUpdated() # init logger printLog("Init Logger") diff --git a/src-python/webui_mainloop.py b/src-python/webui_mainloop.py index 7a588373..e61a3c17 100644 --- a/src-python/webui_mainloop.py +++ b/src-python/webui_mainloop.py @@ -10,9 +10,6 @@ from utils import printLog, printResponse, encodeBase64 controller = Controller() run_mapping = { - "download_software":"/run/download_software", - "update_software":"/run/update_software", - "transcription_mic":"/run/transcription_send_mic_message", "transcription_speaker":"/run/transcription_receive_speaker_message", @@ -35,6 +32,8 @@ run_mapping = { "mic_host_list":"/run/mic_host_list", "mic_device_list":"/run/mic_device_list", "speaker_device_list":"/run/speaker_device_list", + + "update_software_flag":"/run/update_software_flag", } controller.setRunMapping(run_mapping) @@ -85,6 +84,8 @@ mapping = { "/run/swap_your_language_and_target_language": {"status": True, "variable":controller.swapYourLanguageAndTargetLanguage}, + "/run/update_software": {"status": True, "variable":controller.updateSoftware}, + # Config Window # Appearance "/get/data/version": {"status": True, "variable":controller.getVersion}, @@ -304,9 +305,6 @@ mapping = { "/set/data/osc_port": {"status": True, "variable":controller.setOscPort}, "/run/open_filepath_config_file": {"status": True, "variable":controller.openFilepathConfigFile}, - - # "/run/update_software": {"status": True, "variable":controller.updateSoftware}, - # "/run/restart_software": {"status": True, "variable":controller.restartSoftware}, } class Main: