👍️[Update] Controller : software update の処理を追加

This commit is contained in:
misyaguziya
2024-10-07 10:37:45 +09:00
parent 9abf8742f7
commit 94889f5b30
3 changed files with 37 additions and 86 deletions

View File

@@ -351,61 +351,25 @@ class Model:
return update_flag return update_flag
@staticmethod @staticmethod
def updateSoftware(restart:bool=True, download=None, update=None): def updateSoftware():
def updateSoftwareTask(): try:
filename = 'VRCT.zip' program_name = "updater.exe"
program_name = 'VRCT.exe' release_url = "https://api.github.com/repos/misyaguziya/VRCT_updater/releases/latest"
folder_name = '_internal'
tmp_directory_name = 'tmp'
batch_name = 'update.bat'
current_directory = config.PATH_LOCAL 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(url, stream=True)
res = requests_get(config.GITHUB_URL) with open(os_path.join(current_directory, program_name), 'wb') as file:
assets = res.json()['assets'] for chunk in res.iter_content(chunk_size=1024*5):
url = [i["browser_download_url"] for i in assets if i["name"] == filename][0] file.write(chunk)
with tempfile.TemporaryDirectory() as tmp_path: except Exception:
res = requests_get(url, stream=True) import traceback
file_size = int(res.headers.get('content-length', 0)) with open('error.log', 'a') as f:
total_chunk = 0 traceback.print_exc(file=f)
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}")
with ZipFile(os_path.join(tmp_path, filename)) as zf: command = [current_directory, program_name]
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]
Popen(command, cwd=current_directory) Popen(command, cwd=current_directory)
def getListMicHost(self): def getListMicHost(self):

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: