-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathInstall.ps1
More file actions
478 lines (429 loc) · 15.4 KB
/
Install.ps1
File metadata and controls
478 lines (429 loc) · 15.4 KB
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
# Log to file silently
$LogFile = "$env:TEMP\PC-Gaming-Redists-Install.log"
Start-Transcript -Path $LogFile -Force | Out-Null
# PCGR ASCII Art Logo - rainbow gradient left to right
$b = [char]0x2588 # full block
$s = [char]0x2591 # light shade
$e = [char]27 # escape char for ANSI
$r = "$e[0m" # Reset
# Pastel rainbow - super gradual: Pink -> Yellow -> Green -> Cyan -> Blue (no loop back)
$rainbow = @(
# Light Pink
"$e[38;2;255;182;193m",
"$e[38;2;255;186;191m",
"$e[38;2;255;190;189m",
"$e[38;2;255;194;187m",
"$e[38;2;255;198;185m",
"$e[38;2;255;202;183m",
"$e[38;2;255;206;181m",
"$e[38;2;255;210;179m",
"$e[38;2;255;214;177m",
"$e[38;2;255;218;175m",
# Pink to Yellow
"$e[38;2;255;222;173m",
"$e[38;2;255;226;172m",
"$e[38;2;255;230;171m",
"$e[38;2;255;234;170m",
"$e[38;2;255;238;170m",
"$e[38;2;255;242;170m",
"$e[38;2;255;246;170m",
"$e[38;2;255;250;170m",
"$e[38;2;253;252;172m",
"$e[38;2;248;254;174m",
# Yellow to Green
"$e[38;2;243;255;176m",
"$e[38;2;235;255;178m",
"$e[38;2;227;255;180m",
"$e[38;2;219;255;182m",
"$e[38;2;211;255;184m",
"$e[38;2;203;255;186m",
"$e[38;2;195;255;190m",
"$e[38;2;190;255;195m",
"$e[38;2;185;255;200m",
"$e[38;2;180;255;208m",
# Green to Cyan
"$e[38;2;178;255;216m",
"$e[38;2;176;255;224m",
"$e[38;2;174;255;232m",
"$e[38;2;172;255;240m",
"$e[38;2;172;252;248m",
"$e[38;2;172;248;252m",
"$e[38;2;172;244;255m",
"$e[38;2;172;238;255m",
"$e[38;2;174;232;255m",
"$e[38;2;176;226;255m",
# Cyan to Blue
"$e[38;2;178;220;255m",
"$e[38;2;180;214;255m",
"$e[38;2;182;208;255m",
"$e[38;2;184;202;255m",
"$e[38;2;186;196;255m",
"$e[38;2;188;192;255m",
"$e[38;2;190;188;255m",
"$e[38;2;192;185;255m"
)
$line1 = " $b$b$b$b$b$b$b$b$b$b $b$b$b$b$b$b$b$b $b$b$b$b$b$b$b$b$b $b$b$b$b$b$b$b$b$b "
$line2 = " $s$s$b$b$b$s$s$s$b$b$b$s$s$b$b$b$s$s$s$s$b$b $b$b$b$s$s$s$s$s$b$b$b$s$s$b$b$b$s$s$s$b$b$b"
$line3 = " $s$b$b$b $s$s$b$b$b$s$b$b$b $s$s$s$s $b$b$b $s$s$s $s$b$b$b $s$s$b$b$b "
$line4 = " $s$b$b$b$b$b$b$b$b $s$b$b$b $s$b$b$b $s$b$b$b$b$b$b$b$b "
$line5 = " $s$b$b$b$s$s$s$s $s$b$b$b $s$b$b$b $b$b$b$b$b $s$b$b$b$s$b$b$b "
$line6 = " $s$b$b$b $s$s$b$b$b $s$b$b$s$s$b$b$b $s$s$s$b$b$b $s$b$b$b$s$s$b$b$b "
$line7 = " $b$b$b$b$b $s$s$b$b$b$b$b$b$b$b $s$s$b$b$b$b$b$b$b$b$b $b$b$b$b $s$s$b$b$b$b"
$line8 = " $s$s$s$s$s $s$s$s$s$s$s$s$s$s $s$s$s$s$s$s$s$s$s $s$s$s$s$s $s$s$s$s"
$lines = @($line1, $line2, $line3, $line4, $line5, $line6, $line7, $line8)
Write-Host ""
foreach ($line in $lines) {
$chars = $line.ToCharArray()
$len = $chars.Length
$out = ""
for ($i = 0; $i -lt $len; $i++) {
$colorIdx = [Math]::Floor(($i / $len) * $rainbow.Length)
if ($colorIdx -ge $rainbow.Length) { $colorIdx = $rainbow.Length - 1 }
$out += $rainbow[$colorIdx] + $chars[$i]
}
Write-Host "$out$r"
}
Write-Host ""
# Text lines with same gradient
$textLines = @(" PC Gaming Redists", " Downloading installer, please wait...")
foreach ($line in $textLines) {
$chars = $line.ToCharArray()
$len = $chars.Length
$out = ""
for ($i = 0; $i -lt $len; $i++) {
$colorIdx = [Math]::Floor(($i / $len) * $rainbow.Length)
if ($colorIdx -ge $rainbow.Length) { $colorIdx = $rainbow.Length - 1 }
$out += $rainbow[$colorIdx] + $chars[$i]
}
Write-Host "$out$r"
}
Write-Host ""
Function Write-Rainbow
{
Param ([string]$Text)
$chars = $Text.ToCharArray()
$len = $chars.Length
$out = ""
for ($i = 0; $i -lt $len; $i++) {
$colorIdx = [Math]::Floor(($i / $len) * $rainbow.Length)
if ($colorIdx -ge $rainbow.Length) { $colorIdx = $rainbow.Length - 1 }
$out += $rainbow[$colorIdx] + $chars[$i]
}
Write-Host "$out$r"
}
Function Test-CommandExists
{
Param ($command)
try { if (Get-Command $command) { RETURN $true } }
Catch { RETURN $false }
}
Function Test-WingetWorks
{
# Just check winget runs and returns a version. If it does, trust it.
# The AIOInstaller has its own retry/source logic that handles actual failures.
try {
$version = winget --version 2>&1
if ($version -match "^v\d+\.\d+") {
return $true
}
return $false
}
catch {
return $false
}
}
Function Stop-BlockingPackages
{
Param ([string[]]$PackageNames)
foreach ($pkgName in $PackageNames) {
Get-Process | Where-Object { $_.Path -like "*$pkgName*" } | ForEach-Object {
Write-Rainbow " Closing $($_.ProcessName)..."
Stop-Process -Id $_.Id -Force -ErrorAction SilentlyContinue
}
}
Start-Sleep -Seconds 1
}
Function Install-AppxSilent
{
# Try to install silently - no prompts, just try and move on
Param ([string]$Path, [string]$DisplayName)
try {
Add-AppxPackage -Path $Path -ForceApplicationShutdown -ErrorAction Stop
return $true
}
catch {
Write-Rainbow " $DisplayName - skipped (may not be needed on this system)"
return $false
}
}
Function Install-AppxWithRetry
{
# Try to install with interactive prompts on failure - use for critical packages
Param ([string]$Path, [string]$DisplayName)
$maxRetries = 2
for ($attempt = 1; $attempt -le $maxRetries; $attempt++) {
try {
Add-AppxPackage -Path $Path -ForceApplicationShutdown -ErrorAction Stop
Write-Rainbow " $DisplayName installed successfully."
return $true
}
catch {
$errorMsg = $_.Exception.Message
# Check if it's the "resources in use" error (0x80073D02)
if ($errorMsg -match "0x80073D02" -or $errorMsg -match "resources it modifies are currently in use") {
# Parse out the blocking package names from the error
$blockingApps = @()
$lines = $errorMsg -split "`n"
foreach ($line in $lines) {
if ($line -match "(Microsoft\.[A-Za-z0-9_.]+)_[\d.]+_") {
$blockingApps += $matches[1]
}
if ($line -match "(MicrosoftWindows\.[A-Za-z0-9_.]+)_[\d.]+_") {
$blockingApps += $matches[1]
}
}
$blockingApps = $blockingApps | Select-Object -Unique
if ($blockingApps.Count -gt 0 -and $attempt -lt $maxRetries) {
Write-Host ""
Write-Rainbow "The following apps are blocking the installation of $DisplayName :"
foreach ($app in $blockingApps) {
Write-Rainbow " - $app"
}
Write-Host ""
$response = Read-Host "Close these apps to continue? (Y/n)"
if ($response -eq "" -or $response -match "^[Yy]") {
Write-Rainbow "Closing blocking apps..."
Stop-BlockingPackages -PackageNames $blockingApps
# Also kill Edge as a precaution
Get-Process | Where-Object { $_.ProcessName -like "*msedge*" } | Stop-Process -Force -ErrorAction SilentlyContinue
Start-Sleep -Seconds 2
continue
} else {
Write-Rainbow "Couldn't install $DisplayName - continuing anyway (may not be needed)..."
return $false
}
}
}
# Other error or final attempt failed
if ($attempt -eq $maxRetries) {
Write-Rainbow "Failed to install $DisplayName"
Write-Rainbow " Error: $errorMsg"
return $false
}
}
}
return $false
}
Function Update-WingetSources
{
Write-Rainbow "Updating WinGet sources and accepting agreements..."
try {
winget source update --accept-source-agreements 2>&1 | Out-Null
winget search Microsoft.VCRedist --source winget --accept-source-agreements 2>&1 | Out-Null
} catch { }
}
Function Test-WingetSearch
{
try {
$searchResult = winget search Microsoft.VCRedist.2015+.x64 --source winget 2>&1 | Out-String
if ($searchResult -match "Microsoft\.VCRedist") {
return $true
}
return $false
}
catch {
return $false
}
}
Function Install-WingetDependencies
{
Write-Rainbow "Fixing WinGet..."
$ProgressPreference = 'SilentlyContinue'
$tempDir = "$env:TEMP\WinGetBootstrap"
New-Item -ItemType Directory -Path $tempDir -Force | Out-Null
$depsZipUrl = "https://github.com/microsoft/winget-cli/releases/latest/download/DesktopAppInstaller_Dependencies.zip"
$depsZipPath = "$tempDir\Dependencies.zip"
$depsExtractPath = "$tempDir\Dependencies"
Write-Rainbow " Downloading dependencies..."
try {
curl.exe -L -s -o $depsZipPath $depsZipUrl
Expand-Archive -Path $depsZipPath -DestinationPath $depsExtractPath -Force
} catch { }
Update-WingetSources
if (Test-WingetSearch) {
Remove-Item -Path $tempDir -Recurse -Force -ErrorAction SilentlyContinue
return
}
# Install VCLibs
Write-Rainbow " Installing VCLibs..."
$vcLibs = Get-ChildItem -Path $depsExtractPath -Recurse -Filter "*VCLibs*x64*.appx" -ErrorAction SilentlyContinue
foreach ($vc in $vcLibs) {
Install-AppxSilent -Path $vc.FullName -DisplayName $vc.BaseName | Out-Null
}
# Install UI.Xaml
Write-Rainbow " Installing UI.Xaml..."
$uiXaml = Get-ChildItem -Path $depsExtractPath -Recurse -Filter "*UI.Xaml*x64*.appx" -ErrorAction SilentlyContinue | Select-Object -First 1
if ($uiXaml) {
Install-AppxSilent -Path $uiXaml.FullName -DisplayName "Microsoft.UI.Xaml" | Out-Null
} else {
$uiXamlUrl = "https://www.nuget.org/api/v2/package/Microsoft.UI.Xaml/2.8.6"
$uiXamlZip = "$tempDir\Microsoft.UI.Xaml.zip"
$uiXamlExtract = "$tempDir\UIXaml"
curl.exe -L -s -o $uiXamlZip $uiXamlUrl
Expand-Archive -Path $uiXamlZip -DestinationPath $uiXamlExtract -Force -ErrorAction SilentlyContinue
$uiXamlAppx = Get-ChildItem -Path $uiXamlExtract -Recurse -Filter "*x64*.appx" -ErrorAction SilentlyContinue | Select-Object -First 1
if ($uiXamlAppx) {
Install-AppxSilent -Path $uiXamlAppx.FullName -DisplayName "Microsoft.UI.Xaml" | Out-Null
}
}
# Download and install WinGet
Write-Rainbow " Downloading WinGet..."
$tempWinget = "$tempDir\getwinget.msixbundle"
curl.exe -L -s -o $tempWinget "https://aka.ms/getwinget"
Write-Rainbow " Installing WinGet..."
try {
Add-AppxPackage -Path $tempWinget -ForceApplicationShutdown -ErrorAction Stop
}
catch {
$errorMsg = $_.Exception.Message
if ($errorMsg -match "Microsoft\.WindowsAppRuntime\.(\d+\.\d+)") {
$runtimeVersion = $matches[1]
Write-Rainbow " Installing WindowsAppRuntime $runtimeVersion..."
$appRuntimeUrl = "https://aka.ms/windowsappsdk/$runtimeVersion/latest/windowsappruntimeinstall-x64.exe"
$appRuntimeExe = "$tempDir\WindowsAppRuntimeInstall.exe"
curl.exe -L -s -o $appRuntimeExe $appRuntimeUrl
if (Test-Path $appRuntimeExe) {
Start-Process -FilePath $appRuntimeExe -ArgumentList "--quiet" -Wait -ErrorAction SilentlyContinue
Write-Rainbow " Installing WinGet..."
Add-AppxPackage -Path $tempWinget -ForceApplicationShutdown -ErrorAction SilentlyContinue
}
}
}
Update-WingetSources
if (Test-WingetSearch) {
Write-Rainbow " WinGet fixed!"
Remove-Item -Path $tempDir -Recurse -Force -ErrorAction SilentlyContinue
return
}
# Fallback to GitHub
Write-Rainbow " Trying GitHub fallback..."
$wingetBundleUrl = "https://github.com/microsoft/winget-cli/releases/latest/download/Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle"
$wingetBundlePath = "$tempDir\WinGet.msixbundle"
curl.exe -L -s -o $wingetBundlePath $wingetBundleUrl
if (Test-Path $wingetBundlePath) {
Add-AppxPackage -Path $wingetBundlePath -ForceApplicationShutdown -ErrorAction SilentlyContinue
}
Update-WingetSources
if (Test-WingetSearch) {
Write-Rainbow " WinGet fixed!"
Remove-Item -Path $tempDir -Recurse -Force -ErrorAction SilentlyContinue
return
}
Write-Host ""
Write-Rainbow "WinGet could not be fixed automatically."
Write-Rainbow "Report: https://github.com/harryeffinpotter/PC-Gaming-Redists/issues"
Write-Host ""
Remove-Item -Path $tempDir -Recurse -Force -ErrorAction SilentlyContinue
}
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor [System.Net.SecurityProtocolType]::Tls12
$ErrorActionPreference = 'stop'
# Check if winget exists AND actually works
$wingetFixRan = $false
if (!(Test-CommandExists winget) -or !(Test-WingetWorks))
{
$wingetFixRan = $true
Write-Rainbow "WinGet is missing or not working properly..."
Write-Rainbow "This is common on fresh Windows 11 installs."
Write-Host ""
Write-Rainbow "NOTE: This may need to close Edge, Notepad, MS Store, and other apps to install dependencies."
Write-Host ""
Install-WingetDependencies
# Verify it worked
Start-Sleep -Seconds 2
if (Test-WingetWorks) {
Write-Rainbow "WinGet is now working!"
} else {
Write-Rainbow "WinGet may still have issues. Continuing anyway..."
}
}
$progressPreference = 'silentlyContinue'
try { winget source update --accept-source-agreements 2>&1 | Out-Null } catch { }
$DownloadURL = 'https://raw.githubusercontent.com/harryeffinpotter/PC-Gaming-Redists/main/AIOInstaller.bat'
$FilePath = "$env:TEMP\AIOInstaller.bat"
$MenuURL = 'https://raw.githubusercontent.com/harryeffinpotter/PC-Gaming-Redists/main/pcgr_menu.ps1'
$MenuPath = "$env:TEMP\pcgr_menu.ps1"
try {
Invoke-WebRequest -Uri $DownloadURL -UseBasicParsing -OutFile $FilePath -ErrorAction Stop
} catch {
Write-Host "ERROR: Failed to download installer!" -ForegroundColor Red
Write-Host $_.Exception.Message -ForegroundColor Red
Stop-Transcript | Out-Null
pause
Return
}
try {
Invoke-WebRequest -Uri $MenuURL -UseBasicParsing -OutFile $MenuPath -ErrorAction Stop
} catch {
Write-Host "WARNING: Failed to download menu script - options menu will not work" -ForegroundColor Yellow
}
# Fix line endings - GitHub raw serves LF, but batch files need CRLF
try {
$content = [System.IO.File]::ReadAllText($FilePath)
$content = $content -replace "`r`n", "`n" -replace "`n", "`r`n"
[System.IO.File]::WriteAllText($FilePath, $content)
} catch { }
if (!(Test-Path $FilePath)) {
Write-Host "ERROR: Download succeeded but file not found!" -ForegroundColor Red
Stop-Transcript | Out-Null
pause
Return
}
# Rainbow text for launch message (bold)
$bold = "$e[1m"
if ($wingetFixRan) {
$launchLines = @("Launching Installer Window.", "(Be sure to agree to UAC prompt)")
} else {
$launchLines = @(" Launching Installer Window.", " (Be sure to agree to UAC prompt)")
}
foreach ($line in $launchLines) {
$chars = $line.ToCharArray()
$len = $chars.Length
$out = ""
for ($i = 0; $i -lt $len; $i++) {
$colorIdx = [Math]::Floor(($i / $len) * $rainbow.Length)
if ($colorIdx -ge $rainbow.Length) { $colorIdx = $rainbow.Length - 1 }
$out += $bold + $rainbow[$colorIdx] + $chars[$i]
}
Write-Host "$out$r"
}
Start-Sleep -Seconds 3
# Disable QuickEdit for this session only (doesn't modify registry, safe if script is cancelled)
$QuickEditCode = @"
using System;
using System.Runtime.InteropServices;
public class QuickEdit {
[DllImport("kernel32.dll", SetLastError = true)]
public static extern IntPtr GetStdHandle(int nStdHandle);
[DllImport("kernel32.dll", SetLastError = true)]
public static extern bool GetConsoleMode(IntPtr hConsoleHandle, out uint lpMode);
[DllImport("kernel32.dll", SetLastError = true)]
public static extern bool SetConsoleMode(IntPtr hConsoleHandle, uint dwMode);
}
"@
try {
Add-Type -TypeDefinition $QuickEditCode -Language CSharp -ErrorAction SilentlyContinue
$handle = [QuickEdit]::GetStdHandle(-10) # STD_INPUT_HANDLE
$mode = 0
[void][QuickEdit]::GetConsoleMode($handle, [ref]$mode)
$mode = $mode -band (-bnot 0x0040) # Disable ENABLE_QUICK_EDIT_MODE
[void][QuickEdit]::SetConsoleMode($handle, $mode)
} catch { }
try {
Start-Process -Verb runAs $FilePath -Wait
} catch {
Write-Host "ERROR launching installer: $_" -ForegroundColor Red
pause
}
# Cleanup
try { Remove-Item $FilePath -Force -ErrorAction SilentlyContinue } catch { }
Stop-Transcript | Out-Null