Files
ChocolateyPackages/SourceCodePro/tools/chocolateyInstall.ps1
Iristyle 03d686432d Bumped SourceCodePro to 1.017
- Totally overhauled font install process since the previous version
 required lots of interaction / prompting to upgrade existing fonts
 AND had a clunky UI dialog when installing fonts for the first time
 - Leveraging Windows Powershell sample script that compiles C# on
 the fly to call Win32 APIs that deal with fonts
 - Elevate to admin to run the new stuff - no reboot required
2013-03-07 15:33:12 -05:00

45 lines
1.6 KiB
PowerShell

function Get-CurrentDirectory
{
$thisName = $MyInvocation.MyCommand.Name
[IO.Path]::GetDirectoryName((Get-Content function:$thisName).File)
}
try {
$package = 'SourceCodePro'
$fontHelpersPath = (Join-Path (Get-CurrentDirectory) 'FontHelpers.ps1')
. $fontHelpersPath
$fontUrl = 'http://sourceforge.net/projects/sourcecodepro.adobe/files/SourceCodePro_FontsOnly-1.017.zip/download'
$destination = Join-Path $Env:Temp 'SourceCodePro'
Install-ChocolateyZipPackage -url $fontUrl -unzipLocation $destination
$shell = New-Object -ComObject Shell.Application
$fontsFolder = $shell.Namespace(0x14)
$fontFiles = Get-ChildItem $destination -Recurse -Filter *.otf
# unfortunately the font install process totally ignores shell flags :(
# http://social.technet.microsoft.com/Forums/en-IE/winserverpowershell/thread/fcc98ba5-6ce4-466b-a927-bb2cc3851b59
# so resort to a nasty hack of compiling some C#, and running as admin instead of just using CopyHere(file, options)
$commands = $fontFiles |
% { Join-Path $fontsFolder.Self.Path $_.Name } |
? { Test-Path $_ } |
% { "Remove-SingleFont '$_' -Force;" }
# http://blogs.technet.com/b/deploymentguys/archive/2010/12/04/adding-and-removing-fonts-with-windows-powershell.aspx
$fontFiles |
% { $commands += "Add-SingleFont '$($_.FullName)';" }
$toExecute = ". $fontHelpersPath;" + ($commands -join ';')
Start-ChocolateyProcessAsAdmin $toExecute
Remove-Item $destination -Recurse
Write-ChocolateySuccess $package
} catch {
Write-ChocolateyFailure $package "$($_.Exception.Message)"
throw
}