feat: 注册右键菜单"用DrillTools打开",新增.dr3/.trg后缀支持

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
2026-05-23 16:35:56 +08:00
parent cb27e8917a
commit b009ece1cd

View File

@@ -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
{
// 非管理员权限时注册可能失败,静默忽略不影响主功能
}
}
/// <summary>
/// 验证是否为有效的钻带文件
/// </summary>
@@ -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);
}