From c304b7060495be1f5b652148afc12f47774f0cf1 Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Fri, 24 Nov 2023 19:33:35 +0100 Subject: [PATCH] Mod for AppID-notinstalled --- README.md | 3 ++- Winget-AutoUpdate/functions/Test-Mods.ps1 | 6 +++++- Winget-AutoUpdate/functions/Update-App.ps1 | 8 ++++++-- Winget-AutoUpdate/mods/README.md | 3 ++- 4 files changed, 15 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 70af36a..59613d1 100644 --- a/README.md +++ b/README.md @@ -181,7 +181,8 @@ Just put the scripts in question with the **AppID** followed by the `-preinstall >- Runs before upgrade/install: `AppID-preinstall.ps1`
>- Runs during upgrade/install (before install check): `AppID-upgrade.ps1`/`AppID-install.ps1`
->- Runs after upgrade/install has been confirmed: `AppID-installed.ps1` +>- Runs after upgrade/install has been confirmed: `AppID-installed.ps1`
+>- Runs after a failed upgrade/install: `AppID-notinstalled.ps1`
The **-install** mod will be used for upgrades too if **-upgrade** doesn't exist (**WAU** first tries `& $Winget upgrade --id` and if the app isn't detected after that `& $Winget install --id` is tried).
`AppID-install.ps1` is recommended because it's used in **both** scenarios. diff --git a/Winget-AutoUpdate/functions/Test-Mods.ps1 b/Winget-AutoUpdate/functions/Test-Mods.ps1 index f46d4da..8d0e305 100644 --- a/Winget-AutoUpdate/functions/Test-Mods.ps1 +++ b/Winget-AutoUpdate/functions/Test-Mods.ps1 @@ -8,6 +8,7 @@ function Test-Mods ($app) { $ModsUpgrade = $null $ModsInstall = $null $ModsInstalled = $null + $ModsNotInstalled = $ null $Mods = "$WorkingDir\mods" if (Test-Path "$Mods\$app-*") { @@ -27,8 +28,11 @@ function Test-Mods ($app) { if (Test-Path "$Mods\$app-installed.ps1") { $ModsInstalled = "$Mods\$app-installed.ps1" } + if (Test-Path "$Mods\$app-notinstalled.ps1") { + $ModsNotInstalled = "$Mods\$app-notinstalled.ps1" + } } - return $ModsPreInstall, $ModsOverride, $ModsUpgrade, $ModsInstall, $ModsInstalled + return $ModsPreInstall, $ModsOverride, $ModsUpgrade, $ModsInstall, $ModsInstalled, $ModsNotInstalled } diff --git a/Winget-AutoUpdate/functions/Update-App.ps1 b/Winget-AutoUpdate/functions/Update-App.ps1 index 86e4236..9296121 100644 --- a/Winget-AutoUpdate/functions/Update-App.ps1 +++ b/Winget-AutoUpdate/functions/Update-App.ps1 @@ -16,8 +16,8 @@ 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, $ModsOverride, $ModsUpgrade, $ModsInstall, $ModsInstalled = Test-Mods $($app.Id) + #Check if mods exist for preinstall/override/upgrade/install/installed/notinstalled + $ModsPreInstall, $ModsOverride, $ModsUpgrade, $ModsInstall, $ModsInstalled, $ModsNotInstalled = Test-Mods $($app.Id) #Winget upgrade Write-ToLog "########## WINGET UPGRADE PROCESS STARTS FOR APPLICATION ID '$($App.Id)' ##########" "Gray" @@ -87,6 +87,10 @@ Function Update-App ($app) { & "$ModsInstalled" } } + elseif ($FailedToUpgrade -eq $true -and $ModsNotInstalled) { + Write-ToLog "Modifications for $($app.Id) after a failed upgrade/install are being applied..." "Yellow" + & "$ModsNotInstalled" + } Write-ToLog "########## WINGET UPGRADE PROCESS FINISHED FOR APPLICATION ID '$($App.Id)' ##########" "Gray" diff --git a/Winget-AutoUpdate/mods/README.md b/Winget-AutoUpdate/mods/README.md index d25361a..53be96c 100644 --- a/Winget-AutoUpdate/mods/README.md +++ b/Winget-AutoUpdate/mods/README.md @@ -7,12 +7,13 @@ Custom scripts should be placed here. A script **Template** and **Mods Functions** are included as an **example** to get you started... Scripts that are considered: -**AppID**`-preinstall.ps1`, `-upgrade.ps1`, `-install.ps1` or `-installed.ps1`. +**AppID**`-preinstall.ps1`, `-upgrade.ps1`, `-install.ps1`, `-installed.ps1` or `-notinstalled.ps1`. (`-preuninstall.ps1`, `-uninstall.ps1` or `-uninstalled.ps1` - if used together with [Winget-Install](https://github.com/Romanitho/Winget-Install)). > Runs before upgrade/install: `AppID-preinstall.ps1` > Runs during upgrade/install (before install check): `AppID-upgrade.ps1`/`AppID-install.ps1` > Runs after upgrade/install has been confirmed: `AppID-installed.ps1` +> Runs after a failed upgrade/install: `AppID-notinstalled.ps1` The **-install** mod will be used for upgrades too if **-upgrade** doesn't exist (**WAU** first tries `& $Winget upgrade --id` and if the app isn't detected after that `& $Winget install --id` is tried).