From c49f6a084e24c1d925b1cb1d0b2726cd65eb9604 Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Mon, 12 Dec 2022 01:28:38 +0100 Subject: [PATCH] Logic corrected! --- Winget-AutoUpdate/User-Run.ps1 | 7 +---- Winget-AutoUpdate/Winget-Upgrade.ps1 | 45 ++++++---------------------- 2 files changed, 10 insertions(+), 42 deletions(-) diff --git a/Winget-AutoUpdate/User-Run.ps1 b/Winget-AutoUpdate/User-Run.ps1 index 04661a4..c7c3583 100644 --- a/Winget-AutoUpdate/User-Run.ps1 +++ b/Winget-AutoUpdate/User-Run.ps1 @@ -82,14 +82,9 @@ else { Start-Sleep 3 } - #Test if there was a list/winget error as System/User + #Test if there was a list_/winget_error if (Test-Path "$WorkingDir\*_error.txt") { $MessageType = "error" - Remove-Item "$WorkingDir\*_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 b0a5ccf..7b9c9af 100644 --- a/Winget-AutoUpdate/Winget-Upgrade.ps1 +++ b/Winget-AutoUpdate/Winget-Upgrade.ps1 @@ -36,14 +36,6 @@ if ($IsSystem) { Add-ScopeMachine $SettingsPath } -#Delete previous list/winget_error (if they exist) as System/User -if ($IsSystem -and (Test-Path "$WorkingDir\*_error.txt")) { - Remove-Item "$WorkingDir\*_error.txt" -Force -} -elseif (!$IsSystem -and (Test-Path "${env:TEMP}\winget_error.txt")) { - Remove-Item "${env:TEMP}\winget_error.txt" -Force -} - #Get Notif Locale function $LocaleDisplayName = Get-NotifLocale Write-Log "Notification Level: $($WAUConfig.WAU_NotificationLevel). Notification Language: $LocaleDisplayName" "Cyan" @@ -79,6 +71,11 @@ if (Test-Network) { } } + #Delete previous list_/winget_error (if they exist) if System + if (Test-Path "$WorkingDir\*_error.txt") { + Remove-Item "$WorkingDir\*_error.txt" -Force + } + #Get External ListPath if System if ($WAUConfig.WAU_ListPath) { Write-Log "WAU uses External Lists from: $($WAUConfig.WAU_ListPath)" @@ -92,15 +89,7 @@ if (Test-Network) { } else { Write-Log "Critical: List doesn't exist, exiting..." "Red" - $path = "$WorkingDir\list_error.txt" - New-Item "$path" -Force - - #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) - Set-ACL -Path $path -AclObject $acl - + New-Item "$WorkingDir\list_error.txt" -Force Exit 1 } } @@ -142,27 +131,11 @@ if (Test-Network) { Write-Log "Checking application updates on Winget Repository..." "yellow" $outdated = Get-WingetOutdatedApps - #If something is wrong with the winget source, exit as System/User - if ($IsSystem -and $outdated -like "Problem:*") { + #If something is wrong with the winget source, exit + 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 in 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 - } - 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 - + New-Item "$WorkingDir\winget_error.txt" -Value "$outdated" -Force Exit 1 }