$ErrorActionPreference = 'Stop' $repoRoot = (Resolve-Path (Join-Path $PSScriptRoot '..')).Path $source = Join-Path $PSScriptRoot 'appcontainer_probe.cpp' $vcvars = Join-Path ${env:ProgramFiles(x86)} 'Microsoft Visual Studio\2022\BuildTools\VC\Auxiliary\Build\vcvars64.bat' if (-not (Test-Path -LiteralPath $vcvars)) { throw "Visual Studio C++ Build Tools not found: $vcvars" } $outputDir = Join-Path $env:TEMP ("SovereignAI-AppContainer-" + [guid]::NewGuid().ToString('N')) New-Item -ItemType Directory -Path $outputDir | Out-Null $exe = Join-Path $outputDir 'appcontainer_probe.exe' $obj = Join-Path $outputDir 'appcontainer_probe.obj' try { Push-Location $repoRoot try { $compile = 'call "{0}" && cl.exe /nologo /EHsc /W4 /MT /Fo:"{1}" "{2}" /Fe:"{3}" /link Userenv.lib Ole32.lib Advapi32.lib' -f $vcvars, $obj, $source, $exe & cmd.exe /d /s /c $compile if ($LASTEXITCODE -ne 0) { throw "C++ probe compilation failed with exit code $LASTEXITCODE" } & $exe $probeExit = $LASTEXITCODE if ($probeExit -ne 0) { throw "AppContainer probe failed with exit code $probeExit" } } finally { Pop-Location } } finally { $resolvedOutput = (Resolve-Path -LiteralPath $outputDir -ErrorAction SilentlyContinue).Path $tempRoot = [IO.Path]::GetFullPath($env:TEMP).TrimEnd('\') + '\' if ($resolvedOutput -and $resolvedOutput.StartsWith($tempRoot, [StringComparison]::OrdinalIgnoreCase) -and (Split-Path -Leaf $resolvedOutput).StartsWith('SovereignAI-AppContainer-', [StringComparison]::Ordinal)) { Remove-Item -LiteralPath $resolvedOutput -Recurse -Force } }