/
DriverUpdate.ps1
136 lines (119 loc) · 4.17 KB
/
DriverUpdate.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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
$ErrorActionPreference = 'Stop'
if (-not $PSScriptRoot)
{
$PSScriptRoot = Split-Path $MyInvocation.InvocationName
}
if ( -not $env:Path.Contains( "$PSScriptRoot;") )
{
$env:Path = "$PSScriptRoot;$env:Path"
}
$Status = New-PackageStatus -Message 'Update Extension' -Status 'transitioning' -Name 'AmdGpuDriverWindows' -Operation 'Update'
# Read the environment, config settings and get status target
$Env = Get-Environment
$StatusFile = $Env.StatusFile
# Update AMD Driver
try
{
$FatalError = @()
$Status = New-PackageStatus -Message 'Enable Extension' -Status 'transitioning' -Name 'AmdGpuDriverWindows' -Operation 'Enable'
# Read the environment, config settings and get status target
$Env = Get-Environment
$StatusFile = $Env.StatusFile
# Check if the driver is installed
$Driver = Set-DriverInfo
$DriverVersion = Check-Driver $Driver
if ( $Null -ne $DriverVersion )
{
$Message = "AMD GPU driver version $DriverVersion detected. Already installed. Trying to upgrade"
$Status | Add-PackageSubStatus -Message $Message -Status 'success' | Out-Null
#region new driver download and update
# Select the driver to install
if ($Env.DriverUrl -eq $null)
{
Get-DriverDownloadInfo $Driver
}
else
{
$Driver.Url = $Env.DriverUrl
}
# Download Driver archive
$source = $Driver.Url
$Driver.ArchiveFile = $Driver.Url.Substring($Driver.Url.LastIndexOf("/") + 1)
$dest = "$($Driver.InstallFolder)\$($Driver.ArchiveFile)"
. download.ps1
Get-DriverFile $source $dest
#install the driver from the downloaded package
$argumentList = "/S /D=" + $Driver.ExpandFolder
$p = Start-Process -FilePath $dest -ArgumentList $argumentList -PassThru -Wait
# check if installation process was successful
if ($p.ExitCode -eq 0)
{
$Status | Add-PackageSubStatus -Message "Installation process complete." -Status 'success' -Code $p.ExitCode | Out-Null
$Status | Set-PackageStatus -Status 'success'
Write-Host "Installation process complete. Code: $($p.ExitCode)"
}
else
{
$Status | Add-PackageSubStatus -Message "Installation of $dest failed!" -Status 'error' -Code $p.ExitCode | Out-Null
$Status | Set-PackageStatus -Status 'error'
Write-Host "Installation of the driver package failed! Code: $($p.ExitCode)"
}
#endregion
Write-Host $Message
$Status | Set-PackageStatus -Status 'success'
}
else
{
$Status | Add-PackageSubStatus -Message "AMD GPU driver not detected. Attempting to install." -Status 'success' | Out-Null
# Select the driver to install
if ($Env.DriverUrl -eq $null)
{
Get-DriverDownloadInfo $Driver
}
else
{
$Driver.Url = $Env.DriverUrl
}
# Download Driver archive
$source = $Driver.Url
$Driver.ArchiveFile = $Driver.Url.Substring($Driver.Url.LastIndexOf("/") + 1)
$dest = "$($Driver.InstallFolder)\$($Driver.ArchiveFile)"
. download.ps1
Get-DriverFile $source $dest
#install the driver from the downloaded package
$argumentList = "/S /D=" + $Driver.ExpandFolder
$p = Start-Process -FilePath $dest -ArgumentList $argumentList -PassThru -Wait
# check if installation process was successful
if ($p.ExitCode -eq 0)
{
$Status | Add-PackageSubStatus -Message "Installation process complete." -Status 'success' -Code $p.ExitCode | Out-Null
$Status | Set-PackageStatus -Status 'success'
Write-Host "Installation process complete. Code: $($p.ExitCode)"
}
else
{
$Status | Add-PackageSubStatus -Message "Installation of $dest failed!" -Status 'error' -Code $p.ExitCode | Out-Null
$Status | Set-PackageStatus -Status 'error'
Write-Host "Installation of the driver package failed! Code: $($p.ExitCode)"
}
}
}
catch [NotSupportedException]
{
$Message = $_.ToString()
Write-Host $Message
$Status | Add-PackageSubStatus -Message $Message -Status 'error' -Code 100 | Out-Null
$Status | Set-PackageStatus -Status 'error'
$Status | Save-PackageStatus $StatusFile
exit 0
}
catch
{
$FatalError += $_
Write-Host -ForegroundColor Red ($_ | Out-String)
exit $FatalError.Count
}
finally
{
$Status | Save-PackageStatus $StatusFile
}