Files
BT411/players/SENDLOGS.bat
T
Joe DiPrimaandClaude Opus 5 45750a6fcf SENDLOGS.bat: fix the two field failures + stop it lying about success. Two testers hit DIFFERENT errors, both now reproduced on a rig and fixed.
(1) ConstrainedLanguage mode (locked-down Windows, WDAC/AppLocker) blocks .NET method calls, so [Environment]::GetFolderPath('Desktop') returned nothing -> null DestinationPath -> no zip, and [math]::Round blew up on the size. Desktop is now resolved from OneDrive/USERPROFILE env vars (still honouring a redirected Desktop) and the size via -f formatting. Deeper trap found while testing: Compress-Archive ITSELF cannot run in that mode -- it is a script module that calls .NET internally -- so fixing the path alone would only have moved the failure downstream. The zip is now built with Windows' native tar.exe (immune to language mode, present since Win10 1803, verified to emit a real Explorer-readable zip), with Compress-Archive kept only as a fallback.

(2) A log still held open by a running BattleTech made Compress-Archive abort the ENTIRE zip -- one locked file, no logs at all. Files are now staged with Copy-Item first: an unreadable one is skipped and NAMED, the zip still gets made from the rest, and the tester is told to close the game and re-run to capture the missing one.

(3) The script announced 'Wrote <path>' and 'Attach the BTLOGS zip' unconditionally -- tester 2's screenshot shows it claiming '11 files, 0 MB' for a zip that was never created. Success is now gated on Test-Path, failure exits 1, and the batch prints 'Nothing was created' instead of sending people to hunt for a file that does not exist.

Also adds ABOUT.txt inside the zip (machine, pack time, install folder, exe build date/version) so a report can be tied to a BUILD -- the ambiguity that has cost us repeatedly when a Pass/Fail arrives with no build number.

Verified on four scenarios: normal run, a log locked by another process, a session downgraded to ConstrainedLanguage (reproducing tester 1's exact MethodInvocationNotSupportedInConstrainedLanguage error first), and running from a folder with no content dir. Handout updated: close the game first, and what SKIPPED means.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-15 01:10:18 -05:00

65 lines
4.4 KiB
Batchfile

@echo off
rem ==========================================================================
rem BT411 -- package tonight's logs into ONE Discord-attachable zip.
rem Double-click me after a playtest. The zip lands on your DESKTOP as
rem BTLOGS_<machine>_<date>.zip -- attach that one file in Discord.
rem Collects: every session log, matchlog, and launch breadcrumb. Nothing
rem is deleted or modified; this only makes a copy.
rem
rem Field-hardened 2026-08-15 after two testers hit different failures:
rem * ConstrainedLanguage mode (locked-down Windows) blocks .NET calls, so
rem [Environment]::GetFolderPath and [math]::Round are gone -- the Desktop
rem is resolved from environment variables and the size via -f formatting.
rem Compress-Archive ALSO fails there (it is a script module that calls
rem .NET internally), so the zip is made with Windows' native tar.exe and
rem Compress-Archive is only the fallback if tar is missing.
rem * A log still held open by a running BattleTech made Compress-Archive
rem abort the WHOLE zip. Files are now staged with Copy-Item first, so an
rem unreadable one is skipped and named instead of killing the run.
rem * The old script announced success unconditionally. It now only says
rem the zip is ready if the file actually exists.
rem ABOUT.txt (machine, date, folder, exe version) rides inside the zip so we
rem can tell WHICH BUILD a report came from.
rem ==========================================================================
cd /d "%~dp0"
powershell -NoProfile -ExecutionPolicy Bypass -Command ^
"$ErrorActionPreference = 'SilentlyContinue';" ^
"$d = Get-Date -Format yyyyMMdd_HHmm;" ^
"$desk = $null;" ^
"if ($env:OneDrive -and (Test-Path (Join-Path $env:OneDrive 'Desktop'))) { $desk = Join-Path $env:OneDrive 'Desktop' }" ^
"elseif (Test-Path (Join-Path $env:USERPROFILE 'Desktop')) { $desk = Join-Path $env:USERPROFILE 'Desktop' }" ^
"else { $desk = $PWD.Path };" ^
"$out = Join-Path $desk ('BTLOGS_{0}_{1}.zip' -f $env:COMPUTERNAME, $d);" ^
"$files = Get-ChildItem -Path 'content\*.log','content\lastrun_*.txt','content\matchlog_*.txt','content\cdb_*.txt' | Where-Object { $_.LastWriteTime -gt (Get-Date).AddHours(-36) };" ^
"if (-not $files) { Write-Host ''; Write-Host ' No logs found -- run me from the BT411 folder (the one containing content).' -ForegroundColor Yellow; exit 1 };" ^
"$stage = Join-Path $env:TEMP ('BTLOGS_' + $d);" ^
"Remove-Item -Recurse -Force $stage;" ^
"New-Item -ItemType Directory -Path $stage -Force | Out-Null;" ^
"$kept = 0; $skip = @();" ^
"foreach ($f in $files) { Copy-Item -LiteralPath $f.FullName -Destination $stage -Force; if (Test-Path (Join-Path $stage $f.Name)) { $kept = $kept + 1 } else { $skip += $f.Name } };" ^
"$exe = Get-Item 'btl4.exe';" ^
"$about = Join-Path $stage 'ABOUT.txt';" ^
"Set-Content -Path $about -Value ('machine=' + $env:COMPUTERNAME);" ^
"Add-Content -Path $about -Value ('packed=' + $d);" ^
"Add-Content -Path $about -Value ('folder=' + $PWD.Path);" ^
"if ($exe) { Add-Content -Path $about -Value ('btl4.exe built ' + $exe.LastWriteTime); if ($exe.VersionInfo.FileVersion) { Add-Content -Path $about -Value ('btl4.exe version ' + $exe.VersionInfo.FileVersion) } };" ^
"if ($kept -eq 0) { Write-Host ''; Write-Host ' Could not read any log files -- close BattleTech, then run me again.' -ForegroundColor Red; exit 1 };" ^
"Remove-Item -Force $out;" ^
"Push-Location $stage;" ^
"if (Get-Command tar.exe) { tar.exe -a -c -f $out * } ;" ^
"Pop-Location;" ^
"if (-not (Test-Path $out)) { Compress-Archive -Force -Path (Join-Path $stage '*') -DestinationPath $out };" ^
"Remove-Item -Recurse -Force $stage;" ^
"Write-Host '';" ^
"if (Test-Path $out) { Write-Host (' ZIP READY: ' + $out) -ForegroundColor Green; Write-Host (' ' + $kept + ' files, ' + ('{0:N1}' -f ((Get-Item $out).Length/1MB)) + ' MB'); if ($skip.Count -gt 0) { Write-Host (' SKIPPED (still in use): ' + ($skip -join ', ')) -ForegroundColor Yellow; Write-Host ' Close BattleTech and run me again to include those.' -ForegroundColor Yellow } }" ^
"else { Write-Host ' FAILED -- no zip was created.' -ForegroundColor Red; Write-Host ' Screenshot this window and send it to us.' -ForegroundColor Red; exit 1 }"
if errorlevel 1 goto :failed
echo.
echo Attach that BTLOGS zip in Discord. Thanks!
goto :done
:failed
echo.
echo Nothing was created -- see the message above.
:done
pause