From b009ece1cd76a4e691b18439b9335675de8ec421 Mon Sep 17 00:00:00 2001 From: "Mr.Xia" <1424473282@qq.com> Date: Sat, 23 May 2026 16:35:56 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B3=A8=E5=86=8C=E5=8F=B3=E9=94=AE?= =?UTF-8?q?=E8=8F=9C=E5=8D=95"=E7=94=A8DrillTools=E6=89=93=E5=BC=80"?= =?UTF-8?q?=EF=BC=8C=E6=96=B0=E5=A2=9E.dr3/.trg=E5=90=8E=E7=BC=80=E6=94=AF?= =?UTF-8?q?=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 4.7 --- App.xaml.cs | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/App.xaml.cs b/App.xaml.cs index 43e6379..0e5bb3c 100644 --- a/App.xaml.cs +++ b/App.xaml.cs @@ -1,5 +1,6 @@ using System.Configuration; using System.Data; +using System.Diagnostics; using System.IO; using System.Linq; using System.Text; @@ -16,6 +17,7 @@ namespace DrillTools { base.OnStartup(e); Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); + RegisterShellContextMenu(); string? filePath = null; if (e.Args.Length > 0) @@ -246,6 +248,27 @@ namespace DrillTools } } + private static void RegisterShellContextMenu() + { + try + { + string exePath = Process.GetCurrentProcess().MainModule!.FileName!; + string[] extensions = { ".drl", ".dr2", ".dr3", ".trg", ".dpin", ".txt" }; + string menuText = "用DrillTools打开"; + + foreach (string ext in extensions) + { + string keyPath = $@"SystemFileAssociations\{ext}\shell\{menuText}\command"; + using var key = Microsoft.Win32.Registry.ClassesRoot.CreateSubKey(keyPath); + key.SetValue("", $"\"{exePath}\" \"%1\""); + } + } + catch + { + // 非管理员权限时注册可能失败,静默忽略不影响主功能 + } + } + /// /// 验证是否为有效的钻带文件 /// @@ -261,7 +284,7 @@ namespace DrillTools // 检查文件扩展名是否为支持的钻带文件格式 string extension = Path.GetExtension(filePath).ToLowerInvariant(); - string[] supportedExtensions = { ".txt", ".drl", ".dr2", ".dpin" }; + string[] supportedExtensions = { ".txt", ".drl", ".dr2", ".dr3", ".trg", ".dpin" }; return supportedExtensions.Contains(extension); }