X-Git-Url: https://git.josue.xyz/?a=blobdiff_plain;f=nerdfont%2Finstall.ps1;h=668c7585a3ccbdac109632e09a6d36f7f9a5437f;hb=46445e9382905a52e770d44191235be179616049;hp=35ecc2c169e2ffdcc3928a96960a417bfa163c64;hpb=76776e9d5403d59b2cd5cba16d84f819a56bc5aa;p=webi-installers%2F.git diff --git a/nerdfont/install.ps1 b/nerdfont/install.ps1 index 35ecc2c..668c758 100644 --- a/nerdfont/install.ps1 +++ b/nerdfont/install.ps1 @@ -7,20 +7,29 @@ New-Item -Path "$my_fontdir" -ItemType Directory -Force IF (!(Test-Path -Path "$my_fontdir\$my_nerdfont_otf")) { - & curl.exe -fsSLo "$my_nerdfont_otf" 'https://github.com/ryanoasis/nerd-fonts/raw/master/patched-fonts/DroidSansMono/complete/Droid%20Sans%20Mono%20Nerd%20Font%20Complete%20Windows%20Compatible.otf' + & curl.exe -fsSLo "$my_nerdfont_otf" 'https://github.com/ryanoasis/nerd-fonts/raw/master/patched-fonts/DroidSansMono/complete +/Droid%20Sans%20Mono%20Nerd%20Font%20Complete%20Windows%20Compatible.otf' & move "$my_nerdfont_otf" "$my_fontdir" } -# See https://superuser.com/a/1306464/73857 pushd "$my_fontdir" -Add-Type -Name Session -Namespace "" -Member @" -[DllImport("gdi32.dll")] -public static extern int AddFontResource(string filePath); -"@ -$null = foreach($font in Get-ChildItem -Recurse -Include *.ttf, *.otf) { - [Session]::AddFontResource($font.FullName) +$regFontPath = "\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts" +$fontRegistryPath = "HKCU:$regFontPath" +$fontFiles = Get-ChildItem -Recurse -Include *.ttf, *.otf +$null = foreach($font in $fontFiles) { + # See https://github.com/PPOSHGROUP/PPoShTools/blob/master/PPoShTools/Public/FileSystem/Add-Font.ps1#L80 + Add-Type -AssemblyName System.Drawing + $objFontCollection = New-Object System.Drawing.Text.PrivateFontCollection + $objFontCollection.AddFontFile($font.FullName) + $FontName = $objFontCollection.Families.Name + + $regTest = Get-ItemProperty -Path $fontRegistryPath -Name "*$FontName*" -ErrorAction SilentlyContinue + if (-not ($regTest)) { + New-ItemProperty -Name $FontName -Path $fontRegistryPath -PropertyType string -Value $font.FullName + Write-Output "Registering font {$($font.Name)} in registry with name {$FontName}" + } } echo "Installed $my_nerdfont_otf to $my_fontdir"