# post_bootpack_pointer_refresh_v1.0.3.ps1 # Purpose: Post-build hook to refresh the [BUG_KB_JSON_POINTER] block in bootpack.txt # from bootpack_paste.txt, then optionally run acceptance. # Notes : PS 5.1-safe, UTF-8 no BOM, CRLF, no prompts. param( [string]$Root = "", [switch]$NoPrompt, [switch]$Verify ) try { [Console]::OutputEncoding = New-Object System.Text.UTF8Encoding($false) } catch {} function Exists([string]$p){ return (-not [string]::IsNullOrWhiteSpace($p)) -and (Test-Path -LiteralPath $p) } function ReadText([string]$p){ if(-not (Exists $p)){ return '' } try{ return Get-Content -LiteralPath $p -Raw -Encoding UTF8 }catch{ return (Get-Content -LiteralPath $p -Raw) } } # Resolve script dir robustly (no Split-Path paramset clash) $ScriptDir = $PSScriptRoot if([string]::IsNullOrWhiteSpace($ScriptDir)){ $sp = $MyInvocation.MyCommand.Path if([string]::IsNullOrWhiteSpace($sp)){ $sp = $PSCommandPath } if(-not [string]::IsNullOrWhiteSpace($sp)){ $ScriptDir = [System.IO.Path]::GetDirectoryName($sp) } } $PtrRefresh = Join-Path $ScriptDir 'kb_pointer_refresh_v1.0.ps1' $Acceptance = Join-Path $ScriptDir 'kb_acceptance_tests_v1.0.1.ps1' Write-Host '== POST :: bootpack pointer refresh v1.0.3 ==' Write-Host ("Root : {0}" -f $Root) Write-Host ("ScriptDir : {0}" -f $ScriptDir) Write-Host ("PtrRefresh : {0} {1}" -f $PtrRefresh, (Exists $PtrRefresh)) Write-Host ("Acceptance : {0} {1}" -f $Acceptance, (Exists $Acceptance)) if([string]::IsNullOrWhiteSpace($Root) -or (-not (Test-Path -LiteralPath $Root))){ Write-Host "[ERROR] Invalid -Root." exit 3 } if(-not (Exists $PtrRefresh)){ Write-Host "[ERROR] kb_pointer_refresh_v1.0.ps1 not found." exit 3 } # 1) Refresh pointer (force write, no prompt) Write-Host "[STEP] Refreshing KB Pointer..." & powershell -NoProfile -ExecutionPolicy Bypass -File $PtrRefresh -RegistryRoot $Root -Write $rc1 = $LASTEXITCODE if($rc1 -ne 0){ Write-Host ("[FAIL] pointer refresh rc={0}" -f $rc1) exit 3 } Write-Host "[OK] Pointer refreshed." # 2) Optional acceptance if(Exists $Acceptance -and $Verify){ Write-Host "[STEP] Running acceptance (PTR)..." & powershell -NoProfile -ExecutionPolicy Bypass -File $Acceptance $Root $rc2 = $LASTEXITCODE if($rc2 -ne 0){ Write-Host ("[FAIL] Acceptance PTR rc={0}" -f $rc2) exit 2 } Write-Host "[OK] Acceptance PTR PASS." }else{ Write-Host "[INFO] Acceptance skipped (missing script or -Verify not set)." } Write-Host "[OK] post_bootpack_pointer_refresh_v1.0.3 completed."