KAZIK/tools/build_launcher.ps1

27 lines
1.6 KiB
PowerShell

$ErrorActionPreference = 'Stop'
$repoPath = Split-Path -Parent $PSScriptRoot
$gamePath = Join-Path $repoPath 'poker.exe'
$binPath = Join-Path $repoPath 'bin'
New-Item -ItemType Directory -Path $binPath -Force | Out-Null
Copy-Item -LiteralPath $gamePath -Destination (Join-Path $binPath 'poker.exe') -Force
$sha = [System.Security.Cryptography.SHA256]::Create()
$gameStream = [System.IO.File]::OpenRead($gamePath)
try { $gameHash = [System.BitConverter]::ToString($sha.ComputeHash($gameStream)).Replace('-', '') }
finally { $gameStream.Dispose(); $sha.Dispose() }
$sourcePath = Join-Path $repoPath 'build/AssemblerCasinoLauncher.cs'
$sourceText = [System.IO.File]::ReadAllText($sourcePath)
$sourceText = [regex]::Replace($sourceText, 'ExpectedPokerSha256 = "[A-Fa-f0-9]+"', ('ExpectedPokerSha256 = "' + $gameHash + '"'))
[System.IO.File]::WriteAllText($sourcePath, $sourceText, (New-Object System.Text.UTF8Encoding($false)))
$compilerPath = Join-Path $env:WINDIR 'Microsoft.NET/Framework64/v4.0.30319/csc.exe'
if (-not (Test-Path -LiteralPath $compilerPath)) {
$compilerPath = Join-Path $env:WINDIR 'Microsoft.NET/Framework/v4.0.30319/csc.exe'
}
$outputPath = Join-Path $repoPath 'dist/Assembler Casino.exe'
$iconPath = Join-Path $repoPath 'assets/icons/casino.ico'
$savedCompilerLib = $env:LIB
try {
$env:LIB = ''
& $compilerPath /nologo /target:winexe /optimize+ /r:System.Windows.Forms.dll ("/win32icon:$iconPath") ("/out:$outputPath") $sourcePath
} finally { $env:LIB = $savedCompilerLib }
if ($LASTEXITCODE -ne 0) { throw 'Launcher compilation failed' }
Write-Output 'Updated bin/poker.exe and verified-hash launcher.'