From 407efdd8f726d64185849ce129f4663772dc2bc5 Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Thu, 5 Jan 2023 03:31:45 +0100 Subject: [PATCH] Forgot test deletions... --- Winget-AutoUpdate/functions/Test-ModsPath.ps1 | 37 ++++++++++++++++++- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/Winget-AutoUpdate/functions/Test-ModsPath.ps1 b/Winget-AutoUpdate/functions/Test-ModsPath.ps1 index b3e5253..ecb2842 100644 --- a/Winget-AutoUpdate/functions/Test-ModsPath.ps1 +++ b/Winget-AutoUpdate/functions/Test-ModsPath.ps1 @@ -73,15 +73,48 @@ function Test-ModsPath ($ModsPath, $WingetUpdatePath) { $ModsUpdated++ } catch { - return $False + # Error handling } } } catch { - return $False + # Error handling } } } return $ModsUpdated, $DeletedMods } + # If path is UNC or local + else { + if ((Test-Path -Path $ExternalMods"\*.ps1") -or (Test-Path -Path $ExternalMods"\*.txt")) { + #Get File Names Externally + $ExternalModsNames = Get-ChildItem -Path $ExternalMods -Name -Recurse -Include *.ps1, *.txt + #Delete Local Mods that don't exist Externally + foreach ($Mod in $InternalModsNames){ + If($Mod -notin $ExternalModsNames ){ + Remove-Item $LocalMods\$Mod -Force -ErrorAction SilentlyContinue | Out-Null + $DeletedMods++ + } + } + try { + foreach ($Mod in $ExternalModsNames){ + $dateExternalMod = "" + $dateLocalMod ="" + 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) { + Copy-Item $ExternalMods\$Mod -Destination $LocalMods\$Mod -Force -ErrorAction SilentlyContinue | Out-Null + $ModsUpdated++ + } + } + + } + catch { + # Error handling + } + } + return $ModsUpdated, $DeletedMods + } }