From a936740aa4e634043ea2d2fe2ff4a3f4c215e6d4 Mon Sep 17 00:00:00 2001 From: misyaguziya Date: Tue, 3 Oct 2023 02:18:07 +0900 Subject: [PATCH] =?UTF-8?q?=F0=9F=91=8D[Update]=20Model:=20AutoUpdate?= =?UTF-8?q?=E6=A9=9F=E8=83=BD=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.bat | 2 +- model.py | 29 ++++++++++++++++++++++++++++- update.bat | 6 ++++++ 3 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 update.bat diff --git a/build.bat b/build.bat index e7029fb2..8b50ff9c 100644 --- a/build.bat +++ b/build.bat @@ -1 +1 @@ -pyinstaller --onedir --onefile --windowed --clean --icon="./img/vrct_logo_mark_black.ico" --add-data "./img;img/" --add-data "./locales;locales/" --name VRCT --exclude-module numpy --exclude-module pandas --exclude-module matplotlib --exclude-module PyQt5 main.py \ No newline at end of file +pyinstaller --onedir --onefile --windowed --clean --icon="./img/vrct_logo_mark_black.ico" --add-data "./img;img/" --add-data "./locales;locales/" --add-data "./update.bat;./" --name VRCT --exclude-module numpy --exclude-module pandas --exclude-module matplotlib --exclude-module PyQt5 main.py \ No newline at end of file diff --git a/model.py b/model.py index e398c3ba..9916228e 100644 --- a/model.py +++ b/model.py @@ -1,6 +1,9 @@ import sys +from zipfile import ZipFile +from subprocess import Popen from os import makedirs -from os import path as os_path +from os import path as os_path, rename as os_rename, mkdir as os_mkdir +from shutil import rmtree from datetime import datetime from logging import getLogger, FileHandler, Formatter, INFO from time import sleep @@ -229,6 +232,30 @@ class Model: print("software version", "now:", config.VERSION, "new:", new_version) return update_flag + @staticmethod + def updateSoftware(): + filename = 'download.zip' + program_name = 'VRCT.exe' + temporary_name = '_VRCT.exe' + tmp_directory_name = 'tmp' + batch_name = 'update.bat' + current_directory = os_path.dirname(sys.argv[0]) + program_directory = os_path.dirname(__file__) + + os_mkdir(os_path.join(current_directory, tmp_directory_name)) + res = requests_get(config.GITHUB_URL) + url = res.json()['assets'][0]['browser_download_url'] + res = requests_get(url, stream=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.extract(program_name, os_path.join(current_directory, tmp_directory_name)) + os_rename(os_path.join(current_directory, tmp_directory_name, program_name), os_path.join(current_directory, temporary_name)) + rmtree(os_path.join(current_directory, tmp_directory_name)) + command = [os_path.join(program_directory, batch_name), program_name, temporary_name] + Popen(command) + @staticmethod def getListInputHost(): return [host for host in getInputDevices().keys()] diff --git a/update.bat b/update.bat new file mode 100644 index 00000000..cbdef3c4 --- /dev/null +++ b/update.bat @@ -0,0 +1,6 @@ +taskkill /im %1 /F +timeout 2 +del /f %1 +timeout 2 +rename %2 %1 +START "" %1 \ No newline at end of file