Skip to content

Commit 497085e

Browse files
committed
Skip install in Winget-Install too, if Pendig reboot is active it still tries 1 upgrade, Documentation - ALL DONE!
1 parent 5df3299 commit 497085e

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed

Sources/Winget-AutoUpdate/Winget-Install.ps1

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,12 @@ function Install-App ($AppID, $AppArgs) {
138138

139139
#If PreInstall script exist
140140
if ($ModsPreInstall) {
141-
Write-ToLog "-> Modifications for $AppID before install are being applied..." "DarkYellow" -Component "WinGet-Install"
142-
& "$ModsPreInstall"
141+
Write-ToLog "Modifications for $AppID before install are being applied..." "DarkYellow" -Component "WinGet-Install"
142+
$preInstallResult = & "$ModsPreInstall"
143+
if ($preInstallResult -eq $false) {
144+
Write-ToLog "PreInstall script for $AppID requested to skip this installation" "Yellow" -Component "WinGet-Install"
145+
return # Exit the function early
146+
}
143147
}
144148

145149
#Install App

Sources/Winget-AutoUpdate/functions/Update-App.ps1

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,14 @@ Function Update-App ($app) {
9696
#Test for a Pending Reboot (Component Based Servicing/WindowsUpdate/CCM_ClientUtilities)
9797
$PendingReboot = Test-PendingReboot
9898
if ($PendingReboot -eq $true) {
99-
Write-ToLog "-> A Pending Reboot lingers and probably prohibited $($app.Name) from upgrading...`n-> ...an install for $($app.Name) is NOT executed!" "Red"
100-
continue
99+
Write-ToLog "-> A Pending Reboot lingers and probably prohibited $($app.Name) from upgrading...`n-> ...limiting to 1 install attempt instead of 2" "Yellow"
100+
$retry = 2
101101
}
102-
103-
#If app failed to upgrade, run Install command (2 tries max - some apps get uninstalled after single "Install" command.)
104-
$retry = 1
102+
else {
103+
#If app failed to upgrade, run Install command (2 tries max - some apps get uninstalled after single "Install" command.)
104+
$retry = 1
105+
}
106+
105107
While (($ConfirmInstall -eq $false) -and ($retry -le 2)) {
106108

107109
Write-ToLog "-> An upgrade for $($app.Name) failed, now trying an install instead... ($retry/2)" "DarkYellow"

Sources/Winget-AutoUpdate/mods/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ The **-install** mod will be used for upgrades too if **-upgrade** doesn't exist
2424

2525
`AppID-install.ps1` is recommended because it's used in **both** scenarios.
2626

27+
If **AppID**`-preinstall.ps1` returns `$false`, the install/update for that **AppID** is skipped (checking if an App is running, etc...).
28+
2729
A script **Template** for an all-purpose mod (`_WAU-notinstalled-template.ps1`) is included in which actions can be taken if an upgrade/install fails for any **AppID** (any individual `AppID-notinstalled.ps1` overrides this global one)
2830
Name it `_WAU-notinstalled.ps1` for activation
2931

0 commit comments

Comments
 (0)