summaryrefslogtreecommitdiff
path: root/tools/windbg/install.ps1
blob: 4e206e00492c24808c77cd526de0f1b94e9a5683 (plain) (blame)
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
# This script is dedicated to the public domain.

Add-Type -Assembly System.IO.Compression.FileSystem

$OutDir = "tools\windbg\bin"
$Arch = "x64" # can also use x86, arm64

if (!(Test-Path $OutDir)) { $null = mkdir $OutDir }
[xml]$content = (New-Object System.Net.WebClient).DownloadString("https://aka.ms/windbg/download")
$bundleurl = $content.AppInstaller.MainBundle.Uri
# Using curl.exe here instead because it has an actual useful progress bar.
# Modern PowerShell does too, but not the PS 5.1 that still ships with W10
#Invoke-WebRequest $bundleurl -OutFile $OutDir\__bundle.zip
curl.exe "-#o$OutDir\__bundle.zip" "$bundleurl"
$filename = switch ($Arch) {
	"x64" { "windbg_win-x64.msix" }
	"x86" { "windbg_win-x86.msix" }
	"arm64" { "windbg_win-arm64.msix" }
}
$zip = [IO.Compression.ZipFile]::OpenRead("$OutDir\__bundle.zip")
try {
	if ($found = $zip.Entries.Where({ $_.FullName -eq $filename }, "First") ) {
	    $dest = "$OutDir\__msix.zip"
	    [IO.Compression.ZipFileExtensions]::ExtractToFile($found[0], $dest, $false)
	}
	else {
	    Write-Error "File not found in ZIP: $filename"
	    exit 100
	}
}
finally {
	if ($zip) { $zip.Dispose() }
}
rm $OutDir\__bundle.zip
Expand-Archive -DestinationPath "$OutDir" "$OutDir\__msix.zip"
rm $OutDir\__msix.zip
# misc cleanup
rm -r $OutDir\AppxMetadata\
rm $OutDir\'``[Content_Types``].xml' # wtf, microsoft, wtf.
rm $OutDir\AppxBlockMap.xml
rm $OutDir\AppxManifest.xml
rm $OutDir\AppxSignature.p7x
rm -r $OutDir\runtimes\unix\
mv "$OutDir\Third%20Party%20Notices.txt" "$OutDir\Third Party Notices.txt"