Merge branch 'updater' into for_webui

This commit is contained in:
misyaguziya
2024-10-08 18:04:08 +09:00
4 changed files with 40 additions and 84 deletions

View File

@@ -57,6 +57,10 @@ class Config:
def GITHUB_URL(self): def GITHUB_URL(self):
return self._GITHUB_URL return self._GITHUB_URL
@property
def UPDATER_URL(self):
return self._UPDATER_URL
@property @property
def BOOTH_URL(self): def BOOTH_URL(self):
return self._BOOTH_URL return self._BOOTH_URL
@@ -961,6 +965,7 @@ class Config:
self._PATH_LOGS = os_path.join(self._PATH_LOCAL, "logs") self._PATH_LOGS = os_path.join(self._PATH_LOCAL, "logs")
os_makedirs(self._PATH_LOGS, exist_ok=True) os_makedirs(self._PATH_LOGS, exist_ok=True)
self._GITHUB_URL = "https://api.github.com/repos/misyaguziya/VRCT/releases/latest" self._GITHUB_URL = "https://api.github.com/repos/misyaguziya/VRCT/releases/latest"
self._UPDATER_URL = "https://api.github.com/repos/misyaguziya/VRCT_updater/releases/latest"
self._BOOTH_URL = "https://misyaguziya.booth.pm/" self._BOOTH_URL = "https://misyaguziya.booth.pm/"
self._DOCUMENTS_URL = "https://mzsoftware.notion.site/VRCT-Documents-be79b7a165f64442ad8f326d86c22246" self._DOCUMENTS_URL = "https://mzsoftware.notion.site/VRCT-Documents-be79b7a165f64442ad8f326d86c22246"
self._DEEPL_AUTH_KEY_PAGE_URL = "https://www.deepl.com/ja/account/summary" self._DEEPL_AUTH_KEY_PAGE_URL = "https://www.deepl.com/ja/account/summary"

View File

@@ -351,62 +351,26 @@ class Model:
return update_flag return update_flag
@staticmethod @staticmethod
def updateSoftware(restart:bool=True, download=None, update=None): def updateSoftware():
def updateSoftwareTask(): # try to update at most 5 times
filename = 'VRCT.zip' for _ in range(5):
program_name = 'VRCT.exe'
folder_name = '_internal'
tmp_directory_name = 'tmp'
batch_name = 'update.bat'
current_directory = config.PATH_LOCAL
try: try:
res = requests_get(config.GITHUB_URL) program_name = "update.exe"
current_directory = config.PATH_LOCAL
res = requests_get(config.UPDATER_URL)
assets = res.json()['assets'] assets = res.json()['assets']
url = [i["browser_download_url"] for i in assets if i["name"] == filename][0] url = [i["browser_download_url"] for i in assets if i["name"] == program_name][0]
with tempfile.TemporaryDirectory() as tmp_path: res = requests_get(url, stream=True)
res = requests_get(url, stream=True) with open(os_path.join(current_directory, program_name), 'wb') as file:
file_size = int(res.headers.get('content-length', 0)) for chunk in res.iter_content(chunk_size=1024*5):
total_chunk = 0 file.write(chunk)
with open(os_path.join(tmp_path, filename), 'wb') as file: break
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}")
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: except Exception:
import traceback import traceback
with open('error.log', 'a') as f: with open('error.log', 'a') as f:
traceback.print_exc(file=f) traceback.print_exc(file=f)
webbrowser.open(config.BOOTH_URL, new=2, autoraise=True) # run updater
th_update_software = Thread(target=updateSoftwareTask) Popen(program_name, cwd=current_directory)
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]
Popen(command, cwd=current_directory)
def getListMicHost(self): def getListMicHost(self):
result = [host for host in device_manager.getMicDevices().keys()] result = [host for host in device_manager.getMicDevices().keys()]

View File

