From 2f96eee4ad55d63b43c5f34f7a3c679b9ae7ac9e Mon Sep 17 00:00:00 2001 From: rmeijer_huizehetoost Date: Wed, 29 Oct 2025 11:42:18 +0100 Subject: [PATCH] fix --- main-menu.ps1 | 74 +++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 54 insertions(+), 20 deletions(-) diff --git a/main-menu.ps1 b/main-menu.ps1 index bef7479..f7a88f8 100644 --- a/main-menu.ps1 +++ b/main-menu.ps1 @@ -321,22 +321,39 @@ function Install-MedewerkersApps { Write-ColorText "[$currentApp/$totalApps] Installeer $app..." "Cyan" try { - $process = Start-Process -NoNewWindow -Wait -FilePath "winget" -ArgumentList "install --id $app -e --silent --accept-package-agreements --accept-source-agreements --source winget --scope machine" -PassThru + # Capture both output and error streams + $outputFile = "$env:TEMP\winget_$(Get-Random).txt" + $errorFile = "$env:TEMP\winget_error_$(Get-Random).txt" + + $process = Start-Process -NoNewWindow -Wait -FilePath "winget" -ArgumentList "install --id $app -e --silent --accept-package-agreements --accept-source-agreements --source winget --scope machine" -PassThru -RedirectStandardOutput $outputFile -RedirectStandardError $errorFile $exitCode = $process.ExitCode - # Check exit codes: 0 = success, 0x8A150011 = package already installed, others = errors - if ($exitCode -eq 0 -or $exitCode -eq 0x8A150011) { - if ($exitCode -eq 0x8A150011) { - Write-ColorText "✓ $app is al geïnstalleerd" "Yellow" - } else { - Write-ColorText "✓ $app succesvol geïnstalleerd" "Green" - } + # Read output to determine actual result + $outputContent = "" + $errorContent = "" + if (Test-Path $outputFile) { + $outputContent = Get-Content $outputFile -Raw -ErrorAction SilentlyContinue + Remove-Item $outputFile -Force -ErrorAction SilentlyContinue + } + if (Test-Path $errorFile) { + $errorContent = Get-Content $errorFile -Raw -ErrorAction SilentlyContinue + Remove-Item $errorFile -Force -ErrorAction SilentlyContinue + } + + # Check for success indicators in output + $combinedOutput = "$outputContent $errorContent" + if ($combinedOutput -match "Successfully installed" -or $exitCode -eq 0) { + Write-ColorText "✓ $app succesvol geïnstalleerd" "Green" + } elseif ($combinedOutput -match "already installed|No applicable|No available upgrade" -or ($null -ne $exitCode -and $exitCode -ne 0)) { + Write-ColorText "✓ $app is al geïnstalleerd (geen actie nodig)" "Yellow" } else { - Write-ColorText "✗ Fout bij installatie van $app (Exit code: $exitCode)" "Red" + Write-ColorText "✗ Fout bij installatie van $app" "Red" } } catch { Write-ColorText "✗ Fout bij installatie van $app" "Red" - Write-ColorText "Foutdetails: $($_.Exception.Message)" "Red" + if ($_.Exception.Message) { + Write-ColorText "Foutdetails: $($_.Exception.Message)" "Red" + } } Write-Host "" @@ -407,22 +424,39 @@ function Install-GastenApps { Write-ColorText "[$currentApp/$totalApps] Installeer $app..." "Cyan" try { - $process = Start-Process -NoNewWindow -Wait -FilePath "winget" -ArgumentList "install --id $app -e --silent --accept-package-agreements --accept-source-agreements --source winget --scope machine" -PassThru + # Capture both output and error streams + $outputFile = "$env:TEMP\winget_$(Get-Random).txt" + $errorFile = "$env:TEMP\winget_error_$(Get-Random).txt" + + $process = Start-Process -NoNewWindow -Wait -FilePath "winget" -ArgumentList "install --id $app -e --silent --accept-package-agreements --accept-source-agreements --source winget --scope machine" -PassThru -RedirectStandardOutput $outputFile -RedirectStandardError $errorFile $exitCode = $process.ExitCode - # Check exit codes: 0 = success, 0x8A150011 = package already installed, others = errors - if ($exitCode -eq 0 -or $exitCode -eq 0x8A150011) { - if ($exitCode -eq 0x8A150011) { - Write-ColorText "✓ $app is al geïnstalleerd" "Yellow" - } else { - Write-ColorText "✓ $app succesvol geïnstalleerd" "Green" - } + # Read output to determine actual result + $outputContent = "" + $errorContent = "" + if (Test-Path $outputFile) { + $outputContent = Get-Content $outputFile -Raw -ErrorAction SilentlyContinue + Remove-Item $outputFile -Force -ErrorAction SilentlyContinue + } + if (Test-Path $errorFile) { + $errorContent = Get-Content $errorFile -Raw -ErrorAction SilentlyContinue + Remove-Item $errorFile -Force -ErrorAction SilentlyContinue + } + + # Check for success indicators in output + $combinedOutput = "$outputContent $errorContent" + if ($combinedOutput -match "Successfully installed" -or $exitCode -eq 0) { + Write-ColorText "✓ $app succesvol geïnstalleerd" "Green" + } elseif ($combinedOutput -match "already installed|No applicable|No available upgrade" -or ($null -ne $exitCode -and $exitCode -ne 0)) { + Write-ColorText "✓ $app is al geïnstalleerd (geen actie nodig)" "Yellow" } else { - Write-ColorText "✗ Fout bij installatie van $app (Exit code: $exitCode)" "Red" + Write-ColorText "✗ Fout bij installatie van $app" "Red" } } catch { Write-ColorText "✗ Fout bij installatie van $app" "Red" - Write-ColorText "Foutdetails: $($_.Exception.Message)" "Red" + if ($_.Exception.Message) { + Write-ColorText "Foutdetails: $($_.Exception.Message)" "Red" + } } Write-Host ""