Skip to content

Commit

Permalink
Format PowerShell Scripts
Browse files Browse the repository at this point in the history
Using VSCode's PowerShell extension, format and refactor the scripts!
  • Loading branch information
Nirmal4G committed Jul 20, 2021
1 parent d764b7e commit 1ccbdf5
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 151 deletions.
60 changes: 24 additions & 36 deletions build/Find-WindowsSDKVersions.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@ $ErrorActionPreference = 'Stop'
# Unique set of Windows SDK versions referenced in files
$versions = New-Object System.Collections.Generic.HashSet[System.String]

function Get-Nodes
{
function Get-Nodes {
param(
[parameter(ValueFromPipeline=$true)]
[parameter(ValueFromPipeline = $true)]
[xml] $xml,
[parameter(Mandatory=$true)]
[parameter(Mandatory = $true)]
[string] $nodeName)

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

function Get-NodeValue
{
function Get-NodeValue {
param(
[parameter(ValueFromPipeline=$true)]
[parameter(ValueFromPipeline = $true)]
[xml] $xml,
[string] $nodeName)

Expand All @@ -42,10 +40,9 @@ function Get-NodeValue
return [string]""
}

function Get-SdkVersion
{
function Get-SdkVersion {
param(
[Parameter(ValueFromPipeline=$true)] $file)
[Parameter(ValueFromPipeline = $true)] $file)

[xml] $xml = Get-Content $file

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

function Test-RegistryPathAndValue
{
function Test-RegistryPathAndValue {
param (
[parameter(Mandatory=$true)]
[parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[string] $path,
[parameter(Mandatory=$true)]
[parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[string] $value)

try
{
if (Test-Path $path)
{
try {
if (Test-Path $path) {
Get-ItemProperty -Path $path | Select-Object -ExpandProperty $value -ErrorAction Stop | Out-Null
return $true
}
}
catch
{
catch {
}

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

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

if (Test-RegistryPathAndValue -Path $WindowsSDKRegPath -Value $WindowsSDKRegRootKey)
{
if (Test-RegistryPathAndValue -Path $WindowsSDKRegPath -Value $WindowsSDKRegRootKey) {
# A Windows SDK is installed
# Is an SDK of our version installed with the options we need?
if (Test-RegistryPathAndValue -Path $WindowsSDKInstalledRegPath -Value "$WindowsSDKOptions")
{
if (Test-RegistryPathAndValue -Path $WindowsSDKInstalledRegPath -Value "$WindowsSDKOptions") {
# It appears we have what we need. Double check the disk
$sdkRoot = Get-ItemProperty -Path $WindowsSDKRegPath | Select-Object -ExpandProperty $WindowsSDKRegRootKey
if ($sdkRoot)
{
if (Test-Path $sdkRoot)
{
if ($sdkRoot) {
if (Test-Path $sdkRoot) {
$refPath = Join-Path $sdkRoot "References\$WindowsSDKVersion"
if (Test-Path $refPath)
{
if (Test-Path $refPath) {
$umdPath = Join-Path $sdkRoot "UnionMetadata\$WindowsSDKVersion"
if (Test-Path $umdPath)
{
if (Test-Path $umdPath) {
# Pretty sure we have what we need
$retval = $false
}
Expand All @@ -131,13 +118,13 @@ function Test-InstallWindowsSdk([string] $WindowsSDKVersion) {
return $retval
}

if(!$PSScriptRoot){
if (!$PSScriptRoot) {
$PSScriptRoot = Split-Path $MyInvocation.MyCommand.Path -Parent
}

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

Get-ChildItem *.csproj -Recurse | ForEach-Object { get-sdkversion $_}
Get-ChildItem *.csproj -Recurse | ForEach-Object { get-sdkversion $_ }
Get-ChildItem *.targets -Recurse | ForEach-Object { get-sdkversion $_ }
Get-ChildItem *.props -Recurse | ForEach-Object { get-sdkversion $_ }

Expand All @@ -146,7 +133,7 @@ Write-Host

$anyInstallRequired = $false;

foreach($version in $versions) {
foreach ($version in $versions) {
if ($version -match "10\.0\.\d{5}\.0") {
$installRequired = Test-InstallWindowsSDK $version
Write-Host "Windows SDK '$version' install required: $installRequired"
Expand All @@ -160,6 +147,7 @@ foreach($version in $versions) {
Write-Host
if ($anyInstallRequired) {
throw "At least one Windows SDK is missing from this machine"
} else {
}
else {
Write-Host "All referenced Windows SDKs are installed!"
}
12 changes: 8 additions & 4 deletions build/Install-WindowsSDK.ps1
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
mkdir c:\winsdktemp

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

Start-Process -Wait "c:\winsdktemp\winsdksetup.exe" "/features OptionId.UWPCpp /q"
mkdir $WinSdkTempDir

$client = [System.Net.WebClient]::new()
$client.DownloadFile("https://go.microsoft.com/fwlink/p/?linkid=870807", $WinSdkSetupExe)

Start-Process -Wait $WinSdkSetupExe "/features OptionId.UWPCpp /q"
Loading

0 comments on commit 1ccbdf5

Please sign in to comment.