mod\bins for placing MsiZap.exe etc. in

pull/257/head
KnifMelti 2023-01-10 03:35:03 +01:00
parent 2839500448
commit 50263f756e
2 changed files with 89 additions and 19 deletions

View File

@ -8,6 +8,7 @@ function Test-ModsPath ($ModsPath, $WingetUpdatePath) {
#Get File Names Locally #Get File Names Locally
$InternalModsNames = Get-ChildItem -Path $LocalMods -Name -Recurse -Include *.ps1, *.txt $InternalModsNames = Get-ChildItem -Path $LocalMods -Name -Recurse -Include *.ps1, *.txt
$InternalBinsNames = Get-ChildItem -Path $LocalMods"\bins" -Name -Recurse -Include *.exe
# If path is URL # If path is URL
if ($ExternalMods -like "http*") { if ($ExternalMods -like "http*") {
@ -22,6 +23,53 @@ function Test-ModsPath ($ModsPath, $WingetUpdatePath) {
return $False return $False
} }
#Check for bins, download if newer. Delete if not external
$ExternalBins = "$ModsPath/bins"
if ($WebResponse -match "bins/") {
$BinResponse = Invoke-WebRequest -Uri $ExternalBins -UseBasicParsing
# Collect the external list of href links
$BinLinks = $BinResponse.Links | Select-Object -ExpandProperty HREF
#If there's a directory path in the HREF:s, delete it (IIS)
$CleanBinLinks = $BinLinks -replace "/.*/",""
#Modify strings to HREF:s
$index = 0
foreach ($Bin in $CleanBinLinks) {
if ($Bin) {
$CleanBinLinks[$index] = '<a href="' + $Bin + '"> ' + $Bin + '</a>'
}
$index++
}
#Delete Local Bins that don't exist Externally
$index = 0
$CleanLinks = $BinLinks -replace "/.*/",""
foreach ($Bin in $InternalBinsNames) {
If ($CleanLinks -notcontains "$Bin") {
Remove-Item $LocalMods\bins\$Bin -Force -ErrorAction SilentlyContinue | Out-Null
}
$index++
}
$CleanBinLinks = $BinLinks -replace "/.*/",""
$Bin = ""
#Loop through all links
$wc = New-Object System.Net.WebClient
$CleanBinLinks | ForEach-Object {
#Check for .exe in listing/HREF:s in an index page pointing to .exe
if ($_ -like "*.exe") {
$dateExternalBin = ""
$dateLocalBin =""
$wc.OpenRead("$ExternalBins/$_").Close() | Out-Null
$dateExternalBin = ([DateTime]$wc.ResponseHeaders['Last-Modified']).ToString("yyyy-MM-dd HH:mm:ss")
if (Test-Path -Path $LocalMods"\bins\"$_) {
$dateLocalBin = (Get-Item "$LocalMods\bins\$_").LastWriteTime.ToString("yyyy-MM-dd HH:mm:ss")
}
if ($dateExternalBin -gt $dateLocalBin) {
$SaveBin = Join-Path -Path "$LocalMods\bins" -ChildPath $_
Invoke-WebRequest -Uri "$ExternalBins/$_" -OutFile $SaveBin.Replace("%20"," ") -UseBasicParsing
}
}
}
}
# Collect the external list of href links # Collect the external list of href links
$ModLinks = $WebResponse.Links | Select-Object -ExpandProperty HREF $ModLinks = $WebResponse.Links | Select-Object -ExpandProperty HREF
@ -39,8 +87,7 @@ function Test-ModsPath ($ModsPath, $WingetUpdatePath) {
#Delete Local Mods that don't exist Externally #Delete Local Mods that don't exist Externally
$DeletedMods = 0 $DeletedMods = 0
# 0 is the parent HTTP Directory $index = 0
$index = 1
$CleanLinks = $ModLinks -replace "/.*/","" $CleanLinks = $ModLinks -replace "/.*/",""
foreach ($Mod in $InternalModsNames) { foreach ($Mod in $InternalModsNames) {
If ($CleanLinks -notcontains "$Mod") { If ($CleanLinks -notcontains "$Mod") {
@ -87,6 +134,29 @@ function Test-ModsPath ($ModsPath, $WingetUpdatePath) {
} }
# If path is UNC or local # If path is UNC or local
else { else {
$ExternalBins = "$ModsPath\bins"
if (Test-Path -Path $ExternalBins"\*.exe") {
$ExternalBinsNames = Get-ChildItem -Path $ExternalBins -Name -Recurse -Include *.exe
#Delete Local Bins that don't exist Externally
foreach ($Bin in $InternalBinsNames){
If ($Bin -notin $ExternalBinsNames ){
Remove-Item $LocalMods\bins\$Bin -Force -ErrorAction SilentlyContinue | Out-Null
}
}
#Copy newer external bins
foreach ($Bin in $ExternalBinsNames){
$dateExternalBin = ""
$dateLocalBin =""
if (Test-Path -Path $LocalMods"\bins\"$Bin) {
$dateLocalBin = (Get-Item "$LocalMods\bins\$Bin").LastWriteTime.ToString("yyyy-MM-dd HH:mm:ss")
}
$dateExternalBin = (Get-Item "$ExternalBins\$Bin").LastWriteTime.ToString("yyyy-MM-dd HH:mm:ss")
if ($dateExternalBin -gt $dateLocalBin) {
Copy-Item $ExternalBins\$Bin -Destination $LocalMods\bins\$Bin -Force -ErrorAction SilentlyContinue | Out-Null
}
}
}
if ((Test-Path -Path $ExternalMods"\*.ps1") -or (Test-Path -Path $ExternalMods"\*.txt")) { if ((Test-Path -Path $ExternalMods"\*.ps1") -or (Test-Path -Path $ExternalMods"\*.txt")) {
#Get File Names Externally #Get File Names Externally
$ExternalModsNames = Get-ChildItem -Path $ExternalMods -Name -Recurse -Include *.ps1, *.txt $ExternalModsNames = Get-ChildItem -Path $ExternalMods -Name -Recurse -Include *.ps1, *.txt
@ -101,7 +171,6 @@ function Test-ModsPath ($ModsPath, $WingetUpdatePath) {
} }
#Copy newer external mods #Copy newer external mods
try {
foreach ($Mod in $ExternalModsNames){ foreach ($Mod in $ExternalModsNames){
$dateExternalMod = "" $dateExternalMod = ""
$dateLocalMod ="" $dateLocalMod =""
@ -114,11 +183,6 @@ function Test-ModsPath ($ModsPath, $WingetUpdatePath) {
$ModsUpdated++ $ModsUpdated++
} }
} }
}
catch {
$Script:ReachNoPath = $True
}
} }
else { else {
$Script:ReachNoPath = $True $Script:ReachNoPath = $True

View File

@ -0,0 +1,6 @@
A Directory for placing useful **bins** (**MsiZap.exe** as a really good example) for running via the **Template Function**:
#App to Run ($RunWait = $False if it shouldn't be waited for)
$Run = ""
$RunSwitch = ""
$RunWait = $True