From 50b2d383c4f58271bcfe4e9192d8f1a953a47075 Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Sun, 11 Dec 2022 22:22:22 +0100 Subject: [PATCH] ...and, missing list error too! --- Winget-AutoUpdate/User-Run.ps1 | 6 +++--- Winget-AutoUpdate/Winget-Upgrade.ps1 | 27 ++++++++++++++++++--------- 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/Winget-AutoUpdate/User-Run.ps1 b/Winget-AutoUpdate/User-Run.ps1 index 8ec3ff2..04661a4 100644 --- a/Winget-AutoUpdate/User-Run.ps1 +++ b/Winget-AutoUpdate/User-Run.ps1 @@ -82,10 +82,10 @@ else { Start-Sleep 3 } - #Test if there was a winget error as System/User - if (Test-Path "$WorkingDir\winget_error.txt") { + #Test if there was a list/winget error as System/User + if (Test-Path "$WorkingDir\*_error.txt") { $MessageType = "error" - Remove-Item "$WorkingDir\winget_error.txt" -Force + Remove-Item "$WorkingDir\*_error.txt" -Force } elseif (Test-Path "${env:TEMP}\winget_error.txt") { $MessageType = "error" diff --git a/Winget-AutoUpdate/Winget-Upgrade.ps1 b/Winget-AutoUpdate/Winget-Upgrade.ps1 index 82400bc..b0a5ccf 100644 --- a/Winget-AutoUpdate/Winget-Upgrade.ps1 +++ b/Winget-AutoUpdate/Winget-Upgrade.ps1 @@ -36,6 +36,14 @@ 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" @@ -83,7 +91,16 @@ if (Test-Network) { Write-Log "List is up to date." "Green" } else { - Write-Log "List doesn't exist!" "Red" + 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 + Exit 1 } } @@ -110,14 +127,6 @@ if (Test-Network) { } } - #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 if ($WAUConfig.WAU_UseWhiteList -eq 1) { Write-Log "WAU uses White List config"