{"record":{"id":"934a33c040b83d3d","repo":"babalae/better-genshin-impact","slug":"filename-934a33","errorCode":null,"errorMessage":"分层地图数据文件夹中中存在无法解析的文件名: {fileName}","messagePattern":"分层地图数据文件夹中中存在无法解析的文件名: (.+?)","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"critical","filePath":"BetterGenshinImpact/GameTask/Common/Map/Maps/Base/BaseMapLayer.cs","lineNumber":78,"sourceCode":"        var layers = new List<BaseMapLayer>();\n        var layerDir = Path.Combine(Global.Absolute(@\"Assets\\Map\\\"), baseMap.Type.ToString());\n        if (!Directory.Exists(layerDir))\n        {\n            return layers;\n        }\n\n        var files = Directory.GetFiles(layerDir);\n        var validFiles = files.Where(f => (f.EndsWith(\".kp.bin\") || f.EndsWith(\".mat.png\"))\n                                          && !f.EndsWith(\"Teyvat_0_256_SIFT.kp.bin\")\n                                          && !f.EndsWith(\"Teyvat_0_256_SIFT.mat.png\"));\n        // 解析后按 floor 分组，然后按 floor 创建BaseMapLayer\n        var groupedFiles = validFiles.GroupBy(file =>\n        {\n            var fileName = Path.GetFileNameWithoutExtension(file);\n            var parts = fileName.Split('_');\n            if (parts.Length < 3)\n            {\n                throw new Exception($\"分层地图数据文件夹中中存在无法解析的文件名: {fileName}\");\n            }\n\n            return int.TryParse(parts[1], out var floor) ? floor : throw new Exception($\"分层地图数据文件夹中中存在无法解析的文件名: {fileName}\");\n        });\n\n        foreach (var group in groupedFiles)\n        {\n            var floor = group.Key;\n            var layer = new BaseMapLayer(baseMap) { Floor = floor };\n\n            // 查找特征文件路径\n            var kpFilePath = group.First(f => f.EndsWith(\".kp.bin\"));\n            var matFilePath = group.First(f => f.EndsWith(\".mat.png\"));\n\n            SpeedTimer speedTimer = new($\"加载 {Path.GetFileNameWithoutExtension(kpFilePath)} 地图特征\");\n            // 加载特征数据\n            layer.TrainKeyPoints = FeatureStorageHelper.LoadKeyPointArray(kpFilePath) ?? throw new Exception($\"地图数据加载失败，文件: {kpFilePath}\");\n            speedTimer.Record(\"特征点\");","sourceCodeStart":60,"sourceCodeEnd":96,"githubUrl":"https://github.com/babalae/better-genshin-impact/blob/a7cb36712dcb409be610257d877fcea3597e9d6b/BetterGenshinImpact/GameTask/Common/Map/Maps/Base/BaseMapLayer.cs#L60-L96","documentation":"Thrown while grouping map-feature files in BaseMapLayer.LoadLayers when a filename in the map data directory, after stripping extension and splitting on '_', yields fewer than 3 parts. The expected naming convention is '<MapType>_<floor>_<size>_<algo>', e.g. 'Teyvat_0_2048_SIFT'. Fewer than 3 segments means the file does not follow the contract and cannot be assigned a floor.","triggerScenarios":"LoadLayers enumerates Directory.GetFiles(layerDir), filters to *.kp.bin / *.mat.png (excluding the special 256 SIFT files), then GroupBy parses each name. Any stray file matching the extension filter but not the naming convention — e.g. a backup 'Teyvat.kp.bin', a README renamed, a temp download, or a hand-placed file — triggers this on the first GroupBy evaluation (deferred, so it fires when groupedFiles is first enumerated in the foreach).","commonSituations":"User or a tool dropped an unexpectedly named *.kp.bin or *.mat.png into Assets\\Map\\<Type>; a partial/corrupted download left a truncated filename; the map-generation pipeline changed its naming and old files remain; a backup file like 'Teyvat_0_2048_SIFT.kp.bin.bak' was renamed to '.kp.bin'.","solutions":["Inspect the contents of Assets\\Map\\<MapType> for any *.kp.bin / *.mat.png file whose name has fewer than 3 underscore-separated segments and remove or rename it.","Ensure all feature files follow the '<Type>_<floor>_<size>_<algo>' naming convention.","If the directory may legitimately contain non-conforming files, pre-filter validFiles with a regex like ^[^_]+_\\d+_[^_]+_[^_]+$ before grouping.","Re-run the map-data generation/export tool to regenerate a clean dataset."],"exampleFix":"// before\nvar validFiles = files.Where(f => (f.EndsWith(\".kp.bin\") || f.EndsWith(\".mat.png\"))\n                                  && !f.EndsWith(\"Teyvat_0_256_SIFT.kp.bin\")\n                                  && !f.EndsWith(\"Teyvat_0_256_SIFT.mat.png\"));\n\n// after — also enforce the naming convention so stray files are skipped, not fatal\nvar namePattern = new System.Text.RegularExpressions.Regex(@\"^[^_]+_(\\-?\\d+)_\\d+_[^_]+$\");\nvar validFiles = files.Where(f => (f.EndsWith(\".kp.bin\") || f.EndsWith(\".mat.png\"))\n                                  && !f.EndsWith(\"Teyvat_0_256_SIFT.kp.bin\")\n                                  && !f.EndsWith(\"Teyvat_0_256_SIFT.mat.png\")\n                                  && namePattern.IsMatch(Path.GetFileNameWithoutExtension(f)));","handlingStrategy":"validation","validationCode":"// Pre-validate filenames before grouping\nvar namePattern = new System.Text.RegularExpressions.Regex(@\"^[^_]+_\\-?\\d+_\\d+_[^_]+$\");\nvar badFiles = files.Where(f => (f.EndsWith(\".kp.bin\") || f.EndsWith(\".mat.png\"))\n    && !namePattern.IsMatch(Path.GetFileNameWithoutExtension(f))).ToList();\nif (badFiles.Count > 0) throw new Exception($\"存在不符合命名规范的地图文件: {string.Join(\", \", badFiles)}\");","typeGuard":null,"tryCatchPattern":"try { var layers = BaseMapLayer.LoadLayers(baseMap); }\ncatch (Exception ex) when (ex.Message.Contains(\"无法解析的文件名\"))\n{\n    Logger.LogError(\"地图特征文件命名不规范，请检查 Assets\\\\Map 目录: {Msg}\", ex.Message);\n    throw;\n}","preventionTips":["Always name feature files '<Type>_<floor>_<size>_<algo>.kp.bin/.mat.png'.","Keep the Assets\\Map directory clean of stray/backup files.","Regenerate datasets with the official tool rather than hand-placing files."],"tags":["map-data","filename-parse","asset-loading","config"],"backgroundTag":null,"analyzedSha":"a7cb36712dcb409be610257d877fcea3597e9d6b","analyzedAt":"2026-08-13T16:44:57.548Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}