A bit of error handling in ModsProtect

pull/275/head
KnifMelti 2023-02-07 20:06:54 +01:00
parent 2471438c3b
commit c505773f8c
3 changed files with 66 additions and 55 deletions

View File

@ -384,12 +384,15 @@ function Install-WingetAutoUpdate {
Write-host "`nChecking Mods Directory:" -ForegroundColor Yellow
. "$WingetUpdatePath\functions\Invoke-ModsProtect.ps1"
$Protected = Invoke-ModsProtect "$WingetUpdatePath\mods"
if ($Protected) {
if ($Protected -eq $True) {
Write-Host "The mods directory is now secured!`n" -ForegroundColor Green
}
elseif (!$Protected) {
elseif ($Protected -eq $False) {
Write-Host "The mods directory was already secured!`n" -ForegroundColor Green
}
else {
Write-Host "Error: The mods directory couldn't be verified as secured!`n" -ForegroundColor Red
}
#Create Shortcuts
if ($StartMenuShortcut) {

View File

@ -3,7 +3,8 @@
#Check if Local Users have write rights in Mods directory or not (and take action if necessary):
function Invoke-ModsProtect ($ModsPath) {
$directory = Get-Item -Path $ModsPath
try {
$directory = Get-Item -Path $ModsPath -ErrorAction SilentlyContinue
$acl = Get-Acl -Path $directory.FullName
#Local Users - S-1-5-32-545
$userSID = New-Object System.Security.Principal.SecurityIdentifier("S-1-5-32-545")
@ -57,4 +58,8 @@ function Invoke-ModsProtect ($ModsPath) {
return $True
}
return $False
}
catch {
return "Error"
}
}

View File

@ -74,12 +74,15 @@ function Invoke-PostUpdateActions {
#Security check
Write-Log "-> Checking Mods Directory:" "yellow"
$Protected = Invoke-ModsProtect "$($WAUConfig.InstallLocation)\mods"
if ($Protected) {
if ($Protected -eq $True) {
Write-Log "-> The mods directory is now secured!" "green"
}
elseif (!$Protected) {
elseif ($Protected -eq $False) {
Write-Log "-> The mods directory was already secured!" "green"
}
else {
Write-Log "-> Error: The mods directory couldn't be verified as secured!" "red"
}
#Convert about.xml if exists (previous WAU versions) to reg
$WAUAboutPath = "$WorkingDir\config\about.xml"