From f0c3a727b9df9a29da67c6b76d0d23907228cdab Mon Sep 17 00:00:00 2001 From: iTracerFacer <134304944+iTracerFacer@users.noreply.github.com> Date: Sun, 26 Oct 2025 09:05:21 -0500 Subject: [PATCH] Bug fixes on the whatif --- Patch-MooseMissions/Patch-MooseMissions.ps1 | 10 ++++----- Patch-MooseMissions/Patch-MyMooseMissions.ps1 | 22 ++++++++++++++----- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/Patch-MooseMissions/Patch-MooseMissions.ps1 b/Patch-MooseMissions/Patch-MooseMissions.ps1 index e55aec4..bb2c4ba 100644 --- a/Patch-MooseMissions/Patch-MooseMissions.ps1 +++ b/Patch-MooseMissions/Patch-MooseMissions.ps1 @@ -85,7 +85,7 @@ begin { # Validate output path if specified if ($OutputPath -and -not (Test-Path $OutputPath)) { Write-Host "Creating output directory: $OutputPath" -ForegroundColor Yellow - New-Item -Path $OutputPath -ItemType Directory -Force | Out-Null + New-Item -Path $OutputPath -ItemType Directory -Force -WhatIf:$false | Out-Null } $successCount = 0 @@ -161,7 +161,7 @@ process { # Create temporary extraction directory $tempDir = Join-Path $env:TEMP ("DCS_Mission_Patch_" + [System.Guid]::NewGuid().ToString()) - New-Item -Path $tempDir -ItemType Directory -Force | Out-Null + New-Item -Path $tempDir -ItemType Directory -Force -WhatIf:$false | Out-Null try { # Extract mission file (it's a ZIP archive) @@ -178,7 +178,7 @@ process { # Create directory if it doesn't exist if (-not (Test-Path $luaDestDir)) { Write-Host " Creating l10n/DEFAULT directory..." -ForegroundColor Yellow - New-Item -Path $luaDestDir -ItemType Directory -Force | Out-Null + New-Item -Path $luaDestDir -ItemType Directory -Force -WhatIf:$false | Out-Null } $luaDestPath = Join-Path $luaDestDir $ScriptName @@ -191,7 +191,7 @@ process { } # Copy Lua script to mission - Copy-Item $LuaScriptPath $luaDestPath -Force + Copy-Item $LuaScriptPath $luaDestPath -Force -WhatIf:$false # Determine output filename and location $originalFileName = Split-Path $missionFile -Leaf @@ -216,7 +216,7 @@ process { # Remove existing mission file if it exists if (Test-Path $outputMission) { - Remove-Item $outputMission -Force + Remove-Item $outputMission -Force -WhatIf:$false } # Repackage mission file diff --git a/Patch-MooseMissions/Patch-MyMooseMissions.ps1 b/Patch-MooseMissions/Patch-MyMooseMissions.ps1 index 7c74a26..35a1070 100644 --- a/Patch-MooseMissions/Patch-MyMooseMissions.ps1 +++ b/Patch-MooseMissions/Patch-MyMooseMissions.ps1 @@ -303,18 +303,30 @@ foreach ($terrainFolder in $terrainFolders) { # Execute the patch script if (-not $runInWhatIfMode) { try { - # Call Patch-MooseMissions.ps1 - & $patchScriptPath -MissionPath $latestMission.FullName -LuaScriptPath $MooseLuaPath -ErrorAction Stop + # Capture output from Patch-MooseMissions.ps1 + $patchOutput = & $patchScriptPath -MissionPath $latestMission.FullName -LuaScriptPath $MooseLuaPath 2>&1 - # Check if it succeeded (the script will output its own messages) - if ($LASTEXITCODE -eq 0 -or $null -eq $LASTEXITCODE) { + # Display the output + $patchOutput | ForEach-Object { Write-Output $_ } + + # Check if it succeeded by looking for error indicators in output + $errorFound = $false + foreach ($line in $patchOutput) { + if ($line -match "ERROR:" -or $line -match "Failed: [1-9]") { + $errorFound = $true + break + } + } + + if (-not $errorFound) { $totalMissionsPatched++ } else { $totalMissionsFailed++ + Write-Host " Mission patch failed - see errors above" -ForegroundColor Red } } catch { - Write-Host " ERROR: Failed to patch mission - $_" -ForegroundColor Red + Write-Host " ERROR: Failed to execute patch script - $_" -ForegroundColor Red $totalMissionsFailed++ } }