From 8b6b2f673f49b0d17d9023c4a6caed7512f1a0d1 Mon Sep 17 00:00:00 2001 From: AuroraZiling <2935876049@qq.com> Date: Wed, 17 May 2023 13:17:08 +0800 Subject: [PATCH] =?UTF-8?q?[0.1.2]=20=E6=94=AF=E6=8C=81Coding=20Artifact?= =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + src/assets/configs/application.json | 2 +- src/modules/Scripts/Utils/updater.py | 3 +- .../Views/ViewFunctions/settingsFunctions.py | 29 +++++++++------- src/modules/Views/settings_frame.py | 33 ++++++++++++------- 5 files changed, 42 insertions(+), 26 deletions(-) diff --git a/.gitignore b/.gitignore index bd6b14a..25e8cfd 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,4 @@ /old_src/requestUrl.txt /src/data/ /src/configs/ +/src/temp/ diff --git a/src/assets/configs/application.json b/src/assets/configs/application.json index d010edd..25f92bb 100644 --- a/src/assets/configs/application.json +++ b/src/assets/configs/application.json @@ -1,4 +1,4 @@ { - "application_version": "0.1.2", + "application_version": "0.1.1", "ui_version": "0.8.7" } \ No newline at end of file diff --git a/src/modules/Scripts/Utils/updater.py b/src/modules/Scripts/Utils/updater.py index 7261a96..ce21c61 100644 --- a/src/modules/Scripts/Utils/updater.py +++ b/src/modules/Scripts/Utils/updater.py @@ -23,7 +23,8 @@ def installUpdate(): if os.path.exists(f"{utils.workingDir}/asta.py"): return with open('temp/update.bat', 'w') as f: - f.write(UPDATE_SCRIPT_MODEL.format(filename=os.listdir(f"{utils.workingDir}/temp")[0])) + target = [i for i in os.listdir(f"{utils.workingDir}/temp") if not ".bat" in i] + f.write(UPDATE_SCRIPT_MODEL.format(filename=target[0])) subprocess.Popen( [ diff --git a/src/modules/Views/ViewFunctions/settingsFunctions.py b/src/modules/Views/ViewFunctions/settingsFunctions.py index 3a0c26f..f544ecf 100644 --- a/src/modules/Views/ViewFunctions/settingsFunctions.py +++ b/src/modules/Views/ViewFunctions/settingsFunctions.py @@ -9,22 +9,27 @@ class UpdateThread(QThread): trigger = Signal(int, str) - def __init__(self, info, parent=None): + def __init__(self, info, downloadWay, parent=None): super(UpdateThread, self).__init__(parent) self.info = info + self.downloadWay = downloadWay def run(self): - self.trigger.emit(0, "正在从 Github Release 获取更新") - try: - compressed_url = self.info['assets'][0]['browser_download_url'] - file_name = self.info['assets'][0]['name'] - except ConnectionError: - self.trigger.emit(1, "更新失败") - return - except requests.exceptions.SSLError: - self.trigger.emit(1, "更新失败") - return - url = compressed_url + self.trigger.emit(0, f"正在从 {self.downloadWay} 获取更新") + if "Github" in self.downloadWay: + try: + compressed_url = self.info['assets'][0]['browser_download_url'] + file_name = self.info['assets'][0]['name'] + except ConnectionError: + self.trigger.emit(1, "更新失败") + return + except requests.exceptions.SSLError: + self.trigger.emit(1, "更新失败") + return + url = compressed_url + else: + url = f"https://sangonomiya-generic.pkg.coding.net/asta/release/[{self.info['tag_name']}]Asta.zip" + file_name = f"Asta.zip" if not os.path.exists('temp'): os.mkdir('temp') resp = requests.get(url, stream=True) diff --git a/src/modules/Views/settings_frame.py b/src/modules/Views/settings_frame.py index 138837b..2e7fd56 100644 --- a/src/modules/Views/settings_frame.py +++ b/src/modules/Views/settings_frame.py @@ -15,6 +15,7 @@ from ..Core.GachaReport import gacha_report_read from ..Core.GachaReport.gacha_report_utils import getDefaultGameDataPath from ..Scripts.UI import custom_icon, custom_dialog +from ..Scripts.UI.custom_dialog import ComboboxDialog from ..Scripts.UI.style_sheet import StyleSheet from ..Scripts.Utils import config_utils, log_recorder as log, updater from ..Scripts.Utils.updater import installUpdate, cleanUpdateZip @@ -270,19 +271,11 @@ def updateThreadStatusChanged(self, status, content): installUpdate() self.updateThreadStateTooltip = None - def __updateCheckCardClicked(self): - cleanUpdateZip() - newVersion = updater.isNeedUpdate(utils.appVersion) - if newVersion is None: - InfoBar.success("提示", "Asta 无需更新", InfoBarPosition.TOP_RIGHT, parent=self.window()) - return - elif isinstance(newVersion, tuple): - InfoBar.error("错误", f"Asta 更新请求超过限额\n请于{time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(int(newVersion[1]['X-RateLimit-Reset'])))}之后再试", InfoBarPosition.TOP_RIGHT, parent=self.window()) - return - w = MessageBox("更新", f"发现新版本: {newVersion['tag_name']}\n是否更新?", self) - if w.exec(): + def __updateReturnSignal(self, msg): + if msg: + downloadWay = "Github Release" if "Github" in msg else "Coding Artifact" self.updateCheckCard.setEnabled(False) - self.updateThread = UpdateThread(newVersion) + self.updateThread = UpdateThread(self.newVersion, downloadWay) self.updateThreadStateTooltip = StateToolTip("正在更新", "下载更新中...", self) self.updateThreadStateTooltip.closedSignal.connect(self.__updateThreadStateTooltipClosed) self.updateThreadStateTooltip.move(5, 5) @@ -290,6 +283,22 @@ def __updateCheckCardClicked(self): self.updateThread.start() self.updateThread.trigger.connect(self.updateThreadStatusChanged) + def __updateCheckCardClicked(self): + cleanUpdateZip() + self.newVersion = updater.isNeedUpdate(utils.appVersion) + if self.newVersion is None: + InfoBar.success("提示", "Asta 无需更新", InfoBarPosition.TOP_RIGHT, parent=self.window()) + return + elif isinstance(self.newVersion, tuple): + InfoBar.error("错误", + f"Asta 更新请求超过限额\n请于{time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(int(self.newVersion[1]['X-RateLimit-Reset'])))}之后再试", + InfoBarPosition.TOP_RIGHT, parent=self.window()) + return + w = ComboboxDialog("更新", f"发现新版本: {self.newVersion['tag_name']}\n是否更新?", + ["Coding Artifact (国内推荐)", "Github Release (国外推荐)"], self) + w.returnSignal.connect(self.__updateReturnSignal) + w.exec() + def __connectSignalToSlot(self): cfg.appRestartSig.connect(lambda: InfoBar.warning("警告", self.tr( "更改将在应用重启后更新"), parent=self.window(), position=InfoBarPosition.TOP_RIGHT))