Refactor feature handling, update format in Features.json

This commit is contained in:
Raphire
2026-04-01 21:33:24 +02:00
parent 105198e396
commit c79c05f286
9 changed files with 410 additions and 415 deletions

View File

@@ -11,7 +11,7 @@ function PrintPendingChanges {
}
if ($script:Params['CreateRestorePoint']) {
Write-Output "- $($script:Features['CreateRestorePoint'].Label)"
Write-Output "- $($script:Features['CreateRestorePoint'].Action)"
}
foreach ($parameterName in $script:Params.Keys) {
if ($script:ControlParams -contains $parameterName) {
@@ -65,18 +65,17 @@ function PrintPendingChanges {
}
default {
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
}
else {
$script:Features[$parameterName].Action
}
$message = $script:Features[$parameterName].Label
if ($action) {
Write-Output "- $action $message"
if ($message) {
Write-Output "- $message"
}
else {
Write-Output "- $message"
Write-Output "- $parameterName"
}
}
else {
@@ -94,9 +93,7 @@ function PrintPendingChanges {
$uniqueSkipped = $skippedParams | Sort-Object -Unique
foreach ($skippedParam in $uniqueSkipped) {
$action = $script:Features[$skippedParam].Action
$message = $script:Features[$skippedParam].Label
Write-Output "- $action $message"
Write-Output "- $($script:Features[$skippedParam].Action)"
}
}
@@ -104,4 +101,4 @@ function PrintPendingChanges {
Write-Output ""
Write-Output "Press enter to execute the script or press CTRL+C to quit..."
Read-Host | Out-Null
}
}

View File

@@ -30,7 +30,7 @@ function ExecuteParameter {
$undoRegFile = Join-Path 'Undo' $undoRegFile
}
ImportRegistryFile "> $($undoFeature.UndoAction) $($undoFeature.Label)" $undoRegFile
ImportRegistryFile "> $($undoFeature.UndoText)" $undoRegFile
return
}
@@ -219,19 +219,13 @@ function ExecuteAllChanges {
$stepName = $paramKey
if ($script:Features.ContainsKey($paramKey)) {
$feature = $script:Features[$paramKey]
if ($undoChanges -and $feature.UndoAction) {
$stepName = "$($feature.UndoAction) $($feature.Label)"
if ($undoChanges -and $feature.UndoText) {
$stepName = $feature.UndoText
}
elseif ($feature.ApplyText) {
# Prefer explicit ApplyText when provided
$stepName = $feature.ApplyText
} elseif ($feature.Label) {
# Fallback: construct a name from Action and Label, or just Label
if ($feature.Action) {
$stepName = "$($feature.Action) $($feature.Label)"
} else {
$stepName = $feature.Label
}
} elseif ($feature.Action) {
$stepName = $feature.Action
}
}
@@ -241,4 +235,4 @@ function ExecuteAllChanges {
ExecuteParameter -paramKey $paramKey
}
}
}

View File

@@ -10,7 +10,7 @@ function RestartExplorer {
foreach ($paramKey in $script:Params.Keys) {
if ($script:Features.ContainsKey($paramKey) -and $script:Features[$paramKey].RequiresReboot -eq $true) {
$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
}
}

View File

@@ -162,7 +162,7 @@ function Show-ApplyModal {
foreach ($paramKey in $script:Params.Keys) {
if ($script:Features.ContainsKey($paramKey) -and $script:Features[$paramKey].RequiresReboot -eq $true) {
$feature = $script:Features[$paramKey]
$rebootFeatures += "$($feature.Action) $($feature.Label)"
$rebootFeatures += $feature.Action
}
}

View File

@@ -446,7 +446,7 @@ function Show-MainWindow {
# Dynamically builds Tweaks UI from Features.json
function BuildDynamicTweaks {
$featuresJson = LoadJsonFile -filePath $script:FeaturesFilePath -expectedVersion "1.0"
$featuresJson = LoadJsonFile -filePath $script:FeaturesFilePath -expectedVersion $script:FeaturesConfigVersion
if (-not $featuresJson) {
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' }
$items = @('No Change', $opt)
$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
if ($feature.ToolTip) {
$tipBlock = New-Object System.Windows.Controls.TextBlock
@@ -721,7 +721,7 @@ function Show-MainWindow {
try { $lblBorderObj = $window.FindName("$comboName`_LabelBorder") } catch {}
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
$script:FeatureLabelLookup = @{}
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') {
$label = $script:FeatureLabelLookup[$mapping.FeatureId]
if (-not $label) { $label = $mapping.Action + ' ' + $mapping.Label }
$changesList += $label
if ($label) { $changesList += $label }
}
}
}

View File

@@ -70,17 +70,12 @@ function Show-RevertSettingsModal {
$undoFeature = GetUndoFeatureForParam -paramKey $setting.Name
$label = $setting.Name
if ($feature -and $feature.Label) {
if ($feature.Action) {
$label = "$($feature.Action) $($feature.Label)"
}
else {
$label = $feature.Label
}
if ($feature -and $feature.Action) {
$label = $feature.Action
}
$undoLabel = if ($undoFeature -and $undoFeature.Label) {
"$($undoFeature.UndoAction) $($undoFeature.Label)"
$undoLabel = if ($undoFeature -and $undoFeature.UndoAction) {
$undoFeature.UndoAction
} else {
'No revert action available'
}

View File

@@ -9,7 +9,7 @@ function GetUndoFeatureForParam {
}
$feature = $script:Features[$paramKey]
if (-not ($feature.RegistryUndoKey -and $feature.UndoAction)) {
if (-not ($feature.RegistryUndoKey -and ($feature.UndoText -or $feature.UndoAction))) {
return $null
}