2026-05-08 21:19:52 +02:00
|
|
|
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)
|
|
|
|
|
|
2026-05-27 21:36:07 +02:00
|
|
|
$featureIds = New-Object System.Collections.Generic.List[string]
|
|
|
|
|
$seenIds = New-Object 'System.Collections.Generic.HashSet[string]' ([System.StringComparer]::OrdinalIgnoreCase)
|
|
|
|
|
|
|
|
|
|
foreach ($featureId in @($SelectedBackup.SelectedFeatures) + @($SelectedBackup.SelectedUndoFeatures)) {
|
|
|
|
|
if ([string]::IsNullOrWhiteSpace([string]$featureId)) {
|
|
|
|
|
continue
|
2026-05-08 21:19:52 +02:00
|
|
|
}
|
2026-05-27 21:36:07 +02:00
|
|
|
|
|
|
|
|
$normalizedId = [string]$featureId
|
|
|
|
|
if ($seenIds.Add($normalizedId)) {
|
|
|
|
|
$featureIds.Add($normalizedId)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return @($featureIds.ToArray())
|
2026-05-08 21:19:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
}
|
|
|
|
|
}
|