Skip to content

Commit b142a7b

Browse files
committed
Format PowerShell Scripts
Using VSCode's PowerShell extension, format and refactor the scripts!
1 parent 2c0acab commit b142a7b

File tree

6 files changed

+100
-151
lines changed

6 files changed

+100
-151
lines changed

build/Find-WindowsSDKVersions.ps1

Lines changed: 24 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,11 @@ $ErrorActionPreference = 'Stop'
55
# Unique set of Windows SDK versions referenced in files
66
$versions = New-Object System.Collections.Generic.HashSet[System.String]
77

8-
function Get-Nodes
9-
{
8+
function Get-Nodes {
109
param(
11-
[parameter(ValueFromPipeline=$true)]
10+
[parameter(ValueFromPipeline = $true)]
1211
[xml] $xml,
13-
[parameter(Mandatory=$true)]
12+
[parameter(Mandatory = $true)]
1413
[string] $nodeName)
1514

1615
# Try the old style csproj. Also format required for .targets and .props files
@@ -24,10 +23,9 @@ function Get-Nodes
2423
return $r
2524
}
2625

27-
function Get-NodeValue
28-
{
26+
function Get-NodeValue {
2927
param(
30-
[parameter(ValueFromPipeline=$true)]
28+
[parameter(ValueFromPipeline = $true)]
3129
[xml] $xml,
3230
[string] $nodeName)
3331

@@ -42,10 +40,9 @@ function Get-NodeValue
4240
return [string]""
4341
}
4442

45-
function Get-SdkVersion
46-
{
43+
function Get-SdkVersion {
4744
param(
48-
[Parameter(ValueFromPipeline=$true)] $file)
45+
[Parameter(ValueFromPipeline = $true)] $file)
4946

5047
[xml] $xml = Get-Content $file
5148

@@ -67,26 +64,22 @@ function Get-SdkVersion
6764
$versions.Add("10.0." + $version + ".0") | Out-Null
6865
}
6966

70-
function Test-RegistryPathAndValue
71-
{
67+
function Test-RegistryPathAndValue {
7268
param (
73-
[parameter(Mandatory=$true)]
69+
[parameter(Mandatory = $true)]
7470
[ValidateNotNullOrEmpty()]
7571
[string] $path,
76-
[parameter(Mandatory=$true)]
72+
[parameter(Mandatory = $true)]
7773
[ValidateNotNullOrEmpty()]
7874
[string] $value)
7975

80-
try
81-
{
82-
if (Test-Path $path)
83-
{
76+
try {
77+
if (Test-Path $path) {
8478
Get-ItemProperty -Path $path | Select-Object -ExpandProperty $value -ErrorAction Stop | Out-Null
8579
return $true
8680
}
8781
}
88-
catch
89-
{
82+
catch {
9083
}
9184

9285
return $false
@@ -101,24 +94,18 @@ function Test-InstallWindowsSdk([string] $WindowsSDKVersion) {
10194

10295
$WindowsSDKInstalledRegPath = "$WindowsSDKRegPath\$WindowsSDKVersion\Installed Options"
10396

104-
if (Test-RegistryPathAndValue -Path $WindowsSDKRegPath -Value $WindowsSDKRegRootKey)
105-
{
97+
if (Test-RegistryPathAndValue -Path $WindowsSDKRegPath -Value $WindowsSDKRegRootKey) {
10698
# A Windows SDK is installed
10799
# Is an SDK of our version installed with the options we need?
108-
if (Test-RegistryPathAndValue -Path $WindowsSDKInstalledRegPath -Value "$WindowsSDKOptions")
109-
{
100+
if (Test-RegistryPathAndValue -Path $WindowsSDKInstalledRegPath -Value "$WindowsSDKOptions") {
110101
# It appears we have what we need. Double check the disk
111102
$sdkRoot = Get-ItemProperty -Path $WindowsSDKRegPath | Select-Object -ExpandProperty $WindowsSDKRegRootKey
112-
if ($sdkRoot)
113-
{
114-
if (Test-Path $sdkRoot)
115-
{
103+
if ($sdkRoot) {
104+
if (Test-Path $sdkRoot) {
116105
$refPath = Join-Path $sdkRoot "References\$WindowsSDKVersion"
117-
if (Test-Path $refPath)
118-
{
106+
if (Test-Path $refPath) {
119107
$umdPath = Join-Path $sdkRoot "UnionMetadata\$WindowsSDKVersion"
120-
if (Test-Path $umdPath)
121-
{
108+
if (Test-Path $umdPath) {
122109
# Pretty sure we have what we need
123110
$retval = $false
124111
}
@@ -131,13 +118,13 @@ function Test-InstallWindowsSdk([string] $WindowsSDKVersion) {
131118
return $retval
132119
}
133120

134-
if(!$PSScriptRoot){
121+
if (!$PSScriptRoot) {
135122
$PSScriptRoot = Split-Path $MyInvocation.MyCommand.Path -Parent
136123
}
137124

138125
Write-Host -NoNewline "Locating referenced Windows SDK versions..."
139126

140-
Get-ChildItem *.csproj -Recurse | ForEach-Object { get-sdkversion $_}
127+
Get-ChildItem *.csproj -Recurse | ForEach-Object { get-sdkversion $_ }
141128
Get-ChildItem *.targets -Recurse | ForEach-Object { get-sdkversion $_ }
142129
Get-ChildItem *.props -Recurse | ForEach-Object { get-sdkversion $_ }
143130

@@ -146,7 +133,7 @@ Write-Host
146133

147134
$anyInstallRequired = $false;
148135

149-
foreach($version in $versions) {
136+
foreach ($version in $versions) {
150137
if ($version -match "10\.0\.\d{5}\.0") {
151138
$installRequired = Test-InstallWindowsSDK $version
152139
Write-Host "Windows SDK '$version' install required: $installRequired"
@@ -160,6 +147,7 @@ foreach($version in $versions) {
160147
Write-Host
161148
if ($anyInstallRequired) {
162149
throw "At least one Windows SDK is missing from this machine"
163-
} else {
150+
}
151+
else {
164152
Write-Host "All referenced Windows SDKs are installed!"
165153
}

build/Install-WindowsSDK.ps1

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1-
mkdir c:\winsdktemp
21

3-
$client = new-object System.Net.WebClient
4-
$client.DownloadFile("https://go.microsoft.com/fwlink/p/?linkid=870807","c:\winsdktemp\winsdksetup.exe")
2+
$WinSdkTempDir = "C:\WinSdkTemp\"
3+
$WinSdkSetupExe = "C:\WinSdkTemp\" + "WinSdkSetup.exe"
54

6-
Start-Process -Wait "c:\winsdktemp\winsdksetup.exe" "/features OptionId.UWPCpp /q"
5+
mkdir $WinSdkTempDir
6+
7+
$client = [System.Net.WebClient]::new()
8+
$client.DownloadFile("https://go.microsoft.com/fwlink/p/?linkid=870807", $WinSdkSetupExe)
9+
10+
Start-Process -Wait $WinSdkSetupExe "/features OptionId.UWPCpp /q"

0 commit comments

Comments
 (0)