build-dist.ps1 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. # 构建 SteamSH 单文件分发包
  2. # 使用 Python 创建 7z SFX 自解压文件
  3. param(
  4. [string]$OutputFile = "SteamSH_Dist.exe",
  5. [string]$SourceDir = "."
  6. )
  7. $ErrorActionPreference = "Stop"
  8. Write-Host "========================================" -ForegroundColor Cyan
  9. Write-Host "SteamSH 分发包构建工具" -ForegroundColor Cyan
  10. Write-Host "========================================" -ForegroundColor Cyan
  11. # 检查必需文件
  12. Write-Host "`n[1/4] 检查文件..." -ForegroundColor Yellow
  13. $requiredFiles = @("steamSH.exe", "steamAPI.exe", "start.bat")
  14. foreach ($file in $requiredFiles) {
  15. if (-not (Test-Path $file)) {
  16. Write-Host "错误: 缺少文件 $file" -ForegroundColor Red
  17. exit 1
  18. }
  19. Write-Host " ✓ $file" -ForegroundColor Green
  20. }
  21. # 创建临时 zip 文件
  22. Write-Host "`n[2/4] 创建压缩包..." -ForegroundColor Yellow
  23. $zipFile = "SteamSH.zip"
  24. if (Test-Path $zipFile) { Remove-Item $zipFile -Force }
  25. try {
  26. Compress-Archive -Path steamSH.exe, steamAPI.exe, start.bat -DestinationPath $zipFile -Force
  27. Write-Host " ✓ 已创建 $zipFile" -ForegroundColor Green
  28. } catch {
  29. Write-Host "错误: 压缩失败 - $_" -ForegroundColor Red
  30. exit 1
  31. }
  32. # 查找 7zSD.sfx 或其他 SFX 模块
  33. Write-Host "`n[3/4] 准备 SFX 模块..." -ForegroundColor Yellow
  34. $sfxModule = $null
  35. # 检查常见位置
  36. $possiblePaths = @(
  37. "C:\Program Files\7-Zip\7zSD.sfx",
  38. "C:\Program Files\2345Soft\HaoZip\sfx\HaoZip7zSetup.sfx",
  39. "C:\Program Files\2345Soft\HaoZip\sfx\HaoZip7zCon.sfx"
  40. )
  41. foreach ($path in $possiblePaths) {
  42. if (Test-Path $path) {
  43. $sfxModule = $path
  44. Write-Host " ✓ 找到 SFX 模块: $sfxModule" -ForegroundColor Green
  45. break
  46. }
  47. }
  48. if (-not $sfxModule) {
  49. Write-Host "`n警告: 未找到 SFX 模块" -ForegroundColor Yellow
  50. Write-Host "将生成 ZIP 文件代替" -ForegroundColor Yellow
  51. Write-Host "`n提示: 请安装 7-Zip 来创建 SFX 自解压文件" -ForegroundColor Cyan
  52. exit 0
  53. }
  54. # 创建 SFX 自解压文件
  55. Write-Host "`n[4/4] 创建自解压 exe..." -ForegroundColor Yellow
  56. # 方法: 直接拼接二进制文件
  57. try {
  58. # 读取文件
  59. $sfxBytes = [System.IO.File]::ReadAllBytes($sfxModule)
  60. $zipBytes = [System.IO.File]::ReadAllBytes($zipFile)
  61. # 创建输出文件
  62. $outputBytes = $sfxBytes + $zipBytes
  63. [System.IO.File]::WriteAllBytes($OutputFile, $outputBytes)
  64. $sizeMB = [math]::Round((Get-Item $OutputFile).Length / 1MB, 2)
  65. Write-Host " ✓ 已创建 $OutputFile ($sizeMB MB)" -ForegroundColor Green
  66. Write-Host "`n========================================" -ForegroundColor Cyan
  67. Write-Host "构建完成!" -ForegroundColor Green
  68. Write-Host "========================================" -ForegroundColor Cyan
  69. Write-Host "`n分发方式:" -ForegroundColor White
  70. Write-Host " 1. 直接分发 $OutputFile 给用户" -ForegroundColor White
  71. Write-Host " 2. 用户双击即可自动解压并启动" -ForegroundColor White
  72. } catch {
  73. Write-Host "错误: 创建 SFX 失败 - $_" -ForegroundColor Red
  74. exit 1
  75. }