| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118 |
- # 创建 SteamSH 便携式自解压包
- # 将 exe 打包成双击即可运行的便携版
- param(
- [string]$SourceExe = "steamSH_standalone.exe",
- [string]$OutputFile = "SteamSH_Portable.exe"
- )
- $ErrorActionPreference = "Stop"
- [Console]::OutputEncoding = [System.Text.Encoding]::UTF8
- Write-Host "========================================" -ForegroundColor Cyan
- Write-Host "SteamSH 便携版打包工具" -ForegroundColor Cyan
- Write-Host "========================================" -ForegroundColor Cyan
- # 检查输入文件
- Write-Host "`n[1/4] 检查输入文件..." -ForegroundColor Yellow
- if (-not (Test-Path $SourceExe)) {
- Write-Host "错误: 找不到源文件 $SourceExe" -ForegroundColor Red
- Write-Host "请先运行构建脚本生成 exe 文件" -ForegroundColor Yellow
- exit 1
- }
- Write-Host " ✓ 找到源文件: $SourceExe" -ForegroundColor Green
- # 创建临时目录
- Write-Host "`n[2/4] 准备便携包内容..." -ForegroundColor Yellow
- $tempDir = Join-Path $env:TEMP "SteamSH_Portable_$(Get-Date -Format 'yyyyMMdd_HHmmss')"
- New-Item -ItemType Directory -Path $tempDir -Force | Out-Null
- # 复制 exe
- Copy-Item $SourceExe (Join-Path $tempDir "steamSH.exe") -Force
- Write-Host " ✓ 已复制主程序" -ForegroundColor Green
- # 创建启动脚本
- $startBat = @'
- @echo off
- chcp 65001 >nul
- echo 正在启动 SteamSH...
- cd /d "%~dp0"
- start "" "steamSH.exe"
- '@
- $startBat | Out-File (Join-Path $tempDir "启动SteamSH.bat") -Encoding UTF8
- Write-Host " ✓ 已创建启动脚本" -ForegroundColor Green
- # 创建说明文件
- $readme = @'
- SteamSH 便携版
- =============
- 使用说明:
- 1. 双击 "启动SteamSH.bat" 即可启动程序
- 2. 或直接运行 steamSH.exe
- 注意:
- - 这是独立可执行文件,无需安装任何依赖
- - 所有数据会存储在用户目录下
- - 可以直接复制到U盘或移动设备使用
- '@
- $readme | Out-File (Join-Path $tempDir "说明.txt") -Encoding UTF8
- Write-Host " ✓ 已创建说明文件" -ForegroundColor Green
- # 压缩为 zip
- Write-Host "`n[3/4] 创建压缩包..." -ForegroundColor Yellow
- $zipFile = "SteamSH_Portable.zip"
- if (Test-Path $zipFile) { Remove-Item $zipFile -Force }
- Compress-Archive -Path (Join-Path $tempDir "*") -DestinationPath $zipFile -Force
- Write-Host " ✓ 已创建 $zipFile" -ForegroundColor Green
- # 查找 7z SFX 模块
- Write-Host "`n[4/4] 创建自解压 exe..." -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警告: 未找到 7-Zip SFX 模块" -ForegroundColor Yellow
- Write-Host "将只生成 ZIP 压缩包" -ForegroundColor Yellow
- Write-Host "`n提示: 安装 7-Zip 后可创建自解压 exe" -ForegroundColor Cyan
- Write-Host "下载地址: https://www.7-zip.org/" -ForegroundColor Cyan
- exit 0
- }
- # 拼接 SFX
- 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 "`n========================================" -ForegroundColor Green
- Write-Host "便携包构建完成!" -ForegroundColor Green
- Write-Host "========================================" -ForegroundColor Green
- Write-Host "`n输出文件:" -ForegroundColor White
- Write-Host " ZIP 包: $zipFile ($([math]::Round((Get-Item $zipFile).Length / 1MB, 2)) MB)" -ForegroundColor Cyan
- Write-Host " 自解压 exe: $OutputFile ($sizeMB MB)" -ForegroundColor Green
- Write-Host "`n分发方式:" -ForegroundColor White
- Write-Host " 1. 直接分发 $OutputFile 给用户" -ForegroundColor White
- Write-Host " 2. 用户双击即可自动解压并启动" -ForegroundColor White
- } catch {
- Write-Host "错误: 创建 SFX 失败 - $_" -ForegroundColor Red
- exit 1
- }
- # 清理临时文件
- Remove-Item $tempDir -Recurse -Force -ErrorAction SilentlyContinue
|