mirror of
https://github.com/hyb-oyqq/FRAISEMOE-Addons-Installer-NEXT.git
synced 2025-12-15 19:30:28 +00:00
feat(core): 移除资源验证功能,简化主窗口代码
- 删除了关键资源验证和测试功能,优化了主窗口的代码结构。 - 资源加载流程将通过正常的加载机制进行,提升了代码的可读性和维护性。
This commit is contained in:
@@ -4,7 +4,7 @@ import datetime
|
||||
|
||||
# 配置信息
|
||||
app_data = {
|
||||
"APP_VERSION": "1.3.2",
|
||||
"APP_VERSION": "1.4.0",
|
||||
"APP_NAME": "FRAISEMOE Addons Installer NEXT",
|
||||
"TEMP": "TEMP",
|
||||
"CACHE": "FRAISEMOE",
|
||||
|
||||
@@ -87,144 +87,8 @@ class MainWindow(QMainWindow):
|
||||
self.installed_status = {}
|
||||
self.hash_msg_box = None
|
||||
|
||||
# 验证关键资源
|
||||
self._verify_resources()
|
||||
# 资源验证已移除,素材通过正常加载流程使用
|
||||
|
||||
def _verify_resources(self):
|
||||
"""验证关键资源文件是否存在,帮助调试资源加载问题"""
|
||||
from utils import resource_path
|
||||
logger.info("开始验证关键资源文件...")
|
||||
|
||||
# 关键字体文件
|
||||
font_files = [
|
||||
os.path.join("assets", "fonts", "SmileySans-Oblique.ttf")
|
||||
]
|
||||
|
||||
# 关键图标文件
|
||||
icon_files = [
|
||||
os.path.join("assets", "images", "ICO", "icon.png"),
|
||||
os.path.join("assets", "images", "ICO", "icon.ico"),
|
||||
os.path.join("assets", "images", "BTN", "Button.png"),
|
||||
os.path.join("assets", "images", "BTN", "exit.bmp"),
|
||||
os.path.join("assets", "images", "BTN", "start_install.bmp")
|
||||
]
|
||||
|
||||
# 关键背景图片
|
||||
bg_files = [
|
||||
os.path.join("assets", "images", "BG", "bg1.jpg"),
|
||||
os.path.join("assets", "images", "BG", "bg2.jpg"),
|
||||
os.path.join("assets", "images", "BG", "bg3.jpg"),
|
||||
os.path.join("assets", "images", "BG", "bg4.jpg"),
|
||||
os.path.join("assets", "images", "BG", "menubg.jpg")
|
||||
]
|
||||
|
||||
# 记录缺失的资源
|
||||
missing_resources = []
|
||||
|
||||
# 验证字体文件
|
||||
for font_file in font_files:
|
||||
path = resource_path(font_file)
|
||||
if not os.path.exists(path):
|
||||
missing_resources.append(font_file)
|
||||
logger.warning(f"缺失字体文件: {font_file}, 尝试路径: {path}")
|
||||
else:
|
||||
logger.info(f"已找到字体文件: {font_file}")
|
||||
|
||||
# 验证图标文件
|
||||
for icon_file in icon_files:
|
||||
path = resource_path(icon_file)
|
||||
if not os.path.exists(path):
|
||||
missing_resources.append(icon_file)
|
||||
logger.warning(f"缺失图标文件: {icon_file}, 尝试路径: {path}")
|
||||
else:
|
||||
logger.info(f"已找到图标文件: {icon_file}")
|
||||
|
||||
# 验证背景图片
|
||||
for bg_file in bg_files:
|
||||
path = resource_path(bg_file)
|
||||
if not os.path.exists(path):
|
||||
missing_resources.append(bg_file)
|
||||
logger.warning(f"缺失背景图片: {bg_file}, 尝试路径: {path}")
|
||||
else:
|
||||
logger.info(f"已找到背景图片: {bg_file}")
|
||||
|
||||
# 如果有缺失资源,记录摘要
|
||||
if missing_resources:
|
||||
logger.error(f"总计 {len(missing_resources)} 个关键资源文件缺失!")
|
||||
# 如果在调试模式下,显示警告对话框
|
||||
if self.config.get("debug_mode", False):
|
||||
from PySide6.QtWidgets import QMessageBox
|
||||
msg = QMessageBox()
|
||||
msg.setIcon(QMessageBox.Warning)
|
||||
msg.setWindowTitle("资源加载警告")
|
||||
msg.setText("检测到缺失的关键资源文件!")
|
||||
msg.setInformativeText(f"有 {len(missing_resources)} 个资源文件未找到。\n请检查日志文件获取详细信息。")
|
||||
msg.setStandardButtons(QMessageBox.Ok)
|
||||
msg.exec()
|
||||
else:
|
||||
logger.info("所有关键资源文件验证通过")
|
||||
|
||||
# 测试资源加载功能
|
||||
self._test_resource_loading()
|
||||
|
||||
def _test_resource_loading(self):
|
||||
"""测试资源加载功能,验证图片和字体是否可以正确加载"""
|
||||
logger.info("开始测试资源加载功能...")
|
||||
|
||||
from PySide6.QtGui import QFontDatabase, QPixmap, QImage, QFont
|
||||
from utils import resource_path, load_image_from_file
|
||||
|
||||
# 测试字体加载
|
||||
logger.info("测试字体加载...")
|
||||
font_path = resource_path(os.path.join("assets", "fonts", "SmileySans-Oblique.ttf"))
|
||||
if os.path.exists(font_path):
|
||||
font_id = QFontDatabase.addApplicationFont(font_path)
|
||||
if font_id != -1:
|
||||
font_families = QFontDatabase.applicationFontFamilies(font_id)
|
||||
if font_families:
|
||||
logger.info(f"字体加载测试成功: {font_families[0]}")
|
||||
else:
|
||||
logger.error("字体加载测试失败: 无法获取字体族")
|
||||
else:
|
||||
logger.error(f"字体加载测试失败: 无法加载字体文件 {font_path}")
|
||||
else:
|
||||
logger.error(f"字体加载测试失败: 文件不存在 {font_path}")
|
||||
|
||||
# 测试图片加载 - 使用QPixmap直接加载
|
||||
logger.info("测试图片加载 (QPixmap)...")
|
||||
icon_path = resource_path(os.path.join("assets", "images", "ICO", "icon.png"))
|
||||
if os.path.exists(icon_path):
|
||||
pixmap = QPixmap(icon_path)
|
||||
if not pixmap.isNull():
|
||||
logger.info(f"QPixmap加载测试成功: {icon_path}, 大小: {pixmap.width()}x{pixmap.height()}")
|
||||
else:
|
||||
logger.error(f"QPixmap加载测试失败: {icon_path}")
|
||||
else:
|
||||
logger.error(f"QPixmap加载测试失败: 文件不存在 {icon_path}")
|
||||
|
||||
# 测试图片加载 - 使用QImage加载
|
||||
logger.info("测试图片加载 (QImage)...")
|
||||
bg_path = resource_path(os.path.join("assets", "images", "BG", "bg1.jpg"))
|
||||
if os.path.exists(bg_path):
|
||||
image = QImage(bg_path)
|
||||
if not image.isNull():
|
||||
logger.info(f"QImage加载测试成功: {bg_path}, 大小: {image.width()}x{image.height()}")
|
||||
else:
|
||||
logger.error(f"QImage加载测试失败: {bg_path}")
|
||||
else:
|
||||
logger.error(f"QImage加载测试失败: 文件不存在 {bg_path}")
|
||||
|
||||
# 测试自定义加载函数
|
||||
logger.info("测试自定义图片加载函数...")
|
||||
btn_path = resource_path(os.path.join("assets", "images", "BTN", "Button.png"))
|
||||
pixmap = load_image_from_file(btn_path)
|
||||
if not pixmap.isNull():
|
||||
logger.info(f"自定义图片加载函数测试成功: {btn_path}, 大小: {pixmap.width()}x{pixmap.height()}")
|
||||
else:
|
||||
logger.error(f"自定义图片加载函数测试失败: {btn_path}")
|
||||
|
||||
logger.info("资源加载功能测试完成")
|
||||
|
||||
def _init_managers(self):
|
||||
"""初始化所有管理器."""
|
||||
self.animator = MultiStageAnimations(self.ui, self)
|
||||
|
||||
Reference in New Issue
Block a user