From 2dd286f64adfe720df1e846a6bba3fd2575da916 Mon Sep 17 00:00:00 2001 From: WT810787899 Date: Thu, 15 Oct 2026 21:02:41 +0800 Subject: [PATCH] =?UTF-8?q?build(windows):=20=E5=8F=AF=E6=89=A7=E8=A1=8C?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E6=94=B9=E4=B8=BA=20YuChuan.exe=EF=BC=8C?= =?UTF-8?q?=E5=B5=8C=E5=85=A5=E6=96=B0=E5=9B=BE=E6=A0=87=EF=BC=8C=E4=BF=AE?= =?UTF-8?q?=E6=AD=A3=E7=89=88=E6=9C=AC=E8=B5=84=E6=BA=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 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 资源的工具)。 --- .gitignore | 3 ++ build_windows.bat | 2 + scripts/build_windows.ps1 | 2 +- scripts/package_release.ps1 | 87 +++++++++++++++++++++++++++++++++++ scripts/run_two_instances.ps1 | 2 +- windows/CMakeLists.txt | 7 ++- windows/runner/CMakeLists.txt | 5 ++ windows/runner/Runner.rc | 10 ++-- windows/runner/main.cpp | 2 +- 9 files changed, 111 insertions(+), 9 deletions(-) create mode 100644 scripts/package_release.ps1 diff --git a/.gitignore b/.gitignore index 190ca51..d32949e 100644 --- a/.gitignore +++ b/.gitignore @@ -90,3 +90,6 @@ icon.psd /修bug.md /核验.MD /scripts/verify_offline_send.md + +# 发布产物(可重新生成,不进仓库) +/dist/ diff --git a/build_windows.bat b/build_windows.bat index 47a1141..c4b6b75 100644 --- a/build_windows.bat +++ b/build_windows.bat @@ -38,6 +38,8 @@ cargo build --manifest-path rust_builder\Cargo.toml --target x86_64-pc-windows-m if errorlevel 1 goto :err echo [3/3] Flutter build... REM Kill a running instance so MSVC can overwrite the exe (otherwise LINK : fatal error LNK1104) +chcp 65001 >nul 2>&1 +taskkill /f /im 雨传.exe >nul 2>&1 taskkill /f /im rust_flutter_ui.exe >nul 2>&1 call "%FLUTTER_BIN%" build windows 2>&1 if errorlevel 1 goto :err diff --git a/scripts/build_windows.ps1 b/scripts/build_windows.ps1 index 0becc16..9e4fc89 100644 --- a/scripts/build_windows.ps1 +++ b/scripts/build_windows.ps1 @@ -20,4 +20,4 @@ Start-Sleep -Seconds 1 & flutter build windows if ($LASTEXITCODE -ne 0) { throw 'flutter build windows failed' } -Write-Host "OK: $root\build\windows\x64\runner\Release\rust_flutter_ui.exe" +Write-Host "OK: $root\build\windows\x64\runner\Release\雨传.exe" diff --git a/scripts/package_release.ps1 b/scripts/package_release.ps1 new file mode 100644 index 0000000..f823c01 --- /dev/null +++ b/scripts/package_release.ps1 @@ -0,0 +1,87 @@ +# 打包发布产物: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)" } diff --git a/scripts/run_two_instances.ps1 b/scripts/run_two_instances.ps1 index 176e8f4..402e580 100644 --- a/scripts/run_two_instances.ps1 +++ b/scripts/run_two_instances.ps1 @@ -5,7 +5,7 @@ param([int]$WaitSeconds = 20) $ErrorActionPreference = 'Continue' $root = Split-Path $PSScriptRoot -Parent -$exe = "$root\build\windows\x64\runner\Release\rust_flutter_ui.exe" +$exe = "$root\build\windows\x64\runner\Release\雨传.exe" if (-not (Test-Path $exe)) { throw '先构建:.\scripts\build_windows.ps1' } $temp = $env:TEMP diff --git a/windows/CMakeLists.txt b/windows/CMakeLists.txt index 90f22c7..28f7cbb 100644 --- a/windows/CMakeLists.txt +++ b/windows/CMakeLists.txt @@ -4,7 +4,12 @@ project(rust_flutter_ui LANGUAGES CXX) # The name of the executable created for the application. Change this to change # the on-disk name of your application. -set(BINARY_NAME "rust_flutter_ui") +# +# 必须是 ASCII:CMake 的 target 名不支持非 ASCII,写成 "雨传" 会直接报 +# `Cannot specify compile definitions for target "雨传" which is not built`。 +# 发布版里那个「雨传.exe」是由打包脚本重命名得到的(见 scripts/build_windows.ps1), +# 这样 `flutter run -d windows` 也仍然能按 ASCII 名找到可执行文件。 +set(BINARY_NAME "YuChuan") # Explicitly opt in to modern CMake behaviors to avoid warnings with recent # versions of CMake. diff --git a/windows/runner/CMakeLists.txt b/windows/runner/CMakeLists.txt index 394917c..0cf5085 100644 --- a/windows/runner/CMakeLists.txt +++ b/windows/runner/CMakeLists.txt @@ -30,6 +30,11 @@ target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_BUILD=${FLUTT # Disable Windows macros that collide with C++ standard library functions. target_compile_definitions(${BINARY_NAME} PRIVATE "NOMINMAX") +# 源码里有中文字面量(窗口标题、资源字符串),强制 MSVC 按 UTF-8 读源码。 +# 不加这个,MSVC 会按系统代码页(本机 GBK)解释,中文会变成乱码, +# 而且 main.cpp 是无 BOM 的 UTF-8,靠 BOM 识别并不可靠。 +target_compile_options(${BINARY_NAME} PRIVATE "/utf-8") + # Add dependency libraries and include directories. Add any application-specific # dependencies here. target_link_libraries(${BINARY_NAME} PRIVATE flutter flutter_wrapper_app) diff --git a/windows/runner/Runner.rc b/windows/runner/Runner.rc index c91a9c5..daac2bb 100644 --- a/windows/runner/Runner.rc +++ b/windows/runner/Runner.rc @@ -90,12 +90,12 @@ BEGIN BLOCK "040904e4" BEGIN VALUE "CompanyName", "YuChuan" "\0" - VALUE "FileDescription", "YuChuan - LAN Chat" "\0" + VALUE "FileDescription", "雨传 YuChuan - 局域网聊天 / 传文件工具" "\0" VALUE "FileVersion", VERSION_AS_STRING "\0" - VALUE "InternalName", "rust_flutter_ui" "\0" - VALUE "LegalCopyright", "Copyright (C) 2026 com.example. All rights reserved." "\0" - VALUE "OriginalFilename", "rust_flutter_ui.exe" "\0" - VALUE "ProductName", "YuChuan" "\0" + VALUE "InternalName", "雨传" "\0" + VALUE "LegalCopyright", "Copyright (C) 2026 WT810787899" "\0" + VALUE "OriginalFilename", "雨传.exe" "\0" + VALUE "ProductName", "雨传 YuChuan" "\0" VALUE "ProductVersion", VERSION_AS_STRING "\0" END END diff --git a/windows/runner/main.cpp b/windows/runner/main.cpp index 71da6ba..94440e6 100644 --- a/windows/runner/main.cpp +++ b/windows/runner/main.cpp @@ -27,7 +27,7 @@ int APIENTRY wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev, FlutterWindow window(project); Win32Window::Point origin(10, 10); Win32Window::Size size(1280, 720); - if (!window.Create(L"YuChuan", origin, size)) { + if (!window.Create(L"雨传 YuChuan", origin, size)) { return EXIT_FAILURE; } window.SetQuitOnClose(true);