Files
opendance-windows/build/export-windows.ps1
T

113 lines
4.0 KiB
PowerShell
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<#
.SYNOPSIS
OpenDance Studio —— Windows 客户端导出(在 Windows 上执行)
.DESCRIPTION
文档 §5.3 方案 B(兜底):若因插件或引擎限制无法在 Linux 导出,
由用户在 Windows 端执行本脚本。
前置:
1. 已安装 Godot 4 并将其加入 PATH,或用 -GodotBin 指定完整路径
2. 已安装对应版本的 export templates
(Godot 编辑器 → 编辑器 → 管理导出模板 → 下载并安装)
.PARAMETER GodotBin
Godot 可执行文件路径,默认 "godot"
.PARAMETER OutputDir
产物输出目录,默认 ".\build\windows"
.PARAMETER Mode
release 或 debug,默认 release
.EXAMPLE
powershell -ExecutionPolicy Bypass -File build\export-windows.ps1
powershell -ExecutionPolicy Bypass -File build\export-windows.ps1 -GodotBin "C:\Godot\godot.exe"
#>
param(
[string]$GodotBin = "godot",
[string]$OutputDir = ".\build\windows",
[ValidateSet("release", "debug")]
[string]$Mode = "release"
)
$ErrorActionPreference = "Stop"
$ProjectDir = Split-Path -Parent (Split-Path -Parent $MyInvocation.MyCommand.Path)
Set-Location $ProjectDir
Write-Host "[export] 项目:$ProjectDir"
Write-Host "[export] Godot:$GodotBin"
Write-Host "[export] 模式:$Mode"
# ---- 定位 Godot ----
$godotCmd = Get-Command $GodotBin -ErrorAction SilentlyContinue
if (-not $godotCmd -and -not (Test-Path $GodotBin)) {
Write-Error "未找到 Godot 可执行文件「$GodotBin」。请安装 Godot 4 或用 -GodotBin 指定完整路径。"
exit 1
}
$GodotExe = if ($godotCmd) { $godotCmd.Source } else { $GodotBin }
$version = & $GodotExe --version 2>$null | Select-Object -First 1
Write-Host "[export] 版本:$version"
# ---- 导出预设必须位于项目根目录 ----
if (-not (Test-Path (Join-Path $ProjectDir "export_presets.cfg"))) {
$fallback = Join-Path $ProjectDir "build\export_presets.cfg"
if (Test-Path $fallback) {
Copy-Item $fallback (Join-Path $ProjectDir "export_presets.cfg")
Write-Host "[export] 已从 build\ 复制导出预设到项目根目录"
} else {
Write-Error "缺少 export_presets.cfg(Godot 要求放在项目根目录)。"
exit 1
}
}
# ---- 检查导出模板 ----
$templateDir = Join-Path $env:APPDATA "Godot\export_templates"
if (-not (Test-Path $templateDir) -or (Get-ChildItem $templateDir -ErrorAction SilentlyContinue).Count -eq 0) {
Write-Error "未找到导出模板($templateDir)。请在 Godot 编辑器中选择「编辑器 → 管理导出模板」下载安装。"
exit 1
}
Write-Host "[export] 导出模板:$((Get-ChildItem $templateDir | Select-Object -ExpandProperty Name) -join ', ')"
if (-not (Test-Path $OutputDir)) {
New-Item -ItemType Directory -Path $OutputDir -Force | Out-Null
}
# ---- 导入资源 ----
Write-Host "[export] 导入资源…"
& $GodotExe --headless --path $ProjectDir --import 2>&1 | Out-Null
# ---- 导出 ----
Write-Host "[export] 导出中…"
$exePath = Join-Path $OutputDir "OpenDance.exe"
& $GodotExe --headless --path $ProjectDir --export-$Mode "Windows Desktop" $exePath
if ($LASTEXITCODE -ne 0) {
Write-Host "[export] 导出命令返回 $LASTEXITCODE,检查产物是否存在…"
}
# ---- 校验产物 ----
$pckPath = Join-Path $OutputDir "OpenDance.pck"
$missing = $false
if (-not (Test-Path $exePath)) { Write-Error "未生成 $exePath"; $missing = $true }
if (-not (Test-Path $pckPath)) { Write-Error "未生成 $pckPath"; $missing = $true }
if ($missing) { exit 1 }
# 校验 PE 头(MZ)
$bytes = [System.IO.File]::ReadAllBytes($exePath)[0..1]
if ($bytes[0] -ne 0x4D -or $bytes[1] -ne 0x5A) {
Write-Error "$exePath 不是合法的 Windows PE 文件。"
exit 1
}
$exeSize = [math]::Round((Get-Item $exePath).Length / 1KB)
$pckSize = [math]::Round((Get-Item $pckPath).Length / 1KB)
Write-Host ""
Write-Host "[export] 完成:" -ForegroundColor Green
Write-Host " $exePath ($exeSize KiB, PE 头校验通过)"
Write-Host " $pckPath ($pckSize KiB)"
Write-Host ""
Write-Host "在 Windows 10/11 上运行 OpenDance.exe 即可(.pck 必须与 .exe 同目录)。"
exit 0