mirror of
https://github.com/hyb-oyqq/FRAISEMOE-Addons-Installer-NEXT.git
synced 2025-12-19 13:28:36 +00:00
feat(core): 更新日志记录级别,增强调试信息
- 将多个模块中的日志记录级别从info调整为debug,以减少生产环境中的日志噪声,同时在调试模式下提供更详细的信息。 - 更新了主窗口、下载管理器、隐私管理器等多个文件的日志记录,确保在调试过程中能够获取到更丰富的上下文信息,便于问题排查和用户反馈。
This commit is contained in:
@@ -42,8 +42,8 @@ if __name__ == "__main__":
|
||||
sys.excepthook = excepthook
|
||||
|
||||
# 记录程序启动信息
|
||||
logger.info(f"Python版本: {sys.version}")
|
||||
logger.info(f"运行平台: {sys.platform}")
|
||||
logger.debug(f"Python版本: {sys.version}")
|
||||
logger.debug(f"运行平台: {sys.platform}")
|
||||
|
||||
# 检查配置中是否启用了调试模式
|
||||
config = load_config()
|
||||
@@ -51,7 +51,7 @@ if __name__ == "__main__":
|
||||
|
||||
# 在应用启动时清理过期的日志文件
|
||||
cleanup_old_logs(LOG_RETENTION_DAYS)
|
||||
logger.info(f"已执行日志清理,保留最近{LOG_RETENTION_DAYS}天的日志")
|
||||
logger.debug(f"已执行日志清理,保留最近{LOG_RETENTION_DAYS}天的日志")
|
||||
|
||||
# 如果调试模式已启用,确保立即创建主日志文件
|
||||
if debug_mode:
|
||||
@@ -60,17 +60,17 @@ if __name__ == "__main__":
|
||||
log_dir = os.path.dirname(LOG_FILE)
|
||||
if not os.path.exists(log_dir):
|
||||
os.makedirs(log_dir, exist_ok=True)
|
||||
logger.info(f"已创建日志目录: {log_dir}")
|
||||
logger.debug(f"已创建日志目录: {log_dir}")
|
||||
|
||||
# 记录调试会话信息
|
||||
logger.info(f"--- 新调试会话开始于 {os.path.basename(LOG_FILE)} ---")
|
||||
logger.info(f"--- 应用版本: {APP_NAME} ---")
|
||||
logger.debug(f"--- 新调试会话开始于 {os.path.basename(LOG_FILE)} ---")
|
||||
logger.debug(f"--- 应用版本: {APP_NAME} ---")
|
||||
current_time = datetime.datetime.now()
|
||||
formatted_date = current_time.strftime("%Y-%m-%d")
|
||||
formatted_time = current_time.strftime("%H:%M:%S")
|
||||
logger.info(f"--- 日期: {formatted_date} 时间: {formatted_time} ---")
|
||||
logger.debug(f"--- 日期: {formatted_date} 时间: {formatted_time} ---")
|
||||
|
||||
logger.info(f"调试模式已启用,日志文件路径: {os.path.abspath(LOG_FILE)}")
|
||||
logger.debug(f"调试模式已启用,日志文件路径: {os.path.abspath(LOG_FILE)}")
|
||||
except Exception as e:
|
||||
logger.error(f"创建日志文件失败: {e}")
|
||||
|
||||
|
||||
@@ -87,7 +87,7 @@ def get_local_privacy_policy():
|
||||
try:
|
||||
date_obj = datetime.strptime(date_str, '%Y年%m月%d日')
|
||||
date_version = date_obj.strftime('%Y.%m.%d')
|
||||
logger.info(f"成功读取本地隐私协议文件: {path}, 版本: {date_version}")
|
||||
logger.debug(f"成功读取本地隐私协议文件: {path}, 版本: {date_version}")
|
||||
return content, date_version, ""
|
||||
except ValueError:
|
||||
logger.error(f"本地隐私协议日期格式解析错误: {path}")
|
||||
|
||||
@@ -208,7 +208,7 @@ class ExtractionHandler:
|
||||
if install_path and os.path.exists(install_path):
|
||||
try:
|
||||
os.remove(install_path)
|
||||
logger.info(f"已删除校验失败的文件: {install_path}")
|
||||
logger.debug(f"已删除校验失败的文件: {install_path}")
|
||||
except Exception as e:
|
||||
logger.error(f"删除文件失败: {e}")
|
||||
|
||||
|
||||
@@ -176,7 +176,7 @@ class MultiStageAnimations(QObject):
|
||||
widget.setGraphicsEffect(effect)
|
||||
widget.move(-widget.width(), item["end_pos"].y())
|
||||
widget.show()
|
||||
print("初始化支持栏动画")
|
||||
# 初始化支持栏动画,这是内部处理,不需要日志输出
|
||||
|
||||
# 初始化菜单元素(底部外)
|
||||
for item in self.menu_widgets:
|
||||
|
||||
@@ -77,7 +77,7 @@ class DebugManager:
|
||||
elif os.path.exists(debug_file):
|
||||
# 删除标记文件
|
||||
os.remove(debug_file)
|
||||
logger.info(f"已删除调试模式标记文件: {debug_file}")
|
||||
logger.debug(f"已删除调试模式标记文件: {debug_file}")
|
||||
except Exception as e:
|
||||
logger.warning(f"处理调试模式标记文件时发生错误: {e}")
|
||||
|
||||
@@ -113,7 +113,7 @@ class DebugManager:
|
||||
log_dir = os.path.dirname(LOG_FILE)
|
||||
if not os.path.exists(log_dir):
|
||||
os.makedirs(log_dir, exist_ok=True)
|
||||
logger.info(f"已创建日志目录: {log_dir}")
|
||||
logger.debug(f"已创建日志目录: {log_dir}")
|
||||
|
||||
# 创建新的日志文件,使用覆盖模式而不是追加模式
|
||||
with open(LOG_FILE, 'w', encoding='utf-8') as f:
|
||||
@@ -123,13 +123,13 @@ class DebugManager:
|
||||
f.write(f"--- 新调试会话开始于 {os.path.basename(LOG_FILE)} ---\n")
|
||||
f.write(f"--- 应用版本: {APP_NAME} ---\n")
|
||||
f.write(f"--- 日期: {formatted_date} 时间: {formatted_time} ---\n\n")
|
||||
logger.info(f"已创建日志文件: {os.path.abspath(LOG_FILE)}")
|
||||
logger.debug(f"已创建日志文件: {os.path.abspath(LOG_FILE)}")
|
||||
|
||||
# 保存原始的 stdout 并创建Logger实例
|
||||
self.original_stdout = sys.stdout
|
||||
self.logger = Logger(LOG_FILE, self.original_stdout)
|
||||
|
||||
logger.info(f"--- Debug mode enabled (log file: {os.path.abspath(LOG_FILE)}) ---")
|
||||
logger.debug(f"--- Debug mode enabled (log file: {os.path.abspath(LOG_FILE)}) ---")
|
||||
except (IOError, OSError) as e:
|
||||
QtWidgets.QMessageBox.critical(self.main_window, "错误", f"无法创建日志文件: {e}")
|
||||
self.logger = None
|
||||
@@ -137,7 +137,7 @@ class DebugManager:
|
||||
def stop_logging(self):
|
||||
"""停止日志记录"""
|
||||
if self.logger:
|
||||
logger.info("--- Debug mode disabled ---")
|
||||
logger.debug("--- Debug mode disabled ---")
|
||||
# 恢复stdout到原始状态
|
||||
if hasattr(self, 'original_stdout') and self.original_stdout:
|
||||
sys.stdout = self.original_stdout
|
||||
|
||||
@@ -267,25 +267,45 @@ class DownloadManager:
|
||||
self.main_window.ui_manager.set_install_button_state("ready")
|
||||
return
|
||||
|
||||
# 关闭可能存在的哈希校验窗口
|
||||
self.main_window.close_hash_msg_box()
|
||||
# 检查是否禁用了安装前哈希预检查
|
||||
config = getattr(self.main_window, 'config', {})
|
||||
disable_pre_hash = False
|
||||
if isinstance(config, dict):
|
||||
disable_pre_hash = config.get("disable_pre_hash_check", False)
|
||||
|
||||
# 显示文件检验窗口
|
||||
self.main_window.hash_msg_box = self.main_window.hash_manager.hash_pop_window(
|
||||
check_type="pre",
|
||||
auto_close=True, # 添加自动关闭参数
|
||||
close_delay=1000 # 1秒后自动关闭
|
||||
)
|
||||
debug_mode = self.is_debug_mode()
|
||||
|
||||
# 获取安装路径
|
||||
install_paths = self.get_install_paths()
|
||||
if disable_pre_hash:
|
||||
if debug_mode:
|
||||
logger.debug("DEBUG: 哈希预检查已被用户禁用,跳过预检查")
|
||||
# 直接跳过哈希预检查,进入安装流程
|
||||
# 创建一个空的安装状态字典,所有游戏都标记为未安装
|
||||
updated_status = {}
|
||||
for game in game_dirs.keys():
|
||||
updated_status[game] = False
|
||||
|
||||
# 创建并启动哈希线程进行预检查
|
||||
self.main_window.hash_thread = self.main_window.patch_detector.create_hash_thread("pre", install_paths)
|
||||
self.main_window.hash_thread.pre_finished.connect(
|
||||
lambda updated_status: self.on_pre_hash_finished_with_dirs(updated_status, game_dirs)
|
||||
)
|
||||
self.main_window.hash_thread.start()
|
||||
# 直接调用预检查完成的处理方法
|
||||
self.on_pre_hash_finished_with_dirs(updated_status, game_dirs)
|
||||
else:
|
||||
# 关闭可能存在的哈希校验窗口
|
||||
self.main_window.close_hash_msg_box()
|
||||
|
||||
# 显示文件检验窗口
|
||||
self.main_window.hash_msg_box = self.main_window.hash_manager.hash_pop_window(
|
||||
check_type="pre",
|
||||
auto_close=True, # 添加自动关闭参数
|
||||
close_delay=1000 # 1秒后自动关闭
|
||||
)
|
||||
|
||||
# 获取安装路径
|
||||
install_paths = self.get_install_paths()
|
||||
|
||||
# 创建并启动哈希线程进行预检查
|
||||
self.main_window.hash_thread = self.main_window.patch_detector.create_hash_thread("pre", install_paths)
|
||||
self.main_window.hash_thread.pre_finished.connect(
|
||||
lambda updated_status: self.on_pre_hash_finished_with_dirs(updated_status, game_dirs)
|
||||
)
|
||||
self.main_window.hash_thread.start()
|
||||
|
||||
def on_pre_hash_finished_with_dirs(self, updated_status, game_dirs):
|
||||
"""优化的哈希预检查完成处理,带有游戏目录信息
|
||||
@@ -348,7 +368,7 @@ class DownloadManager:
|
||||
already_installed_games.append(game_version)
|
||||
else:
|
||||
if debug_mode:
|
||||
logger.info(f"DEBUG: 用户选择不启用被禁用的补丁,这些游戏将被添加到可安装列表")
|
||||
logger.debug(f"用户选择不启用被禁用的补丁,这些游戏将被添加到可安装列表")
|
||||
# 用户选择不启用,将这些游戏视为可以安装补丁
|
||||
installable_games.extend(disabled_patch_games)
|
||||
|
||||
@@ -439,13 +459,13 @@ class DownloadManager:
|
||||
|
||||
if is_offline_mode:
|
||||
if debug_mode:
|
||||
logger.info("DEBUG: 使用离线模式,跳过网络配置获取")
|
||||
logger.debug("使用离线模式,跳过网络配置获取")
|
||||
self._fill_offline_download_queue(selected_game_dirs)
|
||||
else:
|
||||
# 在线模式下,重新获取云端配置
|
||||
if hasattr(self.main_window, 'fetch_cloud_config'):
|
||||
if debug_mode:
|
||||
logger.info("DEBUG: 重新获取云端配置以确保URL最新")
|
||||
logger.debug("重新获取云端配置以确保URL最新")
|
||||
# 重新获取云端配置并继续下载流程
|
||||
from workers.config_fetch_thread import ConfigFetchThread
|
||||
self.main_window.config_manager.fetch_cloud_config(
|
||||
@@ -531,7 +551,7 @@ class DownloadManager:
|
||||
# 如果是离线模式,直接开始下一个下载任务
|
||||
if is_offline_mode:
|
||||
if debug_mode:
|
||||
logger.info("DEBUG: 离线模式,跳过Cloudflare优化")
|
||||
logger.debug("离线模式,跳过Cloudflare优化")
|
||||
self.next_download_task()
|
||||
else:
|
||||
self._show_cloudflare_option()
|
||||
@@ -791,7 +811,7 @@ class DownloadManager:
|
||||
|
||||
if hash_valid:
|
||||
if debug_mode:
|
||||
logger.info(f"DEBUG: 成功复制并验证补丁文件 {_7z_path}")
|
||||
logger.debug(f"成功复制并验证补丁文件 {_7z_path}")
|
||||
# 直接进入解压阶段
|
||||
self.extraction_handler.start_extraction(_7z_path, game_folder, plugin_path, game_version)
|
||||
else:
|
||||
|
||||
@@ -105,8 +105,8 @@ class OfflineModeManager:
|
||||
|
||||
debug_mode = self._is_debug_mode()
|
||||
|
||||
# 无论是否为调试模式,都记录扫描操作
|
||||
logger.info(f"扫描离线补丁文件,目录: {directory}")
|
||||
# 记录扫描操作
|
||||
logger.debug(f"扫描离线补丁文件,目录: {directory}")
|
||||
|
||||
# 要查找的补丁文件名
|
||||
patch_files = ["vol.1.7z", "vol.2.7z", "vol.3.7z", "vol.4.7z", "after.7z"]
|
||||
@@ -149,7 +149,7 @@ class OfflineModeManager:
|
||||
if found_patches:
|
||||
logger.info(f"共找到 {len(found_patches)} 个离线补丁文件: {list(found_patches.keys())}")
|
||||
else:
|
||||
logger.info("未找到任何离线补丁文件")
|
||||
logger.debug("未找到任何离线补丁文件")
|
||||
|
||||
return found_patches
|
||||
|
||||
@@ -208,8 +208,8 @@ class OfflineModeManager:
|
||||
ui_manager.online_mode_action.setChecked(not enabled)
|
||||
ui_manager.offline_mode_action.setChecked(enabled)
|
||||
|
||||
# 无论是否为调试模式,都记录离线模式状态变化
|
||||
logger.info(f"离线模式已{'启用' if enabled else '禁用'}")
|
||||
# 记录离线模式状态变化
|
||||
logger.debug(f"离线模式已{'启用' if enabled else '禁用'}")
|
||||
if debug_mode:
|
||||
logger.debug(f"DEBUG: 离线模式已{'启用' if enabled else '禁用'}")
|
||||
|
||||
@@ -642,14 +642,14 @@ class OfflineModeManager:
|
||||
if install_path and os.path.exists(install_path):
|
||||
try:
|
||||
os.remove(install_path)
|
||||
logger.info(f"已删除校验失败的文件: {install_path}")
|
||||
logger.debug(f"已删除校验失败的文件: {install_path}")
|
||||
|
||||
# 检查是否为NEKOPARA After,同时删除签名文件
|
||||
if game_version == "NEKOPARA After":
|
||||
sig_path = f"{install_path}.sig"
|
||||
if os.path.exists(sig_path):
|
||||
os.remove(sig_path)
|
||||
logger.info(f"已删除签名文件: {sig_path}")
|
||||
logger.debug(f"已删除签名文件: {sig_path}")
|
||||
except Exception as e:
|
||||
logger.error(f"删除文件失败: {e}")
|
||||
|
||||
@@ -833,7 +833,7 @@ class OfflineModeManager:
|
||||
# 开始执行第一个安装任务
|
||||
if install_tasks:
|
||||
if debug_mode:
|
||||
logger.info(f"DEBUG: 开始离线安装流程,安装游戏数量: {len(install_tasks)}")
|
||||
logger.debug(f"开始离线安装流程,安装游戏数量: {len(install_tasks)}")
|
||||
self.process_next_offline_install_task(install_tasks)
|
||||
return True
|
||||
else:
|
||||
@@ -886,7 +886,7 @@ class OfflineModeManager:
|
||||
if not install_tasks:
|
||||
# 所有任务完成,进行后检查
|
||||
if debug_mode:
|
||||
logger.info("DEBUG: 所有离线安装任务完成,进行后检查")
|
||||
logger.debug("所有离线安装任务完成,进行后检查")
|
||||
|
||||
# 使用patch_detector进行安装后哈希比较
|
||||
self.main_window.patch_detector.after_hash_compare()
|
||||
|
||||
@@ -138,20 +138,20 @@ class PatchDetector:
|
||||
|
||||
if is_patch_installed or hash_check_passed:
|
||||
if debug_mode:
|
||||
logger.info(f"DEBUG: {game_version} 已安装补丁,不需要再次安装")
|
||||
logger.info(f"DEBUG: 文件检查结果: {is_patch_installed}, 哈希检查结果: {hash_check_passed}")
|
||||
logger.debug(f"{game_version} 已安装补丁,不需要再次安装")
|
||||
logger.debug(f"文件检查结果: {is_patch_installed}, 哈希检查结果: {hash_check_passed}")
|
||||
already_installed_games.append(game_version)
|
||||
self.main_window.installed_status[game_version] = True
|
||||
else:
|
||||
is_disabled, disabled_path = self.check_patch_disabled(game_dir, game_version)
|
||||
if is_disabled:
|
||||
if debug_mode:
|
||||
logger.info(f"DEBUG: {game_version} 存在被禁用的补丁: {disabled_path}")
|
||||
logger.debug(f"{game_version} 存在被禁用的补丁: {disabled_path}")
|
||||
disabled_patch_games.append(game_version)
|
||||
else:
|
||||
if debug_mode:
|
||||
logger.info(f"DEBUG: {game_version} 未安装补丁,可以安装")
|
||||
logger.info(f"DEBUG: 文件检查结果: {is_patch_installed}, 哈希检查结果: {hash_check_passed}")
|
||||
logger.debug(f"{game_version} 未安装补丁,可以安装")
|
||||
logger.debug(f"文件检查结果: {is_patch_installed}, 哈希检查结果: {hash_check_passed}")
|
||||
installable_games.append(game_version)
|
||||
|
||||
if debug_mode:
|
||||
|
||||
@@ -135,7 +135,7 @@ class PatchManager:
|
||||
patch_file_found = True
|
||||
if debug_mode:
|
||||
self.logger.debug(f"DEBUG: 找到补丁文件: {patch_path},准备删除")
|
||||
self.logger.info(f"删除补丁文件: {patch_path}")
|
||||
self.logger.debug(f"删除补丁文件: {patch_path}")
|
||||
|
||||
os.remove(patch_path)
|
||||
files_removed += 1
|
||||
@@ -148,7 +148,7 @@ class PatchManager:
|
||||
patch_file_found = True
|
||||
if debug_mode:
|
||||
self.logger.debug(f"DEBUG: 找到被禁用的补丁文件: {disabled_path},准备删除")
|
||||
self.logger.info(f"删除被禁用的补丁文件: {disabled_path}")
|
||||
self.logger.debug(f"删除被禁用的补丁文件: {disabled_path}")
|
||||
|
||||
os.remove(disabled_path)
|
||||
files_removed += 1
|
||||
@@ -172,7 +172,7 @@ class PatchManager:
|
||||
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}")
|
||||
self.logger.debug(f"删除签名文件: {sig_file_path}")
|
||||
|
||||
os.remove(sig_file_path)
|
||||
files_removed += 1
|
||||
@@ -184,7 +184,7 @@ class PatchManager:
|
||||
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}")
|
||||
self.logger.debug(f"删除被禁用补丁的签名文件: {disabled_sig_path}")
|
||||
|
||||
os.remove(disabled_sig_path)
|
||||
files_removed += 1
|
||||
@@ -205,7 +205,7 @@ class PatchManager:
|
||||
if os.path.exists(patch_folder):
|
||||
if debug_mode:
|
||||
self.logger.debug(f"DEBUG: 找到补丁文件夹: {patch_folder},准备删除")
|
||||
self.logger.info(f"删除补丁文件夹: {patch_folder}")
|
||||
self.logger.debug(f"删除补丁文件夹: {patch_folder}")
|
||||
|
||||
import shutil
|
||||
shutil.rmtree(patch_folder)
|
||||
@@ -226,7 +226,7 @@ class PatchManager:
|
||||
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}")
|
||||
self.logger.debug(f"删除game/patch文件夹: {game_patch_folder}")
|
||||
|
||||
import shutil
|
||||
shutil.rmtree(game_patch_folder)
|
||||
@@ -250,7 +250,7 @@ class PatchManager:
|
||||
if os.path.exists(config_path):
|
||||
if debug_mode:
|
||||
self.logger.debug(f"DEBUG: 找到配置文件: {config_path},准备删除")
|
||||
self.logger.info(f"删除配置文件: {config_path}")
|
||||
self.logger.debug(f"删除配置文件: {config_path}")
|
||||
|
||||
os.remove(config_path)
|
||||
files_removed += 1
|
||||
@@ -263,7 +263,7 @@ class PatchManager:
|
||||
if os.path.exists(script_path):
|
||||
if debug_mode:
|
||||
self.logger.debug(f"DEBUG: 找到脚本文件: {script_path},准备删除")
|
||||
self.logger.info(f"删除脚本文件: {script_path}")
|
||||
self.logger.debug(f"删除脚本文件: {script_path}")
|
||||
|
||||
os.remove(script_path)
|
||||
files_removed += 1
|
||||
@@ -356,7 +356,7 @@ class PatchManager:
|
||||
self.logger.debug(f"DEBUG: 要卸载的游戏: {list(game_dirs.keys())}")
|
||||
|
||||
self.logger.info(f"开始批量卸载补丁,游戏数量: {len(game_dirs)}")
|
||||
self.logger.info(f"要卸载的游戏: {list(game_dirs.keys())}")
|
||||
self.logger.debug(f"要卸载的游戏: {list(game_dirs.keys())}")
|
||||
|
||||
for version, path in game_dirs.items():
|
||||
if debug_mode:
|
||||
|
||||
@@ -18,20 +18,20 @@ class PrivacyManager:
|
||||
"""初始化隐私协议管理器"""
|
||||
# 初始化日志
|
||||
self.logger = setup_logger("privacy_manager")
|
||||
self.logger.info("正在初始化隐私协议管理器")
|
||||
self.logger.debug("正在初始化隐私协议管理器")
|
||||
# 确保缓存目录存在
|
||||
os.makedirs(CACHE, exist_ok=True)
|
||||
self.config_file = os.path.join(CACHE, "privacy_config.json")
|
||||
self.privacy_config = self._load_privacy_config()
|
||||
|
||||
# 获取隐私协议内容和版本
|
||||
self.logger.info("读取本地隐私协议文件")
|
||||
self.logger.debug("读取本地隐私协议文件")
|
||||
self.privacy_content, self.current_privacy_version, error = get_local_privacy_policy()
|
||||
if error:
|
||||
self.logger.warning(f"读取本地隐私协议文件警告: {error}")
|
||||
# 使用默认版本作为备用
|
||||
self.current_privacy_version = PRIVACY_POLICY_VERSION
|
||||
self.logger.info(f"隐私协议版本: {self.current_privacy_version}")
|
||||
self.logger.debug(f"隐私协议版本: {self.current_privacy_version}")
|
||||
|
||||
# 检查隐私协议版本和用户同意状态
|
||||
self.privacy_accepted = self._check_privacy_acceptance()
|
||||
@@ -66,9 +66,9 @@ class PrivacyManager:
|
||||
stored_app_version = self.privacy_config.get("app_version", "0.0.0")
|
||||
privacy_accepted = self.privacy_config.get("privacy_accepted", False)
|
||||
|
||||
self.logger.info(f"存储的隐私协议版本: {stored_privacy_version}, 当前版本: {self.current_privacy_version}")
|
||||
self.logger.info(f"存储的应用版本: {stored_app_version}, 当前版本: {APP_VERSION}")
|
||||
self.logger.info(f"隐私协议接受状态: {privacy_accepted}")
|
||||
self.logger.debug(f"存储的隐私协议版本: {stored_privacy_version}, 当前版本: {self.current_privacy_version}")
|
||||
self.logger.debug(f"存储的应用版本: {stored_app_version}, 当前版本: {APP_VERSION}")
|
||||
self.logger.debug(f"隐私协议接受状态: {privacy_accepted}")
|
||||
|
||||
# 如果隐私协议版本变更,需要重新同意
|
||||
if stored_privacy_version != self.current_privacy_version:
|
||||
@@ -125,7 +125,7 @@ class PrivacyManager:
|
||||
"""
|
||||
# 如果用户已经同意了隐私协议,直接返回True不显示对话框
|
||||
if self.privacy_accepted:
|
||||
self.logger.info("用户已同意当前版本的隐私协议,无需再次显示")
|
||||
self.logger.debug("用户已同意当前版本的隐私协议,无需再次显示")
|
||||
return True
|
||||
|
||||
self.logger.info("首次运行或隐私协议版本变更,显示隐私对话框")
|
||||
|
||||
@@ -494,10 +494,32 @@ class UIManager:
|
||||
self.ui.menu.addSeparator()
|
||||
self.ui.menu.addMenu(self.dev_menu) # 添加开发者选项子菜单
|
||||
|
||||
# 创建哈希校验设置子菜单
|
||||
self.hash_settings_menu = QMenu("哈希校验设置", self.main_window)
|
||||
self.hash_settings_menu.setFont(menu_font)
|
||||
self.hash_settings_menu.setStyleSheet(menu_style)
|
||||
|
||||
# 添加禁用安装前哈希预检查选项
|
||||
self.disable_pre_hash_action = QAction("禁用安装前哈希预检查", self.main_window, checkable=True)
|
||||
self.disable_pre_hash_action.setFont(menu_font)
|
||||
|
||||
# 从配置中读取当前状态
|
||||
config = getattr(self.main_window, 'config', {})
|
||||
disable_pre_hash = False
|
||||
if isinstance(config, dict):
|
||||
disable_pre_hash = config.get("disable_pre_hash_check", False)
|
||||
|
||||
self.disable_pre_hash_action.setChecked(disable_pre_hash)
|
||||
self.disable_pre_hash_action.triggered.connect(self.toggle_disable_pre_hash_check)
|
||||
|
||||
# 添加到哈希校验设置子菜单
|
||||
self.hash_settings_menu.addAction(self.disable_pre_hash_action)
|
||||
|
||||
# 添加Debug子菜单到开发者选项菜单
|
||||
self.dev_menu.addMenu(self.debug_submenu)
|
||||
self.dev_menu.addMenu(self.hosts_submenu) # 添加hosts文件选项子菜单
|
||||
self.dev_menu.addMenu(self.ipv6_submenu) # 添加IPv6支持子菜单
|
||||
self.dev_menu.addMenu(self.hash_settings_menu) # 添加哈希校验设置子菜单
|
||||
|
||||
def _handle_ipv6_toggle(self, enabled):
|
||||
"""处理IPv6支持切换事件
|
||||
@@ -918,6 +940,45 @@ class UIManager:
|
||||
)
|
||||
msg_box.exec()
|
||||
|
||||
def toggle_disable_pre_hash_check(self, checked):
|
||||
"""切换禁用安装前哈希预检查的状态
|
||||
|
||||
Args:
|
||||
checked: 是否禁用安装前哈希预检查
|
||||
"""
|
||||
try:
|
||||
# 更新配置
|
||||
if hasattr(self.main_window, 'config'):
|
||||
self.main_window.config['disable_pre_hash_check'] = checked
|
||||
|
||||
# 保存配置到文件
|
||||
if hasattr(self.main_window, 'save_config'):
|
||||
self.main_window.save_config(self.main_window.config)
|
||||
|
||||
# 显示成功提示
|
||||
status = "禁用" if checked else "启用"
|
||||
msg_box = self._create_message_box(
|
||||
"设置已更新",
|
||||
f"\n已{status}安装前哈希预检查。\n\n{'安装时将跳过哈希预检查' if checked else '安装时将进行哈希预检查'}。\n"
|
||||
)
|
||||
msg_box.exec()
|
||||
else:
|
||||
# 如果配置不可用,恢复复选框状态
|
||||
self.disable_pre_hash_action.setChecked(not checked)
|
||||
msg_box = self._create_message_box(
|
||||
"错误",
|
||||
"\n配置管理器不可用,无法更新设置。\n"
|
||||
)
|
||||
msg_box.exec()
|
||||
except Exception as e:
|
||||
# 如果发生异常,恢复复选框状态
|
||||
self.disable_pre_hash_action.setChecked(not checked)
|
||||
msg_box = self._create_message_box(
|
||||
"错误",
|
||||
f"\n更新设置时发生异常:\n\n{str(e)}\n"
|
||||
)
|
||||
msg_box.exec()
|
||||
|
||||
def show_about_dialog(self):
|
||||
"""显示关于对话框"""
|
||||
about_text = f"""
|
||||
|
||||
@@ -144,12 +144,12 @@ class MainWindow(QMainWindow):
|
||||
"""根据配置设置调试模式."""
|
||||
if self.config.get("debug_mode"):
|
||||
self.debug_manager.start_logging()
|
||||
logger.info("通过配置启动调试模式")
|
||||
logger.debug("通过配置启动调试模式")
|
||||
|
||||
if hasattr(self.ui_manager, 'debug_action') and self.ui_manager.debug_action and self.ui_manager.debug_action.isChecked():
|
||||
if not self.debug_manager.logger:
|
||||
self.debug_manager.start_logging()
|
||||
logger.info("通过UI启动调试模式")
|
||||
logger.debug("通过UI启动调试模式")
|
||||
|
||||
self.ui_manager.setup_ui()
|
||||
|
||||
|
||||
@@ -614,7 +614,7 @@ class HostsManager:
|
||||
self.original_content = f.read()
|
||||
with open(self.backup_path, 'w', encoding='utf-8') as f:
|
||||
f.write(self.original_content)
|
||||
logger.info(f"Hosts文件已备份到: {self.backup_path}")
|
||||
logger.debug(f"Hosts文件已备份到: {self.backup_path}")
|
||||
return True
|
||||
except IOError as e:
|
||||
logger.error(f"备份hosts文件失败: {e}")
|
||||
|
||||
@@ -22,7 +22,7 @@ class ConfigFetchThread(QThread):
|
||||
def run(self):
|
||||
try:
|
||||
if self.debug_mode:
|
||||
logger.info("--- Starting to fetch cloud config ---")
|
||||
logger.debug("--- Starting to fetch cloud config ---")
|
||||
# 完全隐藏URL
|
||||
logger.debug(f"DEBUG: Requesting URL: ***URL protection***")
|
||||
logger.debug(f"DEBUG: Using Headers: {self.headers}")
|
||||
@@ -72,7 +72,7 @@ class ConfigFetchThread(QThread):
|
||||
self.finished.emit(None, error_msg)
|
||||
finally:
|
||||
if self.debug_mode:
|
||||
logger.info("--- Finished fetching cloud config ---")
|
||||
logger.debug("--- Finished fetching cloud config ---")
|
||||
|
||||
def _create_safe_config_for_logging(self, config_data):
|
||||
"""创建用于日志记录的安全配置副本,隐藏敏感URL
|
||||
|
||||
Reference in New Issue
Block a user