Compare LastModifiedDate, http remaining

pull/166/head
KnifMelti 2022-09-19 21:12:00 +02:00
parent c928b7aa93
commit 817f61adab
1 changed files with 37 additions and 24 deletions

View File

@ -1,54 +1,67 @@
#Function to check Black/White List Path #Function to check Black/White List Path
function Test-ListPath ($ListPath, $UseWhiteList) { function Test-ListPath ($ListPath, $UseWhiteList) {
# UNC or Local Path # UNC, Web or Local Path
if ($UseWhiteList){ if ($UseWhiteList){
$ListType="included" $ListType="included"
} }
else { else {
$ListType="excluded" $ListType="excluded"
} }
$Path = $ListPath $LocalList = -join($WingetUpdatePath, "\", $ListType, "_apps.txt")
$PathInfo=[System.Uri]$Path $ExternalList = $ListPath
$PathInfo=[System.Uri]$ListPath
if($PathInfo.IsUnc){ if($PathInfo.IsUnc){
$PathType="UNC Path" $PathType="UNC Path"
$ListPath = -join($Path, "\", "$ListType", "_apps.txt") $ExternalList = -join($ListPath, "\", $ListType, "_apps.txt")
if(Test-Path -Path $ListPath -PathType leaf){ if(Test-Path -Path $ExternalList -PathType leaf){
Write-Output "Given path $Path type is $PathType and $ListPath is available..." 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) {
Write-Host("$ExternalList was modified after $LocalList")
}
} }
else { else {
Write-Output "Given path $Path type is $PathType and $ListPath is not available..." Write-Output "Given path $ListPath type is $PathType and $ExternalList is not available..."
} }
} }
elseif ($ListPath -like "http*"){ elseif ($ListPath -like "http*"){
$PathType="Web Path" $PathType="Web Path"
$ListPath = -join($Path, "/", "$ListType", "_apps.txt") $ExternalList = -join($ListPath, "/", $ListType, "_apps.txt")
$wc = New-Object System.Net.WebClient $wc = New-Object System.Net.WebClient
try { try {
$wc.OpenRead("$ListPath") | Out-Null $wc.OpenRead("$ExternalList") | Out-Null
Write-Output "Given path $Path type is $PathType and $ListPath is available..." Write-Output "Given path $ListPath type is $PathType and $ExternalList is available..."
} catch { }
Write-Output "Given path $Path type is $PathType and $ListPath is not available..." catch {
Write-Output "Given path $ListPath type is $PathType and $ExternalList is not available..."
} }
} }
else { else {
$PathType="Local Path" $PathType="Local Path"
$ListPath = -join($Path, "\", "$ListType", "_apps.txt") $ExternalList = -join($ListPath, "\", $ListType, "_apps.txt")
if(Test-Path -Path $ListPath -PathType leaf){ if(Test-Path -Path $ExternalList -PathType leaf){
Write-Output "Given path $Path type is $PathType and $ListPath is available..." 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) {
Write-Host("$ExternalList was modified after $LocalList")
}
} }
else { else {
Write-Output "Given path $Path type is $PathType and $ListPath is not available..." Write-Output "Given path $ListPath type is $PathType and $ExternalList is not available..."
} }
} }
} }
# $WingetUpdatePath = "$env:ProgramData\Winget-AutoUpdate" $WingetUpdatePath = "$env:ProgramData\Winget-AutoUpdate"
# $ListPath = "https://www.knifmelti.se" $ListPath = "D:\Temp"
# $UseWhiteList = $true $UseWhiteList = $false
# #White List or Black List in share/online if differs #White List or Black List in share/online if differs
# if ($WingetUpdatePath -ne $ListPath){ if ($WingetUpdatePath -ne $ListPath){
# Test-ListPath $ListPath $UseWhiteList Test-ListPath $ListPath $UseWhiteList
# } }