From 603ad5bc8b0deb198fbc701bf8ae1e542bf799b5 Mon Sep 17 00:00:00 2001 From: Flern Date: Mon, 30 Dec 2024 17:08:35 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=80=20=E4=BC=98=E5=8C=96=E7=89=88?= =?UTF-8?q?=E6=9C=AC=E6=9B=B4=E6=96=B0=E9=80=BB=E8=BE=91=EF=BC=8C=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E8=B5=84=E6=BA=90=E4=B8=8B=E8=BD=BD=E5=BC=82=E5=B8=B8?= =?UTF-8?q?=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- zhenxun/builtin_plugins/auto_update/_data_source.py | 13 +++++++++++-- zhenxun/utils/manager/resource_manager.py | 10 +++++++--- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/zhenxun/builtin_plugins/auto_update/_data_source.py b/zhenxun/builtin_plugins/auto_update/_data_source.py index e4ee72cc..dae1926e 100644 --- a/zhenxun/builtin_plugins/auto_update/_data_source.py +++ b/zhenxun/builtin_plugins/auto_update/_data_source.py @@ -11,6 +11,10 @@ from zhenxun.services.log import logger from zhenxun.utils.github_utils import GithubUtils from zhenxun.utils.github_utils.models import RepoInfo from zhenxun.utils.http_utils import AsyncHttpx +from zhenxun.utils.manager.resource_manager import ( + DownloadResourceException, + ResourceManager, +) from zhenxun.utils.platform import PlatformUtils from .config import ( @@ -171,7 +175,7 @@ class UpdateManage: url = None new_version = None repo_info = GithubUtils.parse_github_url(DEFAULT_GITHUB_URL) - if version_type in {"dev", "main"}: + if version_type in {"main"}: repo_info.branch = version_type new_version = await cls.__get_version_from_repo(repo_info) if new_version: @@ -203,8 +207,13 @@ class UpdateManage: if await AsyncHttpx.download_file(url, download_file, stream=True): logger.debug("下载真寻最新版文件完成...", "检查更新") await _file_handle(new_version) + result = "版本更新完成\n" + try: + await ResourceManager.init_resources(True) + except DownloadResourceException: + result += "资源下载失败..." return ( - f"版本更新完成\n" + f"{result}\n" f"版本: {cur_version} -> {new_version}\n" "请重新启动真寻以完成更新!" ) diff --git a/zhenxun/utils/manager/resource_manager.py b/zhenxun/utils/manager/resource_manager.py index ea4d63c3..e8a9c737 100644 --- a/zhenxun/utils/manager/resource_manager.py +++ b/zhenxun/utils/manager/resource_manager.py @@ -11,6 +11,10 @@ from zhenxun.utils.http_utils import AsyncHttpx CMD_STRING = "ResourceManager" +class DownloadResourceException(Exception): + pass + + class ResourceManager: GITHUB_URL = "https://github.com/zhenxun-org/zhenxun-bot-resources/tree/main" @@ -23,8 +27,8 @@ class ResourceManager: UNZIP_PATH = None @classmethod - async def init_resources(cls): - if FONT_PATH.exists() and os.listdir(FONT_PATH): + async def init_resources(cls, force: bool = False): + if (FONT_PATH.exists() and os.listdir(FONT_PATH)) and not force: return if cls.TMP_PATH.exists(): logger.debug( @@ -66,7 +70,7 @@ class ResourceManager: url = await repo_info.get_archive_download_urls() logger.debug("开始下载resources资源包...", CMD_STRING) if not await AsyncHttpx.download_file(url, cls.ZIP_FILE, stream=True): - raise Exception("下载resources资源包失败...") + raise DownloadResourceException("下载resources资源包失败...") logger.debug("下载resources资源文件压缩包完成...", CMD_STRING) tf = zipfile.ZipFile(cls.ZIP_FILE) tf.extractall(cls.TMP_PATH)