Appearance
Go 模型库扫描
系统概览
资源库扫描的 Go 侧实现:按 8 个分类(model/motion/audio/pose/scene/environment/outfit/prop)并行扫描目录树,识别扩展名与 ZIP 内部条目(PMX/VMD/Audio/VPD),返回统一 ModelEntry 列表供前端资源库渲染;按需解析 PMX 头部返回 ModelMeta。
核心职责
ScanModelDir()— 触发全量扫描,8 分类各一 goroutine 并行,scanAllCategories合并结果。expandZipEntries()— 打开 ZIP 识别内部可导入文件,Shift-JIS/GBK 用bestDecode()解码文件名。GetModelMeta(path)/GetModelMetaBatch(paths)— 按需解析 PMX 头部(走internal/util/pmx.go的ParsePMXHeader)。LoadOutfitFile— 返回换装文件内容。ToggleFavorite— 收藏标记(写入配置)。
对外 API(节选)
ScanModelDir() ([]ModelEntry, error)— 全库扫描主入口(绑定ScanModelDir)。GetModelMetaBatch(paths []string) (map[string]ModelMeta, error)— 批量元数据,前端缩略图/详情用。SelectDir() (string, error)— 弹目录选择(安卓经fileaccess能力守卫,见 android-file-access 卡)。
与其他子系统关系
- 前端资源库:
frontend/src/menus/library*.ts调用ScanModelDir/GetModelMetaBatch。 - 依赖
internal/util/pmx.go(PMX 头解析)、internal/dialogs(SelectDir)。 - 与
go-zipextract.md共享bestDecode编码兜底逻辑。
前端接入入口
- 资源库菜单 → 加载资源库(
library-setup.ts/library-core.ts)。 - 模型详情/缩略图:
model-detail.ts、thumbnail-capture.ts走GetModelMetaBatch。
不变量
- 分类枚举与前端
mapCategoryKey期望一致;新增分类须同步前端渲染与formatByCategory。 - 扫描结果必须按返回顺序消费,不可依赖 goroutine 完成顺序。
验证入口
- 测试:
internal/app/app_test.go(含bestDecode用例)。 - 命令:
go test ./internal/app/ -run TestApp。