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); }