Merge fdcan-feature into main

This commit is contained in:
2026-01-01 16:59:45 +08:00
26 changed files with 199 additions and 83 deletions

View File

@@ -71,7 +71,7 @@ class analyzing_ioc:
@staticmethod
def get_enabled_can_from_ioc(ioc_path):
"""
获取已启用的CAN列表
获取已启用的CAN列表不包括FDCAN
返回格式: ['CAN1', 'CAN2'] 等
"""
enabled_can = []
@@ -84,6 +84,7 @@ class analyzing_ioc:
key, value = line.split('=', 1)
key = key.strip()
value = value.strip()
# 只匹配CAN不包括FDCAN
if key.startswith('Mcu.IP') and value.startswith('CAN') and not value.startswith('FDCAN'):
can_name = value.split('.')[0] if '.' in value else value
if can_name not in enabled_can:

View File

@@ -97,44 +97,19 @@ class CodeGenerator:
assets_dir = ""
if getattr(sys, 'frozen', False):
# 打包后的环境
print("检测到打包环境")
# 优先使用可执行文件所在目录(支持更新后的文件)
# 打包后的环境 - 始终使用可执行文件所在目录
# 这样可以使用安装目录下的文件,而不是打包进去的文件
exe_dir = os.path.dirname(sys.executable)
exe_assets = os.path.join(exe_dir, "assets")
assets_dir = os.path.join(exe_dir, "assets")
print(f"打包环境:使用可执行文件目录: {assets_dir}")
# 如果exe目录下不存在assets但_MEIPASS中有则首次复制过去
if not os.path.exists(exe_assets) and hasattr(sys, '_MEIPASS'):
base_path = getattr(sys, '_MEIPASS')
meipass_assets = os.path.join(base_path, "assets")
if os.path.exists(meipass_assets):
try:
import shutil
print(f"首次运行:从 {meipass_assets} 复制到 {exe_assets}")
shutil.copytree(meipass_assets, exe_assets)
print("初始资源复制成功")
except Exception as e:
print(f"复制初始资源失败: {e}")
# 优先使用exe目录下的assets这样可以读取更新后的文件
if os.path.exists(exe_assets):
assets_dir = exe_assets
print(f"使用可执行文件目录: {assets_dir}")
# 后备方案使用PyInstaller的临时解包目录
elif hasattr(sys, '_MEIPASS'):
base_path = getattr(sys, '_MEIPASS')
assets_dir = os.path.join(base_path, "assets")
print(f"后备使用PyInstaller临时目录: {assets_dir}")
# 最后尝试工作目录
else:
cwd_assets = os.path.join(os.getcwd(), "assets")
if os.path.exists(cwd_assets):
assets_dir = cwd_assets
print(f"从工作目录找到assets: {assets_dir}")
else:
assets_dir = exe_assets # 即使不存在也使用exe目录后续会创建
print(f"使用默认路径(将创建): {assets_dir}")
# 如果assets目录不存在创建它
if not os.path.exists(assets_dir):
try:
os.makedirs(assets_dir, exist_ok=True)
print(f"创建assets目录: {assets_dir}")
except Exception as e:
print(f"创建assets目录失败: {e}")
else:
# 开发环境
current_dir = os.path.dirname(os.path.abspath(__file__))