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
}
# Use .NET ZipFile for reliable cross-platform zip structure
Add-Type -AssemblyName System.IO.Compression
Add-Type -AssemblyName System.IO.Compression.FileSystem
$tempZip = "$ZipPath.tmp"
[System.IO.Compression.ZipFile]::CreateFromDirectory($ReleaseDir, $tempZip, [System.IO.Compression.CompressionLevel]::Optimal, $true)
$topLevelFolder = "LCEWindows64"
# Rewrite the zip without .pch files
$zipIn = [System.IO.Compression.ZipFile]::Open($tempZip, 'Update')
$toRemove = @($zipIn.Entries | Where-Object { $_.FullName -like "*.pch" -or $_.FullName -like "*.zip" })
foreach ($entry in $toRemove) { $entry.Delete() }
$zipIn.Dispose()
$fs = [System.IO.File]::Open($ZipPath, [System.IO.FileMode]::Create)
try {
$zip = New-Object System.IO.Compression.ZipArchive($fs, [System.IO.Compression.ZipArchiveMode]::Create)
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
# --- Step 3: Get the Nightly release info ---