cockatrice-custom-tokens/install.ps1

48 lines
2.6 KiB
PowerShell

#requires -Version 5.1
<# Windows launcher for the shared, validated Cockatrice custom-set installer. #>
[CmdletBinding()]
param(
[string]$DataDir,
[switch]$Force,
[switch]$Help
)
$ErrorActionPreference = 'Stop'
Set-StrictMode -Version Latest
if ($Help) {
Write-Host 'Usage: .\install.ps1 [-DataDir C:\path\to\Cockatrice\data] [-Force]'
Write-Host 'DataDir is the folder containing cards.xml or settings/, normally alongside decks/.'
Write-Host 'Example: C:\Users\YourName\AppData\Local\Cockatrice\Cockatrice (not its parent or customsets folder). '
Write-Host 'Missing customsets/pics folders are created only after confirmation and successful validation.'
Write-Host 'Requires Windows, Python 3.8+, curl.exe, and an interactive console. Close Cockatrice first.'
return
}
if ($env:OS -ne 'Windows_NT') { throw 'This launcher requires Windows; use install.sh on Linux/macOS.' }
# Publication replaces this marker with the installer, making the download standalone.
$EmbeddedPython = '__COCKATRICE_PYTHON_BASE64__'
$PythonExe = $null
$PythonPrefix = @()
foreach ($candidate in @('py.exe', 'python.exe', 'python3.exe')) {
$command = Get-Command $candidate -CommandType Application -ErrorAction SilentlyContinue
if ($null -eq $command) { continue }
$prefix = @()
if ($candidate -eq 'py.exe') { $prefix = @('-3') }
& $command.Source @prefix -c 'import sys; sys.exit(sys.version_info < (3, 8))' 2>$null
if ($LASTEXITCODE -eq 0) { $PythonExe = $command.Source; $PythonPrefix = $prefix; break }
}
if ($null -eq $PythonExe) { throw 'Python 3.8+ is required. Install Python, reopen PowerShell, and retry.' }
if ($null -eq (Get-Command curl.exe -CommandType Application -ErrorAction SilentlyContinue)) {
throw 'curl.exe is required; install it and retry. Nothing installed.'
}
$InstallerArgs = @()
if ($DataDir) { $InstallerArgs += @('--data-dir', $DataDir) }
if ($Force) { $InstallerArgs += '--force' }
if ($EmbeddedPython.StartsWith('__COCKATRICE_')) {
$SourceFile = Join-Path $PSScriptRoot 'scripts/install.py'
if (-not (Test-Path -LiteralPath $SourceFile -PathType Leaf)) { throw "Installer source missing: $SourceFile" }
& $PythonExe @PythonPrefix $SourceFile @InstallerArgs
} else {
# Use stdin for the embedded payload; prompts read the Windows console separately.
$EmbeddedPython | & $PythonExe @PythonPrefix -c "import base64,sys; exec(compile(base64.b64decode(sys.stdin.read()), 'install.py', 'exec'))" @InstallerArgs
}
if ($LASTEXITCODE -ne 0) { throw "Installer failed (exit $LASTEXITCODE). See the error and any recovery path above." }