# 构建 SteamSH 单文件分发包 # 使用 Python 创建 7z SFX 自解压文件 param( [string]$OutputFile = "SteamSH_Dist.exe", [string]$SourceDir = "." ) $ErrorActionPreference = "Stop" Write-Host "========================================" -ForegroundColor Cyan Write-Host "SteamSH 分发包构建工具" -ForegroundColor Cyan Write-Host "========================================" -ForegroundColor Cyan # 检查必需文件 Write-Host "`n[1/4] 检查文件..." -ForegroundColor Yellow $requiredFiles = @("steamSH.exe", "steamAPI.exe", "start.bat") foreach ($file in $requiredFiles) { if (-not (Test-Path $file)) { Write-Host "错误: 缺少文件 $file" -ForegroundColor Red exit 1 } Write-Host " ✓ $file" -ForegroundColor Green } # 创建临时 zip 文件 Write-Host "`n[2/4] 创建压缩包..." -ForegroundColor Yellow $zipFile = "SteamSH.zip" if (Test-Path $zipFile) { Remove-Item $zipFile -Force } try { Compress-Archive -Path steamSH.exe, steamAPI.exe, start.bat -DestinationPath $zipFile -Force Write-Host " ✓ 已创建 $zipFile" -ForegroundColor Green } catch { Write-Host "错误: 压缩失败 - $_" -ForegroundColor Red exit 1 } # 查找 7zSD.sfx 或其他 SFX 模块 Write-Host "`n[3/4] 准备 SFX 模块..." -ForegroundColor Yellow $sfxModule = $null # 检查常见位置 $possiblePaths = @( "C:\Program Files\7-Zip\7zSD.sfx", "C:\Program Files\2345Soft\HaoZip\sfx\HaoZip7zSetup.sfx", "C:\Program Files\2345Soft\HaoZip\sfx\HaoZip7zCon.sfx" ) foreach ($path in $possiblePaths) { if (Test-Path $path) { $sfxModule = $path Write-Host " ✓ 找到 SFX 模块: $sfxModule" -ForegroundColor Green break } } if (-not $sfxModule) { Write-Host "`n警告: 未找到 SFX 模块" -ForegroundColor Yellow Write-Host "将生成 ZIP 文件代替" -ForegroundColor Yellow Write-Host "`n提示: 请安装 7-Zip 来创建 SFX 自解压文件" -ForegroundColor Cyan exit 0 } # 创建 SFX 自解压文件 Write-Host "`n[4/4] 创建自解压 exe..." -ForegroundColor Yellow # 方法: 直接拼接二进制文件 try { # 读取文件 $sfxBytes = [System.IO.File]::ReadAllBytes($sfxModule) $zipBytes = [System.IO.File]::ReadAllBytes($zipFile) # 创建输出文件 $outputBytes = $sfxBytes + $zipBytes [System.IO.File]::WriteAllBytes($OutputFile, $outputBytes) $sizeMB = [math]::Round((Get-Item $OutputFile).Length / 1MB, 2) Write-Host " ✓ 已创建 $OutputFile ($sizeMB MB)" -ForegroundColor Green Write-Host "`n========================================" -ForegroundColor Cyan Write-Host "构建完成!" -ForegroundColor Green Write-Host "========================================" -ForegroundColor Cyan Write-Host "`n分发方式:" -ForegroundColor White Write-Host " 1. 直接分发 $OutputFile 给用户" -ForegroundColor White Write-Host " 2. 用户双击即可自动解压并启动" -ForegroundColor White } catch { Write-Host "错误: 创建 SFX 失败 - $_" -ForegroundColor Red exit 1 }