From 3a7694f9e2024b73072bb8616d0c51d30fe80594 Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Sun, 11 Dec 2022 17:42:05 +0100 Subject: [PATCH] Old School Error Handling (by file) --- Winget-AutoUpdate/User-Run.ps1 | 10 ++++++++-- Winget-AutoUpdate/Winget-Upgrade.ps1 | 14 ++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/Winget-AutoUpdate/User-Run.ps1 b/Winget-AutoUpdate/User-Run.ps1 index 5ec50a8..36b6eae 100644 --- a/Winget-AutoUpdate/User-Run.ps1 +++ b/Winget-AutoUpdate/User-Run.ps1 @@ -49,7 +49,7 @@ $Balise = "Winget-AutoUpdate (WAU)" $UserRun = $True if ($Logs) { - if ((Test-Path "$WorkingDir\logs\updates.log")) { + if (Test-Path "$WorkingDir\logs\updates.log") { Invoke-Item "$WorkingDir\logs\updates.log" } else { @@ -81,8 +81,14 @@ else { While (Test-WAUisRunning) { Start-Sleep 3 } + if (Test-Path "$WorkingDir\winget_error.txt") { + $MessageType = "error" + Remove-Item "$WorkingDir\winget_error.txt" -Force + } + else { + $MessageType = "success" + } $Message = $NotifLocale.local.outputs.output[9].message - $MessageType = "success" Start-NotifTask -Message $Message -MessageType $MessageType -Button1Text $Button1Text -Button1Action $OnClickAction -ButtonDismiss } catch { diff --git a/Winget-AutoUpdate/Winget-Upgrade.ps1 b/Winget-AutoUpdate/Winget-Upgrade.ps1 index 0be7404..5d867eb 100644 --- a/Winget-AutoUpdate/Winget-Upgrade.ps1 +++ b/Winget-AutoUpdate/Winget-Upgrade.ps1 @@ -108,6 +108,11 @@ if (Test-Network) { Write-Log "$DeletedMods Mods deleted (not externally managed) from local path: $($WAUConfig.InstallLocation)\mods" "Red" } } + + #Delete previous winget_error if exists and System + if (Test-Path "$WorkingDir\winget_error.txt") { + Remove-Item "$WorkingDir\winget_error.txt" -Force + } } #Get White or Black list @@ -129,6 +134,15 @@ if (Test-Network) { if ($outdated -like "Problem:*") { Write-Log "An error occured, exiting..." "red" Write-Log "$outdated" "red" + $path = "$WorkingDir\winget_error.txt" + New-Item "$path" -Value "$outdated" -Force + + #Setting file rights for everyone (so that it can be deleted by User-Run.ps1) + $rule= New-Object System.Security.AccessControl.FileSystemAccessRule ('Everyone', 'FullControl', 'Allow') + $acl = Get-ACL $path + $acl.SetAccessRule($rule) + Set-ACL -Path $path -AclObject $acl + Exit 1 }