feat(core): 优化主窗口和管理器功能

- 在主窗口中重构初始化逻辑,增强UI组件的管理和信号连接,提升代码可读性。
- 添加资源验证和加载测试功能,确保关键资源文件的完整性和可用性。
- 更新下载管理器和离线模式管理器,优化线程管理和状态更新,提升用户体验。
- 增强日志记录,确保在关键操作中提供详细的调试信息,便于后续排查和用户反馈。
- 删除不再使用的进度窗口创建函数,改为由UIManager管理,提升代码整洁性。
This commit is contained in:
hyb-oyqq
2025-08-11 17:42:52 +08:00
parent dc433a2ac9
commit 68bbafc564
12 changed files with 842 additions and 551 deletions

View File

@@ -17,6 +17,11 @@ from core.managers.cloudflare_optimizer import CloudflareOptimizer
from core.managers.download_task_manager import DownloadTaskManager
from core.handlers.extraction_handler import ExtractionHandler
from utils.logger import setup_logger
from utils.url_censor import censor_url
from utils.helpers import (
HashManager, AdminPrivileges, msgbox_frame, HostsManager
)
from workers.download import DownloadThread, ProgressWindow
# 初始化logger
logger = setup_logger("download_manager")
@@ -41,6 +46,12 @@ class DownloadManager:
self.download_task_manager = DownloadTaskManager(main_window, self.download_thread_level)
self.extraction_handler = ExtractionHandler(main_window)
self.extraction_thread = None
self.progress_window = None
# 调试管理器
self.debug_manager = getattr(main_window, 'debug_manager', None)
def file_dialog(self):
"""显示文件夹选择对话框,选择游戏安装目录"""
self.selected_folder = QtWidgets.QFileDialog.getExistingDirectory(
@@ -1058,4 +1069,41 @@ class DownloadManager:
plugin_path = os.path.join(PLUGIN, GAME_INFO[game_version]["plugin_path"])
self.download_queue.append((url, game_folder, game_version, _7z_path, plugin_path))
elif debug_mode:
logger.warning(f"DEBUG: 未找到 {game_version} 的下载URL")
logger.warning(f"DEBUG: 未找到 {game_version} 的下载URL")
def graceful_stop_threads(self, threads_dict, timeout_ms=2000):
"""优雅地停止一组线程.
Args:
threads_dict (dict): 线程名字和线程对象的字典.
timeout_ms (int): 等待线程自然结束的超时时间.
"""
for name, thread_obj in threads_dict.items():
if not thread_obj or not hasattr(thread_obj, 'isRunning') or not thread_obj.isRunning():
continue
try:
if hasattr(thread_obj, 'requestInterruption'):
thread_obj.requestInterruption()
if thread_obj.wait(timeout_ms):
if self.debug_manager:
self.debug_manager.log_debug(f"线程 {name} 已优雅停止.")
else:
if self.debug_manager:
self.debug_manager.log_warning(f"线程 {name} 超时,强制终止.")
thread_obj.terminate()
thread_obj.wait(1000) # a short wait after termination
except Exception as e:
if self.debug_manager:
self.debug_manager.log_error(f"停止线程 {name} 时发生错误: {e}")
def on_game_directories_identified(self, game_dirs):
"""当游戏目录识别完成后的回调.
Args:
game_dirs: 识别到的游戏目录
"""
self.main_window.hide_loading_dialog()
self.main_window.setEnabled(True)
self.main_window.patch_detector.on_offline_pre_hash_finished(updated_status, game_dirs)