build: 打包脚本改为 UTF-8 BOM,兼容 Windows PowerShell 5.1

This commit is contained in:
admin committed 2026-10-29 14:42:56 +08:00
1 parent 550bfaaa00
commit 9ebaf0d177
1 file changed
+9 -15
+9 -15
View File
@@ -1,9 +1,9 @@
# 构建单文件 exe(Windows) # Build a single-file Windows exe.
# #
# powershell -ExecutionPolicy Bypass -File tools\build_exe.ps1 # powershell -ExecutionPolicy Bypass -File tools\build_exe.ps1
# #
# 产物: dist\U盘备份工具.exe # Output: dist\U盘备份工具.exe
# 依赖: python -m pip install pyinstaller # Requires: python -m pip install pyinstaller
param( param(
[string]$Name = "U盘备份工具" [string]$Name = "U盘备份工具"
@@ -14,26 +14,20 @@ $root = Split-Path -Parent (Split-Path -Parent $MyInvocation.MyCommand.Path)
$work = Join-Path $root "build" $work = Join-Path $root "build"
$dist = Join-Path $root "dist" $dist = Join-Path $root "dist"
Write-Host "构建 $Name ..." Write-Host "Building $Name ..."
Push-Location $root Push-Location $root
try { try {
python -m PyInstaller --noconfirm --clean --onefile --windowed ` python -m PyInstaller --noconfirm --clean --onefile --windowed --icon (Join-Path $root "icon.ico") --name $Name --version-file (Join-Path $PSScriptRoot "version_info.txt") --distpath $dist --workpath $work --specpath $work (Join-Path $root "usb_backup.py")
--icon (Join-Path $root "icon.ico") ` if ($LASTEXITCODE -ne 0) { throw "PyInstaller failed with exit code $LASTEXITCODE" }
--name $Name `
--version-file (Join-Path $PSScriptRoot "version_info.txt") `
--distpath $dist `
--workpath $work `
--specpath $work `
(Join-Path $root "usb_backup.py")
if ($LASTEXITCODE -ne 0) { throw "PyInstaller 失败,退出码 $LASTEXITCODE" }
} finally { } finally {
Pop-Location Pop-Location
} }
$exe = Join-Path $dist "$Name.exe" $exe = Join-Path $dist "$Name.exe"
if (-not (Test-Path $exe)) { throw "未生成 $exe" } if (-not (Test-Path $exe)) { throw "missing $exe" }
$size = [math]::Round((Get-Item $exe).Length / 1MB, 2) $size = [math]::Round((Get-Item $exe).Length / 1MB, 2)
$hash = (Get-FileHash $exe -Algorithm SHA256).Hash $hash = (Get-FileHash $exe -Algorithm SHA256).Hash
Write-Host "" Write-Host ""
Write-Host "完成: $exe ($size MB)" Write-Host "OK: $exe ($size MB)"
Write-Host "SHA256: $hash" Write-Host "SHA256: $hash"