@@ -172,16 +172,15 @@ async void InvokeShellMenuItem(ContextMenu contextMenu, object? tag)
172
172
{
173
173
case "install" when isFont :
174
174
{
175
- var userFontDir = Path . Combine ( Environment . GetFolderPath ( Environment . SpecialFolder . LocalApplicationData ) , "Microsoft" , "Windows" , "Fonts" ) ;
176
- var destName = Path . Combine ( userFontDir , Path . GetFileName ( contextMenu . ItemsPath [ 0 ] ) ) ;
177
- Win32API . RunPowershellCommand ( $ "-command \" Copy-Item '{ contextMenu . ItemsPath [ 0 ] } ' '{ userFontDir } '; New-ItemProperty -Name '{ Path . GetFileNameWithoutExtension ( contextMenu . ItemsPath [ 0 ] ) } ' -Path 'HKCU:\\ Software\\ Microsoft\\ Windows NT\\ CurrentVersion\\ Fonts' -PropertyType string -Value '{ destName } '\" ", false ) ;
175
+ foreach ( string path in contextMenu . ItemsPath )
176
+ InstallFont ( path , false ) ;
178
177
}
179
178
break ;
180
179
181
180
case "installAllUsers" when isFont :
182
181
{
183
- var winFontDir = Path . Combine ( Environment . GetFolderPath ( Environment . SpecialFolder . Windows ) , "Fonts" ) ;
184
- Win32API . RunPowershellCommand ( $ "-command \" Copy-Item ' { contextMenu . ItemsPath [ 0 ] } ' ' { winFontDir } '; New-ItemProperty -Name ' { Path . GetFileNameWithoutExtension ( contextMenu . ItemsPath [ 0 ] ) } ' -Path 'HKLM: \\ Software \\ Microsoft \\ Windows NT \\ CurrentVersion \\ Fonts' -PropertyType string -Value ' { Path . GetFileName ( contextMenu . ItemsPath [ 0 ] ) } ' \" " , true ) ;
182
+ foreach ( string path in contextMenu . ItemsPath )
183
+ InstallFont ( path , true ) ;
185
184
}
186
185
break ;
187
186
@@ -199,7 +198,17 @@ async void InvokeShellMenuItem(ContextMenu contextMenu, object? tag)
199
198
await contextMenu . InvokeItem ( menuId ) ;
200
199
break ;
201
200
}
201
+
202
+ void InstallFont ( string path , bool asAdmin )
203
+ {
204
+ string dir = asAdmin ? Path . Combine ( Environment . GetFolderPath ( Environment . SpecialFolder . Windows ) , "Fonts" )
205
+ : Path . Combine ( Environment . GetFolderPath ( Environment . SpecialFolder . LocalApplicationData ) , "Microsoft" , "Windows" , "Fonts" ) ;
206
+
207
+ string registryKey = asAdmin ? "HKLM:\\ Software\\ Microsoft\\ Windows NT\\ CurrentVersion\\ Fonts"
208
+ : "HKCU:\\ Software\\ Microsoft\\ Windows NT\\ CurrentVersion\\ Fonts" ;
202
209
210
+ Win32API . RunPowershellCommand ( $ "-command \" Copy-Item '{ path } ' '{ dir } '; New-ItemProperty -Name '{ Path . GetFileNameWithoutExtension ( path ) } ' -Path '{ registryKey } ' -PropertyType string -Value '{ dir } '\" ", asAdmin ) ;
211
+ }
203
212
//contextMenu.Dispose(); // Prevents some menu items from working (TBC)
204
213
}
205
214
}
@@ -211,4 +220,4 @@ public static List<ContextMenuFlyoutItemViewModel> GetOpenWithItems(List<Context
211
220
return item ? . Items ;
212
221
}
213
222
}
214
- }
223
+ }
0 commit comments