@@ -835,6 +835,36 @@ public static Task InstallFont(string fontFilePath, bool forAllUsers)
835835 return RunPowershellCommandAsync ( $ "-command \" Copy-Item '{ fontFilePath } ' '{ fontDirectory } '; New-ItemProperty -Name '{ Path . GetFileNameWithoutExtension ( fontFilePath ) } ' -Path '{ registryKey } ' -PropertyType string -Value '{ destinationPath } '\" ", forAllUsers ) ;
836836 }
837837
838+ public static async Task InstallFontsAsync ( string [ ] fontFilePaths , bool forAllUsers )
839+ {
840+ string fontDirectory = forAllUsers
841+ ? Path . Combine ( Environment . GetFolderPath ( Environment . SpecialFolder . Windows ) , "Fonts" )
842+ : Path . Combine ( Environment . GetFolderPath ( Environment . SpecialFolder . LocalApplicationData ) , "Microsoft" , "Windows" , "Fonts" ) ;
843+
844+ string registryKey = forAllUsers
845+ ? "HKLM:\\ Software\\ Microsoft\\ Windows NT\\ CurrentVersion\\ Fonts"
846+ : "HKCU:\\ Software\\ Microsoft\\ Windows NT\\ CurrentVersion\\ Fonts" ;
847+
848+ var psCommand = new StringBuilder ( "-command \" " ) ;
849+
850+ foreach ( string fontFilePath in fontFilePaths )
851+ {
852+ var destinationPath = Path . Combine ( fontDirectory , Path . GetFileName ( fontFilePath ) ) ;
853+ var appendCommand = $ "Copy-Item '{ fontFilePath } ' '{ fontDirectory } '; New-ItemProperty -Name '{ Path . GetFileNameWithoutExtension ( fontFilePath ) } ' -Path '{ registryKey } ' -PropertyType string -Value '{ destinationPath } ';";
854+
855+ if ( psCommand . Length + appendCommand . Length > 32766 )
856+ {
857+ // The command is too long to run at once, so run the command once up to this point.
858+ await RunPowershellCommandAsync ( psCommand . Append ( "\" " ) . ToString ( ) , forAllUsers ) ;
859+ psCommand . Clear ( ) . Append ( "-command \" " ) ;
860+ }
861+
862+ psCommand . Append ( appendCommand ) ;
863+ }
864+
865+ await RunPowershellCommandAsync ( psCommand . Append ( "\" " ) . ToString ( ) , forAllUsers ) ;
866+ }
867+
838868 private static Process CreatePowershellProcess ( string command , bool runAsAdmin )
839869 {
840870 Process process = new ( ) ;
0 commit comments