URL Remaining

pull/232/head
KnifMelti 2022-11-03 00:19:59 +01:00
parent 518bcdf4dc
commit 0c1cf4aed0
1 changed files with 34 additions and 13 deletions

View File

@ -4,12 +4,10 @@ function Test-ModsPath ($ModsPath, $WingetUpdatePath) {
# URL, UNC or Local Path # URL, UNC or Local Path
# Get local and external Mods paths # Get local and external Mods paths
$LocalMods = -join ($WingetUpdatePath, "\", "mods") $LocalMods = -join ($WingetUpdatePath, "\", "mods")
$ExternalMods = "$ModsPath\" $ExternalMods = "$ModsPath"
# Check if mods exists #Get File Names Locally
if (Test-Path "$LocalMods\*.ps1") { $InternalModsNames = Get-ChildItem -Path $LocalMods -Name -Recurse -Include *.ps1
$dateLocal = (Get-Item "$LocalMods").LastWriteTime.ToString("yyyy-MM-dd HH:mm:ss")
}
# If path is URL # If path is URL
if ($ModsPath -like "http*") { if ($ModsPath -like "http*") {
@ -34,18 +32,41 @@ function Test-ModsPath ($ModsPath, $WingetUpdatePath) {
} }
# If path is UNC or local # If path is UNC or local
else { else {
if (Test-Path -Path $ExternalMods -PathType leaf) { #Get File Names Externally
$dateExternal = (Get-Item "$ExternalMods").LastWriteTime.ToString("yyyy-MM-dd HH:mm:ss") $ExternalModsNames = Get-ChildItem -Path $ExternalMods -Name -Recurse -Include *.ps1
if ($dateExternal -gt $dateLocal) { if (Test-Path -Path $ExternalMods"\*.ps1") {
#Delete Local Mods that doesn't exist Externally
foreach ($Mod in $InternalModsNames){
try { try {
Copy-Item $ExternalMods -Destination $LocalMods -Force If($Mod -notin $ExternalModsNames ){
Remove-Item $LocalMods\$Mod -Force | Out-Null
}
} }
catch { catch {
return $False #Do nothing
} }
return $true }
try {
foreach ($Mod in $ExternalModsNames){
if (Test-Path -Path $LocalMods"\"$Mod) {
$dateLocalMod = (Get-Item "$LocalMods\$Mod").LastWriteTime.ToString("yyyy-MM-dd HH:mm:ss")
}
$dateExternalMod = (Get-Item "$ExternalMods\$Mod").LastWriteTime.ToString("yyyy-MM-dd HH:mm:ss")
if ($dateExternalMod -gt $dateLocalMod) {
try {
Copy-Item $ExternalMods\$Mod -Destination $LocalMods\$Mod -Force
return $True
}
catch {
return $False
}
}
}
}
catch {
return $False
} }
} }
} }
return $false return $False
} }