Files
umbrix/windows/create-portable-exe.ps1
2026-01-20 13:44:26 +03:00

103 lines
4.4 KiB
PowerShell
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Создание портативного single-file EXE через 7-Zip SFX
# Упаковывает все файлы в один исполняемый файл
param(
[string]$Version = "1.7.4"
)
$ErrorActionPreference = "Stop"
Write-Host "═══════════════════════════════════════════════" -ForegroundColor Cyan
Write-Host " Umbrix Portable EXE Builder v$Version" -ForegroundColor Cyan
Write-Host "═══════════════════════════════════════════════" -ForegroundColor Cyan
Write-Host ""
$ProjectRoot = Split-Path -Parent $PSScriptRoot
$BuildDir = "$ProjectRoot\build\windows\x64\runner\Release"
$DistDir = "$ProjectRoot\dist"
$SevenZip = "C:\Program Files\7-Zip\7z.exe"
$SfxModule = "C:\Program Files\7-Zip\7z.sfx"
# Проверка 7-Zip
if (-not (Test-Path $SevenZip)) {
Write-Host "✗ 7-Zip не найден!" -ForegroundColor Red
Write-Host "Установите с: https://www.7-zip.org/download.html" -ForegroundColor Yellow
exit 1
}
# Проверка SFX модуля
if (-not (Test-Path $SfxModule)) {
Write-Host "✗ 7z.sfx модуль не найден!" -ForegroundColor Red
Write-Host "Путь: $SfxModule" -ForegroundColor Yellow
exit 1
}
# Проверка build
if (-not (Test-Path "$BuildDir\Umbrix.exe")) {
Write-Host "✗ Build не найден! Сначала выполните: flutter build windows --release" -ForegroundColor Red
exit 1
}
# Создание dist папки
if (-not (Test-Path $DistDir)) {
New-Item -ItemType Directory -Path $DistDir -Force | Out-Null
}
# Временные файлы
$TempArchive = "$env:TEMP\umbrix_temp.7z"
$ConfigFile = "$env:TEMP\sfx_config.txt"
$OutputExe = "$DistDir\Umbrix-$Version-Portable.exe"
# Удаление старых файлов
Remove-Item $TempArchive -ErrorAction SilentlyContinue
Remove-Item $ConfigFile -ErrorAction SilentlyContinue
Remove-Item $OutputExe -ErrorAction SilentlyContinue
Write-Host "[1/3] Создание 7z архива..." -ForegroundColor Yellow
& $SevenZip a -t7z -mx9 $TempArchive "$BuildDir\*" | Out-Null
if ($LASTEXITCODE -ne 0) {
Write-Host "✗ Ошибка создания архива!" -ForegroundColor Red
exit 1
}
Write-Host "✓ Архив создан" -ForegroundColor Green
# Создание SFX конфигурации
Write-Host "[2/3] Создание SFX конфигурации..." -ForegroundColor Yellow
@"
;!@Install@!UTF-8!
Title="Umbrix VPN v$Version"
BeginPrompt="Распаковка Umbrix VPN...\n\nНажмите OK для продолжения"
RunProgram="Umbrix.exe"
GUIMode="2"
;!@InstallEnd@!
"@ | Out-File -FilePath $ConfigFile -Encoding UTF8
Write-Host "✓ Конфигурация готова" -ForegroundColor Green
# Объединение SFX модуля + config + архива
Write-Host "[3/3] Создание portable EXE..." -ForegroundColor Yellow
cmd /c copy /b "$SfxModule" + "$ConfigFile" + "$TempArchive" "$OutputExe" | Out-Null
if ($LASTEXITCODE -ne 0) {
Write-Host "✗ Ошибка создания EXE!" -ForegroundColor Red
exit 1
}
# Очистка временных файлов
Remove-Item $TempArchive -ErrorAction SilentlyContinue
Remove-Item $ConfigFile -ErrorAction SilentlyContinue
# Итоги
$FileSize = [math]::Round((Get-Item $OutputExe).Length / 1MB, 2)
Write-Host ""
Write-Host "═══════════════════════════════════════════════" -ForegroundColor Cyan
Write-Host " ✓ Single-File EXE создан успешно!" -ForegroundColor Green
Write-Host "═══════════════════════════════════════════════" -ForegroundColor Cyan
Write-Host ""
Write-Host "Файл: $OutputExe" -ForegroundColor White
Write-Host "Размер: $FileSize MB" -ForegroundColor White
Write-Host ""
Write-Host "При первом запуске:" -ForegroundColor Yellow
Write-Host " • Распакуется во временную папку" -ForegroundColor Gray
Write-Host " • Автоматически запустит Umbrix" -ForegroundColor Gray
Write-Host " • Можно перемещать EXE куда угодно" -ForegroundColor Gray
Write-Host ""