From f86cb7aa7e1f338557544e3848442f47d9b30acb Mon Sep 17 00:00:00 2001 From: hyb-oyqq <1512383570@qq.com> Date: Thu, 24 Jul 2025 16:29:30 +0800 Subject: [PATCH] =?UTF-8?q?refactor(core):=20=E4=BC=98=E5=8C=96=E6=B6=88?= =?UTF-8?q?=E6=81=AF=E6=A1=86=E6=98=BE=E7=A4=BA=E5=92=8C=E4=B8=8B=E8=BD=BD?= =?UTF-8?q?=E6=B5=81=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 修改 hash_pop_window 函数,增加检查类型参数 - 优化 Cloudflare 优选失败和成功消息框显示 - 调整下载前后检查的消息框内容 - 改进解压缩后的文件检查流程 --- source/core/download_manager.py | 76 ++++++++++++++++++++++++++------- source/main_window.py | 2 +- source/utils/helpers.py | 21 ++++++++- 3 files changed, 80 insertions(+), 19 deletions(-) diff --git a/source/core/download_manager.py b/source/core/download_manager.py index 5023e53..a11fe98 100644 --- a/source/core/download_manager.py +++ b/source/core/download_manager.py @@ -4,7 +4,7 @@ import json from collections import deque from urllib.parse import urlparse -from PySide6 import QtWidgets +from PySide6 import QtWidgets, QtCore from PySide6.QtCore import Qt from PySide6.QtGui import QIcon, QPixmap @@ -143,7 +143,7 @@ class DownloadManager: self.main_window.ui.start_install_btn.setEnabled(False) # 显示哈希检查窗口 - self.main_window.hash_msg_box = self.main_window.hash_manager.hash_pop_window() + self.main_window.hash_msg_box = self.main_window.hash_manager.hash_pop_window(check_type="pre") # 执行预检查 install_paths = self.get_install_paths() @@ -185,7 +185,7 @@ class DownloadManager: # 询问用户是否使用Cloudflare加速 msg_box = QtWidgets.QMessageBox(self.main_window) msg_box.setWindowTitle(f"下载优化 - {APP_NAME}") - msg_box.setText("是否愿意通过Cloudflare加速来优化下载速度?\n\n这将临时修改系统的hosts文件,并需要管理员权限。") + msg_box.setText("是否愿意通过Cloudflare加速来优化下载速度?\n\n这将临时修改系统的hosts文件,并需要管理员权限。如您的杀毒软件提醒有软件正在修改hosts文件,请注意放行。") # 设置Cloudflare图标 cf_icon_path = resource_path("IMG/ICO/cloudflare_logo_icon.ico") @@ -293,11 +293,33 @@ class DownloadManager: # 显示优选结果 if not ip: - QtWidgets.QMessageBox.warning( - self.main_window, - f"优选失败 - {APP_NAME}", - "\n未能找到合适的Cloudflare IP,将使用默认网络进行下载。\n" - ) + msg_box = QtWidgets.QMessageBox(self.main_window) + msg_box.setWindowTitle(f"优选失败 - {APP_NAME}") + msg_box.setText("\n未能找到合适的Cloudflare IP,将使用默认网络进行下载。\n\n10秒后自动继续...") + msg_box.setIcon(QtWidgets.QMessageBox.Icon.Warning) + ok_button = msg_box.addButton("确定 (10)", QtWidgets.QMessageBox.ButtonRole.AcceptRole) + + # 创建计时器实现倒计时 + countdown = 10 + timer = QtCore.QTimer(self.main_window) + + def update_countdown(): + nonlocal countdown + countdown -= 1 + ok_button.setText(f"确定 ({countdown})") + if countdown <= 0: + timer.stop() + if msg_box.isVisible(): + msg_box.accept() + + timer.timeout.connect(update_countdown) + timer.start(1000) # 每秒更新一次 + + # 显示对话框,但不阻塞主线程 + msg_box.open() + + # 连接关闭信号以停止计时器 + msg_box.finished.connect(timer.stop) else: # 应用优选IP到hosts文件 if self.download_queue: @@ -308,11 +330,33 @@ class DownloadManager: self.hosts_manager.clean_hostname_entries(hostname) if self.hosts_manager.apply_ip(hostname, ip): - QtWidgets.QMessageBox.information( - self.main_window, - f"成功 - {APP_NAME}", - f"\n已将优选IP ({ip}) 应用到hosts文件。\n" - ) + msg_box = QtWidgets.QMessageBox(self.main_window) + msg_box.setWindowTitle(f"成功 - {APP_NAME}") + msg_box.setText(f"\n已将优选IP ({ip}) 应用到hosts文件。\n\n10秒后自动继续...") + msg_box.setIcon(QtWidgets.QMessageBox.Icon.Information) + ok_button = msg_box.addButton("确定 (10)", QtWidgets.QMessageBox.ButtonRole.AcceptRole) + + # 创建计时器实现倒计时 + countdown = 10 + timer = QtCore.QTimer(self.main_window) + + def update_countdown(): + nonlocal countdown + countdown -= 1 + ok_button.setText(f"确定 ({countdown})") + if countdown <= 0: + timer.stop() + if msg_box.isVisible(): + msg_box.accept() + + timer.timeout.connect(update_countdown) + timer.start(1000) # 每秒更新一次 + + # 显示对话框,但不阻塞主线程 + msg_box.open() + + # 连接关闭信号以停止计时器 + msg_box.finished.connect(timer.stop) else: QtWidgets.QMessageBox.critical( self.main_window, @@ -320,8 +364,8 @@ class DownloadManager: "\n修改hosts文件失败,请检查程序是否以管理员权限运行。\n" ) - # 开始下载 - self.next_download_task() + # 计时器结束或用户点击确定时,继续下载 + QtCore.QTimer.singleShot(10000, self.next_download_task) def next_download_task(self): """处理下载队列中的下一个任务""" @@ -450,7 +494,7 @@ class DownloadManager: return # 下载成功,开始解压缩 - self.main_window.hash_msg_box = self.main_window.hash_manager.hash_pop_window() + self.main_window.hash_msg_box = self.main_window.hash_manager.hash_pop_window(check_type="extraction") # 创建并启动解压线程 self.main_window.extraction_thread = self.main_window.create_extraction_thread( diff --git a/source/main_window.py b/source/main_window.py index b3534d9..e5cb6aa 100644 --- a/source/main_window.py +++ b/source/main_window.py @@ -255,7 +255,7 @@ class MainWindow(QMainWindow): # 禁用退出按钮 self.ui.exit_btn.setEnabled(False) - self.hash_msg_box = self.hash_manager.hash_pop_window() + self.hash_msg_box = self.hash_manager.hash_pop_window(check_type="after") install_paths = self.download_manager.get_install_paths() diff --git a/source/utils/helpers.py b/source/utils/helpers.py index 09f48b5..1e2ffb7 100644 --- a/source/utils/helpers.py +++ b/source/utils/helpers.py @@ -99,8 +99,25 @@ class HashManager: print(f"Error calculating hash for {file_path}: {e}") return results - def hash_pop_window(self): - msg_box = msgbox_frame(f"通知 - {APP_NAME}", "\n正在检验文件状态...\n") + def hash_pop_window(self, check_type="default"): + """显示文件检验窗口 + + Args: + check_type: 检查类型,可以是 'pre'(预检查), 'after'(后检查), 'extraction'(解压后检查) + + Returns: + QMessageBox: 消息框实例 + """ + message = "\n正在检验文件状态...\n" + + if check_type == "pre": + message = "\n正在检查游戏文件以确定需要安装的补丁...\n" + elif check_type == "after": + message = "\n正在检验文件完整性...\n" + elif check_type == "extraction": + message = "\n正在验证解压文件的完整性...\n" + + msg_box = msgbox_frame(f"通知 - {APP_NAME}", message) msg_box.open() QtWidgets.QApplication.processEvents() return msg_box