1
0

watch-staging.ps1 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. # Copy the silent-update staging exe and its provenance before PCL cleanup.
  2. # ASCII only. Windows PowerShell 5.1 compatible.
  3. param(
  4. [string]$Staging,
  5. [string]$Evidence,
  6. [string]$PclDir,
  7. [int]$Timeout = 180
  8. )
  9. if (-not $Staging -and $PclDir) {
  10. $Staging = Join-Path $PclDir 'PCL\Plain Craft Launcher 2.exe'
  11. }
  12. if (-not $Staging) { exit 2 }
  13. $deadline = (Get-Date).AddSeconds($Timeout)
  14. $last = -1
  15. while ((Get-Date) -lt $deadline) {
  16. if (Test-Path -LiteralPath $Staging) {
  17. $len = (Get-Item -LiteralPath $Staging).Length
  18. if ($len -gt 0 -and $len -eq $last) {
  19. Copy-Item -LiteralPath $Staging -Destination (Join-Path $Evidence 'staging.exe') -Force
  20. (Get-FileHash -LiteralPath $Staging -Algorithm SHA256).Hash | Set-Content -LiteralPath (Join-Path $Evidence 'staging.sha256.txt') -Encoding ASCII
  21. if ($PclDir) {
  22. Copy-Item -Path (Join-Path $PclDir 'PCL\Log*.txt') -Destination $Evidence -Force -ErrorAction SilentlyContinue
  23. Copy-Item -LiteralPath (Join-Path $PclDir 'PCL\Setup.ini') -Destination $Evidence -Force -ErrorAction SilentlyContinue
  24. }
  25. Copy-Item -Path (Join-Path $env:TEMP 'PCL\Cache\*') -Destination $Evidence -Force -ErrorAction SilentlyContinue
  26. 'FOUND' | Set-Content -LiteralPath (Join-Path $Evidence 'watch-staging.txt') -Encoding ASCII
  27. exit 0
  28. }
  29. $last = $len
  30. }
  31. Start-Sleep -Milliseconds 250
  32. }
  33. 'TIMEOUT' | Set-Content -LiteralPath (Join-Path $Evidence 'watch-staging.txt') -Encoding ASCII
  34. exit 1