Refactor ZIP creation using System.IO.Compression

Updated the ZIP file creation process to utilize the .NET `System.IO.Compression` library. This change eliminates the need for a temporary ZIP file and directly excludes `.pch` and `.zip` files from the archive. A top-level folder named "LCEWindows64" has been added to the ZIP structure, and resource management has been improved with proper disposal of file streams and ZIP archives.
This commit is contained in:
Revela 2026-03-15 10:05:37 -05:00
parent 20e237dfaf
commit 610a1c7aa7

View file

@ -59,19 +59,46 @@ if (Test-Path $ZipPath) {
Remove-Item $ZipPath -Force Remove-Item $ZipPath -Force
} }
# Use .NET ZipFile for reliable cross-platform zip structure Add-Type -AssemblyName System.IO.Compression
Add-Type -AssemblyName System.IO.Compression.FileSystem Add-Type -AssemblyName System.IO.Compression.FileSystem
$tempZip = "$ZipPath.tmp" $topLevelFolder = "LCEWindows64"
[System.IO.Compression.ZipFile]::CreateFromDirectory($ReleaseDir, $tempZip, [System.IO.Compression.CompressionLevel]::Optimal, $true)
# Rewrite the zip without .pch files $fs = [System.IO.File]::Open($ZipPath, [System.IO.FileMode]::Create)
$zipIn = [System.IO.Compression.ZipFile]::Open($tempZip, 'Update') try {
$toRemove = @($zipIn.Entries | Where-Object { $_.FullName -like "*.pch" -or $_.FullName -like "*.zip" }) $zip = New-Object System.IO.Compression.ZipArchive($fs, [System.IO.Compression.ZipArchiveMode]::Create)
foreach ($entry in $toRemove) { $entry.Delete() }
$zipIn.Dispose() try {
$basePath = (Resolve-Path $ReleaseDir).Path
Get-ChildItem -Path $basePath -Recurse -File | ForEach-Object {
$fullPath = $_.FullName
if ($_.Extension -ieq ".pch" -or $_.Extension -ieq ".zip") {
return
}
$relativePath = $fullPath.Substring($basePath.Length).TrimStart('\','/')
$entryName = ($topLevelFolder + "/" + ($relativePath -replace '\\','/'))
Write-Host " Adding: $entryName"
[System.IO.Compression.ZipFileExtensions]::CreateEntryFromFile(
$zip,
$fullPath,
$entryName,
[System.IO.Compression.CompressionLevel]::Optimal
) | Out-Null
}
}
finally {
$zip.Dispose()
}
}
finally {
$fs.Dispose()
}
Move-Item -Path $tempZip -Destination $ZipPath -Force
Write-Host " Created: $ZipPath" -ForegroundColor Green Write-Host " Created: $ZipPath" -ForegroundColor Green
# --- Step 3: Get the Nightly release info --- # --- Step 3: Get the Nightly release info ---