From 575116e45c264221b4175a90d18eae60fcb708a8 Mon Sep 17 00:00:00 2001 From: hyb-oyqq <1512383570@qq.com> Date: Thu, 7 Aug 2025 16:10:11 +0800 Subject: [PATCH] =?UTF-8?q?feat(core):=20=E5=A2=9E=E5=BC=BA=E7=A6=BB?= =?UTF-8?q?=E7=BA=BF=E6=A8=A1=E5=BC=8F=E5=92=8C=E6=97=A5=E5=BF=97=E8=AE=B0?= =?UTF-8?q?=E5=BD=95=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在主窗口中添加离线模式提示弹窗,用户可清晰了解离线模式切换情况。 - 更新离线模式管理器,优化补丁文件扫描和日志记录,确保无论调试模式下均能记录相关信息。 - 在下载管理器和补丁管理器中增强调试信息的记录,提升错误处理能力。 - 更新卸载处理程序,增加详细的日志记录,确保用户操作的透明性和可追溯性。 --- source/core/download_manager.py | 1 + source/core/offline_mode_manager.py | 17 ++- source/core/patch_detector.py | 51 ++++++-- source/core/patch_manager.py | 178 +++++++++++++++++++++++---- source/handlers/uninstall_handler.py | 110 ++++++++++++++++- source/main_window.py | 14 ++- 6 files changed, 333 insertions(+), 38 deletions(-) diff --git a/source/core/download_manager.py b/source/core/download_manager.py index 8ee957c..510de5f 100644 --- a/source/core/download_manager.py +++ b/source/core/download_manager.py @@ -577,6 +577,7 @@ class DownloadManager: """处理下载队列中的下一个任务""" if not self.download_queue: # 所有下载任务都已完成,进行后检查 + debug_mode = self.is_debug_mode() if debug_mode: logger.debug("DEBUG: 所有下载任务完成,进行后检查") # 使用patch_detector进行安装后哈希比较 diff --git a/source/core/offline_mode_manager.py b/source/core/offline_mode_manager.py index dfec152..b08cc34 100644 --- a/source/core/offline_mode_manager.py +++ b/source/core/offline_mode_manager.py @@ -62,8 +62,9 @@ class OfflineModeManager: directory = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) debug_mode = self._is_debug_mode() - if debug_mode: - logger.debug(f"DEBUG: 扫描离线补丁文件,目录: {directory}") + + # 无论是否为调试模式,都记录扫描操作 + logger.info(f"扫描离线补丁文件,目录: {directory}") # 要查找的补丁文件名 patch_files = ["vol.1.7z", "vol.2.7z", "vol.3.7z", "vol.4.7z", "after.7z"] @@ -77,10 +78,19 @@ class OfflineModeManager: if os.path.isfile(file_path): patch_name = file.lower() found_patches[patch_name] = file_path + # 无论是否为调试模式,都记录找到的补丁文件 + logger.info(f"找到离线补丁文件: {patch_name} 路径: {file_path}") if debug_mode: logger.debug(f"DEBUG: 找到离线补丁文件: {patch_name} 路径: {file_path}") self.offline_patches = found_patches + + # 记录扫描结果 + if found_patches: + logger.info(f"共找到 {len(found_patches)} 个离线补丁文件: {list(found_patches.keys())}") + else: + logger.info("未找到任何离线补丁文件") + return found_patches def has_offline_patches(self): @@ -113,6 +123,7 @@ class OfflineModeManager: "\n未找到任何离线补丁文件,无法启用离线模式。\n\n请将补丁文件放置在软件所在目录后再尝试。\n", QMessageBox.StandardButton.Ok ).exec() + logger.warning("尝试启用离线模式失败:未找到任何离线补丁文件") return False if debug_mode: @@ -137,6 +148,8 @@ class OfflineModeManager: ui_manager.online_mode_action.setChecked(not enabled) ui_manager.offline_mode_action.setChecked(enabled) + # 无论是否为调试模式,都记录离线模式状态变化 + logger.info(f"离线模式已{'启用' if enabled else '禁用'}") if debug_mode: logger.debug(f"DEBUG: 离线模式已{'启用' if enabled else '禁用'}") diff --git a/source/core/patch_detector.py b/source/core/patch_detector.py index 20f19f8..773b65a 100644 --- a/source/core/patch_detector.py +++ b/source/core/patch_detector.py @@ -70,13 +70,21 @@ class PatchDetector: """ debug_mode = self._is_debug_mode() + if debug_mode: + logger.debug(f"DEBUG: 检查 {game_version} 是否已安装补丁,目录: {game_dir}") + if game_version not in self.game_info: + if debug_mode: + logger.debug(f"DEBUG: {game_version} 不在支持的游戏列表中,跳过检查") return False # 获取可能的补丁文件路径 install_path_base = os.path.basename(self.game_info[game_version]["install_path"]) patch_file_path = os.path.join(game_dir, install_path_base) + if debug_mode: + logger.debug(f"DEBUG: 基础补丁文件路径: {patch_file_path}") + # 尝试查找补丁文件,支持不同大小写 patch_files_to_check = [ patch_file_path, @@ -86,18 +94,27 @@ class PatchDetector: patch_file_path.replace("_", "-"), ] + if debug_mode: + logger.debug(f"DEBUG: 将检查以下补丁文件路径: {patch_files_to_check}") + # 查找补丁文件 for patch_path in patch_files_to_check: if os.path.exists(patch_path): if debug_mode: - logger.debug(f"找到补丁文件: {patch_path}") + logger.debug(f"DEBUG: 找到补丁文件: {patch_path}") + logger.debug(f"DEBUG: {game_version} 已安装补丁") return True + # 检查是否存在被禁用的补丁文件(带.fain后缀) disabled_path = f"{patch_path}.fain" if os.path.exists(disabled_path): if debug_mode: - logger.debug(f"找到被禁用的补丁文件: {disabled_path}") + logger.debug(f"DEBUG: 找到被禁用的补丁文件: {disabled_path}") + logger.debug(f"DEBUG: {game_version} 已安装补丁(但被禁用)") return True + + if debug_mode: + logger.debug(f"DEBUG: 未找到补丁文件,继续检查补丁文件夹") # 检查是否有补丁文件夹 patch_folders_to_check = [ @@ -106,28 +123,46 @@ class PatchDetector: os.path.join(game_dir, "PATCH"), ] + if debug_mode: + logger.debug(f"DEBUG: 将检查以下补丁文件夹: {patch_folders_to_check}") + for patch_folder in patch_folders_to_check: if os.path.exists(patch_folder): if debug_mode: - logger.debug(f"找到补丁文件夹: {patch_folder}") + logger.debug(f"DEBUG: 找到补丁文件夹: {patch_folder}") + logger.debug(f"DEBUG: {game_version} 已安装补丁") return True + + if debug_mode: + logger.debug(f"DEBUG: 未找到补丁文件夹,继续检查game/patch文件夹") # 检查game/patch文件夹 game_folders = ["game", "Game", "GAME"] patch_folders = ["patch", "Patch", "PATCH"] + if debug_mode: + logger.debug(f"DEBUG: 将检查以下game/patch组合: {[(g, p) for g in game_folders for p in patch_folders]}") + for game_folder in game_folders: for patch_folder in patch_folders: game_patch_folder = os.path.join(game_dir, game_folder, patch_folder) if os.path.exists(game_patch_folder): if debug_mode: - logger.debug(f"找到game/patch文件夹: {game_patch_folder}") + logger.debug(f"DEBUG: 找到game/patch文件夹: {game_patch_folder}") + logger.debug(f"DEBUG: {game_version} 已安装补丁") return True + if debug_mode: + logger.debug(f"DEBUG: 未找到game/patch文件夹,继续检查配置文件和脚本文件") + # 检查配置文件 config_files = ["config.json", "Config.json", "CONFIG.JSON"] script_files = ["scripts.json", "Scripts.json", "SCRIPTS.JSON"] + if debug_mode: + logger.debug(f"DEBUG: 将在game文件夹中检查以下配置文件: {config_files}") + logger.debug(f"DEBUG: 将在game文件夹中检查以下脚本文件: {script_files}") + for game_folder in game_folders: game_path = os.path.join(game_dir, game_folder) if os.path.exists(game_path): @@ -136,7 +171,8 @@ class PatchDetector: config_path = os.path.join(game_path, config_file) if os.path.exists(config_path): if debug_mode: - logger.debug(f"找到配置文件: {config_path}") + logger.debug(f"DEBUG: 找到配置文件: {config_path}") + logger.debug(f"DEBUG: {game_version} 已安装补丁") return True # 检查脚本文件 @@ -144,12 +180,13 @@ class PatchDetector: script_path = os.path.join(game_path, script_file) if os.path.exists(script_path): if debug_mode: - logger.debug(f"找到脚本文件: {script_path}") + logger.debug(f"DEBUG: 找到脚本文件: {script_path}") + logger.debug(f"DEBUG: {game_version} 已安装补丁") return True # 没有找到补丁文件或文件夹 if debug_mode: - logger.debug(f"{game_version} 在 {game_dir} 中没有安装补丁") + logger.debug(f"DEBUG: {game_version} 在 {game_dir} 中没有安装补丁") return False def check_patch_disabled(self, game_dir, game_version): diff --git a/source/core/patch_manager.py b/source/core/patch_manager.py index 750c342..fa3d8fc 100644 --- a/source/core/patch_manager.py +++ b/source/core/patch_manager.py @@ -86,17 +86,24 @@ class PatchManager: debug_mode = self._is_debug_mode() if debug_mode: - self.logger.debug(f"开始卸载 {game_version} 补丁,目录: {game_dir}") + self.logger.debug(f"DEBUG: 开始卸载 {game_version} 补丁,目录: {game_dir}") + + self.logger.info(f"开始卸载 {game_version} 补丁,目录: {game_dir}") if game_version not in self.game_info: + error_msg = f"无法识别游戏版本: {game_version}" + if debug_mode: + self.logger.debug(f"DEBUG: 卸载失败 - {error_msg}") + self.logger.error(f"卸载失败 - {error_msg}") + if not silent: QMessageBox.critical( None, f"错误 - {self.app_name}", - f"\n无法识别游戏版本: {game_version}\n", + f"\n{error_msg}\n", QMessageBox.StandardButton.Ok, ) - return False if not silent else {"success": False, "message": f"无法识别游戏版本: {game_version}", "files_removed": 0} + return False if not silent else {"success": False, "message": error_msg, "files_removed": 0} try: files_removed = 0 @@ -105,6 +112,9 @@ class PatchManager: install_path_base = os.path.basename(self.game_info[game_version]["install_path"]) patch_file_path = os.path.join(game_dir, install_path_base) + if debug_mode: + self.logger.debug(f"DEBUG: 基础补丁文件路径: {patch_file_path}") + # 尝试查找补丁文件,支持不同大小写 patch_files_to_check = [ patch_file_path, @@ -115,7 +125,7 @@ class PatchManager: ] if debug_mode: - self.logger.debug(f"查找以下可能的补丁文件路径: {patch_files_to_check}") + self.logger.debug(f"DEBUG: 查找以下可能的补丁文件路径: {patch_files_to_check}") # 查找并删除补丁文件,包括启用和禁用的 patch_file_found = False @@ -123,44 +133,68 @@ class PatchManager: # 检查常规补丁文件 if os.path.exists(patch_path): patch_file_found = True + if debug_mode: + self.logger.debug(f"DEBUG: 找到补丁文件: {patch_path},准备删除") + self.logger.info(f"删除补丁文件: {patch_path}") + os.remove(patch_path) files_removed += 1 if debug_mode: - self.logger.debug(f"已删除补丁文件: {patch_path}") + self.logger.debug(f"DEBUG: 已删除补丁文件: {patch_path}") # 检查被禁用的补丁文件(带.fain后缀) disabled_path = f"{patch_path}.fain" if os.path.exists(disabled_path): patch_file_found = True + if debug_mode: + self.logger.debug(f"DEBUG: 找到被禁用的补丁文件: {disabled_path},准备删除") + self.logger.info(f"删除被禁用的补丁文件: {disabled_path}") + os.remove(disabled_path) files_removed += 1 if debug_mode: - self.logger.debug(f"已删除被禁用的补丁文件: {disabled_path}") + self.logger.debug(f"DEBUG: 已删除被禁用的补丁文件: {disabled_path}") - if not patch_file_found and debug_mode: - self.logger.debug(f"未找到补丁文件,检查了以下路径: {patch_files_to_check}") - self.logger.debug(f"也检查了禁用的补丁文件(.fain后缀)") + if not patch_file_found: + if debug_mode: + self.logger.debug(f"DEBUG: 未找到补丁文件,检查了以下路径: {patch_files_to_check}") + self.logger.debug(f"DEBUG: 也检查了禁用的补丁文件(.fain后缀)") + self.logger.warning(f"未找到 {game_version} 的补丁文件") # 检查是否有额外的签名文件 (.sig) if game_version == "NEKOPARA After": + if debug_mode: + self.logger.debug(f"DEBUG: {game_version} 需要检查额外的签名文件") + for patch_path in patch_files_to_check: # 检查常规签名文件 sig_file_path = f"{patch_path}.sig" if os.path.exists(sig_file_path): + if debug_mode: + self.logger.debug(f"DEBUG: 找到签名文件: {sig_file_path},准备删除") + self.logger.info(f"删除签名文件: {sig_file_path}") + os.remove(sig_file_path) files_removed += 1 if debug_mode: - self.logger.debug(f"已删除签名文件: {sig_file_path}") + self.logger.debug(f"DEBUG: 已删除签名文件: {sig_file_path}") # 检查被禁用补丁的签名文件 disabled_sig_path = f"{patch_path}.fain.sig" if os.path.exists(disabled_sig_path): + if debug_mode: + self.logger.debug(f"DEBUG: 找到被禁用补丁的签名文件: {disabled_sig_path},准备删除") + self.logger.info(f"删除被禁用补丁的签名文件: {disabled_sig_path}") + os.remove(disabled_sig_path) files_removed += 1 if debug_mode: - self.logger.debug(f"已删除被禁用补丁的签名文件: {disabled_sig_path}") + self.logger.debug(f"DEBUG: 已删除被禁用补丁的签名文件: {disabled_sig_path}") # 删除patch文件夹 + if debug_mode: + self.logger.debug(f"DEBUG: 检查并删除patch文件夹") + patch_folders_to_check = [ os.path.join(game_dir, "patch"), os.path.join(game_dir, "Patch"), @@ -169,12 +203,20 @@ class PatchManager: for patch_folder in patch_folders_to_check: if os.path.exists(patch_folder): + if debug_mode: + self.logger.debug(f"DEBUG: 找到补丁文件夹: {patch_folder},准备删除") + self.logger.info(f"删除补丁文件夹: {patch_folder}") + + import shutil shutil.rmtree(patch_folder) files_removed += 1 if debug_mode: - self.logger.debug(f"已删除补丁文件夹: {patch_folder}") + self.logger.debug(f"DEBUG: 已删除补丁文件夹: {patch_folder}") # 删除game/patch文件夹 + if debug_mode: + self.logger.debug(f"DEBUG: 检查并删除game/patch文件夹") + game_folders = ["game", "Game", "GAME"] patch_folders = ["patch", "Patch", "PATCH"] @@ -182,12 +224,20 @@ class PatchManager: for patch_folder in patch_folders: game_patch_folder = os.path.join(game_dir, game_folder, patch_folder) if os.path.exists(game_patch_folder): + if debug_mode: + self.logger.debug(f"DEBUG: 找到game/patch文件夹: {game_patch_folder},准备删除") + self.logger.info(f"删除game/patch文件夹: {game_patch_folder}") + + import shutil shutil.rmtree(game_patch_folder) files_removed += 1 if debug_mode: - self.logger.debug(f"已删除game/patch文件夹: {game_patch_folder}") + self.logger.debug(f"DEBUG: 已删除game/patch文件夹: {game_patch_folder}") # 删除配置文件 + if debug_mode: + self.logger.debug(f"DEBUG: 检查并删除配置文件和脚本文件") + config_files = ["config.json", "Config.json", "CONFIG.JSON"] script_files = ["scripts.json", "Scripts.json", "SCRIPTS.JSON"] @@ -198,55 +248,82 @@ class PatchManager: for config_file in config_files: config_path = os.path.join(game_path, config_file) if os.path.exists(config_path): + if debug_mode: + self.logger.debug(f"DEBUG: 找到配置文件: {config_path},准备删除") + self.logger.info(f"删除配置文件: {config_path}") + os.remove(config_path) files_removed += 1 if debug_mode: - self.logger.debug(f"已删除配置文件: {config_path}") + self.logger.debug(f"DEBUG: 已删除配置文件: {config_path}") # 删除脚本文件 for script_file in script_files: script_path = os.path.join(game_path, script_file) if os.path.exists(script_path): + if debug_mode: + self.logger.debug(f"DEBUG: 找到脚本文件: {script_path},准备删除") + self.logger.info(f"删除脚本文件: {script_path}") + os.remove(script_path) files_removed += 1 if debug_mode: - self.logger.debug(f"已删除脚本文件: {script_path}") + self.logger.debug(f"DEBUG: 已删除脚本文件: {script_path}") # 更新安装状态 self.installed_status[game_version] = False + if debug_mode: + self.logger.debug(f"DEBUG: 已更新 {game_version} 的安装状态为未安装") # 在非静默模式且非批量卸载模式下显示卸载成功消息 if not silent and game_version != "all": # 显示卸载成功消息 if files_removed > 0: + success_msg = f"\n{game_version} 补丁卸载成功!\n共删除 {files_removed} 个文件/文件夹。\n" + if debug_mode: + self.logger.debug(f"DEBUG: 显示卸载成功消息: {success_msg}") + QMessageBox.information( None, f"卸载完成 - {self.app_name}", - f"\n{game_version} 补丁卸载成功!\n共删除 {files_removed} 个文件/文件夹。\n", + success_msg, QMessageBox.StandardButton.Ok, ) else: + warning_msg = f"\n未找到 {game_version} 的补丁文件,可能未安装补丁或已被移除。\n" + if debug_mode: + self.logger.debug(f"DEBUG: 显示警告消息: {warning_msg}") + QMessageBox.warning( None, f"警告 - {self.app_name}", - f"\n未找到 {game_version} 的补丁文件,可能未安装补丁或已被移除。\n", + warning_msg, QMessageBox.StandardButton.Ok, ) # 卸载成功 + if debug_mode: + self.logger.debug(f"DEBUG: {game_version} 卸载完成,共删除 {files_removed} 个文件/文件夹") + self.logger.info(f"{game_version} 卸载完成,共删除 {files_removed} 个文件/文件夹") + if silent: return {"success": True, "message": f"{game_version} 补丁卸载成功", "files_removed": files_removed} return True except Exception as e: + error_message = f"卸载 {game_version} 补丁时出错:{str(e)}" + if debug_mode: + self.logger.debug(f"DEBUG: {error_message}") + import traceback + self.logger.debug(f"DEBUG: 错误详情:\n{traceback.format_exc()}") + self.logger.error(error_message) + # 在非静默模式且非批量卸载模式下显示卸载失败消息 if not silent and game_version != "all": # 显示卸载失败消息 error_message = f"\n卸载 {game_version} 补丁时出错:\n\n{str(e)}\n" if debug_mode: - self.logger.debug(f"卸载错误 - {str(e)}") - import traceback - self.logger.debug(f"错误详情:\n{traceback.format_exc()}") + self.logger.debug(f"DEBUG: 显示卸载失败消息") QMessageBox.critical( None, @@ -274,16 +351,38 @@ class PatchManager: debug_mode = self._is_debug_mode() results = [] + if debug_mode: + self.logger.debug(f"DEBUG: 开始批量卸载补丁,游戏数量: {len(game_dirs)}") + self.logger.debug(f"DEBUG: 要卸载的游戏: {list(game_dirs.keys())}") + + self.logger.info(f"开始批量卸载补丁,游戏数量: {len(game_dirs)}") + self.logger.info(f"要卸载的游戏: {list(game_dirs.keys())}") + for version, path in game_dirs.items(): + if debug_mode: + self.logger.debug(f"DEBUG: 处理游戏 {version},路径: {path}") + + self.logger.info(f"开始卸载 {version} 的补丁") + try: # 在批量模式下使用静默卸载 + if debug_mode: + self.logger.debug(f"DEBUG: 使用静默模式卸载 {version}") + result = self.uninstall_patch(path, version, silent=True) if isinstance(result, dict): # 使用了静默模式 if result["success"]: success_count += 1 + if debug_mode: + self.logger.debug(f"DEBUG: {version} 卸载成功,删除了 {result['files_removed']} 个文件/文件夹") + self.logger.info(f"{version} 卸载成功,删除了 {result['files_removed']} 个文件/文件夹") else: fail_count += 1 + if debug_mode: + self.logger.debug(f"DEBUG: {version} 卸载失败,原因: {result['message']}") + self.logger.warning(f"{version} 卸载失败,原因: {result['message']}") + results.append({ "version": version, "success": result["success"], @@ -293,8 +392,15 @@ class PatchManager: else: # 兼容旧代码,不应该执行到这里 if result: success_count += 1 + if debug_mode: + self.logger.debug(f"DEBUG: {version} 卸载成功(旧格式)") + self.logger.info(f"{version} 卸载成功(旧格式)") else: fail_count += 1 + if debug_mode: + self.logger.debug(f"DEBUG: {version} 卸载失败(旧格式)") + self.logger.warning(f"{version} 卸载失败(旧格式)") + results.append({ "version": version, "success": result, @@ -304,7 +410,12 @@ class PatchManager: except Exception as e: if debug_mode: - self.logger.debug(f"卸载 {version} 时出错: {str(e)}") + self.logger.debug(f"DEBUG: 卸载 {version} 时出错: {str(e)}") + import traceback + self.logger.debug(f"DEBUG: 错误详情:\n{traceback.format_exc()}") + + self.logger.error(f"卸载 {version} 时出错: {str(e)}") + fail_count += 1 results.append({ "version": version, @@ -312,7 +423,12 @@ class PatchManager: "message": f"卸载出错: {str(e)}", "files_removed": 0 }) - + + if debug_mode: + self.logger.debug(f"DEBUG: 批量卸载完成,成功: {success_count},失败: {fail_count}") + + self.logger.info(f"批量卸载完成,成功: {success_count},失败: {fail_count}") + return success_count, fail_count, results def show_uninstall_result(self, success_count, fail_count, results=None): @@ -323,6 +439,11 @@ class PatchManager: fail_count: 卸载失败的数量 results: 详细结果列表,如果提供,会显示更详细的信息 """ + debug_mode = self._is_debug_mode() + + if debug_mode: + self.logger.debug(f"DEBUG: 显示卸载结果,成功: {success_count},失败: {fail_count}") + result_text = f"\n批量卸载完成!\n成功: {success_count} 个\n失败: {fail_count} 个\n" # 如果有详细结果,添加到消息中 @@ -330,11 +451,24 @@ class PatchManager: success_list = [r["version"] for r in results if r["success"]] fail_list = [r["version"] for r in results if not r["success"]] + if debug_mode: + self.logger.debug(f"DEBUG: 成功卸载的游戏: {success_list}") + self.logger.debug(f"DEBUG: 卸载失败的游戏: {fail_list}") + if success_list: result_text += f"\n【成功卸载】:\n{chr(10).join(success_list)}\n" if fail_list: result_text += f"\n【卸载失败】:\n{chr(10).join(fail_list)}\n" + + # 记录更详细的失败原因 + if debug_mode: + for r in results: + if not r["success"]: + self.logger.debug(f"DEBUG: {r['version']} 卸载失败原因: {r['message']}") + + if debug_mode: + self.logger.debug(f"DEBUG: 显示卸载结果对话框") QMessageBox.information( None, diff --git a/source/handlers/uninstall_handler.py b/source/handlers/uninstall_handler.py index c3669c1..3067b9b 100644 --- a/source/handlers/uninstall_handler.py +++ b/source/handlers/uninstall_handler.py @@ -28,6 +28,11 @@ class UninstallHandler(QObject): self.game_detector = main_window.game_detector self.patch_manager = main_window.patch_manager self.app_name = main_window.patch_manager.app_name + + # 记录初始化日志 + debug_mode = self.debug_manager._is_debug_mode() if hasattr(self.debug_manager, '_is_debug_mode') else False + if debug_mode: + logger.debug("DEBUG: 卸载处理程序已初始化") def handle_uninstall_button_click(self): """ @@ -37,22 +42,33 @@ class UninstallHandler(QObject): # 获取游戏目录 debug_mode = self.debug_manager._is_debug_mode() + logger.info("用户点击了卸载补丁按钮") + if debug_mode: + logger.debug("DEBUG: 处理卸载补丁按钮点击事件") + # 提示用户选择目录 file_dialog_info = "选择游戏上级目录" if debug_mode else "选择游戏目录" selected_folder = QFileDialog.getExistingDirectory(self.main_window, file_dialog_info, "") if not selected_folder or selected_folder == "": + logger.info("用户取消了目录选择") + if debug_mode: + logger.debug("DEBUG: 用户取消了目录选择,退出卸载流程") return # 用户取消了选择 + logger.info(f"用户选择了目录: {selected_folder}") if debug_mode: logger.debug(f"DEBUG: 卸载功能 - 用户选择了目录: {selected_folder}") # 首先尝试将选择的目录视为上级目录,使用增强的目录识别功能 + logger.info("尝试识别游戏目录") game_dirs = self.game_detector.identify_game_directories_improved(selected_folder) if game_dirs and len(game_dirs) > 0: + logger.info(f"在上级目录中找到游戏: {list(game_dirs.keys())}") self._handle_multiple_games(game_dirs, debug_mode) else: + logger.info("未在上级目录找到游戏,尝试将选择的目录作为单个游戏目录处理") self._handle_single_game(selected_folder, debug_mode) def _handle_multiple_games(self, game_dirs, debug_mode): @@ -67,15 +83,26 @@ class UninstallHandler(QObject): logger.debug(f"DEBUG: 卸载功能 - 在上级目录中找到以下游戏: {list(game_dirs.keys())}") # 查找已安装补丁的游戏,只处理那些已安装补丁的游戏 + logger.info("检查哪些游戏已安装补丁") games_with_patch = {} for game_version, game_dir in game_dirs.items(): - if self.patch_manager.check_patch_installed(game_dir, game_version): + is_installed = self.patch_manager.check_patch_installed(game_dir, game_version) + if is_installed: games_with_patch[game_version] = game_dir + logger.info(f"游戏 {game_version} 已安装补丁") if debug_mode: - logger.debug(f"DEBUG: 卸载功能 - {game_version} 已安装补丁") + logger.debug(f"DEBUG: 卸载功能 - {game_version} 已安装补丁,目录: {game_dir}") + else: + logger.info(f"游戏 {game_version} 未安装补丁") + if debug_mode: + logger.debug(f"DEBUG: 卸载功能 - {game_version} 未安装补丁,跳过") # 检查是否有已安装补丁的游戏 if not games_with_patch: + logger.info("未找到已安装补丁的游戏") + if debug_mode: + logger.debug("DEBUG: 卸载功能 - 未找到已安装补丁的游戏,显示提示消息") + QMessageBox.information( self.main_window, f"提示 - {self.app_name}", @@ -85,16 +112,31 @@ class UninstallHandler(QObject): return # 显示选择对话框 + logger.info("显示游戏选择对话框") + if debug_mode: + logger.debug(f"DEBUG: 卸载功能 - 显示游戏选择对话框,可选游戏: {list(games_with_patch.keys())}") + selected_games = self._show_game_selection_dialog(games_with_patch) if not selected_games: + logger.info("用户未选择任何游戏或取消了选择") + if debug_mode: + logger.debug("DEBUG: 卸载功能 - 用户未选择任何游戏或取消了选择,退出卸载流程") return # 用户取消了选择 + logger.info(f"用户选择了以下游戏: {selected_games}") + if debug_mode: + logger.debug(f"DEBUG: 卸载功能 - 用户选择了以下游戏: {selected_games}") + # 过滤game_dirs,只保留选中的游戏 selected_game_dirs = {game: games_with_patch[game] for game in selected_games if game in games_with_patch} # 确认卸载 game_list = '\n'.join(selected_games) + logger.info("显示卸载确认对话框") + if debug_mode: + logger.debug(f"DEBUG: 卸载功能 - 显示卸载确认对话框,选择的游戏: {selected_games}") + reply = QMessageBox.question( self.main_window, f"确认卸载 - {self.app_name}", @@ -104,10 +146,26 @@ class UninstallHandler(QObject): ) if reply == QMessageBox.StandardButton.No: + logger.info("用户取消了卸载操作") + if debug_mode: + logger.debug("DEBUG: 卸载功能 - 用户取消了卸载操作,退出卸载流程") return + + logger.info("开始批量卸载补丁") + if debug_mode: + logger.debug(f"DEBUG: 卸载功能 - 开始批量卸载补丁,游戏: {list(selected_game_dirs.keys())}") # 使用批量卸载方法 success_count, fail_count, results = self.patch_manager.batch_uninstall_patches(selected_game_dirs) + + logger.info(f"批量卸载完成,成功: {success_count},失败: {fail_count}") + if debug_mode: + logger.debug(f"DEBUG: 卸载功能 - 批量卸载完成,成功: {success_count},失败: {fail_count}") + if results: + for result in results: + status = "成功" if result["success"] else "失败" + logger.debug(f"DEBUG: 卸载结果 - {result['version']}: {status}, 消息: {result['message']}, 删除文件数: {result['files_removed']}") + self.patch_manager.show_uninstall_result(success_count, fail_count, results) def _handle_single_game(self, selected_folder, debug_mode): @@ -122,15 +180,28 @@ class UninstallHandler(QObject): if debug_mode: logger.debug(f"DEBUG: 卸载功能 - 未在上级目录找到游戏,尝试将选择的目录视为游戏目录") + logger.info("尝试识别单个游戏版本") game_version = self.game_detector.identify_game_version(selected_folder) if game_version: + logger.info(f"识别为游戏: {game_version}") if debug_mode: logger.debug(f"DEBUG: 卸载功能 - 识别为游戏: {game_version}") # 检查是否已安装补丁 - if self.patch_manager.check_patch_installed(selected_folder, game_version): + logger.info(f"检查 {game_version} 是否已安装补丁") + is_installed = self.patch_manager.check_patch_installed(selected_folder, game_version) + + if is_installed: + logger.info(f"{game_version} 已安装补丁") + if debug_mode: + logger.debug(f"DEBUG: 卸载功能 - {game_version} 已安装补丁") + # 确认卸载 + logger.info("显示卸载确认对话框") + if debug_mode: + logger.debug(f"DEBUG: 卸载功能 - 显示卸载确认对话框,游戏: {game_version}") + reply = QMessageBox.question( self.main_window, f"确认卸载 - {self.app_name}", @@ -140,11 +211,37 @@ class UninstallHandler(QObject): ) if reply == QMessageBox.StandardButton.Yes: + logger.info(f"开始卸载 {game_version} 的补丁") + if debug_mode: + logger.debug(f"DEBUG: 卸载功能 - 用户确认卸载 {game_version} 的补丁") + # 创建单个游戏的目录字典,使用批量卸载流程 single_game_dir = {game_version: selected_folder} + + logger.info("执行批量卸载方法(单游戏)") + if debug_mode: + logger.debug(f"DEBUG: 卸载功能 - 执行批量卸载方法(单游戏): {game_version}") + success_count, fail_count, results = self.patch_manager.batch_uninstall_patches(single_game_dir) + + logger.info(f"卸载完成,成功: {success_count},失败: {fail_count}") + if debug_mode: + logger.debug(f"DEBUG: 卸载功能 - 卸载完成,成功: {success_count},失败: {fail_count}") + if results: + for result in results: + status = "成功" if result["success"] else "失败" + logger.debug(f"DEBUG: 卸载结果 - {result['version']}: {status}, 消息: {result['message']}, 删除文件数: {result['files_removed']}") + self.patch_manager.show_uninstall_result(success_count, fail_count, results) + else: + logger.info("用户取消了卸载操作") + if debug_mode: + logger.debug(f"DEBUG: 卸载功能 - 用户取消了卸载 {game_version} 的补丁") else: + logger.info(f"{game_version} 未安装补丁") + if debug_mode: + logger.debug(f"DEBUG: 卸载功能 - {game_version} 未安装补丁,显示提示消息") + # 没有安装补丁 QMessageBox.information( self.main_window, @@ -154,8 +251,9 @@ class UninstallHandler(QObject): ) else: # 两种方式都未识别到游戏 + logger.info("无法识别游戏") if debug_mode: - logger.debug(f"DEBUG: 卸载功能 - 无法识别游戏") + logger.debug(f"DEBUG: 卸载功能 - 无法识别游戏,显示错误消息") msg_box = msgbox_frame( f"错误 - {self.app_name}", @@ -182,7 +280,7 @@ class UninstallHandler(QObject): # 添加"已安装补丁的游戏"标签 already_installed_label = QLabel("已安装补丁的游戏:", dialog) - already_installed_label.setFont(QFont(already_installed_label.font().family(), already_installed_label.font().pointSize(), QFont.Bold)) + already_installed_label.setFont(QFont(already_installed_label.font().family(), already_installed_label.font().pointSize(), QFont.Weight.Bold)) layout.addWidget(already_installed_label) # 添加已安装游戏列表(可选,这里使用静态标签替代,保持一致性) @@ -195,7 +293,7 @@ class UninstallHandler(QObject): # 添加"请选择要卸载补丁的游戏"标签 info_label = QLabel("请选择要卸载补丁的游戏:", dialog) - info_label.setFont(QFont(info_label.font().family(), info_label.font().pointSize(), QFont.Bold)) + info_label.setFont(QFont(info_label.font().family(), info_label.font().pointSize(), QFont.Weight.Bold)) layout.addWidget(info_label) # 添加列表控件,只显示已安装补丁的游戏 diff --git a/source/main_window.py b/source/main_window.py index 9026cb7..4350fd0 100644 --- a/source/main_window.py +++ b/source/main_window.py @@ -604,8 +604,20 @@ class MainWindow(QMainWindow): # 启用开始安装按钮 self.set_start_button_enabled(True) - logger.debug(f"DEBUG: 已自动切换到离线模式,找到离线补丁文件: {list(self.offline_mode_manager.offline_patches.keys())}") + # 记录日志 + found_patches = list(self.offline_mode_manager.offline_patches.keys()) + logger.debug(f"DEBUG: 已自动切换到离线模式,找到离线补丁文件: {found_patches}") + logger.info(f"发现离线补丁文件: {found_patches},将自动切换到离线模式") logger.debug(f"DEBUG: 离线模式下启用开始安装按钮") + + # 显示提示弹窗 + from PySide6.QtWidgets import QMessageBox + QMessageBox.information( + self, + f"离线模式提示 - {APP_NAME}", + f"已找到本地补丁,将主动转为离线模式。\n\n检测到的补丁文件: {', '.join(found_patches)}" + ) + return True else: # 如果没有找到离线补丁文件,禁用离线模式