Skip to content

Commit

Permalink
增加右键菜单
Browse files Browse the repository at this point in the history
  • Loading branch information
ldqk committed Oct 5, 2022
1 parent d49e060 commit 8f85ddc
Showing 1 changed file with 29 additions and 2 deletions.
31 changes: 29 additions & 2 deletions Straper/Program.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
using SixLabors.ImageSharp;
using Microsoft.Win32;
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.Metadata.Profiles.Exif;
using SixLabors.ImageSharp.PixelFormats;
using System.Text.RegularExpressions;

Console.WriteLine("欢迎使用清除图像exif信息小工具——ExifStraper by 懒得勤快\n\n");
var dirs = new List<string>();
if (args.Length > 0)
{
if (args[0] == "reg-menu")
{
RegContextMenu();
return;
}
dirs.AddRange(args);
}
else
Expand All @@ -15,12 +22,17 @@
{
Console.WriteLine("请将待处理文件夹拖放到此处:");
dir = Console.ReadLine().Trim('"');
if (dir == "reg-menu")
{
RegContextMenu();
return;
}
}
dirs.Add(dir);
}

Console.WriteLine("正在读取文件目录树......");
dirs.SelectMany(dir => Directory.GetFiles(dir, "*", SearchOption.AllDirectories)).Chunk(32).AsParallel().ForAll(files =>
dirs.SelectMany(dir => Directory.EnumerateFiles(dir, "*", SearchOption.AllDirectories)).Where(s => Regex.IsMatch(s, "(jpg|jpeg|bmp)$")).Chunk(32).AsParallel().ForAll(files =>
{
foreach (var file in files)
{
Expand Down Expand Up @@ -63,3 +75,18 @@
}
}
});

void RegContextMenu()
{
var key = Registry.ClassesRoot.OpenSubKey("Directory", true).OpenSubKey("shell", true).CreateSubKey("ExifStraper", true);
var command = key.CreateSubKey("command", true);
key.SetValue("Icon", "%SystemRoot%\\System32\\shell32.dll,141", RegistryValueKind.ExpandString);
key.SetValue("MUIVerb", "ExifStraper");
command.SetValue("", $"\"{System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName}\" \"%1\"", RegistryValueKind.ExpandString);
var key2 = Registry.ClassesRoot.OpenSubKey("*", true).OpenSubKey("shell", true).CreateSubKey("ExifStraper", true);
var command2 = key2.CreateSubKey("command", true);
key2.SetValue("Icon", "%SystemRoot%\\System32\\shell32.dll,141", RegistryValueKind.ExpandString);
key2.SetValue("MUIVerb", "ExifStraper");
command2.SetValue("", $"\"{System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName}\" \"%1\"", RegistryValueKind.ExpandString);
Console.WriteLine("右键菜单添加成功");
}

0 comments on commit 8f85ddc

Please sign in to comment.