2022-04-13 16:50:06 +00:00
|
|
|
#Function to Update an App
|
|
|
|
|
2022-04-05 13:17:18 +00:00
|
|
|
Function Update-App ($app) {
|
|
|
|
|
|
|
|
#Send available update notification
|
|
|
|
Write-Log "Updating $($app.Name) from $($app.Version) to $($app.AvailableVersion)..." "Cyan"
|
|
|
|
$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)
|
|
|
|
Start-NotifTask $Title $Message $MessageType $Balise
|
|
|
|
|
|
|
|
#Winget upgrade
|
|
|
|
Write-Log "########## WINGET UPGRADE PROCESS STARTS FOR APPLICATION ID '$($App.Id)' ##########" "Gray"
|
2022-04-13 16:50:06 +00:00
|
|
|
|
|
|
|
#Run Winget Upgrade command
|
|
|
|
& $Winget upgrade --id $($app.Id) --all --accept-package-agreements --accept-source-agreements -h | Tee-Object -file $LogFile -Append
|
|
|
|
|
|
|
|
#Check if application updated properly
|
|
|
|
$CheckOutdated = Get-WingetOutdatedApps
|
|
|
|
$FailedToUpgrade = $false
|
2022-05-05 19:48:04 +00:00
|
|
|
#Check if mods exist
|
|
|
|
$ModsInstall, $ModsUpgrade = Test-Mods $($app.Id)
|
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)) {
|
|
|
|
|
|
|
|
#If app failed to upgrade, run Install command
|
|
|
|
& $Winget install --id $($app.Id) --accept-package-agreements --accept-source-agreements -h | Tee-Object -file $LogFile -Append
|
|
|
|
|
|
|
|
#Check if application installed properly
|
|
|
|
$CheckOutdated2 = Get-WingetOutdatedApps
|
2022-06-10 08:26:41 +00:00
|
|
|
foreach ($CheckApp2 in $CheckOutdated2) {
|
2022-04-13 16:50:06 +00:00
|
|
|
if ($($CheckApp2.Id) -eq $($app.Id)) {
|
|
|
|
$FailedToUpgrade = $true
|
2022-05-05 19:48:04 +00:00
|
|
|
}
|
|
|
|
else {
|
2022-06-10 08:26:41 +00:00
|
|
|
if ($ModsInstall) {
|
2022-05-06 00:47:45 +00:00
|
|
|
Write-Log "Modifications for $($app.Id) after install are being applied..." "Yellow"
|
2022-05-05 19:48:04 +00:00
|
|
|
& "$ModsInstall"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2022-06-10 08:26:41 +00:00
|
|
|
if ($ModsUpgrade) {
|
2022-05-06 00:47:45 +00:00
|
|
|
Write-Log "Modifications for $($app.Id) after upgrade are being applied..." "Yellow"
|
2022-05-05 19:48:04 +00:00
|
|
|
& "$ModsUpgrade"
|
2022-04-05 13:17:18 +00:00
|
|
|
}
|
|
|
|
}
|
2022-04-13 16:50:06 +00:00
|
|
|
}
|
|
|
|
|
2022-04-05 13:17:18 +00:00
|
|
|
Write-Log "########## WINGET UPGRADE PROCESS FINISHED FOR APPLICATION ID '$($App.Id)' ##########" "Gray"
|
|
|
|
|
|
|
|
#Notify installation
|
2022-06-10 08:26:41 +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
|
|
|
|
Write-Log "$($app.Name) updated to $($app.AvailableVersion) !" "Green"
|
|
|
|
|
|
|
|
#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)
|
|
|
|
Start-NotifTask $Title $Message $MessageType $Balise
|
|
|
|
|
2022-04-23 18:09:55 +00:00
|
|
|
$Script:InstallOK += 1
|
2022-04-13 16:50:06 +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
|
|
|
|
Write-Log "$($app.Name) update failed." "Red"
|
|
|
|
|
|
|
|
#Send Notif
|
|
|
|
$Title = $NotifLocale.local.outputs.output[4].title -f $($app.Name)
|
|
|
|
$Message = $NotifLocale.local.outputs.output[4].message
|
|
|
|
$MessageType = "error"
|
|
|
|
$Balise = $($app.Name)
|
|
|
|
Start-NotifTask $Title $Message $MessageType $Balise
|
2022-04-13 16:50:06 +00:00
|
|
|
|
2022-04-05 13:17:18 +00:00
|
|
|
}
|
2022-04-13 16:50:06 +00:00
|
|
|
|
2022-04-05 13:17:18 +00:00
|
|
|
}
|