@@ -21,20 +21,6 @@ class Controller:
self.run = run self.run = run
# response functions # 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: def updateMicHostList(self) -> None:
self.run( self.run(
200, 200,
@@ -332,6 +318,14 @@ class Controller:
def getVersion(*args, **kwargs) -> dict: def getVersion(*args, **kwargs) -> dict:
return {"status":200, "result":config.VERSION} 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 @staticmethod
def getTransparencyRange(*args, **kwargs) -> dict: def getTransparencyRange(*args, **kwargs) -> dict:
return {"status":200, "result":config.TRANSPARENCY_RANGE} return {"status":200, "result":config.TRANSPARENCY_RANGE}
@@ -1289,16 +1283,6 @@ class Controller:
config.ENABLE_CHECK_ENERGY_SEND = False config.ENABLE_CHECK_ENERGY_SEND = False
return {"status":200, "result":config.ENABLE_CHECK_ENERGY_SEND} 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 @staticmethod
def openFilepathLogs(*args, **kwargs) -> dict: def openFilepathLogs(*args, **kwargs) -> dict:
Popen(['explorer', config.PATH_LOGS.replace('/', '\\')], shell=True) 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: def downloadCtranslate2Weight(self, *args, **kwargs) -> dict:
self.startThreadingDownloadCtranslate2Weight(self.downloadCTranslate2ProgressBar) self.startThreadingDownloadCtranslate2Weight(self.downloadCTranslate2ProgressBar)
return {"status":200} return {"status":200, "result":True}
def downloadWhisperWeight(self, *args, **kwargs) -> dict: def downloadWhisperWeight(self, *args, **kwargs) -> dict:
self.startThreadingDownloadWhisperWeight(self.downloadWhisperProgressBar) self.startThreadingDownloadWhisperWeight(self.downloadWhisperProgressBar)
return {"status":200} return {"status":200, "result":True}
@staticmethod @staticmethod
def messageFormatter(format_type:str, translation:list, message:list) -> str: def messageFormatter(format_type:str, translation:list, message:list) -> str:
@@ -1583,8 +1573,7 @@ class Controller:
# check Software Updated # check Software Updated
printLog("Check Software Updated") printLog("Check Software Updated")
if model.checkSoftwareUpdated() is True: self.checkSoftwareUpdated()
pass
# init logger # init logger
printLog("Init Logger") printLog("Init Logger")

View File

@@ -10,9 +10,6 @@ from utils import printLog, printResponse, encodeBase64
controller = Controller() controller = Controller()
run_mapping = { run_mapping = {
"download_software":"/run/download_software",
"update_software":"/run/update_software",
"transcription_mic":"/run/transcription_send_mic_message", "transcription_mic":"/run/transcription_send_mic_message",
"transcription_speaker":"/run/transcription_receive_speaker_message", "transcription_speaker":"/run/transcription_receive_speaker_message",
@@ -35,6 +32,8 @@ run_mapping = {
"mic_host_list":"/run/mic_host_list", "mic_host_list":"/run/mic_host_list",
"mic_device_list":"/run/mic_device_list", "mic_device_list":"/run/mic_device_list",
"speaker_device_list":"/run/speaker_device_list", "speaker_device_list":"/run/speaker_device_list",
"update_software_flag":"/run/update_software_flag",
} }
controller.setRunMapping(run_mapping) controller.setRunMapping(run_mapping)
@@ -85,6 +84,8 @@ mapping = {
"/run/swap_your_language_and_target_language": {"status": True, "variable":controller.swapYourLanguageAndTargetLanguage}, "/run/swap_your_language_and_target_language": {"status": True, "variable":controller.swapYourLanguageAndTargetLanguage},
"/run/update_software": {"status": True, "variable":controller.updateSoftware},
# Config Window # Config Window
# Appearance # Appearance
"/get/data/version": {"status": True, "variable":controller.getVersion}, "/get/data/version": {"status": True, "variable":controller.getVersion},
@@ -304,9 +305,6 @@ mapping = {
"/set/data/osc_port": {"status": True, "variable":controller.setOscPort}, "/set/data/osc_port": {"status": True, "variable":controller.setOscPort},
"/run/open_filepath_config_file": {"status": True, "variable":controller.openFilepathConfigFile}, "/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: class Main: