mirror of
https://github.com/Raphire/Win11Debloat.git
synced 2026-11-25 23:16:15 +01:00
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:
co-authored by
Jeffrey
parent
e6184a2597
commit
f39885f6f2
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user