-
-
Notifications
You must be signed in to change notification settings - Fork 274
/
Install-Font.psm1
55 lines (46 loc) · 2.97 KB
/
Install-Font.psm1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
Import-Module -DisableNameChecking "$PSScriptRoot\Get-TempScriptFolder.psm1"
Import-Module -DisableNameChecking "$PSScriptRoot\Title-Templates.psm1"
# Adapted From: https://gist.github.com/anthonyeden/0088b07de8951403a643a8485af2709b?permalink_comment_id=3651336#gistcomment-3651336
function Install-Font() {
[CmdletBinding()]
param (
[Parameter(Position = 0)]
[String] $FontSourceFolder = "$(Get-TempScriptFolder)\downloads\fonts"
)
$PathToLMWindowsFonts = "HKLM:\Software\Microsoft\Windows NT\CurrentVersion\Fonts"
$SystemFontsPath = "$env:SystemRoot\Fonts"
ForEach ($FontFile in Get-ChildItem $FontSourceFolder -Include "*.ttf", "*.ttc", "*.otf" -Recurse) {
$TargetPath = Join-Path $SystemFontsPath $FontFile.Name
Write-Status -Types "+" -Status "Installing `"$($FontFile.Name)`" Font on $TargetPath ..."
Try {
# Extract Font information for Reqistry
$ShellFolder = (New-Object -COMObject Shell.Application).Namespace($FontSourceFolder)
$ShellFile = $ShellFolder.ParseName($FontFile.Name)
$ShellFileType = $ShellFolder.GetDetailsOf($ShellFile, 2)
If ($ShellFileType -Like "*TrueType font file*") { $FontType = "(TrueType)" }
# Update Registry and copy Font to Font directory
$RegName = $ShellFolder.GetDetailsOf($ShellFile, 21) + ' ' + $FontType
} Catch {
# This may not be the better way, but this workaround worked
Write-Status -Types "@" -Status "Got an error, the font type is OpenType" -Warning
$FontType = '(OpenType)'
$RegName = ""
$NameHelper = $FontFile.Name.Replace("-", " ").Replace("_", " ").Trim(" ")
$NameHelper = $FontFile.Name.Replace("[", " ").Replace("]", " ").Trim(" ")
$NameHelper = $FontFile.Name.Replace(".ttf", "").Replace(".ttc", "").Replace(".otf", "").Trim(" ")
$NameHelper = $NameHelper.Replace("Mono", " Mono").Replace("NF", " NF").Replace("NL", " NL").Replace("VF", " VF").Replace("wght", " Variable").Trim(" ")
$NameHelper = $NameHelper.Replace("Thin", " Thin").Replace("Semi", " Semi").Replace("Medium", " Medium").Replace("Extra", " Extra").Trim(" ")
$NameHelper = $NameHelper.Replace("Bold", " Bold").Replace("Italic", " Italic").Replace("Light", " Light").Replace("Regular", " Regular").Trim(" ")
$NameHelper = $NameHelper + " " + $FontType
ForEach ($Item in $NameHelper.Split(" ")) {
If (($Item -ne " ") -or ($null -ne $Item)) {
$RegName = $RegName.Trim(" ") + " " + $Item.Trim(" ")
}
}
}
Write-Status -Types "+" -Status "Creating new Registry to $RegName on: $PathToLMWindowsFonts"
New-ItemProperty -Path "$PathToLMWindowsFonts" -Name $RegName -PropertyType String -Value $FontFile.Name -Force
Copy-item $FontFile.FullName -Destination $SystemFontsPath
Remove-Item $FontFile.FullName
}
}