fix: skip features that the running Windows build does not support (#832)

This commit is contained in:
HetCreep
2026-10-18 22:23:18 +02:00
committed by GitHub
parent 94dd603da4
commit 73834839ff
13 changed files with 240 additions and 5 deletions
+15
View File
@@ -363,6 +363,21 @@ function Invoke-AllChanges {
}
$undoIds = @($script:UndoParams.Keys)
# Features passed as switches are not filtered by the GUI or the config import, so skip the ones this Windows build does not support
$currentBuild = Get-CurrentWindowsBuild
$unsupportedIds = @($applyIds | Where-Object { -not (Test-FeatureSupportedOnBuild -Feature $script:Features[$_] -Build $currentBuild) })
foreach ($id in $unsupportedIds) {
$feature = $script:Features[$id]
$range = @()
if ($feature.MinVersion) { $range += "build $($feature.MinVersion) or newer" }
if ($feature.MaxVersion) { $range += "build $($feature.MaxVersion) or older" }
Write-Warning "Skipping ${id}: it is only supported on Windows $($range -join ' and '), this system runs build $currentBuild."
# Also drop it from the parameters, so that later steps (such as the reboot advice) only see what was applied
[void]$script:Params.Remove($id)
}
$applyIds = @($applyIds | Where-Object { $unsupportedIds -notcontains $_ })
# ---- Determine if registry backup is needed ----
$needsBackup = $false
foreach ($id in $applyIds) {
+1 -1
View File
@@ -28,7 +28,7 @@ function Import-Settings {
if (-not $feature) { continue }
# Check version and feature compatibility using Features.json
if (($feature.MinVersion -and $WinVersion -lt $feature.MinVersion) -or ($feature.MaxVersion -and $WinVersion -gt $feature.MaxVersion) -or ($feature.FeatureId -eq 'DisableModernStandbyNetworking' -and (-not $script:ModernStandbySupported))) {
if (-not (Test-FeatureSupportedOnBuild -Feature $feature -Build $WinVersion) -or ($feature.FeatureId -eq 'DisableModernStandbyNetworking' -and (-not $script:ModernStandbySupported))) {
continue
}
+2 -2
View File
@@ -418,7 +418,7 @@ function New-DynamicTweakControls {
if ($feature.Category -ne $categoryName) { $featureIndex++; continue }
# Check version and feature compatibility using Features.json
if (($feature.MinVersion -and $WinVersion -lt $feature.MinVersion) -or ($feature.MaxVersion -and $WinVersion -gt $feature.MaxVersion) -or ($feature.FeatureId -eq 'DisableModernStandbyNetworking' -and (-not $script:ModernStandbySupported))) {
if (-not (Test-FeatureSupportedOnBuild -Feature $feature -Build $WinVersion) -or ($feature.FeatureId -eq 'DisableModernStandbyNetworking' -and (-not $script:ModernStandbySupported))) {
$featureIndex++; continue
}
@@ -451,7 +451,7 @@ function New-DynamicTweakControls {
foreach ($fid in $_.FeatureIds) {
if ($featureMap.ContainsKey($fid)) {
$f = $featureMap[$fid]
if (($f.MinVersion -and $WinVersion -lt $f.MinVersion) -or ($f.MaxVersion -and $WinVersion -gt $f.MaxVersion)) {
if (-not (Test-FeatureSupportedOnBuild -Feature $f -Build $WinVersion)) {
$allCompatible = $false
break
}
+1 -1
View File
@@ -114,7 +114,7 @@ function Import-ConfigToParams {
continue
}
if (($feature.MinVersion -and $CurrentBuild -lt $feature.MinVersion) -or ($feature.MaxVersion -and $CurrentBuild -gt $feature.MaxVersion) -or ($feature.FeatureId -eq 'DisableModernStandbyNetworking' -and (-not $script:ModernStandbySupported))) {
if (-not (Test-FeatureSupportedOnBuild -Feature $feature -Build $CurrentBuild) -or ($feature.FeatureId -eq 'DisableModernStandbyNetworking' -and (-not $script:ModernStandbySupported))) {
continue
}
+28
View File
@@ -0,0 +1,28 @@
# Returns the build number of the running Windows version, or $null when it cannot be read.
function Get-CurrentWindowsBuild {
$build = 0
try {
# Get-ItemPropertyValue reports a missing value as a terminating error, which -ErrorAction SilentlyContinue does not suppress
$currentBuild = Get-ItemPropertyValue 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion' CurrentBuild -ErrorAction Stop
}
catch {
Write-Verbose "Unable to read the Windows build number: $($_.Exception.Message)"
return $null
}
if ([int]::TryParse([string]$currentBuild, [ref]$build)) { return $build }
return $null
}
# Checks a feature's MinVersion / MaxVersion (Windows build numbers from Features.json) against a build number.
# A feature without limits, or a build that is not known, is treated as supported.
function Test-FeatureSupportedOnBuild {
param(
$Feature,
$Build
)
if ($null -eq $Feature -or $null -eq $Build) { return $true }
if ($Feature.MinVersion -and [int]$Build -lt [int]$Feature.MinVersion) { return $false }
if ($Feature.MaxVersion -and [int]$Build -gt [int]$Feature.MaxVersion) { return $false }
return $true
}