Skip to content

fix: 修复已有 AD 库追加时的名称编码与存储映射 - #9

Merged
Travelerrrrrr merged 2 commits into
Travelerrrrrr:mainfrom
Loppokey:fix/ad-library-name-encoding
Oct 19, 2026
Merged

Travelerrrrrr merged 2 commits into
Travelerrrrrr:mainfrom
Loppokey:fix/ad-library-name-encoding

Conversation

@Loppokey

@Loppokey Loppokey commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

已有 .SchLib / .PcbLib 中的中文、Ω、± 或 *、? 名称会导致“追加”配置被错误拒绝,提示:

无法使用所选文件:所选 AD 库无法读取:原库索引指向不存在的条目

本修复在不重命名旧器件、不改写旧器件数据的前提下恢复追加。报告者已经实际运行修复构建,并反馈验证正常。

复现与原因

  1. 准备包含 GBK/GB18030 名称索引的 AD 原生库,例如符号名 0603_10kΩ ±1%、中文封装名,或包含 * / ? 的名称。
  2. 在 LCSC3D 2.4.4 的“追加”页面选择这些已有库。
  3. 即使库内对应的组件 Data 流实际存在,也会提示“原库索引指向不存在的条目”,无法继续追加。

现有读取器将 ANSI 索引统一按 cp1252 解释,而 CFB 存储名称是 Unicode。GBK/UTF-8 名称因此与实际存储目录不匹配;cp1252 未定义的字节还可能直接触发解码错误。另一个不匹配来自 * / ? 未按 AD 的目录命名方式转换为 _。

修改位置与行为

文件 修改内容
app/lcsc3d/eda/library_merge.py 对照实际 CFB 目录解析名称;原始匹配优先,UTF-8/GB18030 回退仅在唯一匹配时接受。遵守显式 SectionKeys 映射,歧义或确实缺失仍拒绝追加。保留原始二进制名称索引和旧符号头字段;兼容早期导出中保留字面 * / ? 的目录;补充读取和解析诊断。
app/lcsc3d/eda/altium.py 补齐 * / ? 到 _ 的转换;通过 surrogateescape 保留 ANSI 中 cp1252 未定义字节的往返能力。
app/tests/test_legacy_library_names.py 新增 8 项测试,覆盖编码、特殊字符、别名/长名称、二进制索引、旧封装复用、重复追加、歧义/缺失拒绝以及日志不暴露用户路径和器件名。

名称回退只改变查找方式。旧索引名称字节、既有组件、模型和未知数据流保持原样;新内容仍通过现有备份、原子写入及取消恢复流程提交。

验证

  • 新增名称兼容回归:8/8 通过。
  • 既有库集成回归 test_library_integration.py:12/12 通过。
  • 在两份实际库的副本上离线追加 C2040、C20197:符号 277 → 279,封装 381 → 383。
  • 对比原库 3,846 个数据流,变化限于必要索引;旧器件、3D 模型和其他数据保持一致。再次追加相同器件后,结果文件逐字节不变。
  • 最终 Windows EXE 的 --self-test-export:17 个导出/合并/追加/工程流程通过。
  • 核对 EXE 内 93 个应用模块与修复源码一致;报告者随后实测确认修复正常。

全量回归在当前 Windows 环境运行 841 项,仍有 12 个 failure 和 2 个 error,未声称全量通过:其中 12 个失败项在未修改的上游源码中也可复现,涉及路径长度、字体及界面时序;另外 2 项在上游和修复版分别单独重跑均通过。未在本次 PR 中扩展修复这些问题。

没有将报告者的库文件、个人路径、登录信息、日志或 EXE/源码 ZIP 提交到仓库,也未修改版本号或发布 Release。

@Loppokey Loppokey changed the title 已有 AD 库追加误报“原库索引指向不存在的条目”:名称编码与特殊字符映射(含修复补丁) fix: 修复已有 AD 库追加时的名称编码与存储映射 Oct 19, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-19T04:09:56.947396Z 52411bc PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 52411bcf98

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +53 to +54
result[key.removeprefix('%UTF8%').upper()] = value.decode(
'utf-8' if unicode_value else 'cp1252', errors='strict' if unicode_value else 'surrogateescape')

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Parse GBK trail bytes before splitting parameter fields

When a legacy SchLib contains a GBK/GB18030 parameter value whose multibyte character has 0x7c as a trail byte (for example, 東 is 96 7c in GBK), parameters() has already split the block on every b'|' before this new fallback decoding runs. LIBREF0 is therefore truncated to 0x96, so storage_spellings() cannot recover 東 and LibraryIndex still rejects the valid 東/Data storage with the same missing-entry error; the parameter delimiters need to be parsed in an MBCS-aware way while preserving the raw value.

Useful? React with 👍 / 👎.

@Travelerrrrrr
Travelerrrrrr merged commit 52411bc into Travelerrrrrr:main Oct 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants