[Fixes] Improve Error Handling + UI (#3437)

* add proper error handling + Taskbaritem support to WPFSystemRepair

* implement other fixes

- add Taskbarprogress to WPFFixesNetwork
- add Taskbarprogress to WPFFixesUpdate
- add Error handling + Taskbarprogress to WPFFixesWinget
- add finalisation in WPFSystemRepair
This commit is contained in:
MyDrift
2025-06-26 20:35:03 +02:00
committed by GitHub
parent 686e65adcb
commit 5e65505007
4 changed files with 50 additions and 16 deletions

View File

@ -8,13 +8,20 @@ function Invoke-WPFFixesNetwork {
Write-Host "Resetting Network with netsh" Write-Host "Resetting Network with netsh"
Set-WinUtilTaskbaritem -state "Normal" -value 0.01 -overlay "logo"
# Reset WinSock catalog to a clean state # Reset WinSock catalog to a clean state
Start-Process -NoNewWindow -FilePath "netsh" -ArgumentList "winsock", "reset" Start-Process -NoNewWindow -FilePath "netsh" -ArgumentList "winsock", "reset"
Set-WinUtilTaskbaritem -state "Normal" -value 0.35 -overlay "logo"
# Resets WinHTTP proxy setting to DIRECT # Resets WinHTTP proxy setting to DIRECT
Start-Process -NoNewWindow -FilePath "netsh" -ArgumentList "winhttp", "reset", "proxy" Start-Process -NoNewWindow -FilePath "netsh" -ArgumentList "winhttp", "reset", "proxy"
Set-WinUtilTaskbaritem -state "Normal" -value 0.7 -overlay "logo"
# Removes all user configured IP settings # Removes all user configured IP settings
Start-Process -NoNewWindow -FilePath "netsh" -ArgumentList "int", "ip", "reset" Start-Process -NoNewWindow -FilePath "netsh" -ArgumentList "int", "ip", "reset"
Set-WinUtilTaskbaritem -state "None" -overlay "checkmark"
Write-Host "Process complete. Please reboot your computer." Write-Host "Process complete. Please reboot your computer."
$ButtonType = [System.Windows.MessageBoxButton]::OK $ButtonType = [System.Windows.MessageBoxButton]::OK

View File

@ -30,6 +30,8 @@ function Invoke-WPFFixesUpdate {
param($Aggressive = $false) param($Aggressive = $false)
Write-Progress -Id 0 -Activity "Repairing Windows Update" -PercentComplete 0 Write-Progress -Id 0 -Activity "Repairing Windows Update" -PercentComplete 0
Set-WinUtilTaskbaritem -state "Indeterminate" -overlay "logo"
Write-Host "Starting Windows Update Repair..."
# Wait for the first progress bar to show, otherwise the second one won't show # Wait for the first progress bar to show, otherwise the second one won't show
Start-Sleep -Milliseconds 200 Start-Sleep -Milliseconds 200
@ -190,12 +192,15 @@ function Invoke-WPFFixesUpdate {
try { try {
(New-Object -ComObject Microsoft.Update.AutoUpdate).DetectNow() (New-Object -ComObject Microsoft.Update.AutoUpdate).DetectNow()
} catch { } catch {
Set-WinUtilTaskbaritem -state "Error" -overlay "warning"
Write-Warning "Failed to create Windows Update COM object: $_" Write-Warning "Failed to create Windows Update COM object: $_"
} }
Start-Process -NoNewWindow -FilePath "wuauclt" -ArgumentList "/resetauthorization", "/detectnow" Start-Process -NoNewWindow -FilePath "wuauclt" -ArgumentList "/resetauthorization", "/detectnow"
Write-Progress -Id 10 -ParentId 0 -Activity "Forcing discovery" -Status "Completed" -PercentComplete 100 Write-Progress -Id 10 -ParentId 0 -Activity "Forcing discovery" -Status "Completed" -PercentComplete 100
Write-Progress -Id 0 -Activity "Repairing Windows Update" -Status "Completed" -PercentComplete 100 Write-Progress -Id 0 -Activity "Repairing Windows Update" -Status "Completed" -PercentComplete 100
Set-WinUtilTaskbaritem -state "None" -overlay "checkmark"
$ButtonType = [System.Windows.MessageBoxButton]::OK $ButtonType = [System.Windows.MessageBoxButton]::OK
$MessageboxTitle = "Reset Windows Update " $MessageboxTitle = "Reset Windows Update "
$Messageboxbody = ("Stock settings loaded.`n Please reboot your computer") $Messageboxbody = ("Stock settings loaded.`n Please reboot your computer")

View File

@ -8,7 +8,16 @@ function Invoke-WPFFixesWinget {
BravoNorris for the fantastic idea of a button to reinstall winget BravoNorris for the fantastic idea of a button to reinstall winget
#> #>
# Install Choco if not already present # Install Choco if not already present
Install-WinUtilChoco try {
Start-Process -FilePath "choco" -ArgumentList "install winget -y --force" -NoNewWindow -Wait Set-WinUtilTaskbaritem -state "Indeterminate" -overlay "logo"
Install-WinUtilChoco
Start-Process -FilePath "choco" -ArgumentList "install winget -y --force" -NoNewWindow -Wait
} catch {
Write-Error "Failed to install winget: $_"
Set-WinUtilTaskbaritem -state "Error" -overlay "warning"
} finally {
Write-Host "==> Finished Winget Repair"
Set-WinUtilTaskbaritem -state "None" -overlay "checkmark"
}
} }

View File

@ -104,21 +104,34 @@ function Invoke-WPFSystemRepair {
Write-Progress -Id 1 -Activity $childProgressBarActivity -Status "DISM Completed" -PercentComplete 100 -Completed Write-Progress -Id 1 -Activity $childProgressBarActivity -Status "DISM Completed" -PercentComplete 100 -Completed
} }
$childProgressBarActivity = "Scanning for corruption" try {
Write-Progress -Id 0 -Activity "Repairing Windows" -PercentComplete 0 Set-WinUtilTaskbaritem -state "Indeterminate" -overlay "logo"
# Step 1: Run chkdsk to fix disk and filesystem corruption before proceeding with system file repairs
Invoke-Chkdsk
Write-Progress -Id 0 -Activity "Repairing Windows" -PercentComplete 25
# Step 2: Run SFC to fix system file corruption and ensure DISM can operate correctly $childProgressBarActivity = "Scanning for corruption"
Invoke-SFC Write-Progress -Id 0 -Activity "Repairing Windows" -PercentComplete 0
Write-Progress -Id 0 -Activity "Repairing Windows" -PercentComplete 50 # Step 1: Run chkdsk to fix disk and filesystem corruption before proceeding with system file repairs
Invoke-Chkdsk
Write-Progress -Id 0 -Activity "Repairing Windows" -PercentComplete 25
# Step 3: Run DISM to repair the system image, which SFC relies on for accurate repairs # Step 2: Run SFC to fix system file corruption and ensure DISM can operate correctly
Invoke-DISM Invoke-SFC
Write-Progress -Id 0 -Activity "Repairing Windows" -PercentComplete 75 Write-Progress -Id 0 -Activity "Repairing Windows" -PercentComplete 50
# Step 3: Run DISM to repair the system image, which SFC relies on for accurate repairs
Invoke-DISM
Write-Progress -Id 0 -Activity "Repairing Windows" -PercentComplete 75
# Step 4: Run SFC again to ensure system files are repaired using the now-fixed system image
Invoke-SFC
Write-Progress -Id 0 -Activity "Repairing Windows" -PercentComplete 100 -Completed
Set-WinUtilTaskbaritem -state "None" -overlay "checkmark"
} catch {
Write-Error "An error occurred while repairing the system: $_"
Set-WinUtilTaskbaritem -state "Error" -overlay "warning"
} finally {
Write-Host "==> Finished System Repair"
Set-WinUtilTaskbaritem -state "None" -overlay "checkmark"
}
# Step 4: Run SFC again to ensure system files are repaired using the now-fixed system image
Invoke-SFC
Write-Progress -Id 0 -Activity "Repairing Windows" -PercentComplete 100 -Completed
} }