# Flutter Windows 单文件打包脚本 - Enigma Virtual Box # 以管理员身份运行 Write-Host "=== Flutter Windows 单文件打包工具 ===" -ForegroundColor Green # 配置参数 $projectRoot = Split-Path -Parent $MyInvocation.MyCommand.Path $buildPath = "$projectRoot\build\windows\x64\runner\Release" $outputPath = "$projectRoot\dist" $enigmaPath = "C:\Program Files\Enigma Virtual Box\enigmavb.exe" # 检查构建文件 Write-Host "`n检查构建文件..." -ForegroundColor Yellow if (-not (Test-Path $buildPath)) { Write-Host "错误: 构建文件不存在,请先运行 flutter build windows" -ForegroundColor Red exit 1 } # 创建输出目录 if (-not (Test-Path $outputPath)) { New-Item -ItemType Directory -Path $outputPath -Force | Out-Null } # 检查 Enigma Virtual Box if (-not (Test-Path $enigmaPath)) { Write-Host "错误: Enigma Virtual Box 未安装" -ForegroundColor Red Write-Host "请下载安装: https://enigmaprotector.com/en/downloads.html" -ForegroundColor Yellow exit 1 } # 获取主程序名称 $exeFile = Get-ChildItem -Path $buildPath -Filter "*.exe" | Select-Object -First 1 if (-not $exeFile) { Write-Host "错误: 未找到可执行文件" -ForegroundColor Red exit 1 } $inputExe = $exeFile.FullName $outputExe = "$outputPath\$($exeFile.BaseName)_Single.exe" Write-Host "主程序: $inputExe" -ForegroundColor Cyan Write-Host "输出文件: $outputExe" -ForegroundColor Cyan # 创建打包配置文件 $configContent = @" ; Enigma Virtual Box 配置文件 [Config] InputFile=$inputExe OutputFile=$outputExe Files=%DEFAULT FOLDER% VirtualizationMode=Never Write To Disk Compression=Yes ShareVirtualSystem=Yes [Files] ; 添加整个 Release 文件夹 Folder=$buildPath\* "@ $configFile = "$outputPath\package_config.evb" Set-Content -Path $configFile -Value $configContent # 执行打包 Write-Host "`n开始打包..." -ForegroundColor Yellow Write-Host "这可能需要几分钟时间,请耐心等待..." -ForegroundColor Yellow $process = Start-Process -FilePath $enigmaPath -ArgumentList "/sf", $inputExe, "/lf", $outputExe, "/folder", $buildPath, "/compress" -Wait -PassThru if ($process.ExitCode -eq 0) { Write-Host "`n✅ 打包成功!" -ForegroundColor Green # 显示结果信息 $originalSize = (Get-Item $inputExe).Length / 1MB $packedSize = (Get-Item $outputExe).Length / 1MB $compressionRatio = [math]::Round((1 - $packedSize / $originalSize) * 100, 2) Write-Host "`n打包结果:" -ForegroundColor Cyan Write-Host "原始大小: $([math]::Round($originalSize, 2)) MB" -ForegroundColor White Write-Host "打包大小: $([math]::Round($packedSize, 2)) MB" -ForegroundColor White Write-Host "压缩率: $compressionRatio%" -ForegroundColor White Write-Host "输出文件: $outputExe" -ForegroundColor White Write-Host "`n📋 使用说明:" -ForegroundColor Yellow Write-Host "1. 将生成的单文件复制到目标计算机" -ForegroundColor White Write-Host "2. 直接运行即可,无需安装其他依赖" -ForegroundColor White Write-Host "3. 首次运行可能需要管理员权限" -ForegroundColor White } else { Write-Host "`n❌ 打包失败!" -ForegroundColor Red Write-Host "错误代码: $($process.ExitCode)" -ForegroundColor Red } # 清理临时文件 Remove-Item $configFile -ErrorAction SilentlyContinue Write-Host "`n按任意键退出..." -ForegroundColor Gray $null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")