fix: 还原 cmd /c type 读取并移除路径字符黑名单 — 加密钻带文件只能用 cmd type 读取

b75439c 以"命令行是多余的"为由把读取改成 FileStream+StreamReader,是错误前提:
项目存在无法用标准文件 I/O 读取的加密 txt/钻带文件(CLAUDE.md "Encrypted file reading"、
Docs/readme.md "读取加密钻带(使用cmd命令type读取)"、
Docs/刀具列表拖动排序功能说明.md "加密文件:使用 cmd 命令读取"均有记录),
该改动会导致这些文件读取失败。本次回退。

改动:
- 还原 CommandTypeFileReader.cs:cmd.exe /d /c type(ANSI/936 解码),
  失败时退出码与 stderr 保留在异常消息里
- 删除 ForbiddenPathChars 与两处字符校验(本次报错根因):
  ( ) & ^ @ 空格在双引号内对 type 安全,黑名单只会误伤 (D2-f)、(1) 等正常文件名
- 保留"非空路径""文件存在"校验与 ReadAllText(path, encoding) 重载
- 删除 AnsiFileReader.cs,15 处调用点改回
- CLAUDE.md / .trellis/spec/:恢复"加密文件必须用 cmd type"的说明,
  并标注为不可优化掉的硬约束(含 b75439c 反例)

验证:demo_drl 全部 36 个文件与 2335894 实现逐字符一致、行数一致;
含 ( ) & 空格路径实测可读(旧黑名单实现抛"文件路径包含不允许的命令行特殊字符");
cmd 失败消息含退出码与 stderr;dotnet build -p:Platform=x86 0 错误,
警告集与 HEAD 基线完全一致。
This commit is contained in:
2026-09-20 13:28:37 +08:00
parent b75439cff4
commit 209268ee18
11 changed files with 168 additions and 143 deletions

View File

@@ -39,7 +39,7 @@ namespace DrillTools
ShutdownMode = ShutdownMode.OnExplicitShutdown;
// 只读取和解析文件一次,提取所有需要的信息
string content = AnsiFileReader.ReadAllText(filePath);
string content = CommandTypeFileReader.ReadAllText(filePath);
var viewModel = new MainWindowViewModel
{
IsStartupDrillTapeFile = true,
@@ -150,7 +150,7 @@ namespace DrillTools
ShouldCheckSortFileOnLoad = false
};
string content = AnsiFileReader.ReadAllText(filePath);
string content = CommandTypeFileReader.ReadAllText(filePath);
viewModel.OriginalFilePath = filePath;
viewModel.LoadToolsFromDrillTape(content);
@@ -185,7 +185,7 @@ namespace DrillTools
ShouldCheckSortFileOnLoad = false
};
string content = AnsiFileReader.ReadAllText(filePath);
string content = CommandTypeFileReader.ReadAllText(filePath);
viewModel.LoadToolsFromDrillTape(content);
string outputFilePath = viewModel.GeneratePpDrillTape();
@@ -232,7 +232,7 @@ namespace DrillTools
var result = scalingWindow.ScalingResult.Value;
string content = AnsiFileReader.ReadAllText(filePath);
string content = CommandTypeFileReader.ReadAllText(filePath);
string scaledContent = Integration.ExcellonScaler.Scale(content, result.Kx, result.Ky);
// 在源文件所在目录下新建子文件夹 dr2 x{InputX} y{InputY}