Fixes and NoClean for lists

pull/166/head
KnifMelti 2022-09-20 00:54:23 +02:00
parent 515bdfd0a5
commit e05cf326a7
2 changed files with 25 additions and 11 deletions

View File

@ -196,7 +196,7 @@ function Install-WingetAutoUpdate {
#White List or Black List source not Local if differs #White List or Black List source not Local if differs
if ($WingetUpdatePath -ne $ListPath){ if ($WingetUpdatePath -ne $ListPath){
Test-ListPath $ListPath $UseWhiteList $NoClean = Test-ListPath $ListPath $UseWhiteList
} }

View File

@ -9,21 +9,26 @@ function Test-ListPath ($ListPath, $UseWhiteList) {
$ListType="excluded" $ListType="excluded"
} }
$LocalList = -join($WingetUpdatePath, "\", $ListType, "_apps.txt") $LocalList = -join($WingetUpdatePath, "\", $ListType, "_apps.txt")
$dateLocal = (Get-Item "$LocalList").LastWriteTime.ToString("yyyy-MM-dd HH:mm:ss") if (Test-Path "$LocalList") {
$dateLocal = (Get-Item "$LocalList").LastWriteTime.ToString("yyyy-MM-dd HH:mm:ss")
}
$PathInfo=[System.Uri]$ListPath $PathInfo=[System.Uri]$ListPath
if($PathInfo.IsUnc){ if($PathInfo.IsUnc){
$PathType="UNC Path" $PathType="UNC Path"
$ExternalList = -join($ListPath, "\", $ListType, "_apps.txt") $ExternalList = -join($ListPath, "\", $ListType, "_apps.txt")
if(Test-Path -Path $ExternalList -PathType leaf){ if(Test-Path -Path $ExternalList -PathType leaf){
Write-Output "Given path $ListPath type is $PathType and $ExternalList is available..." Write-Host "Given path $ListPath type is $PathType and $ExternalList is available..."
$dateExternal = (Get-Item "$ListPath").LastWriteTime.ToString("yyyy-MM-dd HH:mm:ss") $dateExternal = (Get-Item "$ExternalList").LastWriteTime.ToString("yyyy-MM-dd HH:mm:ss")
if ($dateExternal -gt $dateLocal) { if ($dateExternal -gt $dateLocal) {
Write-Host("$ExternalList is newer than $LocalList") Write-Host("$ExternalList is newer than $LocalList")
return $true
} }
return $false
} }
else { else {
Write-Output "Given path $ListPath type is $PathType and $ExternalList is not available..." Write-Host "Given path $ListPath type is $PathType and $ExternalList is not available..."
return $false
} }
} }
elseif ($ListPath -like "http*"){ elseif ($ListPath -like "http*"){
@ -32,36 +37,45 @@ function Test-ListPath ($ListPath, $UseWhiteList) {
$wc = New-Object System.Net.WebClient $wc = New-Object System.Net.WebClient
try { try {
$wc.OpenRead("$ExternalList").Close() | Out-Null $wc.OpenRead("$ExternalList").Close() | Out-Null
Write-Output "Given path $ListPath type is $PathType and $ExternalList is available..." Write-Host "Given path $ListPath type is $PathType and $ExternalList is available..."
$dateExternal = ([DateTime]$wc.ResponseHeaders['Last-Modified']).ToString("yyyy-MM-dd HH:mm:ss") $dateExternal = ([DateTime]$wc.ResponseHeaders['Last-Modified']).ToString("yyyy-MM-dd HH:mm:ss")
if ($dateExternal -gt $dateLocal) { if ($dateExternal -gt $dateLocal) {
Write-Host("$ExternalList is newer than $LocalList") Write-Host("$ExternalList is newer than $LocalList")
return $true
} }
return $false
} }
catch { catch {
Write-Output "Given path $ListPath type is $PathType and $ExternalList is not available..." Write-Host "Given path $ListPath type is $PathType and $ExternalList is not available..."
return $false
} }
} }
else { else {
$PathType="Local Path" $PathType="Local Path"
$ExternalList = -join($ListPath, "\", $ListType, "_apps.txt") $ExternalList = -join($ListPath, "\", $ListType, "_apps.txt")
if(Test-Path -Path $ExternalList -PathType leaf){ if(Test-Path -Path $ExternalList -PathType leaf){
Write-Output "Given path $ListPath type is $PathType and $ExternalList is available..." Write-Host "Given path $ListPath type is $PathType and $ExternalList is available..."
$dateExternal = (Get-Item "$ListPath").LastWriteTime.ToString("yyyy-MM-dd HH:mm:ss") $dateExternal = (Get-Item "$ExternalList").LastWriteTime.ToString("yyyy-MM-dd HH:mm:ss")
if ($dateExternal -gt $dateLocal) { if ($dateExternal -gt $dateLocal) {
Write-Host("$ExternalList is newer than $LocalList") Write-Host("$ExternalList is newer than $LocalList")
return $true
} }
return $false
} }
else { else {
Write-Output "Given path $ListPath type is $PathType and $ExternalList is not available..." Write-Host "Given path $ListPath type is $PathType and $ExternalList is not available..."
return $false
} }
} }
} }
$WingetUpdatePath = "$env:ProgramData\Winget-AutoUpdate" $WingetUpdatePath = "$env:ProgramData\Winget-AutoUpdate"
$ListPath = "https://www.knifmelti.se" $ListPath = "https://www.knifmelti.se"
#$ListPath = "D:\Temp"
#$UseWhiteList = $true #$UseWhiteList = $true
#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 $NoClean = Test-ListPath $ListPath $UseWhiteList
} }
Write-Host $NoClean