Improve backup validation (#849)

This commit is contained in:
Jeffrey
2026-10-21 22:47:01 +02:00
committed by GitHub
parent 97f3f805ef
commit 039ef80a8b
18 changed files with 1504 additions and 46 deletions
+14 -2
View File
@@ -31,7 +31,10 @@ function Show-MessageBox {
[System.Windows.Window]$Owner = $null,
[Parameter(Mandatory=$false)]
[int]$Width = 0
[int]$Width = 0,
[ValidateSet('OK', 'Cancel', 'Yes', 'No')]
[string]$DefaultResult
)
Add-Type -AssemblyName PresentationFramework,PresentationCore,WindowsBase | Out-Null
@@ -91,7 +94,8 @@ function Show-MessageBox {
default { [System.Windows.MessageBoxImage]::None }
}
$nativeResult = [System.Windows.MessageBox]::Show($Message, $Title, $nativeButton, $nativeIcon)
$nativeDefault = if ($DefaultResult) { [System.Windows.MessageBoxResult]::$DefaultResult } else { [System.Windows.MessageBoxResult]::None }
$nativeResult = [System.Windows.MessageBox]::Show($Message, $Title, $nativeButton, $nativeIcon, $nativeDefault)
return [string]$nativeResult
}
$reader = [System.Xml.XmlReader]::Create([System.IO.StringReader]::new($xaml))
@@ -187,6 +191,14 @@ function Show-MessageBox {
}
}
if ($DefaultResult) {
$useSecondButton = $DefaultResult -in @('Cancel', 'No')
$button1.IsDefault = -not $useSecondButton
$button2.IsDefault = $useSecondButton
$defaultButton = if ($useSecondButton) { $button2 } else { $button1 }
$msgWindow.Add_ContentRendered({ $null = $defaultButton.Focus() })
}
# Title bar drag to move window
$titleBar.Add_MouseLeftButtonDown({
$msgWindow.DragMove()
+1
View File
@@ -331,6 +331,7 @@ function Show-RestoreBackupDialog {
}
}
catch {
Write-Error "Failed to load registry backup '$($openDialog.FileName)': $($_.Exception.Message)" -ErrorAction Continue
Show-MessageBox -Owner $window -Title (Get-Translation -Key 'RestoreInvalidBackupTitle') -Message (Get-Translation -Key 'RestoreInvalidBackupMessage' -FormatArgs @($_.Exception.Message)) -Button 'OK' -Icon 'Error' | Out-Null
return
}
+10 -1
View File
@@ -31,7 +31,16 @@ function Show-RestoreBackupWindow {
}
Write-Host "User confirmed registry restore for $($backup.Target)."
$restoreOpResult = Restore-RegistryBackupState -Backup $backup
$confirmUntrustedValues = {
param($mismatches)
$details = @($mismatches | ForEach-Object {
$valueName = if ([string]::IsNullOrEmpty($_.Name)) { '(Default)' } else { $_.Name }
Get-Translation -Key 'BackupExecutableMismatchDetails' -FormatArgs @($_.Path, $valueName, $_.Kind, ($_.Data | ConvertTo-Json -Compress -Depth 10))
}) -join "`n`n"
$message = Get-Translation -Key 'BackupExecutableWarningMessage' -FormatArgs @($details)
return (Show-MessageBox -Owner $Owner -Title (Get-Translation -Key 'BackupExecutableWarningTitle') -Message $message -Button 'OKCancel' -Icon 'Warning' -DefaultResult 'Cancel' -Width 700) -eq 'OK'
}
$restoreOpResult = Restore-RegistryBackupState -Backup $backup -ConfirmUntrustedValues $confirmUntrustedValues
if ($restoreOpResult -and $restoreOpResult.Result) {
$restoreResult.RestoredRegistry = $true
if ($script:Params.ContainsKey("WhatIf")) {