@@ -172,16 +172,15 @@ async void InvokeShellMenuItem(ContextMenu contextMenu, object? tag)
172172 {
173173 case "install" when isFont :
174174 {
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 ) ;
178177 }
179178 break ;
180179
181180 case "installAllUsers" when isFont :
182181 {
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 ) ;
185184 }
186185 break ;
187186
@@ -199,7 +198,17 @@ async void InvokeShellMenuItem(ContextMenu contextMenu, object? tag)
199198 await contextMenu . InvokeItem ( menuId ) ;
200199 break ;
201200 }
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" ;
202209
210+ Win32API . RunPowershellCommand ( $ "-command \" Copy-Item '{ path } ' '{ dir } '; New-ItemProperty -Name '{ Path . GetFileNameWithoutExtension ( path ) } ' -Path '{ registryKey } ' -PropertyType string -Value '{ dir } '\" ", asAdmin ) ;
211+ }
203212 //contextMenu.Dispose(); // Prevents some menu items from working (TBC)
204213 }
205214 }
@@ -211,4 +220,4 @@ public static List<ContextMenuFlyoutItemViewModel> GetOpenWithItems(List<Context
211220 return item ? . Items ;
212221 }
213222 }
214- }
223+ }
0 commit comments