From 59db4d807e5fabc1a4ea0b64d0c1a9185ccd97f5 Mon Sep 17 00:00:00 2001 From: AuroraZiling <2935876049@qq.com> Date: Wed, 17 May 2023 22:13:47 +0800 Subject: [PATCH] =?UTF-8?q?[0.1.3]=20=E5=AF=BB=E6=89=BE=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E6=97=B6=E4=B8=8D=E4=BC=9A=E5=A0=B5=E5=A1=9E=E4=B8=BB=E7=BA=BF?= =?UTF-8?q?=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/assets/configs/application.json | 2 +- .../GachaReport/MihoyoAPI/by_web_cache.py | 4 +- .../Core/GachaReport/gacha_report_utils.py | 6 ++- .../Views/ViewFunctions/settingsFunctions.py | 29 ++++++++++++- src/modules/Views/gacha_report_frame.py | 4 +- src/modules/Views/settings_frame.py | 41 ++++++++++++------- 6 files changed, 63 insertions(+), 23 deletions(-) diff --git a/src/assets/configs/application.json b/src/assets/configs/application.json index 25f92bb..a0aa40c 100644 --- a/src/assets/configs/application.json +++ b/src/assets/configs/application.json @@ -1,4 +1,4 @@ { - "application_version": "0.1.1", + "application_version": "0.1.3", "ui_version": "0.8.7" } \ No newline at end of file diff --git a/src/modules/Core/GachaReport/MihoyoAPI/by_web_cache.py b/src/modules/Core/GachaReport/MihoyoAPI/by_web_cache.py index 72042ac..0dfa2b3 100644 --- a/src/modules/Core/GachaReport/MihoyoAPI/by_web_cache.py +++ b/src/modules/Core/GachaReport/MihoyoAPI/by_web_cache.py @@ -1,5 +1,5 @@ +import os from pathlib import Path -from urllib import parse from win32api import GetTempFileName, GetTempPath, CopyFile from ....Scripts.Utils.tools import Tools @@ -12,6 +12,8 @@ def getURL(gameDataPath): url = None webCacheData = Path(gameDataPath) / "webCaches/Cache/Cache_Data/data_2" webCacheDataTmp = Path(GetTempFileName(GetTempPath(), f"webCacheData", 0)[0]) + if not os.path.exists(str(webCacheData)): + return None CopyFile(str(webCacheData), str(webCacheDataTmp)) results = [extractAPI(result) for result in [result.split(b"\x00")[0].decode(errors="ignore") for result in webCacheDataTmp.read_bytes().split(b"1/0/")]] results = [result for result in results if result] diff --git a/src/modules/Core/GachaReport/gacha_report_utils.py b/src/modules/Core/GachaReport/gacha_report_utils.py index 725c577..1715b36 100644 --- a/src/modules/Core/GachaReport/gacha_report_utils.py +++ b/src/modules/Core/GachaReport/gacha_report_utils.py @@ -28,8 +28,10 @@ def extractAPI(url): def convertAPI(url): - return "https://api-takumi.mihoyo.com/common/gacha_record/api/getGachaLog?" + url.split("?")[1] - + if url: + return "https://api-takumi.mihoyo.com/common/gacha_record/api/getGachaLog?" + url.split("?")[1] + else: + return None def updateAPI(url, gachaType, size, page, end_id): apiParameters = dict(parse.parse_qsl(parse.urlparse(url).query)) diff --git a/src/modules/Views/ViewFunctions/settingsFunctions.py b/src/modules/Views/ViewFunctions/settingsFunctions.py index f544ecf..7f47861 100644 --- a/src/modules/Views/ViewFunctions/settingsFunctions.py +++ b/src/modules/Views/ViewFunctions/settingsFunctions.py @@ -1,9 +1,13 @@ import os +import time import requests from PySide6.QtCore import Signal, QThread -from ...constant import GITHUB_RELEASE_URL +from ...Scripts.Utils import updater, config_utils +from ...Scripts.Utils.updater import cleanUpdateZip + +utils = config_utils.ConfigUtils() class UpdateThread(QThread): @@ -39,4 +43,25 @@ def run(self): if chunk: f.write(chunk) self.trigger.emit(0, f"正在下载: {f.tell()} 字节/{count} 字节") - self.trigger.emit(2, "更新下载完毕") \ No newline at end of file + self.trigger.emit(2, "更新下载完毕") + + +class IsNeedUpdateThread(QThread): + trigger = Signal(int, object) + + def __init__(self, appVersion, parent=None): + super(IsNeedUpdateThread, self).__init__(parent) + self.appVersion = appVersion + self.newVersion = {} + + def run(self): + cleanUpdateZip() + self.newVersion = updater.isNeedUpdate(utils.appVersion) + if self.newVersion is None: + self.trigger.emit(1, "Asta 无需更新") + return + elif isinstance(self.newVersion, tuple): + self.trigger.emit(2, + f"Asta 更新请求超过限额\n请于{time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(int(self.newVersion[1]['X-RateLimit-Reset'])))}之后再试") + return + self.trigger.emit(0, dict(self.newVersion)) diff --git a/src/modules/Views/gacha_report_frame.py b/src/modules/Views/gacha_report_frame.py index 7cf321b..7b327a1 100644 --- a/src/modules/Views/gacha_report_frame.py +++ b/src/modules/Views/gacha_report_frame.py @@ -144,7 +144,7 @@ def gachaReportStatusChanged(self, msg: tuple): self.headerRightFullUpdateDropBtn.setEnabled(True) def __headerRightFullUpdateDropBtnWebCache(self): - gachaURL = convertAPI(by_web_cache.getURL(getDefaultGameDataPath())) + gachaURL = convertAPI(by_web_cache.getURL(cfg.gameDataFolder.value)) if gachaURL: resp = MessageBox("成功", "请求已被获取,是否更新数据?", self) if resp.exec(): @@ -158,7 +158,7 @@ def __headerRightFullUpdateDropBtnWebCache(self): self.gachaReportThread.start() self.gachaReportThread.trigger.connect(self.gachaReportStatusChanged) else: - MessageBox("失败", "无法从游戏缓存中获取请求", self) + InfoBar.error("失败", "无法从游戏缓存中获取请求", InfoBarPosition.TOP_RIGHT, parent=self) def __headerRightFullUpdateDropBtnURL(self): w = URLDialog("输入URL", "请在下方输入MiHoYoAPI的URL", self) diff --git a/src/modules/Views/settings_frame.py b/src/modules/Views/settings_frame.py index 2e7fd56..0809cb9 100644 --- a/src/modules/Views/settings_frame.py +++ b/src/modules/Views/settings_frame.py @@ -1,4 +1,5 @@ # coding:utf-8 +import json import time from PySide6 import QtGui @@ -11,7 +12,7 @@ from qfluentwidgets import FluentIcon, InfoBarPosition, qconfig from .ViewConfigs.config import cfg -from .ViewFunctions.settingsFunctions import UpdateThread +from .ViewFunctions.settingsFunctions import UpdateThread, IsNeedUpdateThread from ..Core.GachaReport import gacha_report_read from ..Core.GachaReport.gacha_report_utils import getDefaultGameDataPath from ..Scripts.UI import custom_icon, custom_dialog @@ -33,8 +34,11 @@ def __init__(self, parent): self.settingLabel = QLabel("设置", self) self.configPath = utils.configPath + self.newVersion = None self.updateThread = None self.updateThreadStateTooltip = None + self.isNeedUpdateThread = None + self.isNeedUpdateThreadStateTooltip = None # Game @@ -283,21 +287,28 @@ def __updateReturnSignal(self, msg): self.updateThread.start() self.updateThread.trigger.connect(self.updateThreadStatusChanged) + def isNeedUpdateThreadStatusChanged(self, status, content): + if status == 1: + InfoBar.success("提示", content, InfoBarPosition.TOP_RIGHT, parent=self) + elif status == 2: + InfoBar.error("错误", content, InfoBarPosition.TOP_RIGHT, parent=self) + elif status == 0: + self.newVersion = content + self.isNeedUpdateThreadStateTooltip.setState(True) + self.isNeedUpdateThreadStateTooltip = None + w = ComboboxDialog("更新", f"发现新版本: {self.newVersion['tag_name']}\n是否更新?", + ["Coding Artifact (国内推荐)", "Github Release (国外推荐)"], self) + w.returnSignal.connect(self.__updateReturnSignal) + w.exec() + 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() + self.updateCheckCard.setEnabled(False) + self.isNeedUpdateThread = IsNeedUpdateThread(utils.appVersion) + self.isNeedUpdateThreadStateTooltip = StateToolTip("更新", "正在获取版本号...", self) + self.isNeedUpdateThreadStateTooltip.move(5, 5) + self.isNeedUpdateThreadStateTooltip.show() + self.isNeedUpdateThread.start() + self.isNeedUpdateThread.trigger.connect(self.isNeedUpdateThreadStatusChanged) def __connectSignalToSlot(self): cfg.appRestartSig.connect(lambda: InfoBar.warning("警告", self.tr(