From 610a1c7aa7e8f5f22f3a0e46ef8ceb8cdc98a1ef Mon Sep 17 00:00:00 2001 From: Revela Date: Sun, 15 Mar 2026 10:05:37 -0500 Subject: [PATCH] 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. --- Update-NightlyRelease.ps1 | 45 +++++++++++++++++++++++++++++++-------- 1 file changed, 36 insertions(+), 9 deletions(-) diff --git a/Update-NightlyRelease.ps1 b/Update-NightlyRelease.ps1 index 8977d343..78927c0b 100644 --- a/Update-NightlyRelease.ps1 +++ b/Update-NightlyRelease.ps1 @@ -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 ---