ModsPath Done
parent
231e6fa2f2
commit
108df76229
|
@ -90,6 +90,7 @@ Get Black/White List from Path (URL/UNC/Local) (download/copy to Winget-AutoUpda
|
|||
|
||||
**-ModsPath**
|
||||
Get Mods from Path (URL/UNC/Local) (download/copy to `mods` in Winget-AutoUpdate installation location if external mods is newer).
|
||||
For URL: This requires a site with `Options +Indexes` in `.htaccess` and no index page overriding the listing of files or an index page with href listings of all the Mods to be downloaded!
|
||||
|
||||
**-InstallUserContext**
|
||||
Install WAU with system and **user** context executions (From version 1.15.3)
|
||||
|
|
|
@ -10,25 +10,58 @@ function Test-ModsPath ($ModsPath, $WingetUpdatePath) {
|
|||
$InternalModsNames = Get-ChildItem -Path $LocalMods -Name -Recurse -Include *.ps1
|
||||
|
||||
# If path is URL
|
||||
if ($ModsPath -like "http*") {
|
||||
$ExternalMods = "$ModsPath/"
|
||||
if ($ExternalMods -like "http*") {
|
||||
$wc = New-Object System.Net.WebClient
|
||||
try {
|
||||
$wc.OpenRead("$ExternalMods").Close() | Out-Null
|
||||
$dateExternal = ([DateTime]$wc.ResponseHeaders['Last-Modified']).ToString("yyyy-MM-dd HH:mm:ss")
|
||||
if ($dateExternal -gt $dateLocal) {
|
||||
|
||||
# enable TLS 1.2 and TLS 1.1 protocols
|
||||
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12, [Net.SecurityProtocolType]::Tls11
|
||||
#Get Index of $ExternalMods (or index page with href listings of all the Mods)
|
||||
$WebResponse = Invoke-WebRequest -Uri $ExternalMods
|
||||
# Get the list of links, skip the first one ("../") if listing is allowed
|
||||
$ModLinks = $WebResponse.Links | Select-Object -ExpandProperty href -Skip 1
|
||||
|
||||
#Delete Local Mods that doesn't exist Externally
|
||||
foreach ($Mod in $InternalModsNames) {
|
||||
try {
|
||||
If ($Mod -notin $ModLinks) {
|
||||
Remove-Item $LocalMods\$Mod -Force | Out-Null
|
||||
}
|
||||
}
|
||||
catch {
|
||||
#Do nothing
|
||||
}
|
||||
}
|
||||
|
||||
#Loop through all links
|
||||
$WebResponse.Links | Select-Object -ExpandProperty href -Skip 1 | ForEach-Object {
|
||||
#Check for .ps1 in listing/HREF:s in an index page pointing to .ps1
|
||||
if ($_ -like "*.ps1") {
|
||||
try {
|
||||
$wc.DownloadFile($ExternalMods, $LocalMods)
|
||||
$wc.OpenRead("$ExternalMods/$_").Close() | Out-Null
|
||||
$dateExternalMod = ([DateTime]$wc.ResponseHeaders['Last-Modified']).ToString("yyyy-MM-dd HH:mm:ss")
|
||||
if (Test-Path -Path $LocalMods"\"$_) {
|
||||
$dateLocalMod = (Get-Item "$LocalMods\$_").LastWriteTime.ToString("yyyy-MM-dd HH:mm:ss")
|
||||
}
|
||||
|
||||
if ($dateExternalMod -gt $dateLocalMod) {
|
||||
try {
|
||||
$SaveMod = Join-Path -Path "$LocalMods\" -ChildPath $_
|
||||
$Mod = '{0}/{1}' -f $ModsPath.TrimEnd('/'), $_
|
||||
#Write-Host "Downloading file $dateExternal - $ExternalMods/$_ to $SaveMod"
|
||||
Invoke-WebRequest -Uri "$Mod" -OutFile $SaveMod
|
||||
$ModsUpdated++
|
||||
}
|
||||
catch {
|
||||
return $False
|
||||
}
|
||||
}
|
||||
}
|
||||
catch {
|
||||
return $False
|
||||
}
|
||||
return $true
|
||||
}
|
||||
}
|
||||
catch {
|
||||
return $False
|
||||
}
|
||||
return $ModsUpdated
|
||||
}
|
||||
# If path is UNC or local
|
||||
else {
|
||||
|
|
Loading…
Reference in New Issue