diff --git a/Winget-AutoUpdate/User-Run.ps1 b/Winget-AutoUpdate/User-Run.ps1 index 36b6eae..8ec3ff2 100644 --- a/Winget-AutoUpdate/User-Run.ps1 +++ b/Winget-AutoUpdate/User-Run.ps1 @@ -81,10 +81,16 @@ else { While (Test-WAUisRunning) { Start-Sleep 3 } + + #Test if there was a winget error as System/User if (Test-Path "$WorkingDir\winget_error.txt") { $MessageType = "error" Remove-Item "$WorkingDir\winget_error.txt" -Force } + elseif (Test-Path "${env:TEMP}\winget_error.txt") { + $MessageType = "error" + Remove-Item "${env:TEMP}\winget_error.txt" -Force + } else { $MessageType = "success" } diff --git a/Winget-AutoUpdate/Winget-Upgrade.ps1 b/Winget-AutoUpdate/Winget-Upgrade.ps1 index 5d867eb..82400bc 100644 --- a/Winget-AutoUpdate/Winget-Upgrade.ps1 +++ b/Winget-AutoUpdate/Winget-Upgrade.ps1 @@ -108,11 +108,14 @@ 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 - } + #Delete previous winget_error (if exists) as System/User + if ($IsSystem -and (Test-Path "$WorkingDir\winget_error.txt")) { + Remove-Item "$WorkingDir\winget_error.txt" -Force + } + elseif (!$IsSystem -and (Test-Path "${env:TEMP}\winget_error.txt")) { + Remove-Item "${env:TEMP}\winget_error.txt" -Force } #Get White or Black list @@ -130,14 +133,14 @@ if (Test-Network) { Write-Log "Checking application updates on Winget Repository..." "yellow" $outdated = Get-WingetOutdatedApps - #If something is wrong with the winget source, exit - if ($outdated -like "Problem:*") { + #If something is wrong with the winget source, exit as System/User + if ($IsSystem -and $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) + #Setting file rights for everyone (so that it can be deleted by User in User-Run.ps1) $rule= New-Object System.Security.AccessControl.FileSystemAccessRule ('Everyone', 'FullControl', 'Allow') $acl = Get-ACL $path $acl.SetAccessRule($rule) @@ -145,6 +148,14 @@ if (Test-Network) { Exit 1 } + elseif (!$IsSystem -and $outdated -like "Problem:*") { + Write-Log "An error occured, exiting..." "red" + Write-Log "$outdated" "red" + $path = "${env:TEMP}\winget_error.txt" + New-Item "$path" -Value "$outdated" -Force + + Exit 1 + } #Log list of app to update foreach ($app in $outdated) {