2023-03-31 15:56:07 +00:00
#Function to update an App
2022-04-13 16:50:06 +00:00
2022-04-05 13:17:18 +00:00
Function Update-App ( $app ) {
2022-07-05 14:48:23 +00:00
#Get App Info
2022-10-26 22:49:10 +00:00
$ReleaseNoteURL = Get-AppInfo $app . Id
2023-03-31 15:56:07 +00:00
if ( $ReleaseNoteURL ) {
2022-10-26 22:49:10 +00:00
$Button1Text = $NotifLocale . local . outputs . output [ 10 ] . message
}
2022-07-05 14:48:23 +00:00
2022-04-05 13:17:18 +00:00
#Send available update notification
2023-04-01 14:08:52 +00:00
Write-ToLog " Updating $( $app . Name ) from $( $app . Version ) to $( $app . AvailableVersion ) ... " " Cyan "
2022-04-05 13:17:18 +00:00
$Title = $NotifLocale . local . outputs . output [ 2 ] . title -f $ ( $app . Name )
$Message = $NotifLocale . local . outputs . output [ 2 ] . message -f $ ( $app . Version ) , $ ( $app . AvailableVersion )
$MessageType = " info "
$Balise = $ ( $app . Name )
2022-10-26 22:49:10 +00:00
Start-NotifTask -Title $Title -Message $Message -MessageType $MessageType -Balise $Balise -Button1Action $ReleaseNoteURL -Button1Text $Button1Text
2022-04-05 13:17:18 +00:00
2022-11-26 16:47:38 +00:00
#Check if mods exist for preinstall/install/upgrade
2022-12-08 16:53:37 +00:00
$ModsPreInstall , $ModsOverride , $ModsUpgrade , $ModsInstall , $ModsInstalled = Test-Mods $ ( $app . Id )
#Winget upgrade
2023-04-01 14:08:52 +00:00
Write-ToLog " ########## WINGET UPGRADE PROCESS STARTS FOR APPLICATION ID ' $( $App . Id ) ' ########## " " Gray "
2022-11-26 16:47:38 +00:00
#If PreInstall script exist
if ( $ModsPreInstall ) {
2023-04-01 14:08:52 +00:00
Write-ToLog " Modifications for $( $app . Id ) before upgrade are being applied... " " Yellow "
2022-11-26 16:47:38 +00:00
& " $ModsPreInstall "
}
2022-04-13 16:50:06 +00:00
#Run Winget Upgrade command
2022-12-08 16:53:37 +00:00
if ( $ModsOverride ) {
2023-04-01 14:08:52 +00:00
Write-ToLog " -> Running (overriding default): Winget upgrade --id $( $app . Id ) --accept-package-agreements --accept-source-agreements --override $ModsOverride "
2022-12-08 16:53:37 +00:00
& $Winget upgrade - -id $ ( $app . Id ) - -accept -package -agreements - -accept -source -agreements - -override $ModsOverride | Tee-Object -file $LogFile -Append
}
else {
2023-04-01 14:08:52 +00:00
Write-ToLog " -> Running: Winget upgrade --id $( $app . Id ) --accept-package-agreements --accept-source-agreements -h "
2022-12-08 16:53:37 +00:00
& $Winget upgrade - -id $ ( $app . Id ) - -accept -package -agreements - -accept -source -agreements -h | Tee-Object -file $LogFile -Append
}
2022-07-27 07:44:11 +00:00
2022-12-04 00:55:40 +00:00
if ( $ModsUpgrade ) {
2023-04-01 14:08:52 +00:00
Write-ToLog " Modifications for $( $app . Id ) during upgrade are being applied... " " Yellow "
2022-12-04 00:55:40 +00:00
& " $ModsUpgrade "
}
2022-07-28 17:09:50 +00:00
2022-04-13 16:50:06 +00:00
#Check if application updated properly
$CheckOutdated = Get-WingetOutdatedApps
$FailedToUpgrade = $false
2022-06-10 08:26:41 +00:00
foreach ( $CheckApp in $CheckOutdated ) {
2022-04-13 16:50:06 +00:00
if ( $ ( $CheckApp . Id ) -eq $ ( $app . Id ) ) {
2022-10-26 22:49:10 +00:00
2022-08-04 20:04:06 +00:00
#Upgrade failed!
#Test for a Pending Reboot (Component Based Servicing/WindowsUpdate/CCM_ClientUtilities)
$PendingReboot = Test-PendingReboot
if ( $PendingReboot -eq $true ) {
2023-04-01 14:08:52 +00:00
Write-ToLog " -> A Pending Reboot lingers and probably prohibited $( $app . Name ) from upgrading... `n -> ...an install for $( $app . Name ) is NOT executed! " " Red "
2022-08-04 20:04:06 +00:00
$FailedToUpgrade = $true
break
}
2022-10-26 22:49:10 +00:00
2022-08-01 11:25:14 +00:00
#If app failed to upgrade, run Install command
2023-04-01 14:08:52 +00:00
Write-ToLog " -> An upgrade for $( $app . Name ) failed, now trying an install instead... " " Yellow "
2023-03-31 15:56:07 +00:00
2022-12-08 16:53:37 +00:00
if ( $ModsOverride ) {
2023-04-01 14:08:52 +00:00
Write-ToLog " -> Running (overriding default): Winget install --id $( $app . Id ) --accept-package-agreements --accept-source-agreements --override $ModsOverride "
2022-12-08 16:53:37 +00:00
& $Winget install - -id $ ( $app . Id ) - -accept -package -agreements - -accept -source -agreements - -override $ModsOverride | Tee-Object -file $LogFile -Append
}
else {
2023-04-01 14:08:52 +00:00
Write-ToLog " -> Running: Winget install --id $( $app . Id ) --accept-package-agreements --accept-source-agreements -h "
2022-12-08 16:53:37 +00:00
& $Winget install - -id $ ( $app . Id ) - -accept -package -agreements - -accept -source -agreements -h | Tee-Object -file $LogFile -Append
}
2022-08-01 11:25:14 +00:00
2022-12-04 00:55:40 +00:00
if ( $ModsInstall ) {
2023-04-01 14:08:52 +00:00
Write-ToLog " Modifications for $( $app . Id ) during install are being applied... " " Yellow "
2022-12-04 00:55:40 +00:00
& " $ModsInstall "
}
2022-08-01 11:25:14 +00:00
#Check if application installed properly
$CheckOutdated2 = Get-WingetOutdatedApps
foreach ( $CheckApp2 in $CheckOutdated2 ) {
if ( $ ( $CheckApp2 . Id ) -eq $ ( $app . Id ) ) {
$FailedToUpgrade = $true
2022-05-05 19:48:04 +00:00
}
2022-08-01 11:25:14 +00:00
}
2022-04-05 13:17:18 +00:00
}
2022-04-13 16:50:06 +00:00
}
2022-07-27 15:40:40 +00:00
if ( $FailedToUpgrade -eq $false ) {
2022-12-04 00:55:40 +00:00
if ( $ModsInstalled ) {
2023-04-01 14:08:52 +00:00
Write-ToLog " Modifications for $( $app . Id ) after upgrade/install are being applied... " " Yellow "
2022-12-04 01:30:28 +00:00
& " $ModsInstalled "
2022-07-28 17:09:50 +00:00
}
2022-07-27 15:40:40 +00:00
}
2023-04-01 14:08:52 +00:00
Write-ToLog " ########## WINGET UPGRADE PROCESS FINISHED FOR APPLICATION ID ' $( $App . Id ) ' ########## " " Gray "
2022-04-05 13:17:18 +00:00
#Notify installation
2022-10-26 22:49:10 +00:00
if ( $FailedToUpgrade -eq $false ) {
2022-04-13 16:50:06 +00:00
2022-04-05 13:17:18 +00:00
#Send success updated app notification
2023-04-01 14:08:52 +00:00
Write-ToLog " $( $app . Name ) updated to $( $app . AvailableVersion ) ! " " Green "
2022-10-26 22:49:10 +00:00
2022-04-05 13:17:18 +00:00
#Send Notif
$Title = $NotifLocale . local . outputs . output [ 3 ] . title -f $ ( $app . Name )
$Message = $NotifLocale . local . outputs . output [ 3 ] . message -f $ ( $app . AvailableVersion )
$MessageType = " success "
$Balise = $ ( $app . Name )
2022-10-26 22:49:10 +00:00
Start-NotifTask -Title $Title -Message $Message -MessageType $MessageType -Balise $Balise -Button1Action $ReleaseNoteURL -Button1Text $Button1Text
2022-04-05 13:17:18 +00:00
2022-04-23 18:09:55 +00:00
$Script:InstallOK + = 1
2022-10-26 22:49:10 +00:00
2022-04-05 13:17:18 +00:00
}
else {
2022-04-13 16:50:06 +00:00
2022-04-05 13:17:18 +00:00
#Send failed updated app notification
2023-04-01 14:08:52 +00:00
Write-ToLog " $( $app . Name ) update failed. " " Red "
2022-10-26 22:49:10 +00:00
2022-04-05 13:17:18 +00:00
#Send Notif
$Title = $NotifLocale . local . outputs . output [ 4 ] . title -f $ ( $app . Name )
$Message = $NotifLocale . local . outputs . output [ 4 ] . message
$MessageType = " error "
$Balise = $ ( $app . Name )
2022-10-26 22:49:10 +00:00
Start-NotifTask -Title $Title -Message $Message -MessageType $MessageType -Balise $Balise -Button1Action $ReleaseNoteURL -Button1Text $Button1Text
2022-04-05 13:17:18 +00:00
}
2022-04-13 16:50:06 +00:00
2022-04-05 13:17:18 +00:00
}