Files
YuChuan/scripts/package_release.ps1
T
WT810787899 2dd286f64a build(windows): 可执行文件改为 YuChuan.exe,嵌入新图标,修正版本资源
- windows/CMakeLists.txt: BINARY_NAME rust_flutter_ui -> YuChuan
  (CMake 的 target 名不支持非 ASCII,写「雨传」会直接报
   Cannot specify compile definitions for target 雨传 which is not built,
   所以构建名用 ASCII,发布时由 package_release.ps1 改名为「雨传.exe」)
- windows/runner/CMakeLists.txt: 加 /utf-8 —— main.cpp 是无 BOM 的 UTF-8,
  不指定的话 MSVC 按系统代码页(GBK)读,中文字面量会变乱码
- windows/runner/main.cpp: 原生窗口标题 YuChuan -> 雨传 YuChuan
- windows/runner/Runner.rc: 版本资源补齐/修正
  FileDescription -> 雨传 YuChuan - 局域网聊天 / 传文件工具
  ProductName/InternalName/OriginalFilename -> 雨传
  LegalCopyright 去掉模板残留的 com.example
- scripts: 同步 exe 名;新增 package_release.ps1(便携版 zip + 安卓包)

说明:图标是编译期嵌进二进制的,改图标必须重新构建(本机无 rcedit/
ResourceHacker 之类可直接改 exe 资源的工具)。
2026-10-15 21:02:41 +08:00

88 lines
3.2 KiB
PowerShell

# 打包发布产物:Windows 便携版 zip + 安卓安装包。
#
# 用法:
# .\scripts\package_release.ps1 # 版本取 pubspec.yaml
# .\scripts\package_release.ps1 -Version 1.0.1
#
# 前置:先跑过构建
# .\scripts\build_windows.ps1 # 产出 build\windows\x64\runner\Release\
# .\scripts\build_apk.ps1 # 产出 build\app\outputs\flutter-apk\app-release.apk
#
# 为什么在这里把 exe 改名成「雨传.exe」:
# CMake 的 target 名不支持非 ASCII(写 "雨传" 会直接报
# `Cannot specify compile definitions for target "雨传" which is not built`),
# 所以构建产物是 ASCII 的 YuChuan.exe,发布时再改成中文名。
# 改名不影响运行:runner 是按自身所在目录去找 data\ 和各个 dll 的。
param(
[string]$Version = "",
[string]$DistDir = "dist"
)
$ErrorActionPreference = "Stop"
$root = Split-Path -Parent $PSScriptRoot
Set-Location $root
# ---- 版本号:默认读 pubspec.yaml 的 version(去掉 +build 后缀)----
if (-not $Version) {
$line = Select-String -Path "pubspec.yaml" -Pattern '^version:\s*(\S+)' | Select-Object -First 1
if (-not $line) { throw "pubspec.yaml 里读不到 version" }
$Version = ($line.Matches[0].Groups[1].Value -split '\+')[0]
}
Write-Host "版本:$Version"
$stageName = "雨传"
$exeAscii = "YuChuan.exe"
$exeCjk = "雨传.exe"
# ---- 校验前置产物 ----
$winRel = "build\windows\x64\runner\Release"
if (-not (Test-Path "$winRel\$exeAscii")) {
throw "找不到 $winRel\$exeAscii —— 先跑 .\scripts\build_windows.ps1"
}
$apkSrc = "build\app\outputs\flutter-apk\app-release.apk"
if (-not (Test-Path $apkSrc)) {
throw "找不到 $apkSrc —— 先跑 .\scripts\build_apk.ps1"
}
# ---- 暂存 Windows 便携版 ----
New-Item -ItemType Directory -Force -Path $DistDir | Out-Null
$stage = Join-Path $DistDir $stageName
if (Test-Path $stage) { Remove-Item -Recurse -Force $stage }
New-Item -ItemType Directory -Force -Path $stage | Out-Null
Copy-Item -Recurse -Force "$winRel\*" $stage
# exe 改中文名
Move-Item -Force (Join-Path $stage $exeAscii) (Join-Path $stage $exeCjk)
# 附一份使用说明,便携版解压后一眼能看到
$readme = @"
雨传 YuChuan $Version · Windows 便携版
直接双击「$exeCjk」运行,无需安装。
整个文件夹可以放到任意位置(U 盘也行),删掉即卸载。
同一局域网内打开手机端雨传,两端会自动互相发现,配对一次即可互传文件。
"@
Set-Content -Path (Join-Path $stage "使用说明.txt") -Value $readme -Encoding UTF8
# ---- 打 zip ----
$zip = Join-Path $DistDir "雨传-$Version-windows-portable.zip"
if (Test-Path $zip) { Remove-Item -Force $zip }
Compress-Archive -Path $stage -DestinationPath $zip -CompressionLevel Optimal
# ---- 安卓安装包 ----
$apkDst = Join-Path $DistDir "雨传-$Version-android.apk"
Copy-Item -Force $apkSrc $apkDst
# ---- 汇报 ----
Write-Host ""
Write-Host "产物:"
foreach ($f in @($zip, $apkDst)) {
$i = Get-Item $f
Write-Host (" {0} {1:N2} MB" -f $i.Name, ($i.Length / 1MB))
}
Write-Host ""
Write-Host "zip 内含顶层目录:$stageName\"
Get-ChildItem $stage | ForEach-Object { Write-Host " $($_.Name)" }