/
chocolateyInstall.ps1
113 lines (104 loc) · 4.87 KB
/
chocolateyInstall.ps1
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
Set-StrictMode -Version 2
$ErrorActionPreference = 'Stop'
. (Join-Path -Path (Split-Path -Path $MyInvocation.MyCommand.Definition -Parent) -ChildPath 'data.ps1')
$packageName = $otherData.PackageName
$installerType = 'exe'
$silentArgs = '/quiet /norestart'
$validExitCodes = @(0, 1638, 3010)
$force = $Env:chocolateyPackageParameters -like '*Force*'
Write-Verbose 'Checking Service Pack requirements'
$os = Get-WmiObject -Class Win32_OperatingSystem
$version = [Version]$os.Version
if ($version -ge [Version]'6.1' -and $version -lt [Version]'6.2' -and $os.ServicePackMajorVersion -lt 1)
{
# On Windows 7 / Server 2008 R2, Service Pack 1 is required.
throw 'This package requires Service Pack 1 to be installed first. The "KB976932" package may be used to install it.'
}
elseif ($version -ge [Version]'6.0' -and $version -lt [Version]'6.1' -and $os.ServicePackMajorVersion -lt 2)
{
# On Windows Vista / Server 2008, Service Pack 2 is required.
throw 'This package requires Service Pack 2 to be installed first.'
}
elseif ($version -ge [Version]'5.2' -and $version -lt [Version]'6.0' -and $os.ServicePackMajorVersion -lt 2)
{
# On Windows Server 2003 / XP x64, Service Pack 2 is required.
throw 'This package requires Service Pack 2 to be installed first.'
}
elseif ($version -ge [Version]'5.1' -and $version -lt [Version]'5.2' -and $os.ServicePackMajorVersion -lt 3)
{
# On Windows XP, Service Pack 3 is required.
throw 'This package requires Service Pack 3 to be installed first.'
}
$runtimes = @{
'x64' = @{ RegistryPresent = $false; RegistryVersion = $null; DllVersion = $null; InstallData = $installData64; Applicable = ((Get-OSArchitectureWidth) -eq 64) -and ($env:chocolateyForceX86 -ne 'true') }
'x86' = @{ RegistryPresent = $false; RegistryVersion = $null; DllVersion = $null; InstallData = $installData32; Applicable = $true }
}
switch ([string](Get-OSArchitectureWidth))
{
'32' { $registryRoots = @{ x86 = 'HKLM:\SOFTWARE'; x64 = $null } }
'64' { $registryRoots = @{ x86 = 'HKLM:\SOFTWARE\WOW6432Node'; x64 = 'HKLM:\SOFTWARE' } }
default { throw "Unsupported bitness: $_" }
}
Write-Verbose 'Analyzing servicing information in the registry'
foreach ($archAndRegRoot in $registryRoots.GetEnumerator())
{
$arch = $archAndRegRoot.Key
$regRoot = $archAndRegRoot.Value
# https://docs.microsoft.com/en-us/cpp/ide/redistributing-visual-cpp-files
$regData = Get-ItemProperty -Path "$regRoot\Microsoft\DevDiv\vc\Servicing\$($otherData.FamilyRegistryKey)\RuntimeMinimum" -Name 'Version' -ErrorAction SilentlyContinue
if ($regData -ne $null)
{
$versionString = $regData.Version
try
{
$parsedVersion = [version]$versionString
Write-Verbose "Version of installed runtime for architecture $arch in the registry: $versionString"
$normalizedVersion = [version]($parsedVersion.ToString(3)) # future-proofing in case Microsoft starts putting more than 3 parts here
$runtimes[$arch].RegistryVersion = $normalizedVersion
}
catch
{
Write-Warning "The servicing information in the registry is in an unknown format. Please report this to package maintainers. Data from the registry: Version = [$versionString]"
}
}
}
$packageRuntimeVersion = $otherData.ThreePartVersion
Write-Verbose "Version number of runtime installed by this package: $packageRuntimeVersion"
foreach ($archAndRuntime in $runtimes.GetEnumerator())
{
$arch = $archAndRuntime.Key
$runtime = $archAndRuntime.Value
$shouldInstall = $runtime.RegistryVersion -eq $null -or $runtime.RegistryVersion -lt $packageRuntimeVersion
Write-Verbose "Runtime for architecture $arch applicable: $($runtime.Applicable); version in registry: [$($runtime.RegistryVersion)]; should install: $shouldInstall"
if ($runtime.Applicable)
{
if (-not $shouldInstall)
{
if ($force)
{
Write-Warning "Forcing installation of runtime for architecture $arch version $packageRuntimeVersion even though this or later version appears present, because 'Force' was specified in package parameters."
}
else
{
if ($runtime.RegistryVersion -gt $packageRuntimeVersion)
{
Write-Warning "Skipping installation of runtime for architecture $arch version $packageRuntimeVersion because a newer version ($($runtime.RegistryVersion)) is already installed."
}
else
{
Write-Host "Runtime for architecture $arch version $packageRuntimeVersion is already installed."
}
continue
}
}
Write-Verbose "Installing runtime for architecture $arch"
$installData = $runtime.InstallData
Set-StrictMode -Off
Install-ChocolateyPackage -PackageName "${packageName}-$arch" `
-FileType $installerType `
-SilentArgs $silentArgs `
-ValidExitCodes $validExitCodes `
@installData
Set-StrictMode -Version 2
}
}