Improved application detection after upgrade

pull/356/head
romanitho 2023-06-21 15:47:38 +02:00
parent 5efbb98eb1
commit d8d71536e2
4 changed files with 58 additions and 35 deletions

View File

@ -0,0 +1,27 @@
Function Confirm-Installation ($AppName, $AppVer){
#Set json export file
$JsonFile = "$WorkingDir\Config\InstalledApps.json"
#Get installed apps and version in json file
& $Winget export -s winget -o $JsonFile --include-versions | Out-Null
#Get json content
$Json = Get-Content $JsonFile -Raw | ConvertFrom-Json
#Get apps and version in hashtable
$Packages = $Json.Sources.Packages
#Remove json file
Remove-Item $JsonFile -Force
# Search for specific app and version
$Apps = $Packages | Where-Object { $_.PackageIdentifier -eq $AppName -and $_.Version -eq $AppVer}
if ($Apps){
return $true
}
else{
return $false
}
}

View File

@ -5,6 +5,9 @@ function Start-Init {
#Config console output encoding
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
# Workaround for ARM64 (Access Denied / Win32 internal Server error)
$Script:ProgressPreference = 'SilentlyContinue'
$caller = Get-ChildItem $MyInvocation.PSCommandPath | Select-Object -Expand Name
if ($caller -eq "Winget-Upgrade.ps1") {
#Log Header

View File

@ -5,9 +5,6 @@ function Test-Network {
#Init
$timeout = 0
# Workaround for ARM64 (Access Denied / Win32 internal Server error)
$ProgressPreference = 'SilentlyContinue'
#Test connectivity during 30 min then timeout
Write-ToLog "Checking internet connection..." "Yellow"
While ($timeout -lt 1800) {

View File

@ -44,44 +44,40 @@ Function Update-App ($app) {
}
#Check if application updated properly
$CheckOutdated = Get-WingetOutdatedApps
$FailedToUpgrade = $false
foreach ($CheckApp in $CheckOutdated) {
if ($($CheckApp.Id) -eq $($app.Id)) {
$ConfirmInstall = Confirm-Installation $($app.Id) $($app.AvailableVersion)
#Upgrade failed!
#Test for a Pending Reboot (Component Based Servicing/WindowsUpdate/CCM_ClientUtilities)
$PendingReboot = Test-PendingReboot
if ($PendingReboot -eq $true) {
Write-ToLog "-> A Pending Reboot lingers and probably prohibited $($app.Name) from upgrading...`n-> ...an install for $($app.Name) is NOT executed!" "Red"
$FailedToUpgrade = $true
break
}
if ($ConfirmInstall -ne $true) {
#Upgrade failed!
#Test for a Pending Reboot (Component Based Servicing/WindowsUpdate/CCM_ClientUtilities)
$PendingReboot = Test-PendingReboot
if ($PendingReboot -eq $true) {
Write-ToLog "-> A Pending Reboot lingers and probably prohibited $($app.Name) from upgrading...`n-> ...an install for $($app.Name) is NOT executed!" "Red"
$FailedToUpgrade = $true
break
}
#If app failed to upgrade, run Install command
Write-ToLog "-> An upgrade for $($app.Name) failed, now trying an install instead..." "Yellow"
#If app failed to upgrade, run Install command
Write-ToLog "-> An upgrade for $($app.Name) failed, now trying an install instead..." "Yellow"
if ($ModsOverride) {
Write-ToLog "-> Running (overriding default): Winget install --id $($app.Id) --accept-package-agreements --accept-source-agreements --force --override $ModsOverride"
& $Winget install --id $($app.Id) --accept-package-agreements --accept-source-agreements --force --override $ModsOverride | Tee-Object -file $LogFile -Append
}
else {
Write-ToLog "-> Running: Winget install --id $($app.Id) --accept-package-agreements --accept-source-agreements --force -h"
& $Winget install --id $($app.Id) --accept-package-agreements --accept-source-agreements --force -h | Tee-Object -file $LogFile -Append
}
if ($ModsOverride) {
Write-ToLog "-> Running (overriding default): Winget install --id $($app.Id) --accept-package-agreements --accept-source-agreements --force --override $ModsOverride"
& $Winget install --id $($app.Id) --accept-package-agreements --accept-source-agreements --force --override $ModsOverride | Tee-Object -file $LogFile -Append
}
else {
Write-ToLog "-> Running: Winget install --id $($app.Id) --accept-package-agreements --accept-source-agreements --force -h"
& $Winget install --id $($app.Id) --accept-package-agreements --accept-source-agreements --force -h | Tee-Object -file $LogFile -Append
}
if ($ModsInstall) {
Write-ToLog "Modifications for $($app.Id) during install are being applied..." "Yellow"
& "$ModsInstall"
}
if ($ModsInstall) {
Write-ToLog "Modifications for $($app.Id) during install are being applied..." "Yellow"
& "$ModsInstall"
}
#Check if application installed properly
$CheckOutdated2 = Get-WingetOutdatedApps
foreach ($CheckApp2 in $CheckOutdated2) {
if ($($CheckApp2.Id) -eq $($app.Id)) {
$FailedToUpgrade = $true
}
}
#Check if application installed properly
$ConfirmInstall = Confirm-Installation $($app.Id) $($app.AvailableVersion)
if ($ConfirmInstall -eq $false) {
$FailedToUpgrade = $true
}
}