From 5ee4fb9c5903aecba78495e2794daadaa0f42d47 Mon Sep 17 00:00:00 2001 From: "Mr.Xia" <1424473282@qq.com> Date: Mon, 3 Aug 2026 18:28:36 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=9C=AA=E5=8C=B9=E9=85=8D=E7=9B=B4?= =?UTF-8?q?=E5=BE=84=E5=9C=A8=E5=AE=8C=E6=88=90=E5=BC=B9=E7=AA=97=E4=B8=AD?= =?UTF-8?q?=E6=8F=90=E7=A4=BA=20=E2=80=94=20ReplaceParameters=20=E8=BF=94?= =?UTF-8?q?=E5=9B=9E=20unmatchedDiameters=20=E5=88=97=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- App.xaml.cs | 15 ++++++++++++--- RouParameterReplacer.cs | 16 ++++++++++++---- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/App.xaml.cs b/App.xaml.cs index 499da10..0770562 100644 --- a/App.xaml.cs +++ b/App.xaml.cs @@ -1,6 +1,7 @@ using System.Configuration; using System.Data; using System.Diagnostics; +using System.Globalization; using System.IO; using System.Linq; using System.Text; @@ -333,11 +334,19 @@ namespace DrillTools if (selectionWindow.SelectedFilePath == null) return; - RouParameterReplacer.ReplaceParameters(filePath, selectionWindow.SelectedFilePath); + RouParameterReplacer.ReplaceParameters(filePath, selectionWindow.SelectedFilePath, out var unmatchedDiameters); + + string message = $"参数替换完成:\n{filePath}\n原文件已备份为:\n{Path.GetFileName(filePath)}.bak"; + + if (unmatchedDiameters.Count > 0) + { + var diaStrings = unmatchedDiameters.Select(d => d.ToString("F3", CultureInfo.InvariantCulture)).ToList(); + message += $"\n\n⚠ 以下直径未找到匹配参数,已保留原行:\n{string.Join(", ", diaStrings)}"; + } System.Windows.MessageBox.Show( - $"参数替换完成:\n{filePath}\n原文件已备份为 .bak", - "替换完成", + message, + "参数替换完成", MessageBoxButton.OK, MessageBoxImage.Information); } diff --git a/RouParameterReplacer.cs b/RouParameterReplacer.cs index 7639afc..d279ada 100644 --- a/RouParameterReplacer.cs +++ b/RouParameterReplacer.cs @@ -36,7 +36,7 @@ namespace DrillTools /// /// .rou 文件完整路径 /// 参数 .txt 文件完整路径 - public static void ReplaceParameters(string rouFilePath, string paramFilePath) + public static void ReplaceParameters(string rouFilePath, string paramFilePath, out List unmatchedDiameters) { // 1. 读取参数文件,构建直径→参数字符串映射 var paramDict = LoadParameterDictionary(paramFilePath); @@ -47,8 +47,9 @@ namespace DrillTools // 2. 读取 .rou 文件 string rouContent = CommandTypeFileReader.ReadAllText(rouFilePath); - // 3. 执行替换 - string replacedContent = ReplaceParametersInContent(rouContent, paramDict); + // 3. 执行替换(同时收集未匹配直径) + var unmatchedSet = new HashSet(); + string replacedContent = ReplaceParametersInContent(rouContent, paramDict, unmatchedSet); // 4. 备份原文件 string backupFilePath = rouFilePath + ".bak"; @@ -57,6 +58,9 @@ namespace DrillTools // 5. 写回文件 using var writer = new StreamWriter(rouFilePath, false, Encoding.GetEncoding(Gb2312CodePage)); writer.Write(replacedContent); + + // 6. 输出未匹配直径 + unmatchedDiameters = new List(unmatchedSet); } /// @@ -92,7 +96,7 @@ namespace DrillTools /// /// 在 .rou 文件内容中,将 M48~% 区域内的刀径行末尾追加参数。 /// - private static string ReplaceParametersInContent(string rouContent, Dictionary paramDict) + private static string ReplaceParametersInContent(string rouContent, Dictionary paramDict, HashSet unmatchedDiameters) { var lines = DrillTapeLineParser.SplitLines(rouContent); var builder = new StringBuilder(rouContent.Length + 1024); @@ -144,6 +148,10 @@ namespace DrillTools builder.Append(line.LineEnding); continue; } + else + { + unmatchedDiameters.Add(diameter); + } } }