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 #Config console output encoding
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8 [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 $caller = Get-ChildItem $MyInvocation.PSCommandPath | Select-Object -Expand Name
if ($caller -eq "Winget-Upgrade.ps1") { if ($caller -eq "Winget-Upgrade.ps1") {
#Log Header #Log Header

View File

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

View File

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