From 90e631726c6519151ed3dd399f0121d5ec876d3e Mon Sep 17 00:00:00 2001 From: misyaguziya Date: Sat, 6 Jan 2024 22:13:56 +0900 Subject: [PATCH 1/3] =?UTF-8?q?=F0=9F=91=8D[Update]=20Model=20:=20Update?= =?UTF-8?q?=E5=87=A6=E7=90=86=E3=82=92tempfile=E3=82=92=E4=BD=BF=E7=94=A8?= =?UTF-8?q?=E3=81=99=E3=82=8B=E5=87=A6=E7=90=86=E3=81=AB=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- model.py | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/model.py b/model.py index bff713f4..5fbb5825 100644 --- a/model.py +++ b/model.py @@ -1,8 +1,8 @@ +import tempfile from zipfile import ZipFile from subprocess import Popen from os import makedirs as os_makedirs from os import path as os_path -from os import remove as os_remove from shutil import copyfile from datetime import datetime from logging import getLogger, FileHandler, Formatter, INFO @@ -12,6 +12,8 @@ from threading import Thread, Event from requests import get as requests_get import webbrowser +from tqdm import tqdm +from typing import Callable from flashtext import KeywordProcessor from models.translation.translation_translator import Translator from models.transcription.transcription_utils import getInputDevices, getDefaultOutputDevice @@ -265,7 +267,7 @@ class Model: return update_flag @staticmethod - def updateSoftware(restart:bool=True): + def updateSoftware(restart:bool=True, func=None): filename = 'VRCT.zip' program_name = 'VRCT.exe' folder_name = '_internal' @@ -277,14 +279,22 @@ class Model: res = requests_get(config.GITHUB_URL) assets = res.json()['assets'] url = [i["browser_download_url"] for i in assets if i["name"] == filename][0] - res = requests_get(url, stream=True) - os_makedirs(os_path.join(current_directory, tmp_directory_name), exist_ok=True) - with open(os_path.join(current_directory, tmp_directory_name, filename), 'wb') as file: - for chunk in res.iter_content(chunk_size=1024): - file.write(chunk) - with ZipFile(os_path.join(current_directory, tmp_directory_name, filename)) as zf: - zf.extractall(os_path.join(current_directory, tmp_directory_name)) - os_remove(os_path.join(current_directory, tmp_directory_name, filename)) + with tempfile.TemporaryDirectory() as tmp_path: + res = requests_get(url, stream=True) + file_size = int(res.headers.get('content-length', 0)) + pbar = tqdm(total=file_size, unit="B", unit_scale=True) + 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) + pbar.update(len(chunk)) + if isinstance(func, Callable): + total_chunk += len(chunk) + func(total_chunk/file_size) + pbar.close() + + with ZipFile(os_path.join(tmp_path, filename)) as zf: + zf.extractall(os_path.join(current_directory, tmp_directory_name)) 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) From bed525297ec055f930f72f55dacd02f1f9f1a186 Mon Sep 17 00:00:00 2001 From: misyaguziya Date: Sat, 6 Jan 2024 22:15:42 +0900 Subject: [PATCH 2/3] =?UTF-8?q?=F0=9F=91=8D[Update]=20Config=20:=20version?= =?UTF-8?q?=202.0.1=20->=202.0.2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config.py b/config.py index d5d57b4a..030ae2cb 100644 --- a/config.py +++ b/config.py @@ -649,7 +649,7 @@ class Config: def init_config(self): # Read Only - self._VERSION = "2.0.1" + self._VERSION = "2.0.2" self._ENABLE_SPEAKER2CHATBOX = False # Speaker2Chatbox self._LOCAL_PATH = os_path.dirname(sys.argv[0]) self._PATH_CONFIG = os_path.join(self._LOCAL_PATH, "config.json") From ad92e1b5f7c1e351fda18a7aad500e58d83d3220 Mon Sep 17 00:00:00 2001 From: misyaguziya Date: Sat, 6 Jan 2024 23:15:36 +0900 Subject: [PATCH 3/3] =?UTF-8?q?=F0=9F=90=9B[bugfix]=20Model=20:=20Update?= =?UTF-8?q?=E5=87=A6=E7=90=86=E3=81=AE=E4=B8=8D=E8=A6=81=E3=81=AACommand?= =?UTF-8?q?=E3=82=92=E5=89=8A=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- batch/update.bat | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/batch/update.bat b/batch/update.bat index e0e83855..09bd4acb 100644 --- a/batch/update.bat +++ b/batch/update.bat @@ -16,5 +16,5 @@ rmdir /s /q %local_path%%folder_tmp% if %restart% == True ( START "" %local_path%%exe_name% ) -pause + del /f "%~dp0%~nx0" \ No newline at end of file