From baa7ef84a4f488d0d89a438489a1d06336b455a9 Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Sat, 26 Nov 2022 17:47:38 +0100 Subject: [PATCH] Adding PreInstall mods... --- Winget-AutoUpdate/functions/Test-Mods.ps1 | 6 +++++- Winget-AutoUpdate/functions/Update-App.ps1 | 12 +++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/Winget-AutoUpdate/functions/Test-Mods.ps1 b/Winget-AutoUpdate/functions/Test-Mods.ps1 index b161847..e9177a1 100644 --- a/Winget-AutoUpdate/functions/Test-Mods.ps1 +++ b/Winget-AutoUpdate/functions/Test-Mods.ps1 @@ -3,11 +3,15 @@ function Test-Mods ($app) { #Takes care of a null situation + $ModsPreInstall = $null $ModsInstall = $null $ModsUpgrade = $null $Mods = "$WorkingDir\mods" if (Test-Path "$Mods\$app-*") { + if (Test-Path "$Mods\$app-preinstall.ps1") { + $ModsPreInstall = "$Mods\$app-preinstall.ps1" + } if (Test-Path "$Mods\$app-install.ps1") { $ModsInstall = "$Mods\$app-install.ps1" $ModsUpgrade = "$Mods\$app-install.ps1" @@ -17,6 +21,6 @@ function Test-Mods ($app) { } } - return $ModsInstall, $ModsUpgrade + return $ModsPreInstall, $ModsInstall, $ModsUpgrade } diff --git a/Winget-AutoUpdate/functions/Update-App.ps1 b/Winget-AutoUpdate/functions/Update-App.ps1 index efedd64..4a0d7f1 100644 --- a/Winget-AutoUpdate/functions/Update-App.ps1 +++ b/Winget-AutoUpdate/functions/Update-App.ps1 @@ -16,6 +16,15 @@ Function Update-App ($app) { $Balise = $($app.Name) Start-NotifTask -Title $Title -Message $Message -MessageType $MessageType -Balise $Balise -Button1Action $ReleaseNoteURL -Button1Text $Button1Text + #Check if mods exist for preinstall/install/upgrade + $ModsPreInstall, $ModsInstall, $ModsUpgrade = Test-Mods $($app.Id) + + #If PreInstall script exist + if ($ModsPreInstall) { + Write-Log "Modifications for $($app.Id) before upgrade are being applied..." "Yellow" + & "$ModsPreInstall" + } + #Winget upgrade Write-Log "########## WINGET UPGRADE PROCESS STARTS FOR APPLICATION ID '$($App.Id)' ##########" "Gray" @@ -61,9 +70,6 @@ Function Update-App ($app) { if ($FailedToUpgrade -eq $false) { - #Check if mods exist for install/upgrade - $ModsInstall, $ModsUpgrade = Test-Mods $($app.Id) - if (($ModsUpgrade) -and ($ModsMode -eq "Upgrade")) { Write-Log "Modifications for $($app.Id) after upgrade are being applied..." "Yellow" & "$ModsUpgrade"