feat: 注册右键菜单"用DrillTools打开",新增.dr3/.trg后缀支持
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
25
App.xaml.cs
25
App.xaml.cs
@@ -1,5 +1,6 @@
|
|||||||
using System.Configuration;
|
using System.Configuration;
|
||||||
using System.Data;
|
using System.Data;
|
||||||
|
using System.Diagnostics;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
@@ -16,6 +17,7 @@ namespace DrillTools
|
|||||||
{
|
{
|
||||||
base.OnStartup(e);
|
base.OnStartup(e);
|
||||||
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
|
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
|
||||||
|
RegisterShellContextMenu();
|
||||||
|
|
||||||
string? filePath = null;
|
string? filePath = null;
|
||||||
if (e.Args.Length > 0)
|
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>
|
||||||
/// 验证是否为有效的钻带文件
|
/// 验证是否为有效的钻带文件
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -261,7 +284,7 @@ namespace DrillTools
|
|||||||
|
|
||||||
// 检查文件扩展名是否为支持的钻带文件格式
|
// 检查文件扩展名是否为支持的钻带文件格式
|
||||||
string extension = Path.GetExtension(filePath).ToLowerInvariant();
|
string extension = Path.GetExtension(filePath).ToLowerInvariant();
|
||||||
string[] supportedExtensions = { ".txt", ".drl", ".dr2", ".dpin" };
|
string[] supportedExtensions = { ".txt", ".drl", ".dr2", ".dr3", ".trg", ".dpin" };
|
||||||
|
|
||||||
return supportedExtensions.Contains(extension);
|
return supportedExtensions.Contains(extension);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user