mirror of
https://github.com/Baipyrus/dotfiles.git
synced 2024-12-25 10:51:46 +00:00
bugfix: font user-installation using 'hard coded' shell commands
This commit is contained in:
parent
0042e03908
commit
2f71265aa0
@ -58,7 +58,7 @@ Write-Host "============================================" -ForegroundColor DarkG
|
|||||||
Write-Host "Installing Nerd Fonts..." -ForegroundColor Cyan
|
Write-Host "Installing Nerd Fonts..." -ForegroundColor Cyan
|
||||||
ProcessUrlFiles -source "$dotfilesRepo\nerd-fonts" -fileExt ".zip" -progress $false
|
ProcessUrlFiles -source "$dotfilesRepo\nerd-fonts" -fileExt ".zip" -progress $false
|
||||||
Get-ChildItem -Path "$env:TMP\nerd-fonts-config" -Filter "*.zip" | `
|
Get-ChildItem -Path "$env:TMP\nerd-fonts-config" -Filter "*.zip" | `
|
||||||
ForEach-Object { InstallNerdFont -source $_.FullName }
|
ForEach-Object { InstallFont -source $_.FullName }
|
||||||
|
|
||||||
# Final message
|
# Final message
|
||||||
Write-Host "Windows setup complete!" -ForegroundColor Green
|
Write-Host "Windows setup complete!" -ForegroundColor Green
|
||||||
|
@ -127,7 +127,7 @@ function ProcessUrlFiles
|
|||||||
}
|
}
|
||||||
|
|
||||||
# Function to unzip and install nerd fonts
|
# Function to unzip and install nerd fonts
|
||||||
function InstallNerdFont
|
function InstallFont
|
||||||
{
|
{
|
||||||
param (
|
param (
|
||||||
[string]$source
|
[string]$source
|
||||||
@ -151,66 +151,13 @@ function InstallNerdFont
|
|||||||
# Install extracted fonts
|
# Install extracted fonts
|
||||||
$fontFiles = Get-ChildItem -Path $destination -Recurse -Include "*.ttf", "*.otf"
|
$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
|
$fonts.CopyHere(
|
||||||
}
|
$file.FullName,
|
||||||
}
|
0x14
|
||||||
|
)
|
||||||
# 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
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user