Logic corrected!

pull/245/head
KnifMelti 2022-12-12 01:28:38 +01:00
parent 50b2d383c4
commit c49f6a084e
2 changed files with 10 additions and 42 deletions

View File

@ -82,14 +82,9 @@ else {
Start-Sleep 3 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") { if (Test-Path "$WorkingDir\*_error.txt") {
$MessageType = "error" $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 { else {
$MessageType = "success" $MessageType = "success"

View File

@ -36,14 +36,6 @@ if ($IsSystem) {
Add-ScopeMachine $SettingsPath 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 #Get Notif Locale function
$LocaleDisplayName = Get-NotifLocale $LocaleDisplayName = Get-NotifLocale
Write-Log "Notification Level: $($WAUConfig.WAU_NotificationLevel). Notification Language: $LocaleDisplayName" "Cyan" 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 #Get External ListPath if System
if ($WAUConfig.WAU_ListPath) { if ($WAUConfig.WAU_ListPath) {
Write-Log "WAU uses External Lists from: $($WAUConfig.WAU_ListPath)" Write-Log "WAU uses External Lists from: $($WAUConfig.WAU_ListPath)"
@ -92,15 +89,7 @@ if (Test-Network) {
} }
else { else {
Write-Log "Critical: List doesn't exist, exiting..." "Red" Write-Log "Critical: List doesn't exist, exiting..." "Red"
$path = "$WorkingDir\list_error.txt" New-Item "$WorkingDir\list_error.txt" -Force
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 Exit 1
} }
} }
@ -142,27 +131,11 @@ if (Test-Network) {
Write-Log "Checking application updates on Winget Repository..." "yellow" Write-Log "Checking application updates on Winget Repository..." "yellow"
$outdated = Get-WingetOutdatedApps $outdated = Get-WingetOutdatedApps
#If something is wrong with the winget source, exit as System/User #If something is wrong with the winget source, exit
if ($IsSystem -and $outdated -like "Problem:*") { if ($outdated -like "Problem:*") {
Write-Log "An error occured, exiting..." "red" Write-Log "An error occured, exiting..." "red"
Write-Log "$outdated" "red" Write-Log "$outdated" "red"
$path = "$WorkingDir\winget_error.txt" New-Item "$WorkingDir\winget_error.txt" -Value "$outdated" -Force
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
Exit 1 Exit 1
} }