-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild_release.ps1
More file actions
131 lines (108 loc) · 4.42 KB
/
build_release.ps1
File metadata and controls
131 lines (108 loc) · 4.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
<#
.SYNOPSIS
Builds Tron PowerShell release packages (ZIP and SFX EXE).
.DESCRIPTION
This script creates a 'releases' directory and packages the current Tron PowerShell version
into a .zip file and, if 7-Zip is available, a self-extracting .exe.
#>
$Version = "1.0.1"
$ReleaseDate = "2025-12-05"
$OutputDir = Join-Path $PSScriptRoot "releases"
$SourceFiles = @("Tron.ps1", "Modules", "Resources", "Config", "README.md", "LICENSE", "changelog.txt")
# Ensure output directory exists
if (-not (Test-Path $OutputDir)) {
New-Item -ItemType Directory -Path $OutputDir | Out-Null
}
Write-Host "Building Tron PowerShell v$Version ($ReleaseDate)..." -ForegroundColor Cyan
# --- Locate 7-Zip ---
$7zPath = $null
$7zSfxPath = $null
$PossiblePaths = @(
"$env:ProgramFiles\7-Zip\7z.exe",
"$env:ProgramFiles(x86)\7-Zip\7z.exe",
"C:\Program Files\7-Zip\7z.exe"
)
foreach ($path in $PossiblePaths) {
if (Test-Path $path) {
$7zPath = $path
$7zSfxPath = Join-Path (Get-Item $path).Directory.FullName "7z.sfx"
break
}
}
if (-not $7zPath) {
# Check PATH
try {
$7zPath = (Get-Command "7z" -ErrorAction Stop).Source
$7zSfxPath = Join-Path (Get-Item $7zPath).Directory.FullName "7z.sfx"
}
catch {
Write-Warning "7-Zip not found. SFX (.exe) creation will be skipped."
}
}
# --- Create ZIP Package ---
$ZipFileName = "tron_powershell_v$Version.zip"
$ZipFilePath = Join-Path $OutputDir $ZipFileName
Write-Host "Creating ZIP package: $ZipFileName"
if (Test-Path $ZipFilePath) { Remove-Item $ZipFilePath -Force }
# Create a temporary directory for staging
$StageDir = Join-Path $env:TEMP "tron_ps_build_stage_$((Get-Random))"
$TronStageDir = Join-Path $StageDir "tron_powershell"
New-Item -ItemType Directory -Path $TronStageDir -Force | Out-Null
foreach ($item in $SourceFiles) {
$itemPath = Join-Path $PSScriptRoot $item
if (Test-Path $itemPath) {
Copy-Item -Path $itemPath -Destination $TronStageDir -Recurse -Force
}
else {
Write-Warning "Source file not found: $item"
}
}
# Compress
Compress-Archive -Path "$TronStageDir\*" -DestinationPath $ZipFilePath -Force
Write-Host "ZIP package created successfully." -ForegroundColor Green
# --- Create SFX EXE Package ---
if ($7zPath -and (Test-Path $7zSfxPath)) {
$ExeFileName = "tron_powershell_v$Version.exe"
$ExeFilePath = Join-Path $OutputDir $ExeFileName
Write-Host "Creating SFX EXE package: $ExeFileName"
if (Test-Path $ExeFilePath) { Remove-Item $ExeFilePath -Force }
# SFX Config
$SfxConfigPath = Join-Path $StageDir "config.txt"
# Note: Running PowerShell directly from SFX might require a wrapper or specific command
# We'll try to launch PowerShell with the script
$SfxConfigContent = @(
";!@Install@!UTF-8!",
"Title=""Tron PowerShell v$Version""",
"Progress=""yes""",
"RunProgram=""powershell.exe -ExecutionPolicy Bypass -NoProfile -File Tron.ps1""",
";!@InstallEnd@!"
)
Set-Content -Path $SfxConfigPath -Value $SfxConfigContent -Encoding UTF8
# Create 7z archive for SFX
$Temp7zPath = Join-Path $StageDir "payload.7z"
# We use the staging dir content
$ProcessInfo = New-Object System.Diagnostics.ProcessStartInfo
$ProcessInfo.FileName = $7zPath
$ProcessInfo.Arguments = "a -mx9 ""$Temp7zPath"" ""$TronStageDir\*"""
$ProcessInfo.RedirectStandardOutput = $true
$ProcessInfo.UseShellExecute = $false
$Process = [System.Diagnostics.Process]::Start($ProcessInfo)
$Process.WaitForExit()
# Combine SFX module + Config + Archive
# copy /b 7z.sfx + config.txt + payload.7z tron.exe
$SfxBytes = [System.IO.File]::ReadAllBytes($7zSfxPath)
$ConfigBytes = [System.IO.File]::ReadAllBytes($SfxConfigPath)
$PayloadBytes = [System.IO.File]::ReadAllBytes($Temp7zPath)
$OutputStream = [System.IO.File]::OpenWrite($ExeFilePath)
$OutputStream.Write($SfxBytes, 0, $SfxBytes.Length)
$OutputStream.Write($ConfigBytes, 0, $ConfigBytes.Length)
$OutputStream.Write($PayloadBytes, 0, $PayloadBytes.Length)
$OutputStream.Close()
Write-Host "SFX EXE package created successfully." -ForegroundColor Green
}
elseif ($7zPath -and -not (Test-Path $7zSfxPath)) {
Write-Warning "7-Zip found but '7z.sfx' module is missing. Skipping EXE creation."
}
# Cleanup
Remove-Item $StageDir -Recurse -Force
Write-Host "Build complete. Artifacts in: $OutputDir" -ForegroundColor Cyan