|
3 | 3 | using Newtonsoft.Json;
|
4 | 4 | using System;
|
5 | 5 | using System.Collections.Generic;
|
| 6 | +using System.IO; |
6 | 7 | using System.IO.Pipes;
|
7 | 8 | using System.Linq;
|
8 | 9 | using System.Threading.Tasks;
|
@@ -95,14 +96,31 @@ private object HandleMenuMessage(Dictionary<string, object> message, DisposableD
|
95 | 96 | var cMenuExec = table.GetValue<ContextMenu>("MENU");
|
96 | 97 | if (message.TryGetValue("ItemID", out var menuId))
|
97 | 98 | {
|
98 |
| - switch (message.Get("CommandString", (string)null)) |
| 99 | + var isFont = new[] { ".fon", ".otf", ".ttc", ".ttf" }.Contains(Path.GetExtension(cMenuExec.ItemsPath[0]), StringComparer.OrdinalIgnoreCase); |
| 100 | + var verb = message.Get("CommandString", (string)null); |
| 101 | + switch (verb) |
99 | 102 | {
|
100 |
| - case "mount": |
| 103 | + case string _ when verb == "install" && isFont: |
| 104 | + { |
| 105 | + var userFontDir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Microsoft", "Windows", "Fonts"); |
| 106 | + var destName = Path.Combine(userFontDir, Path.GetFileName(cMenuExec.ItemsPath[0])); |
| 107 | + Win32API.RunPowershellCommand($"-command \"Copy-Item '{cMenuExec.ItemsPath[0]}' '{userFontDir}'; New-ItemProperty -Name '{Path.GetFileNameWithoutExtension(cMenuExec.ItemsPath[0])}' -Path 'HKCU:\\Software\\Microsoft\\Windows NT\\CurrentVersion\\Fonts' -PropertyType string -Value '{destName}'\"", false); |
| 108 | + } |
| 109 | + break; |
| 110 | + |
| 111 | + case string _ when verb == "installAllUsers" && isFont: |
| 112 | + { |
| 113 | + var winFontDir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Windows), "Fonts"); |
| 114 | + Win32API.RunPowershellCommand($"-command \"Copy-Item '{cMenuExec.ItemsPath[0]}' '{winFontDir}'; New-ItemProperty -Name '{Path.GetFileNameWithoutExtension(cMenuExec.ItemsPath[0])}' -Path 'HKLM:\\Software\\Microsoft\\Windows NT\\CurrentVersion\\Fonts' -PropertyType string -Value '{Path.GetFileName(cMenuExec.ItemsPath[0])}'\"", true); |
| 115 | + } |
| 116 | + break; |
| 117 | + |
| 118 | + case string _ when verb == "mount": |
101 | 119 | var vhdPath = cMenuExec.ItemsPath[0];
|
102 | 120 | Win32API.MountVhdDisk(vhdPath);
|
103 | 121 | break;
|
104 | 122 |
|
105 |
| - case "format": |
| 123 | + case string _ when verb == "format": |
106 | 124 | var drivePath = cMenuExec.ItemsPath[0];
|
107 | 125 | Win32API.OpenFormatDriveDialog(drivePath);
|
108 | 126 | break;
|
|
0 commit comments