mirror of
https://github.com/Raphire/Win11Debloat.git
synced 2026-05-18 11:46:18 +00:00
Add registry backup & restore (#566)
Starting from this commit, Win11Debloat will automatically create a registry backup every time the script is run. This registry backup can be used to revert any registry changes made by the script.
This commit is contained in:
121
Scripts/GUI/RestoreBackupDialogFeatureLists.ps1
Normal file
121
Scripts/GUI/RestoreBackupDialogFeatureLists.ps1
Normal file
@@ -0,0 +1,121 @@
|
||||
function New-RestoreDialogState {
|
||||
param(
|
||||
[string]$Result = 'Cancel',
|
||||
[string]$SelectedFile = $null,
|
||||
$Backup = $null
|
||||
)
|
||||
|
||||
return @{ Result = $Result; SelectedFile = $SelectedFile; Backup = $Backup }
|
||||
}
|
||||
|
||||
function Get-RestoreDialogFeatureDefinition {
|
||||
param(
|
||||
[string]$FeatureId,
|
||||
[hashtable]$Features
|
||||
)
|
||||
|
||||
if ([string]::IsNullOrWhiteSpace($FeatureId) -or -not $Features) {
|
||||
return $null
|
||||
}
|
||||
|
||||
if ($Features.ContainsKey($FeatureId)) {
|
||||
return $Features[$FeatureId]
|
||||
}
|
||||
|
||||
return $null
|
||||
}
|
||||
|
||||
function Test-RestoreDialogFeatureCanAutoRevert {
|
||||
param(
|
||||
[string]$FeatureId,
|
||||
[hashtable]$Features
|
||||
)
|
||||
|
||||
if ([string]::IsNullOrWhiteSpace($FeatureId)) {
|
||||
return $false
|
||||
}
|
||||
|
||||
$featureDefinition = Get-RestoreDialogFeatureDefinition -FeatureId $FeatureId -Features $Features
|
||||
if ($featureDefinition) {
|
||||
return -not [string]::IsNullOrWhiteSpace([string]$featureDefinition.RegistryKey)
|
||||
}
|
||||
|
||||
return $false
|
||||
}
|
||||
|
||||
function Get-RestoreDialogFeatureDisplayLabel {
|
||||
param(
|
||||
[string]$FeatureId,
|
||||
[hashtable]$Features
|
||||
)
|
||||
|
||||
if ([string]::IsNullOrWhiteSpace($FeatureId)) {
|
||||
return 'Unknown feature'
|
||||
}
|
||||
|
||||
$featureDefinition = Get-RestoreDialogFeatureDefinition -FeatureId $FeatureId -Features $Features
|
||||
if ($featureDefinition -and -not [string]::IsNullOrWhiteSpace([string]$featureDefinition.Label)) {
|
||||
return [string]$featureDefinition.Label
|
||||
}
|
||||
|
||||
return $FeatureId
|
||||
}
|
||||
|
||||
function Test-RestoreDialogFeatureVisibleInOverview {
|
||||
param(
|
||||
[string]$FeatureId,
|
||||
[hashtable]$Features
|
||||
)
|
||||
|
||||
if ([string]::IsNullOrWhiteSpace($FeatureId)) {
|
||||
return $false
|
||||
}
|
||||
|
||||
$featureDefinition = Get-RestoreDialogFeatureDefinition -FeatureId $FeatureId -Features $Features
|
||||
if (-not $featureDefinition) {
|
||||
return $false
|
||||
}
|
||||
|
||||
return -not [string]::IsNullOrWhiteSpace([string]$featureDefinition.Category)
|
||||
}
|
||||
|
||||
function Get-SelectedFeatureIdsFromBackup {
|
||||
param($SelectedBackup)
|
||||
|
||||
return @(
|
||||
foreach ($featureId in @($SelectedBackup.SelectedFeatures)) {
|
||||
if (-not [string]::IsNullOrWhiteSpace([string]$featureId)) {
|
||||
[string]$featureId
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
function Get-RestoreBackupFeatureLists {
|
||||
param(
|
||||
[string[]]$SelectedFeatureIds,
|
||||
[hashtable]$Features
|
||||
)
|
||||
|
||||
$revertibleFeaturesList = @()
|
||||
$nonRevertibleFeaturesList = @()
|
||||
|
||||
foreach ($featureId in $SelectedFeatureIds) {
|
||||
if (-not (Test-RestoreDialogFeatureVisibleInOverview -FeatureId $featureId -Features $Features)) {
|
||||
continue
|
||||
}
|
||||
|
||||
$displayItem = [PSCustomObject]@{ DisplayText = "- $(Get-RestoreDialogFeatureDisplayLabel -FeatureId $featureId -Features $Features)" }
|
||||
if (Test-RestoreDialogFeatureCanAutoRevert -FeatureId $featureId -Features $Features) {
|
||||
$revertibleFeaturesList += $displayItem
|
||||
}
|
||||
else {
|
||||
$nonRevertibleFeaturesList += $displayItem
|
||||
}
|
||||
}
|
||||
|
||||
return [PSCustomObject]@{
|
||||
Revertible = @($revertibleFeaturesList)
|
||||
NonRevertible = @($nonRevertibleFeaturesList)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user