fix(registry-restore): continue restoring remaining keys when one fails (#837)

Co-authored-by: Jeffrey <9938813+Raphire@users.noreply.github.com>
This commit is contained in:
Ahmad Z. Shatnawi
2026-11-08 23:59:47 +01:00
committed by GitHub
co-authored by Jeffrey
parent e6184a2597
commit f39885f6f2
16 changed files with 103 additions and 5 deletions
+23 -3
View File
@@ -246,9 +246,29 @@ function Restore-RegistryBackupState {
$restoreAction = {
param($normalizedBackup)
Write-Host "Applying registry restore from $(@($normalizedBackup.RegistryKeys).Count) root snapshot(s)."
foreach ($rootSnapshot in @($normalizedBackup.RegistryKeys)) {
Restore-RegistryKeySnapshot -Snapshot $rootSnapshot
$rootSnapshots = @($normalizedBackup.RegistryKeys)
foreach ($rootSnapshot in $rootSnapshots) {
Test-RegistryKeySnapshotCanBeRestored -Snapshot $rootSnapshot
}
Write-Host "Applying registry restore from $($rootSnapshots.Count) root snapshot(s)."
$failureCount = 0
foreach ($rootSnapshot in $rootSnapshots) {
try {
Restore-RegistryKeySnapshot -Snapshot $rootSnapshot
}
catch {
$failureCount++
Write-Warning "Failed to restore '$($rootSnapshot.Path)': $($_.Exception.Message)"
}
}
if ($failureCount -gt 0) {
$restoreError = [System.InvalidOperationException]::new("Registry restore finished with $failureCount failed key(s). See console for details.")
$restoreError.Data['RegistryRestoreFailureCount'] = $failureCount
throw $restoreError
}
}
+9 -2
View File
@@ -114,8 +114,15 @@ function Show-RestoreBackupWindow {
}
catch {
$errorMessage = if ($_.Exception.Message) { $_.Exception.Message } else { Get-Translation -Key 'RestoreUnexpectedError' }
Write-Error "Restore operation failed: $errorMessage"
Show-MessageBox -Title (Get-Translation -Key 'ErrorTitle') -Message (Get-Translation -Key 'RestoreOperationFailedMessage' -FormatArgs @($errorMessage)) -Icon Error
$failureCount = $_.Exception.Data['RegistryRestoreFailureCount']
$dialogMessage = if ($failureCount -gt 0) {
Get-Translation -Key 'RestoreRegistryFailures' -Count $failureCount -FormatArgs @($failureCount)
}
else {
Get-Translation -Key 'RestoreOperationFailedMessage' -FormatArgs @($errorMessage)
}
Write-Error "Restore operation failed: $errorMessage" -ErrorAction Continue
Show-MessageBox -Title (Get-Translation -Key 'RestoreOperationFailedTitle') -Message $dialogMessage -Icon Error
return [PSCustomObject]@{
RestoredRegistry = $false
RestoredStartMenu = $false