diff --git a/install_windows.ps1 b/install_windows.ps1 index 1def26b..020ba14 100644 --- a/install_windows.ps1 +++ b/install_windows.ps1 @@ -58,7 +58,7 @@ Write-Host "============================================" -ForegroundColor DarkG Write-Host "Installing Nerd Fonts..." -ForegroundColor Cyan ProcessUrlFiles -source "$dotfilesRepo\nerd-fonts" -fileExt ".zip" -progress $false Get-ChildItem -Path "$env:TMP\nerd-fonts-config" -Filter "*.zip" | ` - ForEach-Object { InstallNerdFont -source $_.FullName } + ForEach-Object { InstallFont -source $_.FullName } # Final message Write-Host "Windows setup complete!" -ForegroundColor Green diff --git a/util/windows.psm1 b/util/windows.psm1 index 77a96d2..36a85b1 100644 --- a/util/windows.psm1 +++ b/util/windows.psm1 @@ -127,7 +127,7 @@ function ProcessUrlFiles } # Function to unzip and install nerd fonts -function InstallNerdFont +function InstallFont { param ( [string]$source @@ -151,66 +151,13 @@ function InstallNerdFont # Install extracted fonts $fontFiles = Get-ChildItem -Path $destination -Recurse -Include "*.ttf", "*.otf" - foreach ($font in $fontFiles) + # Apparently 'hard coded' installation using a 'Shell Application Object' + $fonts = (New-Object -ComObject Shell.Application).Namespace(0x14) + foreach ($file in $fontFiles) { - InstallFont $font - } -} - -# Reference: https://www.alkanesolutions.co.uk/2021/12/06/installing-fonts-with-powershell/ -function InstallFont -{ - param - ( - [System.IO.FileInfo]$file - ) - - # Prerequisites / Constants - Add-Type -AssemblyName PresentationCore - $destination = "$env:LOCALAPPDATA\Microsoft\Windows\Fonts\" - $regKey = "HKCU:\Software\Microsoft\Windows NT\CurrentVersion\Fonts" - - # Create destination directory - if (-not (Test-Path $destination)) - { New-Item -ItemType Directory -Path $destination | Out-Null - } - - # Get Glyph - $glyph = New-Object -TypeName Windows.Media.GlyphTypeface -ArgumentList $file.FullName - - $family = $glyph.Win32FamilyNames['en-us'] - if ($null -eq $family) - { $family = $glyph.Win32FamilyNames.Values | Select-Object -First 1 - } - - $face = $glyph.Win32FaceNames['en-us'] - if ($null -eq $face) - { $face = $glyph.Win32FaceNames.Values | Select-Object -First 1 - } - - $name = ("$family $face").Trim() - switch ($file.Extension) - { - ".ttf" - { $name = "$name (TrueType)" - } - ".otf" - { $name = "$name (OpenType)" - } - } - - $destFileName = Join-Path -Path $destination -ChildPath $file.Name - Write-Host "Installing font: $file with font name '$name'" - If (-not (Test-Path $destFileName)) - { Copy-Item -Path $file.FullName -Destination $destFileName -Force - } - - Write-Host "Registering font: $file with font name '$name'" - $keyValue = Get-ItemProperty -Name $name -Path $regKey -ErrorAction SilentlyContinue - If (-not $keyValue) - { - New-ItemProperty -Name $name -Path $regKey ` - -PropertyType string -Value $file.Name ` - -Force -ErrorAction SilentlyContinue | Out-Null + $fonts.CopyHere( + $file.FullName, + 0x14 + ) } }