From 878b93889f16537a177dd29e68a65c631250f286 Mon Sep 17 00:00:00 2001 From: rbalsleyMSFT <53497092+rbalsleyMSFT@users.noreply.github.com> Date: Wed, 9 Jul 2025 13:26:09 -0700 Subject: [PATCH] Refactors ISO path handling for clarity and robustness Inverts the conditional logic for determining available Windows releases and versions based on whether an ISO path is provided. This change improves code readability by checking for the positive case (an ISO is present) first. It also adds validation to ensure the file path ends with the `.iso` extension. --- .../FFUUI.Core.WindowsSettings.psm1 | 44 ++++++++++--------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/FFUDevelopment/FFUUI.Core/FFUUI.Core.WindowsSettings.psm1 b/FFUDevelopment/FFUUI.Core/FFUUI.Core.WindowsSettings.psm1 index dbcd8ae..1c5144d 100644 --- a/FFUDevelopment/FFUUI.Core/FFUUI.Core.WindowsSettings.psm1 +++ b/FFUDevelopment/FFUUI.Core/FFUUI.Core.WindowsSettings.psm1 @@ -230,11 +230,11 @@ function Get-AvailableWindowsReleases { [psobject]$State ) - if ([string]::IsNullOrEmpty($IsoPath)) { - return $State.Defaults.WindowsSettingsDefaults.MctWindowsReleases + if (-not [string]::IsNullOrEmpty($IsoPath) -and $IsoPath.EndsWith('.iso', [System.StringComparison]::OrdinalIgnoreCase)) { + return $State.Defaults.WindowsSettingsDefaults.AllWindowsReleases } else { - return $State.Defaults.WindowsSettingsDefaults.AllWindowsReleases + return $State.Defaults.WindowsSettingsDefaults.MctWindowsReleases } } @@ -257,27 +257,12 @@ function Get-AvailableWindowsVersions { } if (-not $State.Defaults.WindowsSettingsDefaults.WindowsVersionMap.ContainsKey($SelectedRelease)) { - return $result + return $result } $validVersions = $State.Defaults.WindowsSettingsDefaults.WindowsVersionMap[$SelectedRelease] - if ([string]::IsNullOrEmpty($IsoPath)) { - # Logic for when no ISO is specified (MCT scenario) - switch ($SelectedRelease) { - 10 { $result.DefaultVersion = "22H2" } - 11 { $result.DefaultVersion = "24H2" } - # Server versions typically require an ISO, but handle just in case - 2016 { $result.DefaultVersion = "1607" } - 2019 { $result.DefaultVersion = "1809" } - 2022 { $result.DefaultVersion = "21H2" } - 2025 { $result.DefaultVersion = "24H2" } - default { $result.DefaultVersion = $validVersions[0] } - } - $result.Versions = @($result.DefaultVersion) # Only the default is available/relevant - $result.IsEnabled = $false # Combo should be disabled - } - else { + if (-not [string]::IsNullOrEmpty($IsoPath) -and $IsoPath.EndsWith('.iso', [System.StringComparison]::OrdinalIgnoreCase)) { # Logic for when an ISO is specified $result.Versions = $validVersions # Set default selection logic (e.g., latest for Win11) @@ -287,7 +272,24 @@ function Get-AvailableWindowsVersions { elseif ($validVersions.Count -gt 0) { $result.DefaultVersion = $validVersions[0] } - $result.IsEnabled = $true + $result.IsEnabled = $true + } + else { + # Logic for when no ISO is specified (MCT scenario) + switch ($SelectedRelease) { + 10 { $result.DefaultVersion = "22H2" } + 11 { $result.DefaultVersion = "24H2" } + # Server versions typically require an ISO, but handle just in case + 2016 { $result.DefaultVersion = "1607" } + 2019 { $result.DefaultVersion = "1809" } + 2022 { $result.DefaultVersion = "21H2" } + 2025 { $result.DefaultVersion = "24H2" } + default { + if ($validVersions.Count -gt 0) { $result.DefaultVersion = $validVersions[0] } + } + } + $result.Versions = @($result.DefaultVersion) # Only the default is available/relevant + $result.IsEnabled = $false # Combo should be disabled } return $result