Handling both System/User now

pull/245/head
KnifMelti 2022-12-11 18:40:06 +01:00
parent 3a7694f9e2
commit 7c0c9dcb30
2 changed files with 24 additions and 7 deletions

View File

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

View File

@ -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) {