Add change button and improve localization handling

This commit is contained in:
Pete Batard
2019-02-19 12:21:11 +01:00
parent 39ea6dacf9
commit 3e56db88fa

336
Fido.ps1
View File

@@ -22,43 +22,33 @@
# TODO: # TODO:
# - Add a -NoHide param # - Add a -NoHide param
# - Add translations
# - Sort Windows 7 downloads
# - Display all arch links? # - Display all arch links?
# - Icon does not display in taskbar when shell window is reduced # - Icon does not display in taskbar when shell window is reduced
# - Validate that download links are from Microsoft servers # - Validate that download links are from Microsoft servers
# - Add Expert mode for Home China and suff? # - Add Expert mode for Home China and suff?
# Parameters #region Parameters
param( param(
# (Optional) Name of a pipe the download URL should be sent to. # (Optional) Name of a pipe the download URL should be sent to.
# If not provided, a browser window is opened instead. # If not provided, a browser window is opened instead.
[string]$PipeName, [string]$PipeName,
# (Optional) Name of the perferred locale to use for the UI (e.g. "en-US", "fr-FR") # (Optional) '|' separated UI localization strings.
# If not provided, the current Windows UI locale is used. [string]$Messages,
[string]$Locale = [System.Globalization.CultureInfo]::CurrentUICulture.Name,
# (Optional) Path to the file that should be used for the UI icon. # (Optional) Path to the file that should be used for the UI icon.
[string]$Icon, [string]$Icon,
# (Optional) The title to display on the application window # (Optional) The title to display on the application window
[string]$AppTitle = "Fido - Windows Retail ISO Downloader" [string]$AppTitle = "Fido - Windows Retail ISO Downloader"
) )
#endregion
#region Testing
$Debug = $False $Debug = $False
$Testing = $False $Testing = $False
if ($Testing) { #endregion
$Locale = "fr-CA"
}
$TestLangs = '{"languages":[
{ "language":"English", "text":"Anglais", "id":"100" },
{ "language":"English (International)", "text":"Anglais (International)", "id":"101" },
{ "language":"French", "text":"Français", "id":"102" },
{ "language":"French (Canadian)", "text":"Français (Canadien)", "id":"103" }
]}'
Write-Host Please Wait... Write-Host Please Wait...
# Custom Assembly Types #region Assembly Types
$code = @" $code = @"
[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true, BestFitMapping = false, ThrowOnUnmappableChar = true)] [DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true, BestFitMapping = false, ThrowOnUnmappableChar = true)]
internal static extern IntPtr LoadLibrary(string lpLibFileName); internal static extern IntPtr LoadLibrary(string lpLibFileName);
@@ -101,8 +91,9 @@ Add-Type -MemberDefinition $code -Namespace Gui -UsingNamespace "System.IO", "Sy
Add-Type -AssemblyName PresentationFramework Add-Type -AssemblyName PresentationFramework
# Hide the powershell window: https://stackoverflow.com/a/27992426/1069307 # Hide the powershell window: https://stackoverflow.com/a/27992426/1069307
$null = [Gui.Utils]::ShowWindow(([System.Diagnostics.Process]::GetCurrentProcess() | Get-Process).MainWindowHandle, 0) $null = [Gui.Utils]::ShowWindow(([System.Diagnostics.Process]::GetCurrentProcess() | Get-Process).MainWindowHandle, 0)
#endregion
# Data #region Data
# TODO: Fetch this as JSON data? # TODO: Fetch this as JSON data?
$WindowsVersions = @( $WindowsVersions = @(
@( @(
@@ -262,89 +253,61 @@ $WindowsVersions = @(
) )
) )
) )
#endregion
# Translated messages. Empty string means same as English #region Functions
# TODO: Fetch this as JSON data?
$Translations = @(
@(
"en-US"
"Version"
"Release"
"Edition"
"Language"
"Arch"
"Download"
"Confirm"
"Close"
"Cancel"
"Error"
),
@(
"fr-FR"
""
""
"Édition"
"Langue de produit"
""
"Télécharger"
"Confirmer"
"Fermer"
"Abandonner"
"Erreur"
)
)
# Functions
function Select-Language([int]$ArrayIndex, [string]$LangName) function Select-Language([int]$ArrayIndex, [string]$LangName)
{ {
if (($Locale.StartsWith("ar") -and $LangName -like "*Arabic*") -or ` # Use the system locale to try select the most appropriate language
($Locale -eq "pt-BR" -and $LangName -like "*Brazil*") -or ` [string]$SysLocale = [System.Globalization.CultureInfo]::CurrentUICulture.Name
($Locale.StartsWith("ar") -and $LangName -like "*Bulgar*") -or ` if (($SysLocale.StartsWith("ar") -and $LangName -like "*Arabic*") -or `
($Locale -eq "zh-CN" -and $LangName -like "*Chinese*" -and $LangName -like "*simp*") -or ` ($SysLocale -eq "pt-BR" -and $LangName -like "*Brazil*") -or `
($Locale -eq "zh-TW" -and $LangName -like "*Chinese*" -and $LangName -like "*trad*") -or ` ($SysLocale.StartsWith("ar") -and $LangName -like "*Bulgar*") -or `
($Locale.StartsWith("hr") -and $LangName -like "*Croat*") -or ` ($SysLocale -eq "zh-CN" -and $LangName -like "*Chinese*" -and $LangName -like "*simp*") -or `
($Locale.StartsWith("cz") -and $LangName -like "*Czech*") -or ` ($SysLocale -eq "zh-TW" -and $LangName -like "*Chinese*" -and $LangName -like "*trad*") -or `
($Locale.StartsWith("da") -and $LangName -like "*Danish*") -or ` ($SysLocale.StartsWith("hr") -and $LangName -like "*Croat*") -or `
($Locale.StartsWith("nl") -and $LangName -like "*Dutch*") -or ` ($SysLocale.StartsWith("cz") -and $LangName -like "*Czech*") -or `
($Locale -eq "en-US" -and $LangName -eq "English") -or ` ($SysLocale.StartsWith("da") -and $LangName -like "*Danish*") -or `
($Locale.StartsWith("en") -and $LangName -like "*English*" -and $LangName -like "*inter*") -or ` ($SysLocale.StartsWith("nl") -and $LangName -like "*Dutch*") -or `
($Locale.StartsWith("et") -and $LangName -like "*Eston*") -or ` ($SysLocale -eq "en-US" -and $LangName -eq "English") -or `
($Locale.StartsWith("fi") -and $LangName -like "*Finn*") -or ` ($SysLocale.StartsWith("en") -and $LangName -like "*English*" -and $LangName -like "*inter*") -or `
($Locale -eq "fr-CA" -and $LangName -like "*French*" -and $LangName -like "*Canad*") -or ` ($SysLocale.StartsWith("et") -and $LangName -like "*Eston*") -or `
($Locale.StartsWith("fr") -and $LangName -eq "French") -or ` ($SysLocale.StartsWith("fi") -and $LangName -like "*Finn*") -or `
($Locale.StartsWith("de") -and $LangName -like "*German*") -or ` ($SysLocale -eq "fr-CA" -and $LangName -like "*French*" -and $LangName -like "*Canad*") -or `
($Locale.StartsWith("el") -and $LangName -like "*Greek*") -or ` ($SysLocale.StartsWith("fr") -and $LangName -eq "French") -or `
($Locale.StartsWith("he") -and $LangName -like "*Hebrew*") -or ` ($SysLocale.StartsWith("de") -and $LangName -like "*German*") -or `
($Locale.StartsWith("hu") -and $LangName -like "*Hungar*") -or ` ($SysLocale.StartsWith("el") -and $LangName -like "*Greek*") -or `
($Locale.StartsWith("id") -and $LangName -like "*Indones*") -or ` ($SysLocale.StartsWith("he") -and $LangName -like "*Hebrew*") -or `
($Locale.StartsWith("it") -and $LangName -like "*Italia*") -or ` ($SysLocale.StartsWith("hu") -and $LangName -like "*Hungar*") -or `
($Locale.StartsWith("ja") -and $LangName -like "*Japan*") -or ` ($SysLocale.StartsWith("id") -and $LangName -like "*Indones*") -or `
($Locale.StartsWith("ko") -and $LangName -like "*Korea*") -or ` ($SysLocale.StartsWith("it") -and $LangName -like "*Italia*") -or `
($Locale.StartsWith("lv") -and $LangName -like "*Latvia*") -or ` ($SysLocale.StartsWith("ja") -and $LangName -like "*Japan*") -or `
($Locale.StartsWith("lt") -and $LangName -like "*Lithuania*") -or ` ($SysLocale.StartsWith("ko") -and $LangName -like "*Korea*") -or `
($Locale.StartsWith("ms") -and $LangName -like "*Malay*") -or ` ($SysLocale.StartsWith("lv") -and $LangName -like "*Latvia*") -or `
($Locale.StartsWith("nb") -and $LangName -like "*Norw*") -or ` ($SysLocale.StartsWith("lt") -and $LangName -like "*Lithuania*") -or `
($Locale.StartsWith("fa") -and $LangName -like "*Persia*") -or ` ($SysLocale.StartsWith("ms") -and $LangName -like "*Malay*") -or `
($Locale.StartsWith("pl") -and $LangName -like "*Polish*") -or ` ($SysLocale.StartsWith("nb") -and $LangName -like "*Norw*") -or `
($Locale -eq "pt-PT" -and $LangName -eq "Portuguese") -or ` ($SysLocale.StartsWith("fa") -and $LangName -like "*Persia*") -or `
($Locale.StartsWith("ro") -and $LangName -like "*Romania*") -or ` ($SysLocale.StartsWith("pl") -and $LangName -like "*Polish*") -or `
($Locale.StartsWith("ru") -and $LangName -like "*Russia*") -or ` ($SysLocale -eq "pt-PT" -and $LangName -eq "Portuguese") -or `
($Locale.StartsWith("sr") -and $LangName -like "*Serbia*") -or ` ($SysLocale.StartsWith("ro") -and $LangName -like "*Romania*") -or `
($Locale.StartsWith("sk") -and $LangName -like "*Slovak*") -or ` ($SysLocale.StartsWith("ru") -and $LangName -like "*Russia*") -or `
($Locale.StartsWith("sl") -and $LangName -like "*Slovenia*") -or ` ($SysLocale.StartsWith("sr") -and $LangName -like "*Serbia*") -or `
($Locale -eq "es-ES" -and $LangName -eq "Spanish") -or ` ($SysLocale.StartsWith("sk") -and $LangName -like "*Slovak*") -or `
($Locale.StartsWith("es") -and $Locale -ne "es-ES" -and $LangName -like "*Spanish*") -or ` ($SysLocale.StartsWith("sl") -and $LangName -like "*Slovenia*") -or `
($Locale.StartsWith("sv") -and $LangName -like "*Swed*") -or ` ($SysLocale -eq "es-ES" -and $LangName -eq "Spanish") -or `
($Locale.StartsWith("th") -and $LangName -like "*Thai*") -or ` ($SysLocale.StartsWith("es") -and $Locale -ne "es-ES" -and $LangName -like "*Spanish*") -or `
($Locale.StartsWith("tr") -and $LangName -like "*Turk*") -or ` ($SysLocale.StartsWith("sv") -and $LangName -like "*Swed*") -or `
($Locale.StartsWith("uk") -and $LangName -like "*Ukrain*") -or ` ($SysLocale.StartsWith("th") -and $LangName -like "*Thai*") -or `
($Locale.StartsWith("vi") -and $LangName -like "*Vietnam*")) { ($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 $ArrayIndex
} }
return -1 return -1
} }
function Add-Title([string]$Name) function Add-Entry([int]$pos, [string]$Name, [array]$Items, [string]$DisplayName)
{ {
$Title = New-Object System.Windows.Controls.TextBlock $Title = New-Object System.Windows.Controls.TextBlock
$Title.FontSize = $WindowsVersionTitle.FontSize $Title.FontSize = $WindowsVersionTitle.FontSize
@@ -353,14 +316,11 @@ function Add-Title([string]$Name)
$Title.HorizontalAlignment = "Left" $Title.HorizontalAlignment = "Left"
$Title.VerticalAlignment = "Top" $Title.VerticalAlignment = "Top"
$Margin = $WindowsVersionTitle.Margin $Margin = $WindowsVersionTitle.Margin
$Margin.Top += $script:Stage * $script:dh $Margin.Top += $pos * $dh
$Title.Margin = $Margin $Title.Margin = $Margin
$Title.Text = $Name $Title.Text = Get-Translation($Name)
return $Title $XMLGrid.Children.Insert(2 * $Stage + 2, $Title)
}
function Add-Combo
{
$Combo = New-Object System.Windows.Controls.ComboBox $Combo = New-Object System.Windows.Controls.ComboBox
$Combo.FontSize = $WindowsVersion.FontSize $Combo.FontSize = $WindowsVersion.FontSize
$Combo.Height = $WindowsVersion.Height; $Combo.Height = $WindowsVersion.Height;
@@ -368,9 +328,27 @@ function Add-Combo
$Combo.HorizontalAlignment = "Left" $Combo.HorizontalAlignment = "Left"
$Combo.VerticalAlignment = "Top" $Combo.VerticalAlignment = "Top"
$Margin = $WindowsVersion.Margin $Margin = $WindowsVersion.Margin
$Margin.Top += $script:Stage * $script:dh $Margin.Top += $pos * $script:dh
$Combo.Margin = $Margin $Combo.Margin = $Margin
$Combo.SelectedIndex = 0 $Combo.SelectedIndex = 0
if ($Items) {
$Combo.ItemsSource = $Items
if ($DisplayName) {
$Combo.DisplayMemberPath = $DisplayName
} else {
$Combo.DisplayMemberPath = $Name
}
}
$XMLGrid.Children.Insert(2 * $Stage + 3, $Combo)
$XMLForm.Height += $dh;
$Margin = $Confirm.Margin
$Margin.Top += $dh
$Confirm.Margin = $Margin
$Margin = $Back.Margin
$Margin.Top += $dh
$Back.Margin = $Margin
return $Combo return $Combo
} }
@@ -420,17 +398,20 @@ function ConvertTo-ImageSource
# Translate a message string # Translate a message string
function Get-Translation([string]$Text) function Get-Translation([string]$Text)
{ {
if (-not $Translations[0].Contains($Text)) { if (-not $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)"
} }
foreach($Translation in $Translations) { if ($Localized) {
if ($Translation[0].StartsWith($ShortLocale)) { if ($Localized.Length -ne $English.Length) {
for ($i = 1; $i -lt $Translation.Length; $i++) { Write-Host "Error: '$Text' is not a translatable string"
if ($Translations[0][$i] -eq $Text) { }
if ($Translation[$i]) { for ($i = 0; $i -lt $English.Length; $i++) {
return $Translation[$i] if ($English[$i] -eq $Text) {
} if ($Localized[$i]) {
return $Localized[$i]
} else {
return $Text
} }
} }
} }
@@ -450,40 +431,55 @@ function Error([string]$ErrorMessage)
$script:Stage = -1 $script:Stage = -1
$Confirm.IsEnabled = $True $Confirm.IsEnabled = $True
} }
#endregion
# XAML Form #region Form
[xml]$Form = @" [xml]$Form = @"
<Window xmlns = "http://schemas.microsoft.com/winfx/2006/xaml/presentation" Height = "162" Width = "380" ResizeMode = "NoResize"> <Window xmlns = "http://schemas.microsoft.com/winfx/2006/xaml/presentation" Height = "162" Width = "384" ResizeMode = "NoResize">
<Grid Name = "Grid"> <Grid Name = "Grid">
<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"/> <TextBlock Name = "WindowsVersionTitle" FontSize = "16" Width="340" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="16,8,0,0"/>
<ComboBox Name = "WindowsVersion" FontSize = "14" Height = "24" Width = "340" HorizontalAlignment = "Left" VerticalAlignment="Top" Margin = "14,34,0,0" SelectedIndex = "0"/> <ComboBox Name = "WindowsVersion" FontSize = "14" Height = "24" Width = "340" HorizontalAlignment = "Left" VerticalAlignment="Top" Margin = "14,34,0,0" SelectedIndex = "0"/>
<Button Name = "Confirm" FontSize = "16" Height = "26" Width = "160" HorizontalAlignment = "Left" VerticalAlignment = "Top" Margin = "14,78,0,0"/>
</Grid> </Grid>
</Window> </Window>
"@ "@
#endregion
# Globals #region Globals
$dh = 58; $dh = 58;
$Stage = 0 $Stage = 0
$MaxStage = 4 $MaxStage = 4
$SessionId = "" $SessionId = ""
$ExitCode = 0 $ExitCode = 0
$PageType = "windows10ISO" $PageType = "windows10ISO"
$Locale = "en-US"
$RequestData = @{} $RequestData = @{}
$RequestData["GetLangs"] = @("a8f8f489-4c7f-463a-9ca6-5cff94d8d041", "GetSkuInformationByProductEdition" ) $RequestData["GetLangs"] = @("a8f8f489-4c7f-463a-9ca6-5cff94d8d041", "GetSkuInformationByProductEdition" )
$RequestData["GetLinks"] = @("cfa9e580-a81e-4a4b-a846-7b21bf4e2e5b", "GetProductDownloadLinksBySku" ) $RequestData["GetLinks"] = @("cfa9e580-a81e-4a4b-a846-7b21bf4e2e5b", "GetProductDownloadLinksBySku" )
#endregion
# Locale handling # Localization
if (-not $Locale) { $EnglishMessages = "en-US|Version|Release|Edition|Language|Architecture|Download|Confirm|Change|Close|Cancel|Error"
$Locale = "en-US" if ($Testing) {
$Messages = "fr-FR|||Édition|Langue de produit||Télécharger|Confirmer|Changer|Fermer|Abandonner|Erreur"
$TestLangs = '{"languages":[
{ "language":"English", "text":"Anglais", "id":"100" },
{ "language":"English (International)", "text":"Anglais (International)", "id":"101" },
{ "language":"French", "text":"Français", "id":"102" },
{ "language":"French (Canadian)", "text":"Français (Canadien)", "id":"103" }
]}'
} }
$ShortLocale = $Locale [string[]]$English = $EnglishMessages.Split('|')
if (-not $Locale.StartsWith("zh") -and -not $Locale.StartsWith("pt")) { [string[]]$Localized = $null
$ShortLocale = $Locale.Substring(0, 2) if ($Messages) {
} $Localized = $Messages.Split('|')
if ($Debug) { if ($Localized.Length -ne $English.Length) {
Write-Host Using locale "$Locale" Write-Host Error: Missing or extra translated messages provided
exit 1
}
$Locale = $Localized[0]
} }
# Form creation # Form creation
@@ -501,13 +497,17 @@ if ($Locale.StartsWith("ar") -or $Locale.StartsWith("fa") -or $Locale.StartsWit
$XMLGrid = $XMLForm.FindName("Grid") $XMLGrid = $XMLForm.FindName("Grid")
$Confirm = $XMLForm.FindName("Confirm") $Confirm = $XMLForm.FindName("Confirm")
$Confirm.Content = Get-Translation("Confirm") $Confirm.Content = Get-Translation("Confirm")
$Back = $XMLForm.FindName("Back")
$Back.Content = Get-Translation("Change")
$Back.IsEnabled = $False
# Populate in the Windows Version dropdown # Populate in the Windows Version dropdown
$WindowsVersionTitle = $XMLForm.FindName("WindowsVersionTitle") $WindowsVersionTitle = $XMLForm.FindName("WindowsVersionTitle")
$WindowsVersionTitle.Text = Get-Translation("Version") $WindowsVersionTitle.Text = Get-Translation("Version")
$WindowsVersion = $XMLForm.FindName("WindowsVersion") $WindowsVersion = $XMLForm.FindName("WindowsVersion")
$array = @()
$i = 0 $i = 0
$array = @()
foreach($Version in $WindowsVersions) { foreach($Version in $WindowsVersions) {
$array += @(New-Object PsObject -Property @{ Version = $Version[0]; Index = $i }) $array += @(New-Object PsObject -Property @{ Version = $Version[0]; Index = $i })
$i++ $i++
@@ -522,14 +522,17 @@ $Confirm.add_click({
return return
} }
$XMLGrid.Children[2 * $Stage + 1].IsEnabled = $False
$Confirm.IsEnabled = $False
$Back.IsEnabled = $False
Refresh-Control($Confirm)
Refresh-Control($Back)
switch ($Stage) { switch ($Stage) {
1 { # Windows Version selection => Get a Session ID and populate Windows Release 1 { # Windows Version selection => Get a Session ID and populate Windows Release
$XMLForm.Title = "Querying Microsoft download servers..." $XMLForm.Title = "Querying Microsoft download servers..."
Refresh-Control($XMLForm) Refresh-Control($XMLForm)
$WindowsVersion.IsEnabled = $False;
$Confirm.IsEnabled = $False
Refresh-Control($Confirm)
$url = "https://www.microsoft.com/" + $Locale + "/software-download/windows10ISO/" $url = "https://www.microsoft.com/" + $Locale + "/software-download/windows10ISO/"
Write-Host Querying $url Write-Host Querying $url
@@ -550,8 +553,6 @@ $Confirm.add_click({
return return
} }
} }
$script:WindowsReleaseTitle = Add-Title(Get-Translation("Release"))
$script:WindowsRelease = Add-Combo
$i = 0 $i = 0
$array = @() $array = @()
@@ -561,20 +562,12 @@ $Confirm.add_click({
} }
$i++ $i++
} }
$WindowsRelease.ItemsSource = $array
$WindowsRelease.DisplayMemberPath = "Release"
$XMLGrid.AddChild($WindowsReleaseTitle) $script:WindowsRelease = Add-Entry $Stage "Release" $array
$XMLGrid.AddChild($WindowsRelease)
$XMLForm.Title = $AppTitle $XMLForm.Title = $AppTitle
$Confirm.IsEnabled = $True
} }
2 { # Windows Release selection => Populate Product Edition 2 { # Windows Release selection => Populate Product Edition
$WindowsRelease.IsEnabled = $False
$ProductEditionTitle = Add-Title(Get-Translation("Edition"))
$script:ProductEdition = Add-Combo
$array = @() $array = @()
foreach ($Release in $WindowsVersions[$WindowsVersion.SelectedValue.Index][$WindowsRelease.SelectedValue.Index]) foreach ($Release in $WindowsVersions[$WindowsVersion.SelectedValue.Index][$WindowsRelease.SelectedValue.Index])
{ {
@@ -582,19 +575,10 @@ $Confirm.add_click({
$array += @(New-Object PsObject -Property @{ Edition = $Release[0]; Id = $Release[1] }) $array += @(New-Object PsObject -Property @{ Edition = $Release[0]; Id = $Release[1] })
} }
} }
$ProductEdition.ItemsSource = $array $script:ProductEdition = Add-Entry $Stage "Edition" $array
$ProductEdition.DisplayMemberPath = "Edition"
$XMLGrid.AddChild($ProductEditionTitle)
$XMLGrid.AddChild($ProductEdition)
} }
3 { # Product Edition selection => Request and populate Languages 3 { # Product Edition selection => Request and populate Languages
$ProductEdition.IsEnabled = $False
$Confirm.IsEnabled = $False
$Confirm.Dispatcher.Invoke("Render", [Windows.Input.InputEventHandler] { $Confirm.UpdateLayout() }, $null, $null)
$LanguageTitle = Add-Title(Get-Translation("Language"))
$script:Language = Add-Combo
# Get the Product Edition # Get the Product Edition
$url = "https://www.microsoft.com/" + $Locale + "/api/controls/contentinclude/html" $url = "https://www.microsoft.com/" + $Locale + "/api/controls/contentinclude/html"
@@ -612,14 +596,12 @@ $Confirm.add_click({
if (-not $Testing) { if (-not $Testing) {
try { try {
$r = Invoke-WebRequest -WebSession $Session $url $r = Invoke-WebRequest -WebSession $Session $url
Write-Host $r.ParsedHtml.body.innerHTML
foreach ($var in $r.ParsedHtml.IHTMLDocument3_GetElementByID("product-languages")) { foreach ($var in $r.ParsedHtml.IHTMLDocument3_GetElementByID("product-languages")) {
if ($Debug) { if ($Debug) {
Write-Host $var.value $var.text Write-Host $var.value $var.text
} }
$json = $var.value | ConvertFrom-Json; $json = $var.value | ConvertFrom-Json;
if ($json) { if ($json) {
Write-Host $var.text $json.language; $json.id
$array += @(New-Object PsObject -Property @{ DisplayLanguage = $var.text; Language = $json.language; Id = $json.id }) $array += @(New-Object PsObject -Property @{ DisplayLanguage = $var.text; Language = $json.language; Id = $json.id })
$s = Select-Language -ArrayIndex $index -LangName $json.language $s = Select-Language -ArrayIndex $index -LangName $json.language
if ($s -ge 0) { if ($s -ge 0) {
@@ -649,24 +631,10 @@ $Confirm.add_click({
$index++ $index++
} }
} }
$Language.ItemsSource = $array $script:Language = Add-Entry $Stage "Language" $array "DisplayLanguage"
$Language.DisplayMemberPath = "DisplayLanguage"
$XMLGrid.AddChild($LanguageTitle)
$XMLGrid.AddChild($Language)
$Confirm.IsEnabled = $True
} }
# https://www.microsoft.com/en-us/api/controls/contentinclude/html?pageId=160bb813-f54e-4e9f-bffc-38c6eb56e061&host=www.microsoft.com&segments=software-download%2cwindows10&query=&action=GetProductDownloadLinkForFriendlyFileName&friendlyFileName=
# https://www.microsoft.com/en-us/api/controls/contentinclude/html?pageId=cfa9e580-a81e-4a4b-a846-7b21bf4e2e5b&host=www.microsoft.com&segments=software-download,windows10ISO&query=&action=GetProductDownloadLinksBySku&skuId=
4 { # Language selection => Request and populate Arch download links 4 { # Language selection => Request and populate Arch download links
$Language.IsEnabled = $False
$Confirm.IsEnabled = $False
$Confirm.Dispatcher.Invoke("Render", [Windows.Input.InputEventHandler] { $Confirm.UpdateLayout() }, $null, $null)
$ArchTitle = Add-Title("Architecture")
$script:Arch = Add-Combo
$url = "https://www.microsoft.com/" + $Locale + "/api/controls/contentinclude/html" $url = "https://www.microsoft.com/" + $Locale + "/api/controls/contentinclude/html"
$url += "?pageId=" + $RequestData["GetLinks"][0] $url += "?pageId=" + $RequestData["GetLinks"][0]
$url += "&host=www.microsoft.com" $url += "&host=www.microsoft.com"
@@ -683,7 +651,6 @@ $Confirm.add_click({
if (-not $Testing) { if (-not $Testing) {
try { try {
$r = Invoke-WebRequest -WebSession $Session $url $r = Invoke-WebRequest -WebSession $Session $url
Write-Host $r.ParsedHtml.body.innerText
foreach ($var in $r.ParsedHtml.IHTMLDocument3_GetElementsByTagName("span") | Where-Object { $_.className -eq "product-download-type" }) { foreach ($var in $r.ParsedHtml.IHTMLDocument3_GetElementsByTagName("span") | Where-Object { $_.className -eq "product-download-type" }) {
$Link = $var.ParentNode | Select -Expand href $Link = $var.ParentNode | Select -Expand href
$Type = $var.innerText $Type = $var.innerText
@@ -731,17 +698,12 @@ $Confirm.add_click({
$Arch.SelectedIndex = $index $Arch.SelectedIndex = $index
} }
} }
$Arch.ItemsSource = $array
$Arch.DisplayMemberPath = "Type" $script:Arch = Add-Entry $Stage "Architecture" $array "Type"
$XMLGrid.AddChild($ArchTitle)
$XMLGrid.AddChild($Arch)
$Confirm.Content = Get-Translation("Download") $Confirm.Content = Get-Translation("Download")
$Confirm.IsEnabled = $True
} }
5 { # Arch selection => Return selected download link 5 { # Arch selection => Return selected download link
$Arch.IsEnabled = $False
$Confirm.Content = Get-Translation("Close")
$script:Stage = -1 $script:Stage = -1
if ($PipeName) { if ($PipeName) {
Send-Message -PipeName $PipeName -Message $Arch.SelectedValue.Link Send-Message -PipeName $PipeName -Message $Arch.SelectedValue.Link
@@ -749,18 +711,36 @@ $Confirm.add_click({
Write-Host Download Link: $Arch.SelectedValue.Link Write-Host Download Link: $Arch.SelectedValue.Link
Start-Process -FilePath $Arch.SelectedValue.Link Start-Process -FilePath $Arch.SelectedValue.Link
} }
$Confirm.Content = Get-Translation("Close")
} }
} }
$Confirm.IsEnabled = $True
if ($Stage -gt 0) { if ($Stage -ge 0) {
$XMLForm.Height += $dh; $Back.IsEnabled = $True;
$Margin = $Confirm.Margin
$Margin.Top += $dh
$Confirm.Margin = $Margin
} }
}) })
# We need a job in the background to close the obnoxious Windows "Do you want to accept this cookie" alerts $Back.add_click({
$XMLGrid.Children.RemoveAt(2 * $Stage + 3)
$XMLGrid.Children.RemoveAt(2 * $Stage + 2)
$XMLGrid.Children[2 * $Stage + 1].IsEnabled = $True
$XMLForm.Height -= $dh;
$Margin = $Confirm.Margin
$Margin.Top -= $dh
$Confirm.Margin = $Margin
$Margin = $Back.Margin
$Margin.Top -= $dh
$Back.Margin = $Margin
$script:Stage = $Stage - 1
if ($Stage -eq 0) {
$Back.IsEnabled = $False
}
if ($Stage -eq 3) {
$Confirm.Content = Get-Translation("Confirm")
}
})
# We need a job in the background to close the obnoxious "Do you want to accept this cookie?" Windows alerts
$ClosePrompt = { $ClosePrompt = {
param($PromptTitle) param($PromptTitle)
while ($True) { while ($True) {