[Update] Model : Update処理をthreads処理に変更
- fncにプログレスの数値情報を設定できるように追加 - スプラッシュUIから処理が抜けるのでUIの修正が必要
This commit is contained in:
@@ -8,9 +8,9 @@ from utils import getKeyByValue, isUniqueStrings, strPctToInt
|
|||||||
import argparse
|
import argparse
|
||||||
|
|
||||||
# Common
|
# Common
|
||||||
def callbackUpdateSoftware():
|
def callbackUpdateSoftware(fnc=None):
|
||||||
setMainWindowGeometry()
|
setMainWindowGeometry()
|
||||||
model.updateSoftware()
|
model.updateSoftware(restart=True, fnc=fnc)
|
||||||
|
|
||||||
def callbackRestartSoftware():
|
def callbackRestartSoftware():
|
||||||
setMainWindowGeometry()
|
setMainWindowGeometry()
|
||||||
|
|||||||
68
model.py
68
model.py
@@ -256,35 +256,51 @@ class Model:
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def updateSoftware(restart:bool=True, func=None):
|
def updateSoftware(restart:bool=True, func=None):
|
||||||
filename = 'VRCT.zip'
|
def updateSoftwareTask():
|
||||||
program_name = 'VRCT.exe'
|
filename = 'VRCT.zip'
|
||||||
folder_name = '_internal'
|
program_name = 'VRCT.exe'
|
||||||
tmp_directory_name = 'tmp'
|
folder_name = '_internal'
|
||||||
batch_name = 'update.bat'
|
tmp_directory_name = 'tmp'
|
||||||
current_directory = config.PATH_LOCAL
|
batch_name = 'update.bat'
|
||||||
|
current_directory = config.PATH_LOCAL
|
||||||
|
|
||||||
try:
|
try:
|
||||||
res = requests_get(config.GITHUB_URL)
|
res = requests_get(config.GITHUB_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"] == filename][0]
|
||||||
with tempfile.TemporaryDirectory() as tmp_path:
|
with tempfile.TemporaryDirectory() as tmp_path:
|
||||||
res = requests_get(url, stream=True)
|
res = requests_get(url, stream=True)
|
||||||
file_size = int(res.headers.get('content-length', 0))
|
file_size = int(res.headers.get('content-length', 0))
|
||||||
total_chunk = 0
|
total_chunk = 0
|
||||||
with open(os_path.join(tmp_path, filename), 'wb') as file:
|
with open(os_path.join(tmp_path, filename), 'wb') as file:
|
||||||
for chunk in res.iter_content(chunk_size=1024*5):
|
for chunk in res.iter_content(chunk_size=1024*5):
|
||||||
file.write(chunk)
|
file.write(chunk)
|
||||||
if isinstance(func, Callable):
|
|
||||||
total_chunk += len(chunk)
|
total_chunk += len(chunk)
|
||||||
func(total_chunk/file_size)
|
if isinstance(func, Callable):
|
||||||
|
func(total_chunk/file_size)
|
||||||
|
print(f"downloaded {total_chunk}/{file_size}")
|
||||||
|
|
||||||
with ZipFile(os_path.join(tmp_path, filename)) as zf:
|
with ZipFile(os_path.join(tmp_path, filename)) as zf:
|
||||||
zf.extractall(os_path.join(current_directory, tmp_directory_name))
|
total_files = len(zf.infolist())
|
||||||
copyfile(os_path.join(current_directory, folder_name, "batch", batch_name), os_path.join(current_directory, batch_name))
|
extracted_files = 0
|
||||||
command = [os_path.join(current_directory, batch_name), program_name, folder_name, tmp_directory_name, str(restart)]
|
for file_info in zf.infolist():
|
||||||
Popen(command, cwd=current_directory)
|
extracted_files += 1
|
||||||
except Exception:
|
zf.extract(file_info, os_path.join(current_directory, tmp_directory_name))
|
||||||
webbrowser.open(config.BOOTH_URL, new=2, autoraise=True)
|
if isinstance(func, Callable):
|
||||||
|
func(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 as e:
|
||||||
|
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 = threadFnc(updateSoftwareTask)
|
||||||
|
th_update_software.daemon = True
|
||||||
|
th_update_software.start()
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def reStartSoftware():
|
def reStartSoftware():
|
||||||
|
|||||||
Reference in New Issue
Block a user