mirror of
https://github.com/pbatard/Fido.git
synced 2025-09-16 14:18:02 +02:00
Add change button and improve localization handling
This commit is contained in:
336
Fido.ps1
336
Fido.ps1
@@ -22,43 +22,33 @@
|
||||
|
||||
# TODO:
|
||||
# - Add a -NoHide param
|
||||
# - Add translations
|
||||
# - Sort Windows 7 downloads
|
||||
# - 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?
|
||||
|
||||
# Parameters
|
||||
#region Parameters
|
||||
param(
|
||||
# (Optional) Name of a pipe the download URL should be sent to.
|
||||
# If not provided, a browser window is opened instead.
|
||||
[string]$PipeName,
|
||||
# (Optional) Name of the perferred locale to use for the UI (e.g. "en-US", "fr-FR")
|
||||
# If not provided, the current Windows UI locale is used.
|
||||
[string]$Locale = [System.Globalization.CultureInfo]::CurrentUICulture.Name,
|
||||
# (Optional) '|' separated UI localization strings.
|
||||
[string]$Messages,
|
||||
# (Optional) Path to the file that should be used for the UI icon.
|
||||
[string]$Icon,
|
||||
# (Optional) The title to display on the application window
|
||||
[string]$AppTitle = "Fido - Windows Retail ISO Downloader"
|
||||
)
|
||||
#endregion
|
||||
|
||||
#region Testing
|
||||
$Debug = $False
|
||||
$Testing = $False
|
||||
if ($Testing) {
|
||||
$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" }
|
||||
]}'
|
||||
#endregion
|
||||
|
||||
Write-Host Please Wait...
|
||||
|
||||
# Custom Assembly Types
|
||||
#region Assembly Types
|
||||
$code = @"
|
||||
[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true, BestFitMapping = false, ThrowOnUnmappableChar = true)]
|
||||
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
|
||||
# Hide the powershell window: https://stackoverflow.com/a/27992426/1069307
|
||||
$null = [Gui.Utils]::ShowWindow(([System.Diagnostics.Process]::GetCurrentProcess() | Get-Process).MainWindowHandle, 0)
|
||||
#endregion
|
||||
|
||||
# Data
|
||||
#region Data
|
||||
# TODO: Fetch this as JSON data?
|
||||
$WindowsVersions = @(
|
||||
@(
|
||||
@@ -262,89 +253,61 @@ $WindowsVersions = @(
|
||||
)
|
||||
)
|
||||
)
|
||||
#endregion
|
||||
|
||||
# Translated messages. Empty string means same as English
|
||||
# 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
|
||||
#region Functions
|
||||
function Select-Language([int]$ArrayIndex, [string]$LangName)
|
||||
{
|
||||
if (($Locale.StartsWith("ar") -and $LangName -like "*Arabic*") -or `
|
||||
($Locale -eq "pt-BR" -and $LangName -like "*Brazil*") -or `
|
||||
($Locale.StartsWith("ar") -and $LangName -like "*Bulgar*") -or `
|
||||
($Locale -eq "zh-CN" -and $LangName -like "*Chinese*" -and $LangName -like "*simp*") -or `
|
||||
($Locale -eq "zh-TW" -and $LangName -like "*Chinese*" -and $LangName -like "*trad*") -or `
|
||||
($Locale.StartsWith("hr") -and $LangName -like "*Croat*") -or `
|
||||
($Locale.StartsWith("cz") -and $LangName -like "*Czech*") -or `
|
||||
($Locale.StartsWith("da") -and $LangName -like "*Danish*") -or `
|
||||
($Locale.StartsWith("nl") -and $LangName -like "*Dutch*") -or `
|
||||
($Locale -eq "en-US" -and $LangName -eq "English") -or `
|
||||
($Locale.StartsWith("en") -and $LangName -like "*English*" -and $LangName -like "*inter*") -or `
|
||||
($Locale.StartsWith("et") -and $LangName -like "*Eston*") -or `
|
||||
($Locale.StartsWith("fi") -and $LangName -like "*Finn*") -or `
|
||||
($Locale -eq "fr-CA" -and $LangName -like "*French*" -and $LangName -like "*Canad*") -or `
|
||||
($Locale.StartsWith("fr") -and $LangName -eq "French") -or `
|
||||
($Locale.StartsWith("de") -and $LangName -like "*German*") -or `
|
||||
($Locale.StartsWith("el") -and $LangName -like "*Greek*") -or `
|
||||
($Locale.StartsWith("he") -and $LangName -like "*Hebrew*") -or `
|
||||
($Locale.StartsWith("hu") -and $LangName -like "*Hungar*") -or `
|
||||
($Locale.StartsWith("id") -and $LangName -like "*Indones*") -or `
|
||||
($Locale.StartsWith("it") -and $LangName -like "*Italia*") -or `
|
||||
($Locale.StartsWith("ja") -and $LangName -like "*Japan*") -or `
|
||||
($Locale.StartsWith("ko") -and $LangName -like "*Korea*") -or `
|
||||
($Locale.StartsWith("lv") -and $LangName -like "*Latvia*") -or `
|
||||
($Locale.StartsWith("lt") -and $LangName -like "*Lithuania*") -or `
|
||||
($Locale.StartsWith("ms") -and $LangName -like "*Malay*") -or `
|
||||
($Locale.StartsWith("nb") -and $LangName -like "*Norw*") -or `
|
||||
($Locale.StartsWith("fa") -and $LangName -like "*Persia*") -or `
|
||||
($Locale.StartsWith("pl") -and $LangName -like "*Polish*") -or `
|
||||
($Locale -eq "pt-PT" -and $LangName -eq "Portuguese") -or `
|
||||
($Locale.StartsWith("ro") -and $LangName -like "*Romania*") -or `
|
||||
($Locale.StartsWith("ru") -and $LangName -like "*Russia*") -or `
|
||||
($Locale.StartsWith("sr") -and $LangName -like "*Serbia*") -or `
|
||||
($Locale.StartsWith("sk") -and $LangName -like "*Slovak*") -or `
|
||||
($Locale.StartsWith("sl") -and $LangName -like "*Slovenia*") -or `
|
||||
($Locale -eq "es-ES" -and $LangName -eq "Spanish") -or `
|
||||
($Locale.StartsWith("es") -and $Locale -ne "es-ES" -and $LangName -like "*Spanish*") -or `
|
||||
($Locale.StartsWith("sv") -and $LangName -like "*Swed*") -or `
|
||||
($Locale.StartsWith("th") -and $LangName -like "*Thai*") -or `
|
||||
($Locale.StartsWith("tr") -and $LangName -like "*Turk*") -or `
|
||||
($Locale.StartsWith("uk") -and $LangName -like "*Ukrain*") -or `
|
||||
($Locale.StartsWith("vi") -and $LangName -like "*Vietnam*")) {
|
||||
# Use the system locale to try select the most appropriate language
|
||||
[string]$SysLocale = [System.Globalization.CultureInfo]::CurrentUICulture.Name
|
||||
if (($SysLocale.StartsWith("ar") -and $LangName -like "*Arabic*") -or `
|
||||
($SysLocale -eq "pt-BR" -and $LangName -like "*Brazil*") -or `
|
||||
($SysLocale.StartsWith("ar") -and $LangName -like "*Bulgar*") -or `
|
||||
($SysLocale -eq "zh-CN" -and $LangName -like "*Chinese*" -and $LangName -like "*simp*") -or `
|
||||
($SysLocale -eq "zh-TW" -and $LangName -like "*Chinese*" -and $LangName -like "*trad*") -or `
|
||||
($SysLocale.StartsWith("hr") -and $LangName -like "*Croat*") -or `
|
||||
($SysLocale.StartsWith("cz") -and $LangName -like "*Czech*") -or `
|
||||
($SysLocale.StartsWith("da") -and $LangName -like "*Danish*") -or `
|
||||
($SysLocale.StartsWith("nl") -and $LangName -like "*Dutch*") -or `
|
||||
($SysLocale -eq "en-US" -and $LangName -eq "English") -or `
|
||||
($SysLocale.StartsWith("en") -and $LangName -like "*English*" -and $LangName -like "*inter*") -or `
|
||||
($SysLocale.StartsWith("et") -and $LangName -like "*Eston*") -or `
|
||||
($SysLocale.StartsWith("fi") -and $LangName -like "*Finn*") -or `
|
||||
($SysLocale -eq "fr-CA" -and $LangName -like "*French*" -and $LangName -like "*Canad*") -or `
|
||||
($SysLocale.StartsWith("fr") -and $LangName -eq "French") -or `
|
||||
($SysLocale.StartsWith("de") -and $LangName -like "*German*") -or `
|
||||
($SysLocale.StartsWith("el") -and $LangName -like "*Greek*") -or `
|
||||
($SysLocale.StartsWith("he") -and $LangName -like "*Hebrew*") -or `
|
||||
($SysLocale.StartsWith("hu") -and $LangName -like "*Hungar*") -or `
|
||||
($SysLocale.StartsWith("id") -and $LangName -like "*Indones*") -or `
|
||||
($SysLocale.StartsWith("it") -and $LangName -like "*Italia*") -or `
|
||||
($SysLocale.StartsWith("ja") -and $LangName -like "*Japan*") -or `
|
||||
($SysLocale.StartsWith("ko") -and $LangName -like "*Korea*") -or `
|
||||
($SysLocale.StartsWith("lv") -and $LangName -like "*Latvia*") -or `
|
||||
($SysLocale.StartsWith("lt") -and $LangName -like "*Lithuania*") -or `
|
||||
($SysLocale.StartsWith("ms") -and $LangName -like "*Malay*") -or `
|
||||
($SysLocale.StartsWith("nb") -and $LangName -like "*Norw*") -or `
|
||||
($SysLocale.StartsWith("fa") -and $LangName -like "*Persia*") -or `
|
||||
($SysLocale.StartsWith("pl") -and $LangName -like "*Polish*") -or `
|
||||
($SysLocale -eq "pt-PT" -and $LangName -eq "Portuguese") -or `
|
||||
($SysLocale.StartsWith("ro") -and $LangName -like "*Romania*") -or `
|
||||
($SysLocale.StartsWith("ru") -and $LangName -like "*Russia*") -or `
|
||||
($SysLocale.StartsWith("sr") -and $LangName -like "*Serbia*") -or `
|
||||
($SysLocale.StartsWith("sk") -and $LangName -like "*Slovak*") -or `
|
||||
($SysLocale.StartsWith("sl") -and $LangName -like "*Slovenia*") -or `
|
||||
($SysLocale -eq "es-ES" -and $LangName -eq "Spanish") -or `
|
||||
($SysLocale.StartsWith("es") -and $Locale -ne "es-ES" -and $LangName -like "*Spanish*") -or `
|
||||
($SysLocale.StartsWith("sv") -and $LangName -like "*Swed*") -or `
|
||||
($SysLocale.StartsWith("th") -and $LangName -like "*Thai*") -or `
|
||||
($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 -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.FontSize = $WindowsVersionTitle.FontSize
|
||||
@@ -353,14 +316,11 @@ function Add-Title([string]$Name)
|
||||
$Title.HorizontalAlignment = "Left"
|
||||
$Title.VerticalAlignment = "Top"
|
||||
$Margin = $WindowsVersionTitle.Margin
|
||||
$Margin.Top += $script:Stage * $script:dh
|
||||
$Margin.Top += $pos * $dh
|
||||
$Title.Margin = $Margin
|
||||
$Title.Text = $Name
|
||||
return $Title
|
||||
}
|
||||
$Title.Text = Get-Translation($Name)
|
||||
$XMLGrid.Children.Insert(2 * $Stage + 2, $Title)
|
||||
|
||||
function Add-Combo
|
||||
{
|
||||
$Combo = New-Object System.Windows.Controls.ComboBox
|
||||
$Combo.FontSize = $WindowsVersion.FontSize
|
||||
$Combo.Height = $WindowsVersion.Height;
|
||||
@@ -368,9 +328,27 @@ function Add-Combo
|
||||
$Combo.HorizontalAlignment = "Left"
|
||||
$Combo.VerticalAlignment = "Top"
|
||||
$Margin = $WindowsVersion.Margin
|
||||
$Margin.Top += $script:Stage * $script:dh
|
||||
$Margin.Top += $pos * $script:dh
|
||||
$Combo.Margin = $Margin
|
||||
$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
|
||||
}
|
||||
|
||||
@@ -420,17 +398,20 @@ function ConvertTo-ImageSource
|
||||
# Translate a message string
|
||||
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"
|
||||
return "(Untranslated)"
|
||||
}
|
||||
foreach($Translation in $Translations) {
|
||||
if ($Translation[0].StartsWith($ShortLocale)) {
|
||||
for ($i = 1; $i -lt $Translation.Length; $i++) {
|
||||
if ($Translations[0][$i] -eq $Text) {
|
||||
if ($Translation[$i]) {
|
||||
return $Translation[$i]
|
||||
}
|
||||
if ($Localized) {
|
||||
if ($Localized.Length -ne $English.Length) {
|
||||
Write-Host "Error: '$Text' is not a translatable string"
|
||||
}
|
||||
for ($i = 0; $i -lt $English.Length; $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
|
||||
$Confirm.IsEnabled = $True
|
||||
}
|
||||
#endregion
|
||||
|
||||
# XAML Form
|
||||
#region 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">
|
||||
<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"/>
|
||||
<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>
|
||||
</Window>
|
||||
"@
|
||||
#endregion
|
||||
|
||||
# Globals
|
||||
#region Globals
|
||||
$dh = 58;
|
||||
$Stage = 0
|
||||
$MaxStage = 4
|
||||
$SessionId = ""
|
||||
$ExitCode = 0
|
||||
$PageType = "windows10ISO"
|
||||
$Locale = "en-US"
|
||||
|
||||
$RequestData = @{}
|
||||
$RequestData["GetLangs"] = @("a8f8f489-4c7f-463a-9ca6-5cff94d8d041", "GetSkuInformationByProductEdition" )
|
||||
$RequestData["GetLinks"] = @("cfa9e580-a81e-4a4b-a846-7b21bf4e2e5b", "GetProductDownloadLinksBySku" )
|
||||
#endregion
|
||||
|
||||
# Locale handling
|
||||
if (-not $Locale) {
|
||||
$Locale = "en-US"
|
||||
# Localization
|
||||
$EnglishMessages = "en-US|Version|Release|Edition|Language|Architecture|Download|Confirm|Change|Close|Cancel|Error"
|
||||
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
|
||||
if (-not $Locale.StartsWith("zh") -and -not $Locale.StartsWith("pt")) {
|
||||
$ShortLocale = $Locale.Substring(0, 2)
|
||||
}
|
||||
if ($Debug) {
|
||||
Write-Host Using locale "$Locale"
|
||||
[string[]]$English = $EnglishMessages.Split('|')
|
||||
[string[]]$Localized = $null
|
||||
if ($Messages) {
|
||||
$Localized = $Messages.Split('|')
|
||||
if ($Localized.Length -ne $English.Length) {
|
||||
Write-Host Error: Missing or extra translated messages provided
|
||||
exit 1
|
||||
}
|
||||
$Locale = $Localized[0]
|
||||
}
|
||||
|
||||
# Form creation
|
||||
@@ -501,13 +497,17 @@ if ($Locale.StartsWith("ar") -or $Locale.StartsWith("fa") -or $Locale.StartsWit
|
||||
$XMLGrid = $XMLForm.FindName("Grid")
|
||||
$Confirm = $XMLForm.FindName("Confirm")
|
||||
$Confirm.Content = Get-Translation("Confirm")
|
||||
$Back = $XMLForm.FindName("Back")
|
||||
$Back.Content = Get-Translation("Change")
|
||||
$Back.IsEnabled = $False
|
||||
|
||||
# Populate in the Windows Version dropdown
|
||||
$WindowsVersionTitle = $XMLForm.FindName("WindowsVersionTitle")
|
||||
$WindowsVersionTitle.Text = Get-Translation("Version")
|
||||
$WindowsVersion = $XMLForm.FindName("WindowsVersion")
|
||||
$array = @()
|
||||
|
||||
$i = 0
|
||||
$array = @()
|
||||
foreach($Version in $WindowsVersions) {
|
||||
$array += @(New-Object PsObject -Property @{ Version = $Version[0]; Index = $i })
|
||||
$i++
|
||||
@@ -522,14 +522,17 @@ $Confirm.add_click({
|
||||
return
|
||||
}
|
||||
|
||||
$XMLGrid.Children[2 * $Stage + 1].IsEnabled = $False
|
||||
$Confirm.IsEnabled = $False
|
||||
$Back.IsEnabled = $False
|
||||
Refresh-Control($Confirm)
|
||||
Refresh-Control($Back)
|
||||
|
||||
switch ($Stage) {
|
||||
|
||||
1 { # Windows Version selection => Get a Session ID and populate Windows Release
|
||||
$XMLForm.Title = "Querying Microsoft download servers..."
|
||||
Refresh-Control($XMLForm)
|
||||
$WindowsVersion.IsEnabled = $False;
|
||||
$Confirm.IsEnabled = $False
|
||||
Refresh-Control($Confirm)
|
||||
|
||||
$url = "https://www.microsoft.com/" + $Locale + "/software-download/windows10ISO/"
|
||||
Write-Host Querying $url
|
||||
@@ -550,8 +553,6 @@ $Confirm.add_click({
|
||||
return
|
||||
}
|
||||
}
|
||||
$script:WindowsReleaseTitle = Add-Title(Get-Translation("Release"))
|
||||
$script:WindowsRelease = Add-Combo
|
||||
|
||||
$i = 0
|
||||
$array = @()
|
||||
@@ -561,20 +562,12 @@ $Confirm.add_click({
|
||||
}
|
||||
$i++
|
||||
}
|
||||
$WindowsRelease.ItemsSource = $array
|
||||
$WindowsRelease.DisplayMemberPath = "Release"
|
||||
|
||||
$XMLGrid.AddChild($WindowsReleaseTitle)
|
||||
$XMLGrid.AddChild($WindowsRelease)
|
||||
$script:WindowsRelease = Add-Entry $Stage "Release" $array
|
||||
$XMLForm.Title = $AppTitle
|
||||
$Confirm.IsEnabled = $True
|
||||
}
|
||||
|
||||
2 { # Windows Release selection => Populate Product Edition
|
||||
$WindowsRelease.IsEnabled = $False
|
||||
$ProductEditionTitle = Add-Title(Get-Translation("Edition"))
|
||||
$script:ProductEdition = Add-Combo
|
||||
|
||||
$array = @()
|
||||
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] })
|
||||
}
|
||||
}
|
||||
$ProductEdition.ItemsSource = $array
|
||||
$ProductEdition.DisplayMemberPath = "Edition"
|
||||
|
||||
$XMLGrid.AddChild($ProductEditionTitle)
|
||||
$XMLGrid.AddChild($ProductEdition)
|
||||
$script:ProductEdition = Add-Entry $Stage "Edition" $array
|
||||
}
|
||||
|
||||
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
|
||||
$url = "https://www.microsoft.com/" + $Locale + "/api/controls/contentinclude/html"
|
||||
@@ -612,14 +596,12 @@ $Confirm.add_click({
|
||||
if (-not $Testing) {
|
||||
try {
|
||||
$r = Invoke-WebRequest -WebSession $Session $url
|
||||
Write-Host $r.ParsedHtml.body.innerHTML
|
||||
foreach ($var in $r.ParsedHtml.IHTMLDocument3_GetElementByID("product-languages")) {
|
||||
if ($Debug) {
|
||||
Write-Host $var.value $var.text
|
||||
}
|
||||
$json = $var.value | ConvertFrom-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 })
|
||||
$s = Select-Language -ArrayIndex $index -LangName $json.language
|
||||
if ($s -ge 0) {
|
||||
@@ -649,24 +631,10 @@ $Confirm.add_click({
|
||||
$index++
|
||||
}
|
||||
}
|
||||
$Language.ItemsSource = $array
|
||||
$Language.DisplayMemberPath = "DisplayLanguage"
|
||||
$XMLGrid.AddChild($LanguageTitle)
|
||||
$XMLGrid.AddChild($Language)
|
||||
$Confirm.IsEnabled = $True
|
||||
$script:Language = Add-Entry $Stage "Language" $array "DisplayLanguage"
|
||||
}
|
||||
|
||||
# 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
|
||||
$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 += "?pageId=" + $RequestData["GetLinks"][0]
|
||||
$url += "&host=www.microsoft.com"
|
||||
@@ -683,7 +651,6 @@ $Confirm.add_click({
|
||||
if (-not $Testing) {
|
||||
try {
|
||||
$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" }) {
|
||||
$Link = $var.ParentNode | Select -Expand href
|
||||
$Type = $var.innerText
|
||||
@@ -731,17 +698,12 @@ $Confirm.add_click({
|
||||
$Arch.SelectedIndex = $index
|
||||
}
|
||||
}
|
||||
$Arch.ItemsSource = $array
|
||||
$Arch.DisplayMemberPath = "Type"
|
||||
$XMLGrid.AddChild($ArchTitle)
|
||||
$XMLGrid.AddChild($Arch)
|
||||
|
||||
$script:Arch = Add-Entry $Stage "Architecture" $array "Type"
|
||||
$Confirm.Content = Get-Translation("Download")
|
||||
$Confirm.IsEnabled = $True
|
||||
}
|
||||
|
||||
5 { # Arch selection => Return selected download link
|
||||
$Arch.IsEnabled = $False
|
||||
$Confirm.Content = Get-Translation("Close")
|
||||
$script:Stage = -1
|
||||
if ($PipeName) {
|
||||
Send-Message -PipeName $PipeName -Message $Arch.SelectedValue.Link
|
||||
@@ -749,18 +711,36 @@ $Confirm.add_click({
|
||||
Write-Host Download Link: $Arch.SelectedValue.Link
|
||||
Start-Process -FilePath $Arch.SelectedValue.Link
|
||||
}
|
||||
$Confirm.Content = Get-Translation("Close")
|
||||
}
|
||||
}
|
||||
|
||||
if ($Stage -gt 0) {
|
||||
$XMLForm.Height += $dh;
|
||||
$Margin = $Confirm.Margin
|
||||
$Margin.Top += $dh
|
||||
$Confirm.Margin = $Margin
|
||||
$Confirm.IsEnabled = $True
|
||||
if ($Stage -ge 0) {
|
||||
$Back.IsEnabled = $True;
|
||||
}
|
||||
})
|
||||
|
||||
# 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 = {
|
||||
param($PromptTitle)
|
||||
while ($True) {
|
||||
|
Reference in New Issue
Block a user