feat(core): 增强主窗口功能和解压处理

- 在主窗口中添加解压进度窗口和解压线程创建功能,提升用户体验。
- 优化退出逻辑,确保在用户确认退出后和强制退出时均执行hosts相关操作。
- 移除不必要的hosts操作,简化代码结构。
- 更新UI管理器,确保加载对话框的显示和隐藏逻辑更加清晰。
This commit is contained in:
hyb-oyqq
2025-08-12 13:14:32 +08:00
parent 7d71ffe099
commit 1b6d275433
3 changed files with 40 additions and 34 deletions

View File

@@ -822,35 +822,6 @@ class OfflineModeManager:
# 添加到安装任务列表
install_tasks.append((patch_file, game_folder, game_version, _7z_path, plugin_path))
# 检查是否有未找到离线补丁文件的游戏
if self.missing_offline_patches:
if debug_mode:
logger.debug(f"DEBUG: 有未找到离线补丁文件的游戏: {self.missing_offline_patches}")
# 询问用户是否切换到在线模式
msg_box = msgbox_frame(
f"离线安装信息 - {self.app_name}",
f"\n本地未发现对应离线文件,是否切换为在线模式安装?\n\n以下游戏未找到对应的离线补丁文件:\n\n{chr(10).join(self.missing_offline_patches)}\n",
QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No
)
result = msg_box.exec()
if result == QMessageBox.StandardButton.Yes:
if debug_mode:
logger.debug("DEBUG: 用户选择切换到在线模式")
# 切换到在线模式
if hasattr(self.main_window, 'ui_manager'):
self.main_window.ui_manager.switch_work_mode("online")
# 直接启动下载流程
self.main_window.setEnabled(True)
# 保存当前选择的游戏列表,以便在线模式使用
missing_games = self.missing_offline_patches.copy()
# 启动下载流程
QTimer.singleShot(500, lambda: self._start_online_download(missing_games))
return True
# 开始执行第一个安装任务
if install_tasks:
if debug_mode:
@@ -923,8 +894,8 @@ class OfflineModeManager:
else:
installed_msg = ""
# 使用QTimer延迟显示询问对话框确保安装结果窗口先显示并关闭
QTimer.singleShot(500, lambda: self._show_missing_patches_dialog(installed_msg))
# 在安装完成后询问用户是否切换到在线模式
self._show_missing_patches_dialog(installed_msg)
else:
# 恢复UI状态
self.main_window.setEnabled(True)

View File

@@ -1066,7 +1066,8 @@ class UIManager:
self.loading_dialog.show()
# force UI update
QMessageBox.QApplication.processEvents()
from PySide6.QtWidgets import QApplication
QApplication.processEvents()
def hide_loading_dialog(self):
"""隐藏并销毁加载对话框."""

View File

@@ -85,6 +85,8 @@ class MainWindow(QMainWindow):
self.progress_window = None
self.pre_hash_thread = None
self.hash_thread = None
self.installed_status = {}
self.hash_msg_box = None
# 验证关键资源
self._verify_resources()
@@ -468,8 +470,9 @@ class MainWindow(QMainWindow):
self.download_manager.graceful_stop_threads(threads_to_stop)
self.download_manager.hosts_manager.restore()
self.download_manager.hosts_manager.check_and_clean_all_entries()
# 移除此处的hosts操作
# self.download_manager.hosts_manager.restore()
# self.download_manager.hosts_manager.check_and_clean_all_entries()
self.debug_manager.stop_logging()
if not force_exit:
@@ -482,6 +485,14 @@ class MainWindow(QMainWindow):
if event:
event.ignore()
return
# 用户确认退出后再执行hosts相关操作
self.download_manager.hosts_manager.restore()
self.download_manager.hosts_manager.check_and_clean_all_entries()
else:
# 强制退出时也需执行hosts相关操作
self.download_manager.hosts_manager.restore()
self.download_manager.hosts_manager.check_and_clean_all_entries()
if event:
event.accept()
@@ -710,6 +721,29 @@ class MainWindow(QMainWindow):
logger.error(f"关闭哈希校验窗口时发生错误: {e}")
self.hash_msg_box = None
def create_extraction_progress_window(self):
"""创建一个用于显示解压进度的窗口
Returns:
QDialog: 配置好的解压进度窗口实例
"""
return self.ui_manager.create_progress_window("解压进度", "正在准备解压...")
def create_extraction_thread(self, patch_file, game_folder, plugin_path, game_version):
"""创建一个解压线程
Args:
patch_file: 补丁文件路径
game_folder: 游戏目录路径
plugin_path: 插件路径
game_version: 游戏版本
Returns:
ExtractionThread: 配置好的解压线程实例
"""
from workers.extraction_thread import ExtractionThread
return ExtractionThread(patch_file, game_folder, plugin_path, game_version, self)