mirror of
https://github.com/Raphire/Win11Debloat.git
synced 2026-07-02 22:58:34 +00:00
Guard against loading, saving & executing undefined features (#665)
This commit is contained in:
@@ -1,29 +1,8 @@
|
||||
# MainWindow-Deployment.ps1
|
||||
# Overview generation, pending tweak actions, feature labels, tweak preset maps, apply logic, user mode state, user selection, and validation.
|
||||
|
||||
function Get-FeatureLabel {
|
||||
param(
|
||||
[string]$FeatureId,
|
||||
$FallbackLabel = $null
|
||||
)
|
||||
|
||||
$label = $script:FeatureLabelLookup[$FeatureId]
|
||||
if (-not [string]::IsNullOrWhiteSpace([string]$label)) {
|
||||
return [string]$label
|
||||
}
|
||||
|
||||
if (-not [string]::IsNullOrWhiteSpace([string]$FallbackLabel)) {
|
||||
return [string]$FallbackLabel
|
||||
}
|
||||
|
||||
return [string]$FeatureId
|
||||
}
|
||||
|
||||
function Get-UndoFeatureLabel {
|
||||
param(
|
||||
[string]$FeatureId,
|
||||
$FallbackLabel = $null
|
||||
)
|
||||
param([string]$FeatureId)
|
||||
|
||||
$undoLabel = $script:UndoFeatureLabelLookup[$FeatureId]
|
||||
if (-not [string]::IsNullOrWhiteSpace([string]$undoLabel)) {
|
||||
@@ -31,8 +10,7 @@ function Get-UndoFeatureLabel {
|
||||
}
|
||||
|
||||
# Fall back to the regular label (prefixed for undo context)
|
||||
$label = Get-FeatureLabel -FeatureId $FeatureId -FallbackLabel $FallbackLabel
|
||||
return [string]$label
|
||||
return [string]$script:FeatureLabelLookup[$FeatureId]
|
||||
}
|
||||
|
||||
function Get-PendingTweakActions {
|
||||
@@ -69,14 +47,14 @@ function Get-PendingTweakActions {
|
||||
$actions.Add([PSCustomObject]@{
|
||||
Action = 'Apply'
|
||||
FeatureId = [string]$mapping.FeatureId
|
||||
Label = (Get-FeatureLabel -FeatureId $mapping.FeatureId -FallbackLabel $mapping.Label)
|
||||
Label = [string]$script:FeatureLabelLookup[$mapping.FeatureId]
|
||||
})
|
||||
}
|
||||
elseif ($wasApplied -and -not $isNowChecked) {
|
||||
$actions.Add([PSCustomObject]@{
|
||||
Action = 'Undo'
|
||||
FeatureId = [string]$mapping.FeatureId
|
||||
Label = (Get-FeatureLabel -FeatureId $mapping.FeatureId -FallbackLabel $mapping.Label)
|
||||
Label = [string]$script:FeatureLabelLookup[$mapping.FeatureId]
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -101,7 +79,7 @@ function Get-PendingTweakActions {
|
||||
$actions.Add([PSCustomObject]@{
|
||||
Action = 'Apply'
|
||||
FeatureId = [string]$fid
|
||||
Label = (Get-FeatureLabel -FeatureId $fid)
|
||||
Label = [string]$script:FeatureLabelLookup[$fid]
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,11 @@
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Creates a lightweight state object for the restore-backup dialog result.
|
||||
|
||||
.DESCRIPTION
|
||||
Encapsulates the user's dialog choice (Result), the selected backup file
|
||||
path, and the parsed backup payload so callers receive a single object.
|
||||
#>
|
||||
function New-RestoreDialogState {
|
||||
param(
|
||||
[string]$Result = 'Cancel',
|
||||
@@ -8,6 +16,16 @@ function New-RestoreDialogState {
|
||||
return @{ Result = $Result; SelectedFile = $SelectedFile; Backup = $Backup }
|
||||
}
|
||||
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Looks up a feature definition by ID from the provided feature catalog.
|
||||
|
||||
.PARAMETER FeatureId
|
||||
The identifier to search for (e.g. 'DisableTelemetry').
|
||||
|
||||
.PARAMETER Features
|
||||
A hashtable loaded from Features.json (FeatureId -> feature object).
|
||||
#>
|
||||
function Get-RestoreDialogFeatureDefinition {
|
||||
param(
|
||||
[string]$FeatureId,
|
||||
@@ -25,6 +43,21 @@ function Get-RestoreDialogFeatureDefinition {
|
||||
return $null
|
||||
}
|
||||
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Determines whether a feature can be automatically reverted via registry restore.
|
||||
|
||||
.DESCRIPTION
|
||||
Returns $true when the feature has a non-empty RegistryKey, indicating
|
||||
an apply .reg file exists that can be undone automatically. Features
|
||||
with custom logic (no RegistryKey) must be manually reverted.
|
||||
|
||||
.PARAMETER FeatureId
|
||||
The feature identifier to check.
|
||||
|
||||
.PARAMETER Features
|
||||
A hashtable loaded from Features.json.
|
||||
#>
|
||||
function Test-RestoreDialogFeatureCanAutoRevert {
|
||||
param(
|
||||
[string]$FeatureId,
|
||||
@@ -43,6 +76,20 @@ function Test-RestoreDialogFeatureCanAutoRevert {
|
||||
return $false
|
||||
}
|
||||
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Resolves a human-readable label for a feature shown in the restore dialog.
|
||||
|
||||
.DESCRIPTION
|
||||
Returns the feature's Label from Features.json when found, falling back
|
||||
to the raw FeatureId string. For null/empty FeatureIds returns 'Unknown feature'.
|
||||
|
||||
.PARAMETER FeatureId
|
||||
The feature identifier to resolve a label for.
|
||||
|
||||
.PARAMETER Features
|
||||
A hashtable loaded from Features.json.
|
||||
#>
|
||||
function Get-RestoreDialogFeatureDisplayLabel {
|
||||
param(
|
||||
[string]$FeatureId,
|
||||
@@ -54,13 +101,28 @@ function Get-RestoreDialogFeatureDisplayLabel {
|
||||
}
|
||||
|
||||
$featureDefinition = Get-RestoreDialogFeatureDefinition -FeatureId $FeatureId -Features $Features
|
||||
if ($featureDefinition -and -not [string]::IsNullOrWhiteSpace([string]$featureDefinition.Label)) {
|
||||
if ($featureDefinition) {
|
||||
return [string]$featureDefinition.Label
|
||||
}
|
||||
|
||||
return $FeatureId
|
||||
}
|
||||
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Checks whether a feature should appear in the restore dialog's overview list.
|
||||
|
||||
.DESCRIPTION
|
||||
A feature is considered visible when it exists in the catalog and has
|
||||
a non-empty Category (meaning it belongs to a UI grouping). Features
|
||||
without a Category are hidden from the overview.
|
||||
|
||||
.PARAMETER FeatureId
|
||||
The feature identifier to check.
|
||||
|
||||
.PARAMETER Features
|
||||
A hashtable loaded from Features.json.
|
||||
#>
|
||||
function Test-RestoreDialogFeatureVisibleInOverview {
|
||||
param(
|
||||
[string]$FeatureId,
|
||||
@@ -79,6 +141,13 @@ function Test-RestoreDialogFeatureVisibleInOverview {
|
||||
return -not [string]::IsNullOrWhiteSpace([string]$featureDefinition.Category)
|
||||
}
|
||||
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Extracts deduplicated forward (apply) feature IDs from a backup payload.
|
||||
|
||||
.PARAMETER SelectedBackup
|
||||
The parsed backup object containing a SelectedFeatures property.
|
||||
#>
|
||||
function Get-SelectedForwardFeatureIdsFromBackup {
|
||||
param($SelectedBackup)
|
||||
|
||||
@@ -99,6 +168,13 @@ function Get-SelectedForwardFeatureIdsFromBackup {
|
||||
return @($selectedFeatureIds.ToArray())
|
||||
}
|
||||
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Extracts deduplicated undo feature IDs from a backup payload.
|
||||
|
||||
.PARAMETER SelectedBackup
|
||||
The parsed backup object containing a SelectedUndoFeatures property.
|
||||
#>
|
||||
function Get-SelectedUndoFeatureIdsFromBackup {
|
||||
param($SelectedBackup)
|
||||
|
||||
@@ -119,6 +195,13 @@ function Get-SelectedUndoFeatureIdsFromBackup {
|
||||
return @($selectedUndoFeatureIds.ToArray())
|
||||
}
|
||||
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Merges forward and undo feature IDs from a backup into a single deduplicated list.
|
||||
|
||||
.PARAMETER SelectedBackup
|
||||
The parsed backup object containing SelectedFeatures and SelectedUndoFeatures.
|
||||
#>
|
||||
function Get-CombinedSelectedFeatureIdsFromBackup {
|
||||
param($SelectedBackup)
|
||||
|
||||
@@ -139,12 +222,34 @@ function Get-CombinedSelectedFeatureIdsFromBackup {
|
||||
return @($featureIds.ToArray())
|
||||
}
|
||||
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Convenience wrapper that returns all combined feature IDs from a backup.
|
||||
|
||||
.PARAMETER SelectedBackup
|
||||
The parsed backup object.
|
||||
#>
|
||||
function Get-SelectedFeatureIdsFromBackup {
|
||||
param($SelectedBackup)
|
||||
|
||||
return @(Get-CombinedSelectedFeatureIdsFromBackup -SelectedBackup $SelectedBackup)
|
||||
}
|
||||
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Splits selected feature IDs into revertible and non-revertible lists for display.
|
||||
|
||||
.DESCRIPTION
|
||||
Iterates the provided feature IDs, filters to those visible in the overview,
|
||||
and separates them into auto-revertible (has a RegistryKey) and non-revertible
|
||||
(requires manual undo) buckets. Each entry includes a display label.
|
||||
|
||||
.PARAMETER SelectedFeatureIds
|
||||
The list of feature IDs to categorize.
|
||||
|
||||
.PARAMETER Features
|
||||
A hashtable loaded from Features.json.
|
||||
#>
|
||||
function Get-RestoreBackupFeatureLists {
|
||||
param(
|
||||
[string[]]$SelectedFeatureIds,
|
||||
|
||||
Reference in New Issue
Block a user