wingetautoupdate/Winget-AutoUpdate/functions/Test-ListPath.ps1

70 lines
2.7 KiB
PowerShell
Raw Normal View History

2022-09-17 19:22:41 +00:00
#Function to check Black/White List Path
function Test-ListPath ($ListPath, $UseWhiteList) {
# UNC, Web or Local Path
2022-09-18 18:25:14 +00:00
if ($UseWhiteList){
$ListType="included"
}
else {
$ListType="excluded"
}
$LocalList = -join($WingetUpdatePath, "\", $ListType, "_apps.txt")
$PathInfo=[System.Uri]$ListPath
2022-09-18 18:40:22 +00:00
2022-09-18 18:25:14 +00:00
if($PathInfo.IsUnc){
$PathType="UNC Path"
$ExternalList = -join($ListPath, "\", $ListType, "_apps.txt")
if(Test-Path -Path $ExternalList -PathType leaf){
Write-Output "Given path $ListPath type is $PathType and $ExternalList is available..."
$dateLocal = (Get-Item "$LocalList").LastWriteTime
$dateExternal = (Get-Item "$ListPath").LastWriteTime
if ($dateExternal -gt $dateLocal) {
2022-09-19 21:10:00 +00:00
Write-Host("$ExternalList is newer than $LocalList")
2022-09-18 18:25:14 +00:00
}
}
2022-09-18 18:25:14 +00:00
else {
Write-Output "Given path $ListPath type is $PathType and $ExternalList is not available..."
2022-09-18 18:25:14 +00:00
}
}
2022-09-18 18:40:22 +00:00
elseif ($ListPath -like "http*"){
$PathType="Web Path"
$ExternalList = -join($ListPath, "/", $ListType, "_apps.txt")
2022-09-18 18:25:14 +00:00
$wc = New-Object System.Net.WebClient
try {
2022-09-19 21:10:00 +00:00
$wc.OpenRead("$ExternalList").Close() | Out-Null
Write-Output "Given path $ListPath type is $PathType and $ExternalList is available..."
2022-09-19 21:10:00 +00:00
$dateLocal = (Get-Item "$LocalList").LastWriteTime
$dateExternal = $wc.ResponseHeaders['Last-Modified']
if ($dateExternal -gt $dateLocal) {
Write-Host("$ExternalList is newer than $LocalList")
}
}
catch {
Write-Output "Given path $ListPath type is $PathType and $ExternalList is not available..."
2022-09-18 18:25:14 +00:00
}
}
else {
$PathType="Local Path"
$ExternalList = -join($ListPath, "\", $ListType, "_apps.txt")
if(Test-Path -Path $ExternalList -PathType leaf){
Write-Output "Given path $ListPath type is $PathType and $ExternalList is available..."
$dateLocal = (Get-Item "$LocalList").LastWriteTime
$dateExternal = (Get-Item "$ListPath").LastWriteTime
if ($dateExternal -gt $dateLocal) {
2022-09-19 21:10:00 +00:00
Write-Host("$ExternalList is newer than $LocalList")
2022-09-18 18:25:14 +00:00
}
}
2022-09-18 18:25:14 +00:00
else {
Write-Output "Given path $ListPath type is $PathType and $ExternalList is not available..."
2022-09-18 18:25:14 +00:00
}
}
}
2022-09-17 19:22:41 +00:00
$WingetUpdatePath = "$env:ProgramData\Winget-AutoUpdate"
2022-09-19 21:10:00 +00:00
$ListPath = "https://www.knifmelti.se"
#$UseWhiteList = $true
#White List or Black List in share/online if differs
if ($WingetUpdatePath -ne $ListPath){
Test-ListPath $ListPath $UseWhiteList
}