Old School Error Handling (by file)

pull/245/head
KnifMelti 2022-12-11 17:42:05 +01:00
parent d6abb076c3
commit 3a7694f9e2
2 changed files with 22 additions and 2 deletions

View File

@ -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
}
$Message = $NotifLocale.local.outputs.output[9].message
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
Start-NotifTask -Message $Message -MessageType $MessageType -Button1Text $Button1Text -Button1Action $OnClickAction -ButtonDismiss
}
catch {

View File

@ -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
}