Harmonise the use of $true/$false and not operator

This commit is contained in:
Pete Batard
2023-04-14 11:20:34 +01:00
parent 425eb4da24
commit 9025d258e8

View File

@@ -43,9 +43,9 @@ param(
# (Optional) Specify Windows architecture [Toggles commandline mode] # (Optional) Specify Windows architecture [Toggles commandline mode]
[string]$Arch, [string]$Arch,
# (Optional) Only display the download URL [Toggles commandline mode] # (Optional) Only display the download URL [Toggles commandline mode]
[switch]$GetUrl = $False, [switch]$GetUrl = $false,
# (Optional) Increase verbosity # (Optional) Increase verbosity
[switch]$Verbose = $False [switch]$Verbose = $false
) )
#endregion #endregion
@@ -53,9 +53,9 @@ try {
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8 [Console]::OutputEncoding = [System.Text.Encoding]::UTF8
} catch {} } catch {}
$Cmd = $False $Cmd = $false
if ($Win -or $Rel -or $Ed -or $Lang -or $Arch -or $GetUrl) { if ($Win -or $Rel -or $Ed -or $Lang -or $Arch -or $GetUrl) {
$Cmd = $True $Cmd = $true
} }
# Return a decimal Windows version that we can then check for platform support. # Return a decimal Windows version that we can then check for platform support.
@@ -425,9 +425,9 @@ function Select-Language([string]$LangName)
($SysLocale.StartsWith("tr") -and $LangName -like "*Turk*") -or ` ($SysLocale.StartsWith("tr") -and $LangName -like "*Turk*") -or `
($SysLocale.StartsWith("uk") -and $LangName -like "*Ukrain*") -or ` ($SysLocale.StartsWith("uk") -and $LangName -like "*Ukrain*") -or `
($SysLocale.StartsWith("vi") -and $LangName -like "*Vietnam*")) { ($SysLocale.StartsWith("vi") -and $LangName -like "*Vietnam*")) {
return $True return $true
} }
return $False return $false
} }
function Add-Entry([int]$pos, [string]$Name, [array]$Items, [string]$DisplayName) function Add-Entry([int]$pos, [string]$Name, [array]$Items, [string]$DisplayName)
@@ -520,7 +520,7 @@ function ConvertTo-ImageSource
function Throw-Error([object]$Req, [string]$Alt) function Throw-Error([object]$Req, [string]$Alt)
{ {
$Err = $(GetElementById -Request $Req -Id "errorModalMessage").innerText -replace "<[^>]+>" -replace "\s+", " " $Err = $(GetElementById -Request $Req -Id "errorModalMessage").innerText -replace "<[^>]+>" -replace "\s+", " "
if (-not $Err) { if (!$Err) {
$Err = $Alt $Err = $Alt
} else { } else {
$Err = [System.Text.Encoding]::UTF8.GetString([byte[]][char[]]$Err) $Err = [System.Text.Encoding]::UTF8.GetString([byte[]][char[]]$Err)
@@ -531,7 +531,7 @@ function Throw-Error([object]$Req, [string]$Alt)
# Translate a message string # Translate a message string
function Get-Translation([string]$Text) function Get-Translation([string]$Text)
{ {
if (-not $English -contains $Text) { if (!($English -contains $Text)) {
Write-Host "Error: '$Text' is not a translatable string" Write-Host "Error: '$Text' is not a translatable string"
return "(Untranslated)" return "(Untranslated)"
} }
@@ -569,7 +569,7 @@ function Error([string]$ErrorMessage)
if (!$Cmd) { if (!$Cmd) {
$XMLForm.Title = $(Get-Translation("Error")) + ": " + $ErrorMessage $XMLForm.Title = $(Get-Translation("Error")) + ": " + $ErrorMessage
Refresh-Control($XMLForm) Refresh-Control($XMLForm)
$XMLGrid.Children[2 * $script:Stage + 1].IsEnabled = $True $XMLGrid.Children[2 * $script:Stage + 1].IsEnabled = $true
$UserInput = [System.Windows.MessageBox]::Show($XMLForm.Title, $(Get-Translation("Error")), "OK", "Error") $UserInput = [System.Windows.MessageBox]::Show($XMLForm.Title, $(Get-Translation("Error")), "OK", "Error")
$script:ExitCode = $script:Stage-- $script:ExitCode = $script:Stage--
} else { } else {
@@ -642,7 +642,7 @@ $EnglishMessages = "en-US|Version|Release|Edition|Language|Architecture|Download
"This feature is not available on this platform." "This feature is not available on this platform."
[string[]]$English = $EnglishMessages.Split('|') [string[]]$English = $EnglishMessages.Split('|')
[string[]]$Localized = $null [string[]]$Localized = $null
if ($LocData -and (-not $LocData.StartsWith("en-US"))) { if ($LocData -and !$LocData.StartsWith("en-US")) {
$Localized = $LocData.Split('|') $Localized = $LocData.Split('|')
# Adjust the $Localized array if we have more or fewer strings than in $EnglishMessages # Adjust the $Localized array if we have more or fewer strings than in $EnglishMessages
if ($Localized.Length -lt $English.Length) { if ($Localized.Length -lt $English.Length) {
@@ -844,7 +844,7 @@ function Get-Windows-Download-Links([int]$SelectedVersion, [int]$SelectedRelease
$r = Invoke-WebRequest -Method Post -Headers @{ "Referer" = $ref } -UseBasicParsing -UserAgent $UserAgent -WebSession $Session $url $r = Invoke-WebRequest -Method Post -Headers @{ "Referer" = $ref } -UseBasicParsing -UserAgent $UserAgent -WebSession $Session $url
if ($r -match "errorModalMessage") { if ($r -match "errorModalMessage") {
$Alt = [regex]::Match($r, '<p id="errorModalMessage">(.+?)<\/p>').Groups[1].Value -replace "<[^>]+>" -replace "\s+", " " -replace "\?\?\?", "-" $Alt = [regex]::Match($r, '<p id="errorModalMessage">(.+?)<\/p>').Groups[1].Value -replace "<[^>]+>" -replace "\s+", " " -replace "\?\?\?", "-"
if (-not $Alt) { if (!$Alt) {
$Alt = "Could not retrieve architectures from server" $Alt = "Could not retrieve architectures from server"
} else { } else {
$Alt += " " + $SessionId + "." $Alt += " " + $SessionId + "."
@@ -864,7 +864,7 @@ function Get-Windows-Download-Links([int]$SelectedVersion, [int]$SelectedRelease
foreach ($var in $xml.inputs.input) { foreach ($var in $xml.inputs.input) {
$json = $var.value | ConvertFrom-Json; $json = $var.value | ConvertFrom-Json;
if ($json) { if ($json) {
if (($Is64 -and $json.DownloadType -eq "x64") -or (-not $Is64 -and $json.DownloadType -eq "x86")) { if (($Is64 -and $json.DownloadType -eq "x64") -or (!$Is64 -and $json.DownloadType -eq "x86")) {
$script:SelectedIndex = $i $script:SelectedIndex = $i
} }
$links += @(New-Object PsObject -Property @{ Type = $json.DownloadType; Link = $json.Uri }) $links += @(New-Object PsObject -Property @{ Type = $json.DownloadType; Link = $json.Uri })
@@ -886,7 +886,7 @@ function Get-Windows-Download-Links([int]$SelectedVersion, [int]$SelectedRelease
function Process-Download-Link([string]$Url) function Process-Download-Link([string]$Url)
{ {
try { try {
if ($PipeName -and -not $Check.IsChecked) { if ($PipeName -and !$Check.IsChecked) {
Send-Message -PipeName $PipeName -Message $Url Send-Message -PipeName $PipeName -Message $Url
} else { } else {
if ($Cmd) { if ($Cmd) {
@@ -1110,9 +1110,9 @@ $WindowsVersion.DisplayMemberPath = "Version"
# Button Action # Button Action
$Continue.add_click({ $Continue.add_click({
$script:Stage++ $script:Stage++
$XMLGrid.Children[2 * $Stage + 1].IsEnabled = $False $XMLGrid.Children[2 * $Stage + 1].IsEnabled = $false
$Continue.IsEnabled = $False $Continue.IsEnabled = $false
$Back.IsEnabled = $False $Back.IsEnabled = $false
Refresh-Control($Continue) Refresh-Control($Continue)
Refresh-Control($Back) Refresh-Control($Back)
@@ -1180,9 +1180,9 @@ $Continue.add_click({
$XMLForm.Close() $XMLForm.Close()
} }
} }
$Continue.IsEnabled = $True $Continue.IsEnabled = $true
if ($Stage -ge 0) { if ($Stage -ge 0) {
$Back.IsEnabled = $True $Back.IsEnabled = $true
} }
}) })
@@ -1192,7 +1192,7 @@ $Back.add_click({
} else { } else {
$XMLGrid.Children.RemoveAt(2 * $Stage + 3) $XMLGrid.Children.RemoveAt(2 * $Stage + 3)
$XMLGrid.Children.RemoveAt(2 * $Stage + 2) $XMLGrid.Children.RemoveAt(2 * $Stage + 2)
$XMLGrid.Children[2 * $Stage + 1].IsEnabled = $True $XMLGrid.Children[2 * $Stage + 1].IsEnabled = $true
$dh2 = $dh $dh2 = $dh
if ($Stage -eq 4 -and $PipeName) { if ($Stage -eq 4 -and $PipeName) {
$Check.Visibility = "Collapsed" $Check.Visibility = "Collapsed"
@@ -1217,7 +1217,7 @@ $Back.add_click({
}) })
# Display the dialog # Display the dialog
$XMLForm.Add_Loaded( { $XMLForm.Activate() } ) $XMLForm.Add_Loaded({$XMLForm.Activate()})
$XMLForm.ShowDialog() | Out-Null $XMLForm.ShowDialog() | Out-Null
# Clean up & exit # Clean up & exit