From d30271249a58f04f3623047fe97749c43e5d933d Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Sat, 17 Sep 2022 21:22:41 +0200 Subject: [PATCH 01/18] Parameter + Function $ListPath --- Winget-AutoUpdate-Install.ps1 | 1 + Winget-AutoUpdate/functions/Test-ListPath.ps1 | 6 ++++++ 2 files changed, 7 insertions(+) create mode 100644 Winget-AutoUpdate/functions/Test-ListPath.ps1 diff --git a/Winget-AutoUpdate-Install.ps1 b/Winget-AutoUpdate-Install.ps1 index 68fb824..9c27ece 100644 --- a/Winget-AutoUpdate-Install.ps1 +++ b/Winget-AutoUpdate-Install.ps1 @@ -58,6 +58,7 @@ Run WAU on metered connection. Default No. param( [Parameter(Mandatory = $False)] [Alias('S')] [Switch] $Silent = $false, [Parameter(Mandatory = $False)] [Alias('Path')] [String] $WingetUpdatePath = "$env:ProgramData\Winget-AutoUpdate", + [Parameter(Mandatory = $False)] [Alias('List')] [String] $ListPath = $WingetUpdatePath, [Parameter(Mandatory = $False)] [Switch] $DoNotUpdate = $false, [Parameter(Mandatory = $False)] [Switch] $DisableWAUAutoUpdate = $false, [Parameter(Mandatory = $False)] [Switch] $RunOnMetered = $false, diff --git a/Winget-AutoUpdate/functions/Test-ListPath.ps1 b/Winget-AutoUpdate/functions/Test-ListPath.ps1 new file mode 100644 index 0000000..dde6b28 --- /dev/null +++ b/Winget-AutoUpdate/functions/Test-ListPath.ps1 @@ -0,0 +1,6 @@ +#Function to check Black/White List Path + +function Test-ListPath ($ListPath, $UseWhiteList) { + + +} From 43d531d51f59752c552b3ad4135f459723abc799 Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Sun, 18 Sep 2022 20:25:14 +0200 Subject: [PATCH 02/18] Prepared UNC/Local --- Winget-AutoUpdate-Install.ps1 | 6 +++ Winget-AutoUpdate/functions/Test-ListPath.ps1 | 46 ++++++++++++++++++- 2 files changed, 51 insertions(+), 1 deletion(-) diff --git a/Winget-AutoUpdate-Install.ps1 b/Winget-AutoUpdate-Install.ps1 index 9c27ece..3bd5daa 100644 --- a/Winget-AutoUpdate-Install.ps1 +++ b/Winget-AutoUpdate-Install.ps1 @@ -193,6 +193,12 @@ function Install-WingetAutoUpdate { } } Copy-Item -Path "$PSScriptRoot\Winget-AutoUpdate\*" -Destination $WingetUpdatePath -Recurse -Force -ErrorAction SilentlyContinue + + #White List or Black List source not Local if differs + if ($WingetUpdatePath -ne $ListPath){ + Test-ListPath $ListPath $UseWhiteList + } + #White List or Black List apps if ($UseWhiteList) { diff --git a/Winget-AutoUpdate/functions/Test-ListPath.ps1 b/Winget-AutoUpdate/functions/Test-ListPath.ps1 index dde6b28..e4e831e 100644 --- a/Winget-AutoUpdate/functions/Test-ListPath.ps1 +++ b/Winget-AutoUpdate/functions/Test-ListPath.ps1 @@ -1,6 +1,50 @@ #Function to check Black/White List Path function Test-ListPath ($ListPath, $UseWhiteList) { - + # UNC or Local Path + if ($UseWhiteList){ + $ListType="included" + } + else { + $ListType="excluded" + } + $Path = $ListPath + $PathInfo=[System.Uri]$Path + $ListPath = -join($Path, "\", "$ListType", "_apps.txt") + if($PathInfo.IsUnc){ + $PathType="UNC Path" + if(Test-Path -Path $ListPath -PathType leaf){ + Write-Output "Given path $Path type is $PathType and $ListPath is available..." + } + else { + Write-Output "Given path $Path type is $PathType and $ListPath is not available..." + } + } + elseif ($ListPath -like "http"){ + $wc = New-Object System.Net.WebClient + try { + $wc.OpenRead('http://www.domain.com/test.csv') | Out-Null + Write-Output 'File Exists' + } catch { + Write-Output 'Error / Not Found' + } + } + else { + $PathType="Local Path" + if(Test-Path -Path $ListPath -PathType leaf){ + Write-Output "Given path $Path type is $PathType and $ListPath is available..." + } + else { + Write-Output "Given path $Path type is $PathType and $ListPath is not available..." + } + } } + +$WingetUpdatePath = "$env:ProgramData\Winget-AutoUpdate" +$ListPath = "D:\Temp" +$UseWhiteList = $true +#White List or Black List in share/online if differs +if ($WingetUpdatePath -ne $ListPath){ + Test-ListPath $ListPath $UseWhiteList +} From c928b7aa933962c46e959718a17b25e5a9d69d33 Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Sun, 18 Sep 2022 20:40:22 +0200 Subject: [PATCH 03/18] Prepared Web Path --- Winget-AutoUpdate/functions/Test-ListPath.ps1 | 28 +++++++++++-------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/Winget-AutoUpdate/functions/Test-ListPath.ps1 b/Winget-AutoUpdate/functions/Test-ListPath.ps1 index e4e831e..7b50f1d 100644 --- a/Winget-AutoUpdate/functions/Test-ListPath.ps1 +++ b/Winget-AutoUpdate/functions/Test-ListPath.ps1 @@ -10,9 +10,10 @@ function Test-ListPath ($ListPath, $UseWhiteList) { } $Path = $ListPath $PathInfo=[System.Uri]$Path - $ListPath = -join($Path, "\", "$ListType", "_apps.txt") + if($PathInfo.IsUnc){ $PathType="UNC Path" + $ListPath = -join($Path, "\", "$ListType", "_apps.txt") if(Test-Path -Path $ListPath -PathType leaf){ Write-Output "Given path $Path type is $PathType and $ListPath is available..." } @@ -20,17 +21,20 @@ function Test-ListPath ($ListPath, $UseWhiteList) { Write-Output "Given path $Path type is $PathType and $ListPath is not available..." } } - elseif ($ListPath -like "http"){ + elseif ($ListPath -like "http*"){ + $PathType="Web Path" + $ListPath = -join($Path, "/", "$ListType", "_apps.txt") $wc = New-Object System.Net.WebClient try { - $wc.OpenRead('http://www.domain.com/test.csv') | Out-Null - Write-Output 'File Exists' + $wc.OpenRead("$ListPath") | Out-Null + Write-Output "Given path $Path type is $PathType and $ListPath is available..." } catch { - Write-Output 'Error / Not Found' + Write-Output "Given path $Path type is $PathType and $ListPath is not available..." } } else { $PathType="Local Path" + $ListPath = -join($Path, "\", "$ListType", "_apps.txt") if(Test-Path -Path $ListPath -PathType leaf){ Write-Output "Given path $Path type is $PathType and $ListPath is available..." } @@ -41,10 +45,10 @@ function Test-ListPath ($ListPath, $UseWhiteList) { } -$WingetUpdatePath = "$env:ProgramData\Winget-AutoUpdate" -$ListPath = "D:\Temp" -$UseWhiteList = $true -#White List or Black List in share/online if differs -if ($WingetUpdatePath -ne $ListPath){ - Test-ListPath $ListPath $UseWhiteList -} +# $WingetUpdatePath = "$env:ProgramData\Winget-AutoUpdate" +# $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 +# } From 817f61adab63d34cb4c129c8bf51220e05f74391 Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Mon, 19 Sep 2022 21:12:00 +0200 Subject: [PATCH 04/18] Compare LastModifiedDate, http remaining --- Winget-AutoUpdate/functions/Test-ListPath.ps1 | 61 +++++++++++-------- 1 file changed, 37 insertions(+), 24 deletions(-) diff --git a/Winget-AutoUpdate/functions/Test-ListPath.ps1 b/Winget-AutoUpdate/functions/Test-ListPath.ps1 index 7b50f1d..870dad4 100644 --- a/Winget-AutoUpdate/functions/Test-ListPath.ps1 +++ b/Winget-AutoUpdate/functions/Test-ListPath.ps1 @@ -1,54 +1,67 @@ #Function to check Black/White List Path function Test-ListPath ($ListPath, $UseWhiteList) { - # UNC or Local Path + # UNC, Web or Local Path if ($UseWhiteList){ $ListType="included" } else { $ListType="excluded" } - $Path = $ListPath - $PathInfo=[System.Uri]$Path + $LocalList = -join($WingetUpdatePath, "\", $ListType, "_apps.txt") + $ExternalList = $ListPath + $PathInfo=[System.Uri]$ListPath if($PathInfo.IsUnc){ $PathType="UNC Path" - $ListPath = -join($Path, "\", "$ListType", "_apps.txt") - if(Test-Path -Path $ListPath -PathType leaf){ - Write-Output "Given path $Path type is $PathType and $ListPath is available..." + $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) { + Write-Host("$ExternalList was modified after $LocalList") } + } 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*"){ $PathType="Web Path" - $ListPath = -join($Path, "/", "$ListType", "_apps.txt") + $ExternalList = -join($ListPath, "/", $ListType, "_apps.txt") $wc = New-Object System.Net.WebClient try { - $wc.OpenRead("$ListPath") | Out-Null - Write-Output "Given path $Path type is $PathType and $ListPath is available..." - } catch { - Write-Output "Given path $Path type is $PathType and $ListPath is not available..." + $wc.OpenRead("$ExternalList") | Out-Null + Write-Output "Given path $ListPath type is $PathType and $ExternalList is available..." + } + catch { + Write-Output "Given path $ListPath type is $PathType and $ExternalList is not available..." } } else { $PathType="Local Path" - $ListPath = -join($Path, "\", "$ListType", "_apps.txt") - if(Test-Path -Path $ListPath -PathType leaf){ - Write-Output "Given path $Path type is $PathType and $ListPath is available..." + $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) { + Write-Host("$ExternalList was modified after $LocalList") } + } 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" -# $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 -# } +$WingetUpdatePath = "$env:ProgramData\Winget-AutoUpdate" +$ListPath = "D:\Temp" +$UseWhiteList = $false +#White List or Black List in share/online if differs +if ($WingetUpdatePath -ne $ListPath){ + Test-ListPath $ListPath $UseWhiteList +} From 895222c784f4ebd3aae8e06856a61ac42b6b469b Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Mon, 19 Sep 2022 23:10:00 +0200 Subject: [PATCH 05/18] Compare done, actions now... --- Winget-AutoUpdate/functions/Test-ListPath.ps1 | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/Winget-AutoUpdate/functions/Test-ListPath.ps1 b/Winget-AutoUpdate/functions/Test-ListPath.ps1 index 870dad4..7265d06 100644 --- a/Winget-AutoUpdate/functions/Test-ListPath.ps1 +++ b/Winget-AutoUpdate/functions/Test-ListPath.ps1 @@ -9,7 +9,6 @@ function Test-ListPath ($ListPath, $UseWhiteList) { $ListType="excluded" } $LocalList = -join($WingetUpdatePath, "\", $ListType, "_apps.txt") - $ExternalList = $ListPath $PathInfo=[System.Uri]$ListPath if($PathInfo.IsUnc){ @@ -17,11 +16,10 @@ function Test-ListPath ($ListPath, $UseWhiteList) { $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) { - Write-Host("$ExternalList was modified after $LocalList") + Write-Host("$ExternalList is newer than $LocalList") } } else { @@ -33,8 +31,13 @@ function Test-ListPath ($ListPath, $UseWhiteList) { $ExternalList = -join($ListPath, "/", $ListType, "_apps.txt") $wc = New-Object System.Net.WebClient try { - $wc.OpenRead("$ExternalList") | Out-Null + $wc.OpenRead("$ExternalList").Close() | Out-Null Write-Output "Given path $ListPath type is $PathType and $ExternalList is available..." + $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..." @@ -45,11 +48,10 @@ function Test-ListPath ($ListPath, $UseWhiteList) { $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) { - Write-Host("$ExternalList was modified after $LocalList") + Write-Host("$ExternalList is newer than $LocalList") } } else { @@ -59,8 +61,8 @@ function Test-ListPath ($ListPath, $UseWhiteList) { } $WingetUpdatePath = "$env:ProgramData\Winget-AutoUpdate" -$ListPath = "D:\Temp" -$UseWhiteList = $false +$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 From ec73a55fe4a5b3eb7dcc58a5fc772effcc0e5436 Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Mon, 19 Sep 2022 23:45:18 +0200 Subject: [PATCH 06/18] Format Date/Time --- Winget-AutoUpdate/functions/Test-ListPath.ps1 | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Winget-AutoUpdate/functions/Test-ListPath.ps1 b/Winget-AutoUpdate/functions/Test-ListPath.ps1 index 7265d06..a7eb71d 100644 --- a/Winget-AutoUpdate/functions/Test-ListPath.ps1 +++ b/Winget-AutoUpdate/functions/Test-ListPath.ps1 @@ -16,8 +16,8 @@ function Test-ListPath ($ListPath, $UseWhiteList) { $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 + $dateLocal = (Get-Item "$LocalList").LastWriteTime.ToString("yyyy-MM-dd HH:mm:ss") + $dateExternal = (Get-Item "$ListPath").LastWriteTime.ToString("yyyy-MM-dd HH:mm:ss") if ($dateExternal -gt $dateLocal) { Write-Host("$ExternalList is newer than $LocalList") } @@ -33,8 +33,8 @@ function Test-ListPath ($ListPath, $UseWhiteList) { try { $wc.OpenRead("$ExternalList").Close() | Out-Null Write-Output "Given path $ListPath type is $PathType and $ExternalList is available..." - $dateLocal = (Get-Item "$LocalList").LastWriteTime - $dateExternal = $wc.ResponseHeaders['Last-Modified'] + $dateLocal = (Get-Item "$LocalList").LastWriteTime.ToString("yyyy-MM-dd HH:mm:ss") + $dateExternal = ([DateTime]$wc.ResponseHeaders['Last-Modified']).ToString("yyyy-MM-dd HH:mm:ss") if ($dateExternal -gt $dateLocal) { Write-Host("$ExternalList is newer than $LocalList") } @@ -48,8 +48,8 @@ function Test-ListPath ($ListPath, $UseWhiteList) { $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 + $dateLocal = (Get-Item "$LocalList").LastWriteTime.ToString("yyyy-MM-dd HH:mm:ss") + $dateExternal = (Get-Item "$ListPath").LastWriteTime.ToString("yyyy-MM-dd HH:mm:ss") if ($dateExternal -gt $dateLocal) { Write-Host("$ExternalList is newer than $LocalList") } From 515bdfd0a59be8bd50dff5ee54024598411416c0 Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Mon, 19 Sep 2022 23:55:07 +0200 Subject: [PATCH 07/18] Optimized $dateLocal --- Winget-AutoUpdate/functions/Test-ListPath.ps1 | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Winget-AutoUpdate/functions/Test-ListPath.ps1 b/Winget-AutoUpdate/functions/Test-ListPath.ps1 index a7eb71d..c472734 100644 --- a/Winget-AutoUpdate/functions/Test-ListPath.ps1 +++ b/Winget-AutoUpdate/functions/Test-ListPath.ps1 @@ -9,6 +9,7 @@ function Test-ListPath ($ListPath, $UseWhiteList) { $ListType="excluded" } $LocalList = -join($WingetUpdatePath, "\", $ListType, "_apps.txt") + $dateLocal = (Get-Item "$LocalList").LastWriteTime.ToString("yyyy-MM-dd HH:mm:ss") $PathInfo=[System.Uri]$ListPath if($PathInfo.IsUnc){ @@ -16,7 +17,6 @@ function Test-ListPath ($ListPath, $UseWhiteList) { $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.ToString("yyyy-MM-dd HH:mm:ss") $dateExternal = (Get-Item "$ListPath").LastWriteTime.ToString("yyyy-MM-dd HH:mm:ss") if ($dateExternal -gt $dateLocal) { Write-Host("$ExternalList is newer than $LocalList") @@ -33,7 +33,6 @@ function Test-ListPath ($ListPath, $UseWhiteList) { try { $wc.OpenRead("$ExternalList").Close() | Out-Null Write-Output "Given path $ListPath type is $PathType and $ExternalList is available..." - $dateLocal = (Get-Item "$LocalList").LastWriteTime.ToString("yyyy-MM-dd HH:mm:ss") $dateExternal = ([DateTime]$wc.ResponseHeaders['Last-Modified']).ToString("yyyy-MM-dd HH:mm:ss") if ($dateExternal -gt $dateLocal) { Write-Host("$ExternalList is newer than $LocalList") @@ -48,7 +47,6 @@ function Test-ListPath ($ListPath, $UseWhiteList) { $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.ToString("yyyy-MM-dd HH:mm:ss") $dateExternal = (Get-Item "$ListPath").LastWriteTime.ToString("yyyy-MM-dd HH:mm:ss") if ($dateExternal -gt $dateLocal) { Write-Host("$ExternalList is newer than $LocalList") From e05cf326a7c637cf32984a1d2476eac12c43d226 Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Tue, 20 Sep 2022 00:54:23 +0200 Subject: [PATCH 08/18] Fixes and NoClean for lists --- Winget-AutoUpdate-Install.ps1 | 2 +- Winget-AutoUpdate/functions/Test-ListPath.ps1 | 34 +++++++++++++------ 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/Winget-AutoUpdate-Install.ps1 b/Winget-AutoUpdate-Install.ps1 index 3bd5daa..e36a3ab 100644 --- a/Winget-AutoUpdate-Install.ps1 +++ b/Winget-AutoUpdate-Install.ps1 @@ -196,7 +196,7 @@ function Install-WingetAutoUpdate { #White List or Black List source not Local if differs if ($WingetUpdatePath -ne $ListPath){ - Test-ListPath $ListPath $UseWhiteList + $NoClean = Test-ListPath $ListPath $UseWhiteList } diff --git a/Winget-AutoUpdate/functions/Test-ListPath.ps1 b/Winget-AutoUpdate/functions/Test-ListPath.ps1 index c472734..3598c46 100644 --- a/Winget-AutoUpdate/functions/Test-ListPath.ps1 +++ b/Winget-AutoUpdate/functions/Test-ListPath.ps1 @@ -9,21 +9,26 @@ function Test-ListPath ($ListPath, $UseWhiteList) { $ListType="excluded" } $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 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..." - $dateExternal = (Get-Item "$ListPath").LastWriteTime.ToString("yyyy-MM-dd HH:mm:ss") + Write-Host "Given path $ListPath type is $PathType and $ExternalList is available..." + $dateExternal = (Get-Item "$ExternalList").LastWriteTime.ToString("yyyy-MM-dd HH:mm:ss") if ($dateExternal -gt $dateLocal) { Write-Host("$ExternalList is newer than $LocalList") + return $true } + return $false } 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*"){ @@ -32,36 +37,45 @@ function Test-ListPath ($ListPath, $UseWhiteList) { $wc = New-Object System.Net.WebClient try { $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") if ($dateExternal -gt $dateLocal) { Write-Host("$ExternalList is newer than $LocalList") + return $true } + return $false } 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 { $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..." - $dateExternal = (Get-Item "$ListPath").LastWriteTime.ToString("yyyy-MM-dd HH:mm:ss") + Write-Host "Given path $ListPath type is $PathType and $ExternalList is available..." + $dateExternal = (Get-Item "$ExternalList").LastWriteTime.ToString("yyyy-MM-dd HH:mm:ss") if ($dateExternal -gt $dateLocal) { Write-Host("$ExternalList is newer than $LocalList") + return $true } + return $false } 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" $ListPath = "https://www.knifmelti.se" +#$ListPath = "D:\Temp" #$UseWhiteList = $true #White List or Black List in share/online if differs if ($WingetUpdatePath -ne $ListPath){ - Test-ListPath $ListPath $UseWhiteList + $NoClean = Test-ListPath $ListPath $UseWhiteList } + +Write-Host $NoClean From 6ce3171b67a12c00ce590efa63169cee30f6bf1a Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Tue, 20 Sep 2022 01:02:51 +0200 Subject: [PATCH 09/18] Optimized --- Winget-AutoUpdate/functions/Test-ListPath.ps1 | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/Winget-AutoUpdate/functions/Test-ListPath.ps1 b/Winget-AutoUpdate/functions/Test-ListPath.ps1 index 3598c46..e60e653 100644 --- a/Winget-AutoUpdate/functions/Test-ListPath.ps1 +++ b/Winget-AutoUpdate/functions/Test-ListPath.ps1 @@ -1,4 +1,4 @@ -#Function to check Black/White List Path +#Function to check Black/White List External Path function Test-ListPath ($ListPath, $UseWhiteList) { # UNC, Web or Local Path @@ -24,11 +24,9 @@ function Test-ListPath ($ListPath, $UseWhiteList) { Write-Host("$ExternalList is newer than $LocalList") return $true } - return $false } else { Write-Host "Given path $ListPath type is $PathType and $ExternalList is not available..." - return $false } } elseif ($ListPath -like "http*"){ @@ -43,11 +41,9 @@ function Test-ListPath ($ListPath, $UseWhiteList) { Write-Host("$ExternalList is newer than $LocalList") return $true } - return $false } catch { Write-Host "Given path $ListPath type is $PathType and $ExternalList is not available..." - return $false } } else { @@ -60,18 +56,19 @@ function Test-ListPath ($ListPath, $UseWhiteList) { Write-Host("$ExternalList is newer than $LocalList") return $true } - return $false } else { Write-Host "Given path $ListPath type is $PathType and $ExternalList is not available..." - return $false } } + return $false } $WingetUpdatePath = "$env:ProgramData\Winget-AutoUpdate" $ListPath = "https://www.knifmelti.se" #$ListPath = "D:\Temp" +#$ListPath = "\\TempSERVER" + #$UseWhiteList = $true #White List or Black List in share/online if differs if ($WingetUpdatePath -ne $ListPath){ From 9133b9bac579fd38d8e3bfdd2a6a905745834de9 Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Tue, 20 Sep 2022 01:32:23 +0200 Subject: [PATCH 10/18] More optimizations --- Winget-AutoUpdate/functions/Test-ListPath.ps1 | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Winget-AutoUpdate/functions/Test-ListPath.ps1 b/Winget-AutoUpdate/functions/Test-ListPath.ps1 index e60e653..2a2bb91 100644 --- a/Winget-AutoUpdate/functions/Test-ListPath.ps1 +++ b/Winget-AutoUpdate/functions/Test-ListPath.ps1 @@ -12,11 +12,11 @@ function Test-ListPath ($ListPath, $UseWhiteList) { if (Test-Path "$LocalList") { $dateLocal = (Get-Item "$LocalList").LastWriteTime.ToString("yyyy-MM-dd HH:mm:ss") } + $ExternalList = -join($ListPath, "\", $ListType, "_apps.txt") $PathInfo=[System.Uri]$ListPath if($PathInfo.IsUnc){ $PathType="UNC Path" - $ExternalList = -join($ListPath, "\", $ListType, "_apps.txt") if(Test-Path -Path $ExternalList -PathType leaf){ Write-Host "Given path $ListPath type is $PathType and $ExternalList is available..." $dateExternal = (Get-Item "$ExternalList").LastWriteTime.ToString("yyyy-MM-dd HH:mm:ss") @@ -48,7 +48,6 @@ function Test-ListPath ($ListPath, $UseWhiteList) { } else { $PathType="Local Path" - $ExternalList = -join($ListPath, "\", $ListType, "_apps.txt") if(Test-Path -Path $ExternalList -PathType leaf){ Write-Host "Given path $ListPath type is $PathType and $ExternalList is available..." $dateExternal = (Get-Item "$ExternalList").LastWriteTime.ToString("yyyy-MM-dd HH:mm:ss") @@ -68,8 +67,8 @@ $WingetUpdatePath = "$env:ProgramData\Winget-AutoUpdate" $ListPath = "https://www.knifmelti.se" #$ListPath = "D:\Temp" #$ListPath = "\\TempSERVER" - #$UseWhiteList = $true + #White List or Black List in share/online if differs if ($WingetUpdatePath -ne $ListPath){ $NoClean = Test-ListPath $ListPath $UseWhiteList From 077dee73dc484c0da5e00ea18e65b9f0462aedac Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Tue, 20 Sep 2022 03:08:06 +0200 Subject: [PATCH 11/18] Finalized Install --- Winget-AutoUpdate/functions/Test-ListPath.ps1 | 55 ++++++++++--------- 1 file changed, 29 insertions(+), 26 deletions(-) diff --git a/Winget-AutoUpdate/functions/Test-ListPath.ps1 b/Winget-AutoUpdate/functions/Test-ListPath.ps1 index 2a2bb91..7644001 100644 --- a/Winget-AutoUpdate/functions/Test-ListPath.ps1 +++ b/Winget-AutoUpdate/functions/Test-ListPath.ps1 @@ -16,62 +16,65 @@ function Test-ListPath ($ListPath, $UseWhiteList) { $PathInfo=[System.Uri]$ListPath if($PathInfo.IsUnc){ - $PathType="UNC Path" if(Test-Path -Path $ExternalList -PathType leaf){ - Write-Host "Given path $ListPath type is $PathType and $ExternalList is available..." $dateExternal = (Get-Item "$ExternalList").LastWriteTime.ToString("yyyy-MM-dd HH:mm:ss") if ($dateExternal -gt $dateLocal) { - Write-Host("$ExternalList is newer than $LocalList") + try { + Copy-Item $ExternalList -Destination $LocalList -Force + } + catch { + return $False + } return $true } } - else { - Write-Host "Given path $ListPath type is $PathType and $ExternalList is not available..." - } } elseif ($ListPath -like "http*"){ - $PathType="Web Path" $ExternalList = -join($ListPath, "/", $ListType, "_apps.txt") $wc = New-Object System.Net.WebClient try { $wc.OpenRead("$ExternalList").Close() | Out-Null - 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") if ($dateExternal -gt $dateLocal) { - Write-Host("$ExternalList is newer than $LocalList") + try { + $wc.DownloadFile($ExternalList, $LocalList) + } + catch { + return $False + } return $true } } catch { - Write-Host "Given path $ListPath type is $PathType and $ExternalList is not available..." + return $False } } else { - $PathType="Local Path" if(Test-Path -Path $ExternalList -PathType leaf){ - Write-Host "Given path $ListPath type is $PathType and $ExternalList is available..." $dateExternal = (Get-Item "$ExternalList").LastWriteTime.ToString("yyyy-MM-dd HH:mm:ss") if ($dateExternal -gt $dateLocal) { - Write-Host("$ExternalList is newer than $LocalList") + try { + Copy-Item $ExternalList -Destination $LocalList -Force + } + catch { + return $False + } return $true } } - else { - Write-Host "Given path $ListPath type is $PathType and $ExternalList is not available..." - } } return $false } -$WingetUpdatePath = "$env:ProgramData\Winget-AutoUpdate" -$ListPath = "https://www.knifmelti.se" -#$ListPath = "D:\Temp" -#$ListPath = "\\TempSERVER" -#$UseWhiteList = $true +# $WingetUpdatePath = "$env:ProgramData\Winget-AutoUpdate" +# $ListPath = "https://www.knifmelti.se" +# #$ListPath = "D:\Temp" +# #$ListPath = "\\TempSERVER" +# #$UseWhiteList = $true -#White List or Black List in share/online if differs -if ($WingetUpdatePath -ne $ListPath){ - $NoClean = Test-ListPath $ListPath $UseWhiteList -} +# #White List or Black List in share/online if differs +# if ($WingetUpdatePath -ne $ListPath){ +# $NoClean = Test-ListPath $ListPath $UseWhiteList +# } -Write-Host $NoClean +# Write-Host $NoClean From e7c73f8b1bb2e976a88709390ec4d20da928b5ef Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Tue, 20 Sep 2022 03:22:29 +0200 Subject: [PATCH 12/18] .PARAMETER ListPath and .Example --- Winget-AutoUpdate-Install.ps1 | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Winget-AutoUpdate-Install.ps1 b/Winget-AutoUpdate-Install.ps1 index e36a3ab..d81c184 100644 --- a/Winget-AutoUpdate-Install.ps1 +++ b/Winget-AutoUpdate-Install.ps1 @@ -22,6 +22,9 @@ Disable Winget-AutoUpdate update checking. By default, WAU auto update if new ve .PARAMETER UseWhiteList Use White List instead of Black List. This setting will not create the "exclude_apps.txt" but "include_apps.txt" +.PARAMETER ListPath +Get Black/White List from Path (UNC/Web/Local). Default: C:\ProgramData\Winget-AutoUpdate\ + .PARAMETER Uninstall Remove scheduled tasks and scripts. @@ -46,6 +49,9 @@ Run WAU on metered connection. Default No. .EXAMPLE .\winget-install-and-update.ps1 -Silent -UseWhiteList +.EXAMPLE +.\winget-install-and-update.ps1 -Silent -ListPath https://www.domain.com/WAULists + .EXAMPLE .\winget-install-and-update.ps1 -Silent -UpdatesAtLogon -UpdatesInterval Weekly From d296f955ce4e49497bd3ff8bf88e8a068517c2a9 Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Tue, 20 Sep 2022 21:33:46 +0200 Subject: [PATCH 13/18] Fully functional external lists (UNC/Web/Local) --- Winget-AutoUpdate-Install.ps1 | 84 +++++++++++++++++-- Winget-AutoUpdate/functions/Test-ListPath.ps1 | 4 +- Winget-AutoUpdate/winget-upgrade.ps1 | 9 ++ 3 files changed, 89 insertions(+), 8 deletions(-) diff --git a/Winget-AutoUpdate-Install.ps1 b/Winget-AutoUpdate-Install.ps1 index d81c184..5c8044a 100644 --- a/Winget-AutoUpdate-Install.ps1 +++ b/Winget-AutoUpdate-Install.ps1 @@ -180,6 +180,72 @@ function Install-WinGet { } +function Test-ListPath ($ListPath, $UseWhiteList) { + # UNC, Web or Local Path + if ($UseWhiteList){ + $ListType="included" + } + else { + $ListType="excluded" + } + $LocalList = -join($WingetUpdatePath, "\", $ListType, "_apps.txt") + if (Test-Path "$LocalList") { + $dateLocal = (Get-Item "$LocalList").LastWriteTime.ToString("yyyy-MM-dd HH:mm:ss") + } + $ExternalList = -join($ListPath, "\", $ListType, "_apps.txt") + $PathInfo=[System.Uri]$ListPath + + if($PathInfo.IsUnc){ + if(Test-Path -Path $ExternalList -PathType leaf){ + $dateExternal = (Get-Item "$ExternalList").LastWriteTime.ToString("yyyy-MM-dd HH:mm:ss") + if ($dateExternal -gt $dateLocal) { + try { + Copy-Item $ExternalList -Destination $LocalList -Force + } + catch { + return $False + } + return $true + } + } + } + elseif ($ListPath -like "http*"){ + $ExternalList = -join($ListPath, "/", $ListType, "_apps.txt") + $wc = New-Object System.Net.WebClient + try { + $wc.OpenRead("$ExternalList").Close() | Out-Null + $dateExternal = ([DateTime]$wc.ResponseHeaders['Last-Modified']).ToString("yyyy-MM-dd HH:mm:ss") + if ($dateExternal -gt $dateLocal) { + try { + $wc.DownloadFile($ExternalList, $LocalList) + } + catch { + return $False + } + return $true + } + } + catch { + return $False + } + } + else { + if(Test-Path -Path $ExternalList -PathType leaf){ + $dateExternal = (Get-Item "$ExternalList").LastWriteTime.ToString("yyyy-MM-dd HH:mm:ss") + if ($dateExternal -gt $dateLocal) { + try { + Copy-Item $ExternalList -Destination $LocalList -Force + } + catch { + return $False + } + return $true + } + } + } + return $false +} + function Install-WingetAutoUpdate { Write-Host "`nInstalling WAU..." -ForegroundColor Yellow @@ -188,8 +254,17 @@ function Install-WingetAutoUpdate { #Copy files to location (and clean old install) if (!(Test-Path $WingetUpdatePath)) { New-Item -ItemType Directory -Force -Path $WingetUpdatePath | Out-Null + #White List or Black List source not Local if differs + if ($WingetUpdatePath -ne $ListPath){ + $NoClean = Test-ListPath $ListPath $UseWhiteList + } + } else { + #White List or Black List source not Local if differs + if ($WingetUpdatePath -ne $ListPath){ + $NoClean = Test-ListPath $ListPath $UseWhiteList + } if (!$NoClean) { Remove-Item -Path "$WingetUpdatePath\*" -Exclude *.log -Recurse -Force } @@ -200,12 +275,6 @@ function Install-WingetAutoUpdate { } Copy-Item -Path "$PSScriptRoot\Winget-AutoUpdate\*" -Destination $WingetUpdatePath -Recurse -Force -ErrorAction SilentlyContinue - #White List or Black List source not Local if differs - if ($WingetUpdatePath -ne $ListPath){ - $NoClean = Test-ListPath $ListPath $UseWhiteList - } - - #White List or Black List apps if ($UseWhiteList) { if (!$NoClean) { @@ -279,6 +348,9 @@ function Install-WingetAutoUpdate { New-ItemProperty $regPath -Name DisplayIcon -Value "C:\Windows\System32\shell32.dll,-16739" -Force | Out-Null New-ItemProperty $regPath -Name DisplayVersion -Value $WAUVersion -Force | Out-Null New-ItemProperty $regPath -Name InstallLocation -Value $WingetUpdatePath -Force | Out-Null + if ($WingetUpdatePath -ne $ListPath){ + New-ItemProperty $regPath -Name ListPath -Value $ListPath -Force | Out-Null + } New-ItemProperty $regPath -Name UninstallString -Value "powershell.exe -noprofile -executionpolicy bypass -file `"$WingetUpdatePath\WAU-Uninstall.ps1`"" -Force | Out-Null New-ItemProperty $regPath -Name QuietUninstallString -Value "powershell.exe -noprofile -executionpolicy bypass -file `"$WingetUpdatePath\WAU-Uninstall.ps1`"" -Force | Out-Null New-ItemProperty $regPath -Name NoModify -Value 1 -Force | Out-Null diff --git a/Winget-AutoUpdate/functions/Test-ListPath.ps1 b/Winget-AutoUpdate/functions/Test-ListPath.ps1 index 7644001..3b13d24 100644 --- a/Winget-AutoUpdate/functions/Test-ListPath.ps1 +++ b/Winget-AutoUpdate/functions/Test-ListPath.ps1 @@ -1,6 +1,6 @@ #Function to check Black/White List External Path -function Test-ListPath ($ListPath, $UseWhiteList) { +function Test-ListPath ($ListPath, $UseWhiteList, $WingetUpdatePath) { # UNC, Web or Local Path if ($UseWhiteList){ $ListType="included" @@ -74,7 +74,7 @@ function Test-ListPath ($ListPath, $UseWhiteList) { # #White List or Black List in share/online if differs # if ($WingetUpdatePath -ne $ListPath){ -# $NoClean = Test-ListPath $ListPath $UseWhiteList +# $NoClean = Test-ListPath $ListPath $UseWhiteList $WingetUpdatePath # } # Write-Host $NoClean diff --git a/Winget-AutoUpdate/winget-upgrade.ps1 b/Winget-AutoUpdate/winget-upgrade.ps1 index 0d700ef..9f00f44 100644 --- a/Winget-AutoUpdate/winget-upgrade.ps1 +++ b/Winget-AutoUpdate/winget-upgrade.ps1 @@ -58,6 +58,15 @@ if (Test-Network) { } } + #Get External ListPath + if ($WAUConfig.ListPath) { + Write-Log "WAU uses External Lists" + $NewList = Test-ListPath $WAUConfig.ListPath $WAUConfig.WAU_UseWhiteList $WAUConfig.InstallLocation + if ($NewList) { + Write-Log "Newer List downloaded to local path" + } + } + #Get White or Black list if ($WAUConfig.WAU_UseWhiteList -eq 1) { Write-Log "WAU uses White List config" From 322cd19b6ed28296bc1e87286a46851ccf33436e Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Tue, 20 Sep 2022 21:35:22 +0200 Subject: [PATCH 14/18] Cleaned from tests --- Winget-AutoUpdate/functions/Test-ListPath.ps1 | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/Winget-AutoUpdate/functions/Test-ListPath.ps1 b/Winget-AutoUpdate/functions/Test-ListPath.ps1 index 3b13d24..6d4a689 100644 --- a/Winget-AutoUpdate/functions/Test-ListPath.ps1 +++ b/Winget-AutoUpdate/functions/Test-ListPath.ps1 @@ -65,16 +65,3 @@ function Test-ListPath ($ListPath, $UseWhiteList, $WingetUpdatePath) { } return $false } - -# $WingetUpdatePath = "$env:ProgramData\Winget-AutoUpdate" -# $ListPath = "https://www.knifmelti.se" -# #$ListPath = "D:\Temp" -# #$ListPath = "\\TempSERVER" -# #$UseWhiteList = $true - -# #White List or Black List in share/online if differs -# if ($WingetUpdatePath -ne $ListPath){ -# $NoClean = Test-ListPath $ListPath $UseWhiteList $WingetUpdatePath -# } - -# Write-Host $NoClean From 27ba6464923bb06a5a6f259290def45975754513 Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Tue, 20 Sep 2022 21:44:38 +0200 Subject: [PATCH 15/18] Some README --- README.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 08f1d49..811dfca 100644 --- a/README.md +++ b/README.md @@ -80,10 +80,13 @@ Do not run Winget-AutoUpdate after installation. By default, Winget-AutoUpdate i Disable Winget-AutoUpdate update checking. By default, WAU auto updates if new version is available on Github. **-UseWhiteList** -Use White List instead of Black List. This setting will not create the "exclude_apps.txt" but "include_apps.txt" +Use White List instead of Black List. This setting will not create the "excluded_apps.txt" but "included_apps.txt" + +**-ListPath** +Get Black/White List from Path (UNC/Web/Local). Default: `C:\ProgramData\Winget-AutoUpdate\` (copy/download to Winget-AutoUpdate installation location if external list is newer) **-NoClean** -Keep critical files when installing/uninstalling. This setting will keep "exclude_apps.txt", "include_apps.txt", "mods" and "logs" as they were. +Keep critical files when installing/uninstalling. This setting will keep "excluded_apps.txt", "included_apps.txt", "mods" and "logs" as they were. **-NotificationLevel** Specify the Notification level: Full (Default, displays all notification), SuccessOnly (Only displays notification for success) or None (Does not show any popup). From 5ae3adfe904695348297abb8d20d09638213dd3a Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Tue, 20 Sep 2022 21:47:14 +0200 Subject: [PATCH 16/18] Pathclean --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 811dfca..4a9ab0c 100644 --- a/README.md +++ b/README.md @@ -71,7 +71,7 @@ You can run the `winget-install-and-update.ps1` script with parameters : Install Winget-AutoUpdate and prerequisites silently **-WingetUpdatePath** -Specify Winget-AutoUpdate installation location. Default: `C:\ProgramData\Winget-AutoUpdate\` (Recommended to leave default) +Specify Winget-AutoUpdate installation location. Default: `C:\ProgramData\Winget-AutoUpdate` (Recommended to leave default) **-DoNotUpdate** Do not run Winget-AutoUpdate after installation. By default, Winget-AutoUpdate is run just after installation. @@ -83,7 +83,7 @@ Disable Winget-AutoUpdate update checking. By default, WAU auto updates if new v Use White List instead of Black List. This setting will not create the "excluded_apps.txt" but "included_apps.txt" **-ListPath** -Get Black/White List from Path (UNC/Web/Local). Default: `C:\ProgramData\Winget-AutoUpdate\` (copy/download to Winget-AutoUpdate installation location if external list is newer) +Get Black/White List from Path (UNC/Web/Local). Default: `C:\ProgramData\Winget-AutoUpdate` (copy/download to Winget-AutoUpdate installation location if external list is newer) **-NoClean** Keep critical files when installing/uninstalling. This setting will keep "excluded_apps.txt", "included_apps.txt", "mods" and "logs" as they were. From 2c47e7735728f39c7a85fe15561546e8566fd458 Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Wed, 21 Sep 2022 21:07:45 +0200 Subject: [PATCH 17/18] Forgotten Pathlean --- Winget-AutoUpdate-Install.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Winget-AutoUpdate-Install.ps1 b/Winget-AutoUpdate-Install.ps1 index 5c8044a..0b97d27 100644 --- a/Winget-AutoUpdate-Install.ps1 +++ b/Winget-AutoUpdate-Install.ps1 @@ -23,7 +23,7 @@ Disable Winget-AutoUpdate update checking. By default, WAU auto update if new ve Use White List instead of Black List. This setting will not create the "exclude_apps.txt" but "include_apps.txt" .PARAMETER ListPath -Get Black/White List from Path (UNC/Web/Local). Default: C:\ProgramData\Winget-AutoUpdate\ +Get Black/White List from Path (UNC/Web/Local). Default: C:\ProgramData\Winget-AutoUpdate .PARAMETER Uninstall Remove scheduled tasks and scripts. From 647664d84dae5cd6ebb7f41c65846c1fd4a85881 Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Fri, 23 Sep 2022 18:00:46 +0200 Subject: [PATCH 18/18] Fixes after @Romanitho tips! --- README.md | 2 +- Winget-AutoUpdate-Install.ps1 | 89 ++----------------- Winget-AutoUpdate/functions/Test-ListPath.ps1 | 35 +++----- 3 files changed, 23 insertions(+), 103 deletions(-) diff --git a/README.md b/README.md index 4a9ab0c..a9ea4fe 100644 --- a/README.md +++ b/README.md @@ -83,7 +83,7 @@ Disable Winget-AutoUpdate update checking. By default, WAU auto updates if new v Use White List instead of Black List. This setting will not create the "excluded_apps.txt" but "included_apps.txt" **-ListPath** -Get Black/White List from Path (UNC/Web/Local). Default: `C:\ProgramData\Winget-AutoUpdate` (copy/download to Winget-AutoUpdate installation location if external list is newer) +Get Black/White List from Path (URL/UNC/Local) (copy/download to Winget-AutoUpdate installation location if external list is newer). **-NoClean** Keep critical files when installing/uninstalling. This setting will keep "excluded_apps.txt", "included_apps.txt", "mods" and "logs" as they were. diff --git a/Winget-AutoUpdate-Install.ps1 b/Winget-AutoUpdate-Install.ps1 index 0b97d27..9585956 100644 --- a/Winget-AutoUpdate-Install.ps1 +++ b/Winget-AutoUpdate-Install.ps1 @@ -23,7 +23,7 @@ Disable Winget-AutoUpdate update checking. By default, WAU auto update if new ve Use White List instead of Black List. This setting will not create the "exclude_apps.txt" but "include_apps.txt" .PARAMETER ListPath -Get Black/White List from Path (UNC/Web/Local). Default: C:\ProgramData\Winget-AutoUpdate +Get Black/White List from Path (URL/UNC/Local) .PARAMETER Uninstall Remove scheduled tasks and scripts. @@ -64,7 +64,7 @@ Run WAU on metered connection. Default No. param( [Parameter(Mandatory = $False)] [Alias('S')] [Switch] $Silent = $false, [Parameter(Mandatory = $False)] [Alias('Path')] [String] $WingetUpdatePath = "$env:ProgramData\Winget-AutoUpdate", - [Parameter(Mandatory = $False)] [Alias('List')] [String] $ListPath = $WingetUpdatePath, + [Parameter(Mandatory = $False)] [Alias('List')] [String] $ListPath, [Parameter(Mandatory = $False)] [Switch] $DoNotUpdate = $false, [Parameter(Mandatory = $False)] [Switch] $DisableWAUAutoUpdate = $false, [Parameter(Mandatory = $False)] [Switch] $RunOnMetered = $false, @@ -180,72 +180,6 @@ function Install-WinGet { } -function Test-ListPath ($ListPath, $UseWhiteList) { - # UNC, Web or Local Path - if ($UseWhiteList){ - $ListType="included" - } - else { - $ListType="excluded" - } - $LocalList = -join($WingetUpdatePath, "\", $ListType, "_apps.txt") - if (Test-Path "$LocalList") { - $dateLocal = (Get-Item "$LocalList").LastWriteTime.ToString("yyyy-MM-dd HH:mm:ss") - } - $ExternalList = -join($ListPath, "\", $ListType, "_apps.txt") - $PathInfo=[System.Uri]$ListPath - - if($PathInfo.IsUnc){ - if(Test-Path -Path $ExternalList -PathType leaf){ - $dateExternal = (Get-Item "$ExternalList").LastWriteTime.ToString("yyyy-MM-dd HH:mm:ss") - if ($dateExternal -gt $dateLocal) { - try { - Copy-Item $ExternalList -Destination $LocalList -Force - } - catch { - return $False - } - return $true - } - } - } - elseif ($ListPath -like "http*"){ - $ExternalList = -join($ListPath, "/", $ListType, "_apps.txt") - $wc = New-Object System.Net.WebClient - try { - $wc.OpenRead("$ExternalList").Close() | Out-Null - $dateExternal = ([DateTime]$wc.ResponseHeaders['Last-Modified']).ToString("yyyy-MM-dd HH:mm:ss") - if ($dateExternal -gt $dateLocal) { - try { - $wc.DownloadFile($ExternalList, $LocalList) - } - catch { - return $False - } - return $true - } - } - catch { - return $False - } - } - else { - if(Test-Path -Path $ExternalList -PathType leaf){ - $dateExternal = (Get-Item "$ExternalList").LastWriteTime.ToString("yyyy-MM-dd HH:mm:ss") - if ($dateExternal -gt $dateLocal) { - try { - Copy-Item $ExternalList -Destination $LocalList -Force - } - catch { - return $False - } - return $true - } - } - } - return $false -} - function Install-WingetAutoUpdate { Write-Host "`nInstalling WAU..." -ForegroundColor Yellow @@ -254,17 +188,8 @@ function Install-WingetAutoUpdate { #Copy files to location (and clean old install) if (!(Test-Path $WingetUpdatePath)) { New-Item -ItemType Directory -Force -Path $WingetUpdatePath | Out-Null - #White List or Black List source not Local if differs - if ($WingetUpdatePath -ne $ListPath){ - $NoClean = Test-ListPath $ListPath $UseWhiteList - } - } else { - #White List or Black List source not Local if differs - if ($WingetUpdatePath -ne $ListPath){ - $NoClean = Test-ListPath $ListPath $UseWhiteList - } if (!$NoClean) { Remove-Item -Path "$WingetUpdatePath\*" -Exclude *.log -Recurse -Force } @@ -282,7 +207,9 @@ function Install-WingetAutoUpdate { Copy-Item -Path "$PSScriptRoot\included_apps.txt" -Destination $WingetUpdatePath -Recurse -Force -ErrorAction SilentlyContinue } else { - New-Item -Path $WingetUpdatePath -Name "included_apps.txt" -ItemType "file" -ErrorAction SilentlyContinue | Out-Null + if (!$ListPath){ + New-Item -Path $WingetUpdatePath -Name "included_apps.txt" -ItemType "file" -ErrorAction SilentlyContinue | Out-Null + } } } elseif (!(Test-Path "$WingetUpdatePath\included_apps.txt")) { @@ -290,7 +217,9 @@ function Install-WingetAutoUpdate { Copy-Item -Path "$PSScriptRoot\included_apps.txt" -Destination $WingetUpdatePath -Recurse -Force -ErrorAction SilentlyContinue } else { - New-Item -Path $WingetUpdatePath -Name "included_apps.txt" -ItemType "file" -ErrorAction SilentlyContinue | Out-Null + if (!$ListPath){ + New-Item -Path $WingetUpdatePath -Name "included_apps.txt" -ItemType "file" -ErrorAction SilentlyContinue | Out-Null + } } } } @@ -348,7 +277,7 @@ function Install-WingetAutoUpdate { New-ItemProperty $regPath -Name DisplayIcon -Value "C:\Windows\System32\shell32.dll,-16739" -Force | Out-Null New-ItemProperty $regPath -Name DisplayVersion -Value $WAUVersion -Force | Out-Null New-ItemProperty $regPath -Name InstallLocation -Value $WingetUpdatePath -Force | Out-Null - if ($WingetUpdatePath -ne $ListPath){ + if ($ListPath){ New-ItemProperty $regPath -Name ListPath -Value $ListPath -Force | Out-Null } New-ItemProperty $regPath -Name UninstallString -Value "powershell.exe -noprofile -executionpolicy bypass -file `"$WingetUpdatePath\WAU-Uninstall.ps1`"" -Force | Out-Null diff --git a/Winget-AutoUpdate/functions/Test-ListPath.ps1 b/Winget-AutoUpdate/functions/Test-ListPath.ps1 index 6d4a689..8e2a43e 100644 --- a/Winget-AutoUpdate/functions/Test-ListPath.ps1 +++ b/Winget-AutoUpdate/functions/Test-ListPath.ps1 @@ -1,36 +1,26 @@ #Function to check Black/White List External Path function Test-ListPath ($ListPath, $UseWhiteList, $WingetUpdatePath) { - # UNC, Web or Local Path + # URL, UNC or Local Path if ($UseWhiteList){ - $ListType="included" + $ListType="included_apps.txt" } else { - $ListType="excluded" + $ListType="excluded_apps.txt" } - $LocalList = -join($WingetUpdatePath, "\", $ListType, "_apps.txt") + + # Get local and external list paths + $LocalList = -join($WingetUpdatePath, "\", $ListType) + $ExternalList = -join($ListPath, "\", $ListType) + + # Check if a list exists if (Test-Path "$LocalList") { $dateLocal = (Get-Item "$LocalList").LastWriteTime.ToString("yyyy-MM-dd HH:mm:ss") } - $ExternalList = -join($ListPath, "\", $ListType, "_apps.txt") - $PathInfo=[System.Uri]$ListPath - if($PathInfo.IsUnc){ - if(Test-Path -Path $ExternalList -PathType leaf){ - $dateExternal = (Get-Item "$ExternalList").LastWriteTime.ToString("yyyy-MM-dd HH:mm:ss") - if ($dateExternal -gt $dateLocal) { - try { - Copy-Item $ExternalList -Destination $LocalList -Force - } - catch { - return $False - } - return $true - } - } - } - elseif ($ListPath -like "http*"){ - $ExternalList = -join($ListPath, "/", $ListType, "_apps.txt") + # If path is URL + if ($ListPath -like "http*"){ + $ExternalList = -join($ListPath, "/", $ListType) $wc = New-Object System.Net.WebClient try { $wc.OpenRead("$ExternalList").Close() | Out-Null @@ -49,6 +39,7 @@ function Test-ListPath ($ListPath, $UseWhiteList, $WingetUpdatePath) { return $False } } + # If path is UNC or local else { if(Test-Path -Path $ExternalList -PathType leaf){ $dateExternal = (Get-Item "$ExternalList").LastWriteTime.ToString("yyyy-MM-dd HH:mm:ss")