Don't display special Korean/Chinese versions by default

* Also simplify some of the script
This commit is contained in:
Pete Batard
2019-02-20 16:08:57 +01:00
parent 3e56db88fa
commit 167569c043

208
Fido.ps1
View File

@@ -18,14 +18,7 @@
#
# NB: You must have a BOM on your .ps1 if you want Powershell to actually
# realise it should use Unicode for the UI controls and not ISO-8859-1
# TODO:
# - Add a -NoHide param
# - Display all arch links?
# - Icon does not display in taskbar when shell window is reduced
# - Validate that download links are from Microsoft servers
# - Add Expert mode for Home China and suff?
# realise it should use Unicode for the UI rather than ISO-8859-1.
#region Parameters
param(
@@ -33,7 +26,7 @@ param(
# If not provided, a browser window is opened instead.
[string]$PipeName,
# (Optional) '|' separated UI localization strings.
[string]$Messages,
[string]$LocData,
# (Optional) Path to the file that should be used for the UI icon.
[string]$Icon,
# (Optional) The title to display on the application window
@@ -44,6 +37,7 @@ param(
#region Testing
$Debug = $False
$Testing = $False
$Expert = $False
#endregion
Write-Host Please Wait...
@@ -54,10 +48,10 @@ $code = @"
internal static extern IntPtr LoadLibrary(string lpLibFileName);
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true, BestFitMapping = false, ThrowOnUnmappableChar = true)]
internal static extern int LoadString(IntPtr hInstance, uint wID, StringBuilder lpBuffer, int nBufferMax);
[DllImport("Shell32.dll", CharSet = CharSet.Auto, SetLastError = true, BestFitMapping = false, ThrowOnUnmappableChar = true)]
[DllImport("shell32.dll", CharSet = CharSet.Auto, SetLastError = true, BestFitMapping = false, ThrowOnUnmappableChar = true)]
internal static extern int ExtractIconEx(string sFile, int iIndex, out IntPtr piLargeVersion, out IntPtr piSmallVersion, int amountIcons);
[DllImport("user32.dll")]
public static extern bool ShowWindow(int handle, int state);
public static extern bool ShowWindow(IntPtr handle, int state);
// Returns a localized MUI string from the specified DLL
public static string GetMuiString(string dll, uint index)
@@ -90,7 +84,7 @@ $code = @"
Add-Type -MemberDefinition $code -Namespace Gui -UsingNamespace "System.IO", "System.Text", "System.Drawing", "System.Globalization" -ReferencedAssemblies System.Drawing -Name Utils -ErrorAction Stop
Add-Type -AssemblyName PresentationFramework
# Hide the powershell window: https://stackoverflow.com/a/27992426/1069307
$null = [Gui.Utils]::ShowWindow(([System.Diagnostics.Process]::GetCurrentProcess() | Get-Process).MainWindowHandle, 0)
[Gui.Utils]::ShowWindow(([System.Diagnostics.Process]::GetCurrentProcess() | Get-Process).MainWindowHandle, 0) | Out-Null
#endregion
#region Data
@@ -102,51 +96,51 @@ $WindowsVersions = @(
"1809 R2 (Build 17763.107 - 2018.10)",
@("Windows 10 Home/Pro", 1060),
@("Windows 10 Education", 1056),
@("Windows 10 Home China ", 1061)
@("Windows 10 Home China ", -1061)
),
@(
"1809 R1 (Build 17763.1 - 2018.09)",
@("Windows 10 Home/Pro", 1019),
@("Windows 10 Education", 1021),
@("Windows 10 Home China ", 1020)
@("Windows 10 Home China ", -1020)
),
@(
"1803 (Build 17134.1 - 2018.04)",
@("Windows 10 Home/Pro", 651),
@("Windows 10 Education", 655),
@("Windows 10 Enterprise Eval", 629)
@("Windows 10 COEM 1803 Home China", 640),
@("Windows 10 COEM 1803", 639),
@("Windows 10 1803 Home China", 638),
@("Windows 10 Enterprise Eval", -629)
@("Windows 10 COEM 1803 Home China", -640),
@("Windows 10 COEM 1803", -639),
@("Windows 10 1803 Home China", -638),
@("Windows 10 1803", 637),
@("Windows 10 COEM 1803_1 Home China", 654),
@("Windows 10 COEM 1803_1", 653),
@("Windows 10 1803_1 Home China", 652)
@("Windows 10 COEM 1803_1 Home China", -654),
@("Windows 10 COEM 1803_1", -653),
@("Windows 10 1803_1 Home China", -652)
),
@(
"1709 (Build 16299.15 - 2017.09)",
@("Windows 10 Education 1709", 488),
@("Windows 10 COEM 1709 Home China", 487),
@("Windows 10 COEM 1709", 486),
@("Windows 10 1709 Home China", 485),
@("Windows 10 COEM 1709 Home China", -487),
@("Windows 10 COEM 1709", -486),
@("Windows 10 1709 Home China", -485),
@("Windows 10 1709", 484)
),
@(
"1703 (Build 15063.0 - 2017.03)",
@("Windows 10 1703 Education N", 424),
@("Windows 10 1703 Education", 423),
@("Windows 10 COEM 1703 Home China", 372),
@("Windows 10 COEM 1703 Home China", -372),
@("Windows 10 COEM 1703 Single Language", 371),
@("Windows 10 COEM 1703 N", 370),
@("Windows 10 COEM 1703", 369),
@("Windows 10 1703 Home China (Redstone 2)", 364),
@("Windows 10 1703 Single Language (Redstone 2)", 363),
@("Windows 10 1703 Home China (Redstone 2)", -364),
@("Windows 10 1703 Single Language (Redstone 2)", -363),
@("Windows 10 1703 N (Redstone 2)", 362),
@("Windows 10 1703 (Redstone 2)", 361)
),
@(
"1607 (Build 14393.0 - 2017.07)",
@("Windows 10 China Get Genuine (Redstone 1)", 247),
@("Windows 10 China Get Genuine (Redstone 1)", -247),
@("Windows 10 Single Language (Redstone 1)", 246),
@("Windows 10 N (Redstone 1)", 245),
@("Windows 10 (Redstone 1)", 244),
@@ -155,12 +149,12 @@ $WindowsVersions = @(
),
@(
"1511 R3 (Build 10586.164 - 2016.04)",
@("Windows 10 China Get Genuine (Threshold 2, April 2016 Update)", 185),
@("Windows 10 China Get Genuine (Threshold 2, April 2016 Update)", -185),
@("Windows 10 Single Language (Threshold 2, April 2016 Update)", 184),
@("Windows 10 N (Threshold 2, April 2016 Update)", 183),
@("Windows 10 KN (Threshold 2, April 2016 Update)", 182),
@("Windows 10 N (Threshold 2, April 2016 Update)", -183),
@("Windows 10 KN (Threshold 2, April 2016 Update)", -182),
@("Windows 10 Education N (Threshold 2, April 2016 Update)", 181),
@("Windows 10 Education KN (Threshold 2, April 2016 Update)", 180),
@("Windows 10 Education KN (Threshold 2, April 2016 Update)", -180),
@("Windows 10 Education (Threshold 2, April 2016 Update)", 179),
@("Windows 10 (Threshold 2, April 2016 Update)", 178)
),
@@ -168,10 +162,10 @@ $WindowsVersions = @(
"1511 R2 (Build 10586.104 - 2016.02)",
@("Windows 10 Single Language (Threshold 2, February 2016 Update)", 116),
@("Windows 10 N (Threshold 2, February 2016 Update)", 115),
@("Windows 10 KN (Threshold 2, February 2016 Update)", 114),
@("Windows 10 China Get Genuine (Threshold 2, February 2016 Update)", 113),
@("Windows 10 KN (Threshold 2, February 2016 Update)", -114),
@("Windows 10 China Get Genuine (Threshold 2, February 2016 Update)", -113),
@("Windows 10 Education N (Threshold 2, February 2016 Update)", 112),
@("Windows 10 Education KN (Threshold 2, February 2016 Update)", 111),
@("Windows 10 Education KN (Threshold 2, February 2016 Update)", -111),
@("Windows 10 Education (Threshold 2, February 2016 Update)", 110),
@("Windows 10 (Threshold 2, February 2016 Update)", 109)
),
@@ -179,10 +173,10 @@ $WindowsVersions = @(
"1511 R1 (Build 10586.0 - 2015.11)",
@("Windows 10 Single Language (Threshold 2)", 106),
@("Windows 10 N (Threshold 2)", 105),
@("Windows 10 KN (Threshold 2)", 104),
@("Windows 10 China Get Genuine (Threshold 2)", 103),
@("Windows 10 KN (Threshold 2)", -104),
@("Windows 10 China Get Genuine (Threshold 2)", -103),
@("Windows 10 Education N (Threshold 2)", 102),
@("Windows 10 Education KN (Threshold 2)", 101),
@("Windows 10 Education KN (Threshold 2)", -101),
@("Windows 10 Education (Threshold 2)", 100),
@("Windows 10 (Threshold 2)", 99)
),
@@ -190,11 +184,11 @@ $WindowsVersions = @(
"1507 (Build 10240.16384 - 2015.07)",
@("Windows 10 Single Language (Threshold 1)", 82),
@("Windows 10 N (Threshold 1)", 81),
@("Windows 10 KN (Threshold 1)", 80),
@("Windows 10 KN (Threshold 1)", -80),
@("Windows 10 (Threshold 1)", 79),
@("Windows 10 China Get Genuine (Threshold 1)", 78),
@("Windows 10 China Get Genuine (Threshold 1)", -78),
@("Windows 10 Education N (Threshold 1)", 77),
@("Windows 10 Education KN (Threshold 1)", 76),
@("Windows 10 Education KN (Threshold 1)", -76),
@("Windows 10 Education (Threshold 1)", 75)
)
),
@@ -206,11 +200,11 @@ $WindowsVersions = @(
@("Windows 8.1/Windows 8.1 Pro N", 55)
@("Windows 8.1 Single Language", 48),
@("Windows 8.1 Professional LE N", 71),
@("Windows 8.1 Professional LE KN", 70),
@("Windows 8.1 Professional LE K", 69),
@("Windows 8.1 Professional LE KN", -70),
@("Windows 8.1 Professional LE K", -69),
@("Windows 8.1 Professional LE", 68),
@("Windows 8.1 KN", 62),
@("Windows 8.1 K", 61)
@("Windows 8.1 KN", -62),
@("Windows 8.1 K", -61)
)
),
@(
@@ -221,28 +215,28 @@ $WindowsVersions = @(
@("Windows 7 Pro", 4),
@("Windows 7 Home Premium", 6),
@("Windows 7 Home Basic", 2),
@("Windows 7 Professional KN SP1 COEM", 98),
@("Windows 7 Home Premium KN SP1 COEM", 97),
@("Windows 7 Ultimate SP1 COEM", 96),
@("Windows 7 Ultimate N SP1 COEM", 95),
@("Windows 7 Ultimate KN SP1 COEM", 94),
@("Windows 7 Ultimate K SP1 COEM", 93),
@("Windows 7 Starter SP1 COEM", 92),
@("Windows 7 Professional SP1 COEM", 91),
@("Windows 7 Professional N SP1 COEM", 90),
@("Windows 7 Home Premium K SP1 COEM", 89),
@("Windows 7 Home Premium SP1 COEM GGK", 88),
@("Windows 7 Home Premium SP1 COEM", 87),
@("Windows 7 Home Premium N SP1 COEM", 86),
@("Windows 7 Home Basic SP1 COEM GGK", 85),
@("Windows 7 Home Basic SP1 COEM", 83),
@("Windows 7 Professional KN SP1 COEM", -98),
@("Windows 7 Home Premium KN SP1 COEM", -97),
@("Windows 7 Ultimate SP1 COEM", -96),
@("Windows 7 Ultimate N SP1 COEM", -95),
@("Windows 7 Ultimate KN SP1 COEM", -94),
@("Windows 7 Ultimate K SP1 COEM", -93),
@("Windows 7 Starter SP1 COEM", -92),
@("Windows 7 Professional SP1 COEM", -91),
@("Windows 7 Professional N SP1 COEM", -90),
@("Windows 7 Home Premium K SP1 COEM", -89),
@("Windows 7 Home Premium SP1 COEM GGK", -88),
@("Windows 7 Home Premium SP1 COEM", -87),
@("Windows 7 Home Premium N SP1 COEM", -86),
@("Windows 7 Home Basic SP1 COEM GGK", -85),
@("Windows 7 Home Basic SP1 COEM", -83),
@("Windows 7 Starter SP1", 28),
@("Windows 7 Ultimate K SP1", 26),
@("Windows 7 Ultimate KN SP1", 24),
@("Windows 7 Home Premium KN SP1", 22),
@("Windows 7 Home Premium K SP1", 20),
@("Windows 7 Professional KN SP1", 18),
@("Windows 7 Professional K SP1", 16),
@("Windows 7 Ultimate K SP1", -26),
@("Windows 7 Ultimate KN SP1", -24),
@("Windows 7 Home Premium KN SP1", -22),
@("Windows 7 Home Premium K SP1", -20),
@("Windows 7 Professional KN SP1", -18),
@("Windows 7 Professional K SP1", -16),
@("Windows 7 Ultimate N SP1", 14),
@("Windows 7 Professional N SP1", 12),
@("Windows 7 Home Premium N SP1", 10),
@@ -256,7 +250,7 @@ $WindowsVersions = @(
#endregion
#region Functions
function Select-Language([int]$ArrayIndex, [string]$LangName)
function Select-Language([string]$LangName)
{
# Use the system locale to try select the most appropriate language
[string]$SysLocale = [System.Globalization.CultureInfo]::CurrentUICulture.Name
@@ -302,9 +296,9 @@ function Select-Language([int]$ArrayIndex, [string]$LangName)
($SysLocale.StartsWith("tr") -and $LangName -like "*Turk*") -or `
($SysLocale.StartsWith("uk") -and $LangName -like "*Ukrain*") -or `
($SysLocale.StartsWith("vi") -and $LangName -like "*Vietnam*")) {
return $ArrayIndex
return $True
}
return -1
return $False
}
function Add-Entry([int]$pos, [string]$Name, [array]$Items, [string]$DisplayName)
@@ -434,9 +428,9 @@ function Error([string]$ErrorMessage)
#endregion
#region Form
[xml]$Form = @"
[xml]$XAML = @"
<Window xmlns = "http://schemas.microsoft.com/winfx/2006/xaml/presentation" Height = "162" Width = "384" ResizeMode = "NoResize">
<Grid Name = "Grid">
<Grid Name = "XMLGrid">
<Button Name = "Confirm" FontSize = "16" Height = "26" Width = "160" HorizontalAlignment = "Left" VerticalAlignment = "Top" Margin = "14,78,0,0"/>
<Button Name = "Back" FontSize = "16" Height = "26" Width = "160" HorizontalAlignment = "Left" VerticalAlignment = "Top" Margin = "194,78,0,0"/>
<TextBlock Name = "WindowsVersionTitle" FontSize = "16" Width="340" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="16,8,0,0"/>
@@ -461,9 +455,9 @@ $RequestData["GetLinks"] = @("cfa9e580-a81e-4a4b-a846-7b21bf4e2e5b", "GetProduct
#endregion
# Localization
$EnglishMessages = "en-US|Version|Release|Edition|Language|Architecture|Download|Confirm|Change|Close|Cancel|Error"
$EnglishMessages = "en-US|Version|Release|Edition|Language|Architecture|Download|Confirm|Back|Close|Error|Please wait..."
if ($Testing) {
$Messages = "fr-FR|||Édition|Langue de produit||Télécharger|Confirmer|Changer|Fermer|Abandonner|Erreur"
$LocData = "fr-FR|||Édition|Langue de produit||Télécharger|Confirmer|Retour|Fermer|Erreur|Veuillez patienter..."
$TestLangs = '{"languages":[
{ "language":"English", "text":"Anglais", "id":"100" },
{ "language":"English (International)", "text":"Anglais (International)", "id":"101" },
@@ -473,18 +467,18 @@ if ($Testing) {
}
[string[]]$English = $EnglishMessages.Split('|')
[string[]]$Localized = $null
if ($Messages) {
$Localized = $Messages.Split('|')
if ($LocData -and (-not $LocData.StartsWith("en-US"))) {
$Localized = $LocData.Split('|')
if ($Localized.Length -ne $English.Length) {
Write-Host Error: Missing or extra translated messages provided
Write-Host "Error: Missing or extra translated messages provided ($($Localized.Length)/$($English.Length))"
exit 1
}
$Locale = $Localized[0]
}
# Form creation
$XMLReader = New-Object System.Xml.XmlNodeReader $Form
$XMLForm = [Windows.Markup.XamlReader]::Load($XMLReader)
$XMLForm = [Windows.Markup.XamlReader]::Load((New-Object System.Xml.XmlNodeReader $XAML))
$XAML.SelectNodes("//*[@Name]") | ForEach-Object { Set-Variable -Name ($_.Name) -Value $XMLForm.FindName($_.Name) -Scope Script }
$XMLForm.Title = $AppTitle
if ($Icon) {
$XMLForm.Icon = $Icon
@@ -494,18 +488,12 @@ if ($Icon) {
if ($Locale.StartsWith("ar") -or $Locale.StartsWith("fa") -or $Locale.StartsWith("he")) {
$XMLForm.FlowDirection = "RightToLeft"
}
$XMLGrid = $XMLForm.FindName("Grid")
$Confirm = $XMLForm.FindName("Confirm")
$WindowsVersionTitle.Text = Get-Translation("Version")
$Confirm.Content = Get-Translation("Confirm")
$Back = $XMLForm.FindName("Back")
$Back.Content = Get-Translation("Change")
$Back.Content = Get-Translation("Back")
$Back.IsEnabled = $False
# Populate in the Windows Version dropdown
$WindowsVersionTitle = $XMLForm.FindName("WindowsVersionTitle")
$WindowsVersionTitle.Text = Get-Translation("Version")
$WindowsVersion = $XMLForm.FindName("WindowsVersion")
# Populate the Windows versions
$i = 0
$array = @()
foreach($Version in $WindowsVersions) {
@@ -531,7 +519,7 @@ $Confirm.add_click({
switch ($Stage) {
1 { # Windows Version selection => Get a Session ID and populate Windows Release
$XMLForm.Title = "Querying Microsoft download servers..."
$XMLForm.Title = Get-Translation("Please wait...")
Refresh-Control($XMLForm)
$url = "https://www.microsoft.com/" + $Locale + "/software-download/windows10ISO/"
@@ -572,9 +560,11 @@ $Confirm.add_click({
foreach ($Release in $WindowsVersions[$WindowsVersion.SelectedValue.Index][$WindowsRelease.SelectedValue.Index])
{
if ($Release -is [array]) {
if ($Expert -or ($Release[1] -ge 0)) {
$array += @(New-Object PsObject -Property @{ Edition = $Release[0]; Id = $Release[1] })
}
}
}
$script:ProductEdition = Add-Entry $Stage "Edition" $array
}
@@ -587,12 +577,13 @@ $Confirm.add_click({
$url += "&segments=software-download," + $PageType
$url += "&query=&action=" + $RequestData["GetLangs"][1]
$url += "&sessionId=" + $SessionId
$url += "&productEditionId=" + $ProductEdition.SelectedValue.Id
$url += "&productEditionId=" + [Math]::Abs($ProductEdition.SelectedValue.Id)
$url += "&sdVersion=2"
Write-Host Querying $url
$array = @()
$index = 0
$i = 0
$SelectedIndex = 0
if (-not $Testing) {
try {
$r = Invoke-WebRequest -WebSession $Session $url
@@ -603,11 +594,10 @@ $Confirm.add_click({
$json = $var.value | ConvertFrom-Json;
if ($json) {
$array += @(New-Object PsObject -Property @{ DisplayLanguage = $var.text; Language = $json.language; Id = $json.id })
$s = Select-Language -ArrayIndex $index -LangName $json.language
if ($s -ge 0) {
$Language.SelectedIndex = $s
if (Select-Language($json.language)) {
$SelectedIndex = $i
}
$index++
$i++
}
}
if ($array.Length -eq 0) {
@@ -624,14 +614,14 @@ $Confirm.add_click({
} else {
foreach ($var in $(ConvertFrom-Json InputObject $TestLangs).languages) {
$array += @(New-Object PsObject -Property @{ DisplayLanguage = $var.text; Language = $var.language; Id = $var.id })
$s = Select-Language -ArrayIndex $index -LangName $var.language
if ($s -ge 0) {
$Language.SelectedIndex = $s
if (Select-Language($var.language)) {
$SelectedIndex = $i
}
$index++
$i++
}
}
$script:Language = Add-Entry $Stage "Language" $array "DisplayLanguage"
$Language.SelectedIndex = $SelectedIndex
}
4 { # Language selection => Request and populate Arch download links
@@ -646,7 +636,8 @@ $Confirm.add_click({
$url += "&sdVersion=2"
Write-Host Querying $url
$index = 0
$i = 0
$SelectedIndex = 0
$array = @()
if (-not $Testing) {
try {
@@ -658,26 +649,26 @@ $Confirm.add_click({
if ($Type -like "*arm64*") {
$Type = "Arm64"
if ($ENV:PROCESSOR_ARCHITECTURE -eq "ARM64") {
$Arch.SelectedIndex = $index
$SelectedIndex = $i
}
} elseif ($Type -like "*arm*") {
$Type = "Arm"
if ($ENV:PROCESSOR_ARCHITECTURE -eq "ARM") {
$Arch.SelectedIndex = $index
$SelectedIndex = $i
}
} elseif ($Type -like "*x64*") {
$Type = "x64"
if ($ENV:PROCESSOR_ARCHITECTURE -eq "AMD64") {
$Arch.SelectedIndex = $index
$SelectedIndex = $i
}
} elseif ($Type -like "*x86*") {
$Type = "x86"
if ($ENV:PROCESSOR_ARCHITECTURE -eq "X86") {
$Arch.SelectedIndex = $index
$SelectedIndex = $i
}
}
$array += @(New-Object PsObject -Property @{ Type = $Type; Link = $Link })
$index++
$i++
}
if ($array.Length -eq 0) {
$ErrorMessage = $r.ParsedHtml.IHTMLDocument3_GetElementByID("errorModalMessage").innerHtml
@@ -692,14 +683,15 @@ $Confirm.add_click({
}
} else {
$array += @(New-Object PsObject -Property @{ Type = "x86"; Link = "https://rufus.ie" })
$index++
$i++
$array += @(New-Object PsObject -Property @{ Type = "x64"; Link = "https://rufus.ie" })
if ($ENV:PROCESSOR_ARCHITECTURE -eq "AMD64") {
$Arch.SelectedIndex = $index
$SelectedIndex = $i
}
}
$script:Arch = Add-Entry $Stage "Architecture" $array "Type"
$Arch.SelectedIndex = $SelectedIndex
$Confirm.Content = Get-Translation("Download")
}
@@ -745,7 +737,7 @@ $ClosePrompt = {
param($PromptTitle)
while ($True) {
Get-Process | Where-Object { $_.MainWindowTitle -match $PromptTitle } | ForEach-Object { $_.CloseMainWindow() }
Start-Sleep -Milliseconds 200
Start-Sleep -Milliseconds 100
}
}
# Get the localized version of the 'Windows Security Warning' title of the cookie prompt
@@ -756,7 +748,7 @@ if (-not $SecurityWarningTitle) {
$Job = Start-Job -ScriptBlock $ClosePrompt -ArgumentList $SecurityWarningTitle
# Display the dialog
$null = $XMLForm.ShowDialog()
$XMLForm.ShowDialog() | Out-Null
# Clean up & exit
Stop-Job -Job $Job