# # Fido v1.59 - Feature ISO Downloader, for retail Windows images and UEFI Shell # Copyright © 2019-2024 Pete Batard # Command line support: Copyright © 2021 flx5 # ConvertTo-ImageSource: Copyright © 2016 Chris Carter # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . # # NB: You must have a BOM on your .ps1 if you want Powershell to actually # realise it should use Unicode for the UI rather than ISO-8859-1. #region Parameters param( # (Optional) The title to display on the application window. [string]$AppTitle = "Fido - Feature ISO Downloader", # (Optional) '|' separated UI localization strings. [string]$LocData, # (Optional) Forced locale [string]$Locale = "en-US", # (Optional) Path to a file that should be used for the UI icon. [string]$Icon, # (Optional) Name of a pipe the download URL should be sent to. # If not provided, a browser window is opened instead. [string]$PipeName, # (Optional) Specify Windows version (e.g. "Windows 10") [Toggles commandline mode] [string]$Win, # (Optional) Specify Windows release (e.g. "21H1") [Toggles commandline mode] [string]$Rel, # (Optional) Specify Windows edition (e.g. "Pro") [Toggles commandline mode] [string]$Ed, # (Optional) Specify Windows language [Toggles commandline mode] [string]$Lang, # (Optional) Specify Windows architecture [Toggles commandline mode] [string]$Arch, # (Optional) Only display the download URL [Toggles commandline mode] [switch]$GetUrl = $false, # (Optional) Increase verbosity [switch]$Verbose = $false ) #endregion try { [Console]::OutputEncoding = [System.Text.Encoding]::UTF8 } catch {} $Cmd = $false if ($Win -or $Rel -or $Ed -or $Lang -or $Arch -or $GetUrl) { $Cmd = $true } # Return a decimal Windows version that we can then check for platform support. # Note that because we don't want to have to support this script on anything # other than Windows, this call returns 0.0 for PowerShell running on Linux/Mac. function Get-Platform-Version() { $version = 0.0 $platform = [string][System.Environment]::OSVersion.Platform # This will filter out non Windows platforms if ($platform.StartsWith("Win")) { # Craft a decimal numeric version of Windows $version = [System.Environment]::OSVersion.Version.Major * 1.0 + [System.Environment]::OSVersion.Version.Minor * 0.1 } return $version } $winver = Get-Platform-Version # The default TLS for Windows 8.x doesn't work with Microsoft's servers so we must force it if ($winver -lt 10.0) { [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls -bor [Net.SecurityProtocolType]::Tls11 -bor [Net.SecurityProtocolType]::Tls12 } #region Assembly Types $Drawing_Assembly = "System.Drawing" # PowerShell 7 altered the name of the Drawing assembly... if ($host.version -ge "7.0") { $Drawing_Assembly += ".Common" } $Signature = @{ Namespace = "WinAPI" Name = "Utils" Language = "CSharp" UsingNamespace = "System.Runtime", "System.IO", "System.Text", "System.Drawing", "System.Globalization" ReferencedAssemblies = $Drawing_Assembly ErrorAction = "Stop" WarningAction = "Ignore" IgnoreWarnings = $true MemberDefinition = @" [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(IntPtr handle, int state); // Extract an icon from a DLL public static Icon ExtractIcon(string file, int number, bool largeIcon) { IntPtr large, small; ExtractIconEx(file, number, out large, out small, 1); try { return Icon.FromHandle(largeIcon ? large : small); } catch { return null; } } "@ } if (!$Cmd) { Write-Host Please Wait... if (!("WinAPI.Utils" -as [type])) { Add-Type @Signature } Add-Type -AssemblyName PresentationFramework # Hide the powershell window: https://stackoverflow.com/a/27992426/1069307 [WinAPI.Utils]::ShowWindow(([System.Diagnostics.Process]::GetCurrentProcess() | Get-Process).MainWindowHandle, 0) | Out-Null } #endregion #region Data $zh = 0x10000 $ko = 0x20000 $WindowsVersions = @( @( @("Windows 11", "windows11"), @( "24H2 (Build 26100.1742 - 2024.10)", @("Windows 11 Home/Pro/Edu", 3113), @("Windows 11 Home China ", ($zh + 3115)) @("Windows 11 Pro China ", ($zh + 3114)) ), @( "23H2 v2 (Build 22631.2861 - 2023.12)", @("Windows 11 Home/Pro/Edu", 2935), @("Windows 11 Home China ", ($zh + 2936)) ) ), @( @("Windows 10", "Windows10ISO"), @( "22H2 v1 (Build 19045.2965 - 2023.05)", @("Windows 10 Home/Pro/Edu", 2618), @("Windows 10 Home China ", ($zh + 2378)) ) ) @( @("UEFI Shell 2.2", "UEFI_SHELL 2.2"), @( "24H1 (edk2-stable202405)", @("Release", 0), @("Debug", 1) ), @( "23H2 (edk2-stable202311)", @("Release", 0), @("Debug", 1) ), @( "23H1 (edk2-stable202305)", @("Release", 0), @("Debug", 1) ), @( "22H2 (edk2-stable202211)", @("Release", 0), @("Debug", 1) ), @( "22H1 (edk2-stable202205)", @("Release", 0), @("Debug", 1) ), @( "21H2 (edk2-stable202108)", @("Release", 0), @("Debug", 1) ), @( "21H1 (edk2-stable202105)", @("Release", 0), @("Debug", 1) ), @( "20H2 (edk2-stable202011)", @("Release", 0), @("Debug", 1) ) ), @( @("UEFI Shell 2.0", "UEFI_SHELL 2.0"), @( "4.632 [20100426]", @("Release", 0) ) ) ) #endregion #region Functions function Select-Language([string]$LangName) { # 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 $LangName -like "*ingdom*")) -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 $true } return $false } function Add-Entry([int]$pos, [string]$Name, [array]$Items, [string]$DisplayName) { $Title = New-Object System.Windows.Controls.TextBlock $Title.FontSize = $WindowsVersionTitle.FontSize $Title.Height = $WindowsVersionTitle.Height; $Title.Width = $WindowsVersionTitle.Width; $Title.HorizontalAlignment = "Left" $Title.VerticalAlignment = "Top" $Margin = $WindowsVersionTitle.Margin $Margin.Top += $pos * $dh $Title.Margin = $Margin $Title.Text = Get-Translation($Name) $XMLGrid.Children.Insert(2 * $Stage + 2, $Title) $Combo = New-Object System.Windows.Controls.ComboBox $Combo.FontSize = $WindowsVersion.FontSize $Combo.Height = $WindowsVersion.Height; $Combo.Width = $WindowsVersion.Width; $Combo.HorizontalAlignment = "Left" $Combo.VerticalAlignment = "Top" $Margin = $WindowsVersion.Margin $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 = $Continue.Margin $Margin.Top += $dh $Continue.Margin = $Margin $Margin = $Back.Margin $Margin.Top += $dh $Back.Margin = $Margin return $Combo } function Refresh-Control([object]$Control) { $Control.Dispatcher.Invoke("Render", [Windows.Input.InputEventHandler] { $Continue.UpdateLayout() }, $null, $null) | Out-Null } function Send-Message([string]$PipeName, [string]$Message) { [System.Text.Encoding]$Encoding = [System.Text.Encoding]::UTF8 $Pipe = New-Object -TypeName System.IO.Pipes.NamedPipeClientStream -ArgumentList ".", $PipeName, ([System.IO.Pipes.PipeDirection]::Out), ([System.IO.Pipes.PipeOptions]::None), ([System.Security.Principal.TokenImpersonationLevel]::Impersonation) try { $Pipe.Connect(1000) } catch { Write-Host $_.Exception.Message } $bRequest = $Encoding.GetBytes($Message) $cbRequest = $bRequest.Length; $Pipe.Write($bRequest, 0, $cbRequest); $Pipe.Dispose() } # From https://www.powershellgallery.com/packages/IconForGUI/1.5.2 # Copyright © 2016 Chris Carter. All rights reserved. # License: https://creativecommons.org/licenses/by-sa/4.0/ function ConvertTo-ImageSource { [CmdletBinding()] Param( [Parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true)] [System.Drawing.Icon]$Icon ) Process { foreach ($i in $Icon) { [System.Windows.Interop.Imaging]::CreateBitmapSourceFromHIcon( $i.Handle, (New-Object System.Windows.Int32Rect -Args 0,0,$i.Width, $i.Height), [System.Windows.Media.Imaging.BitmapSizeOptions]::FromEmptyOptions() ) } } } function Throw-Error([object]$Req, [string]$Alt) { $Err = $(GetElementById -Request $Req -Id "errorModalMessage").innerText -replace "<[^>]+>" -replace "\s+", " " if (!$Err) { $Err = $Alt } else { $Err = [System.Text.Encoding]::UTF8.GetString([byte[]][char[]]$Err) } throw $Err } # Translate a message string function Get-Translation([string]$Text) { if (!($English -contains $Text)) { Write-Host "Error: '$Text' is not a translatable string" return "(Untranslated)" } 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 } } } } return $Text } # Some PowerShells don't have Microsoft.mshtml assembly (comes with MS Office?) # so we can't use ParsedHtml or IHTMLDocument[2|3] features there... function GetElementById([object]$Request, [string]$Id) { try { return $Request.ParsedHtml.IHTMLDocument3_GetElementByID($Id) } catch { return $Request.AllElements | ? {$_.id -eq $Id} } } function Error([string]$ErrorMessage) { Write-Host Error: $ErrorMessage if (!$Cmd) { $XMLForm.Title = $(Get-Translation("Error")) + ": " + $ErrorMessage Refresh-Control($XMLForm) $XMLGrid.Children[2 * $script:Stage + 1].IsEnabled = $true $UserInput = [System.Windows.MessageBox]::Show($XMLForm.Title, $(Get-Translation("Error")), "OK", "Error") $script:ExitCode = $script:Stage-- } else { $script:ExitCode = 2 } } function Get-RandomDate() { [DateTime]$Min = "1/1/2008" [DateTime]$Max = [DateTime]::Now $RandomGen = new-object random $RandomTicks = [Convert]::ToInt64( ($Max.ticks * 1.0 - $Min.Ticks * 1.0 ) * $RandomGen.NextDouble() + $Min.Ticks * 1.0 ) $Date = new-object DateTime($RandomTicks) return $Date.ToString("yyyyMMdd") } #endregion #region Form [xml]$XAML = @"