mirror of
https://github.com/Raphire/Win11Debloat.git
synced 2026-04-03 14:06:27 +00:00
Refactor feature handling, update format in Features.json
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -11,7 +11,7 @@ function PrintPendingChanges {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($script:Params['CreateRestorePoint']) {
|
if ($script:Params['CreateRestorePoint']) {
|
||||||
Write-Output "- $($script:Features['CreateRestorePoint'].Label)"
|
Write-Output "- $($script:Features['CreateRestorePoint'].Action)"
|
||||||
}
|
}
|
||||||
foreach ($parameterName in $script:Params.Keys) {
|
foreach ($parameterName in $script:Params.Keys) {
|
||||||
if ($script:ControlParams -contains $parameterName) {
|
if ($script:ControlParams -contains $parameterName) {
|
||||||
@@ -65,18 +65,17 @@ function PrintPendingChanges {
|
|||||||
}
|
}
|
||||||
default {
|
default {
|
||||||
if ($script:Features -and $script:Features.ContainsKey($parameterName)) {
|
if ($script:Features -and $script:Features.ContainsKey($parameterName)) {
|
||||||
$action = if ($undoChanges -and $script:Features[$parameterName].UndoAction) {
|
$message = if ($undoChanges -and $script:Features[$parameterName].UndoAction) {
|
||||||
$script:Features[$parameterName].UndoAction
|
$script:Features[$parameterName].UndoAction
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$script:Features[$parameterName].Action
|
$script:Features[$parameterName].Action
|
||||||
}
|
}
|
||||||
$message = $script:Features[$parameterName].Label
|
if ($message) {
|
||||||
if ($action) {
|
Write-Output "- $message"
|
||||||
Write-Output "- $action $message"
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Write-Output "- $message"
|
Write-Output "- $parameterName"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -94,9 +93,7 @@ function PrintPendingChanges {
|
|||||||
|
|
||||||
$uniqueSkipped = $skippedParams | Sort-Object -Unique
|
$uniqueSkipped = $skippedParams | Sort-Object -Unique
|
||||||
foreach ($skippedParam in $uniqueSkipped) {
|
foreach ($skippedParam in $uniqueSkipped) {
|
||||||
$action = $script:Features[$skippedParam].Action
|
Write-Output "- $($script:Features[$skippedParam].Action)"
|
||||||
$message = $script:Features[$skippedParam].Label
|
|
||||||
Write-Output "- $action $message"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ function ExecuteParameter {
|
|||||||
$undoRegFile = Join-Path 'Undo' $undoRegFile
|
$undoRegFile = Join-Path 'Undo' $undoRegFile
|
||||||
}
|
}
|
||||||
|
|
||||||
ImportRegistryFile "> $($undoFeature.UndoAction) $($undoFeature.Label)" $undoRegFile
|
ImportRegistryFile "> $($undoFeature.UndoText)" $undoRegFile
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -219,19 +219,13 @@ function ExecuteAllChanges {
|
|||||||
$stepName = $paramKey
|
$stepName = $paramKey
|
||||||
if ($script:Features.ContainsKey($paramKey)) {
|
if ($script:Features.ContainsKey($paramKey)) {
|
||||||
$feature = $script:Features[$paramKey]
|
$feature = $script:Features[$paramKey]
|
||||||
if ($undoChanges -and $feature.UndoAction) {
|
if ($undoChanges -and $feature.UndoText) {
|
||||||
$stepName = "$($feature.UndoAction) $($feature.Label)"
|
$stepName = $feature.UndoText
|
||||||
}
|
}
|
||||||
elseif ($feature.ApplyText) {
|
elseif ($feature.ApplyText) {
|
||||||
# Prefer explicit ApplyText when provided
|
|
||||||
$stepName = $feature.ApplyText
|
$stepName = $feature.ApplyText
|
||||||
} elseif ($feature.Label) {
|
} elseif ($feature.Action) {
|
||||||
# Fallback: construct a name from Action and Label, or just Label
|
$stepName = $feature.Action
|
||||||
if ($feature.Action) {
|
|
||||||
$stepName = "$($feature.Action) $($feature.Label)"
|
|
||||||
} else {
|
|
||||||
$stepName = $feature.Label
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ function RestartExplorer {
|
|||||||
foreach ($paramKey in $script:Params.Keys) {
|
foreach ($paramKey in $script:Params.Keys) {
|
||||||
if ($script:Features.ContainsKey($paramKey) -and $script:Features[$paramKey].RequiresReboot -eq $true) {
|
if ($script:Features.ContainsKey($paramKey) -and $script:Features[$paramKey].RequiresReboot -eq $true) {
|
||||||
$feature = $script:Features[$paramKey]
|
$feature = $script:Features[$paramKey]
|
||||||
Write-Host "Warning: '$($feature.Action) $($feature.Label)' requires a reboot to take full effect" -ForegroundColor Yellow
|
Write-Host "Warning: '$($feature.Action)' requires a reboot to take full effect" -ForegroundColor Yellow
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -162,7 +162,7 @@ function Show-ApplyModal {
|
|||||||
foreach ($paramKey in $script:Params.Keys) {
|
foreach ($paramKey in $script:Params.Keys) {
|
||||||
if ($script:Features.ContainsKey($paramKey) -and $script:Features[$paramKey].RequiresReboot -eq $true) {
|
if ($script:Features.ContainsKey($paramKey) -and $script:Features[$paramKey].RequiresReboot -eq $true) {
|
||||||
$feature = $script:Features[$paramKey]
|
$feature = $script:Features[$paramKey]
|
||||||
$rebootFeatures += "$($feature.Action) $($feature.Label)"
|
$rebootFeatures += $feature.Action
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -446,7 +446,7 @@ function Show-MainWindow {
|
|||||||
|
|
||||||
# Dynamically builds Tweaks UI from Features.json
|
# Dynamically builds Tweaks UI from Features.json
|
||||||
function BuildDynamicTweaks {
|
function BuildDynamicTweaks {
|
||||||
$featuresJson = LoadJsonFile -filePath $script:FeaturesFilePath -expectedVersion "1.0"
|
$featuresJson = LoadJsonFile -filePath $script:FeaturesFilePath -expectedVersion $script:FeaturesConfigVersion
|
||||||
|
|
||||||
if (-not $featuresJson) {
|
if (-not $featuresJson) {
|
||||||
Show-MessageBox -Message "Unable to load Features.json file!" -Title "Error" -Button 'OK' -Icon 'Error' | Out-Null
|
Show-MessageBox -Message "Unable to load Features.json file!" -Title "Error" -Button 'OK' -Icon 'Error' | Out-Null
|
||||||
@@ -709,7 +709,7 @@ function Show-MainWindow {
|
|||||||
if ($feature.FeatureId -match '^Disable') { $opt = 'Disable' } elseif ($feature.FeatureId -match '^Enable') { $opt = 'Enable' }
|
if ($feature.FeatureId -match '^Disable') { $opt = 'Disable' } elseif ($feature.FeatureId -match '^Enable') { $opt = 'Enable' }
|
||||||
$items = @('No Change', $opt)
|
$items = @('No Change', $opt)
|
||||||
$comboName = ("Feature_{0}_Combo" -f $feature.FeatureId) -replace '[^a-zA-Z0-9_]',''
|
$comboName = ("Feature_{0}_Combo" -f $feature.FeatureId) -replace '[^a-zA-Z0-9_]',''
|
||||||
$combo = CreateLabeledCombo -parent $panel -labelText ($feature.Action + ' ' + $feature.Label) -comboName $comboName -items $items
|
$combo = CreateLabeledCombo -parent $panel -labelText $feature.Action -comboName $comboName -items $items
|
||||||
# attach tooltip from Features.json if present
|
# attach tooltip from Features.json if present
|
||||||
if ($feature.ToolTip) {
|
if ($feature.ToolTip) {
|
||||||
$tipBlock = New-Object System.Windows.Controls.TextBlock
|
$tipBlock = New-Object System.Windows.Controls.TextBlock
|
||||||
@@ -721,7 +721,7 @@ function Show-MainWindow {
|
|||||||
try { $lblBorderObj = $window.FindName("$comboName`_LabelBorder") } catch {}
|
try { $lblBorderObj = $window.FindName("$comboName`_LabelBorder") } catch {}
|
||||||
if ($lblBorderObj) { $lblBorderObj.ToolTip = $tipBlock }
|
if ($lblBorderObj) { $lblBorderObj.ToolTip = $tipBlock }
|
||||||
}
|
}
|
||||||
$script:UiControlMappings[$comboName] = @{ Type='feature'; FeatureId = $feature.FeatureId; Action = $feature.Action; Label = $feature.Label }
|
$script:UiControlMappings[$comboName] = @{ Type='feature'; FeatureId = $feature.FeatureId; Action = $feature.Action }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -729,7 +729,7 @@ function Show-MainWindow {
|
|||||||
# Build a feature-label lookup so GenerateOverview can resolve feature IDs without reloading JSON
|
# Build a feature-label lookup so GenerateOverview can resolve feature IDs without reloading JSON
|
||||||
$script:FeatureLabelLookup = @{}
|
$script:FeatureLabelLookup = @{}
|
||||||
foreach ($f in $featuresJson.Features) {
|
foreach ($f in $featuresJson.Features) {
|
||||||
$script:FeatureLabelLookup[$f.FeatureId] = $f.Action + ' ' + $f.Label
|
$script:FeatureLabelLookup[$f.FeatureId] = $f.Action
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1466,8 +1466,7 @@ function Show-MainWindow {
|
|||||||
}
|
}
|
||||||
elseif ($mapping.Type -eq 'feature') {
|
elseif ($mapping.Type -eq 'feature') {
|
||||||
$label = $script:FeatureLabelLookup[$mapping.FeatureId]
|
$label = $script:FeatureLabelLookup[$mapping.FeatureId]
|
||||||
if (-not $label) { $label = $mapping.Action + ' ' + $mapping.Label }
|
if ($label) { $changesList += $label }
|
||||||
$changesList += $label
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -70,17 +70,12 @@ function Show-RevertSettingsModal {
|
|||||||
$undoFeature = GetUndoFeatureForParam -paramKey $setting.Name
|
$undoFeature = GetUndoFeatureForParam -paramKey $setting.Name
|
||||||
|
|
||||||
$label = $setting.Name
|
$label = $setting.Name
|
||||||
if ($feature -and $feature.Label) {
|
if ($feature -and $feature.Action) {
|
||||||
if ($feature.Action) {
|
$label = $feature.Action
|
||||||
$label = "$($feature.Action) $($feature.Label)"
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$label = $feature.Label
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$undoLabel = if ($undoFeature -and $undoFeature.Label) {
|
$undoLabel = if ($undoFeature -and $undoFeature.UndoAction) {
|
||||||
"$($undoFeature.UndoAction) $($undoFeature.Label)"
|
$undoFeature.UndoAction
|
||||||
} else {
|
} else {
|
||||||
'No revert action available'
|
'No revert action available'
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ function GetUndoFeatureForParam {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$feature = $script:Features[$paramKey]
|
$feature = $script:Features[$paramKey]
|
||||||
if (-not ($feature.RegistryUndoKey -and $feature.UndoAction)) {
|
if (-not ($feature.RegistryUndoKey -and ($feature.UndoText -or $feature.UndoAction))) {
|
||||||
return $null
|
return $null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -106,6 +106,7 @@ param (
|
|||||||
|
|
||||||
# Define script-level variables & paths
|
# Define script-level variables & paths
|
||||||
$script:Version = "2026.03.15"
|
$script:Version = "2026.03.15"
|
||||||
|
$script:FeaturesConfigVersion = "2.0"
|
||||||
$script:AppsListFilePath = "$PSScriptRoot/Config/Apps.json"
|
$script:AppsListFilePath = "$PSScriptRoot/Config/Apps.json"
|
||||||
$script:DefaultSettingsFilePath = "$PSScriptRoot/Config/DefaultSettings.json"
|
$script:DefaultSettingsFilePath = "$PSScriptRoot/Config/DefaultSettings.json"
|
||||||
$script:FeaturesFilePath = "$PSScriptRoot/Config/Features.json"
|
$script:FeaturesFilePath = "$PSScriptRoot/Config/Features.json"
|
||||||
@@ -199,6 +200,15 @@ if ($missingRequiredPaths.Count -gt 0) {
|
|||||||
$script:Features = @{}
|
$script:Features = @{}
|
||||||
try {
|
try {
|
||||||
$featuresData = Get-Content -Path $script:FeaturesFilePath -Raw | ConvertFrom-Json
|
$featuresData = Get-Content -Path $script:FeaturesFilePath -Raw | ConvertFrom-Json
|
||||||
|
|
||||||
|
if (-not $featuresData.Version -or $featuresData.Version -ne $script:FeaturesConfigVersion) {
|
||||||
|
Write-Error "Features.json version mismatch (expected $($script:FeaturesConfigVersion), found $($featuresData.Version))"
|
||||||
|
Write-Output ""
|
||||||
|
Write-Output "Press any key to exit..."
|
||||||
|
$null = [System.Console]::ReadKey()
|
||||||
|
Exit
|
||||||
|
}
|
||||||
|
|
||||||
foreach ($feature in $featuresData.Features) {
|
foreach ($feature in $featuresData.Features) {
|
||||||
$script:Features[$feature.FeatureId] = $feature
|
$script:Features[$feature.FeatureId] = $feature
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user