diff --git a/pack/pack.lock.json b/pack/pack.lock.json index c8b03bf..5330146 100644 --- a/pack/pack.lock.json +++ b/pack/pack.lock.json @@ -1,7 +1,7 @@ { "$schema": "Brass-and-Sigil pack.lock.json - generated, do not edit by hand unless you know what you are doing", "name": "Brass and Sigil", - "version": "0.9.2", + "version": "0.9.3", "minecraft": "1.21.1", "loader": { "type": "neoforge", diff --git a/scripts/Build-Tweaks.ps1 b/scripts/Build-Tweaks.ps1 index 4e8d819..763b1a8 100644 --- a/scripts/Build-Tweaks.ps1 +++ b/scripts/Build-Tweaks.ps1 @@ -100,12 +100,27 @@ foreach ($dir in $tweakDirs) { if (Test-Path $jarPath) { Remove-Item $jarPath -Force } - [System.IO.Compression.ZipFile]::CreateFromDirectory( - $dir.FullName, - $jarPath, - [System.IO.Compression.CompressionLevel]::Optimal, - $false - ) + # NB: PowerShell 5.1's [ZipFile]::CreateFromDirectory() writes Windows- + # native path separators (\) into ZIP entry names on Windows, producing + # entries like "META-INF\neoforge.mods.toml" instead of the spec-required + # "META-INF/neoforge.mods.toml". NeoForge's mod scanner then can't find + # the manifest and silently rejects the jar with "not a valid mod file". + # We build the archive manually so we control the entry name format. + # 'Create' string maps to ZipArchiveMode.Create -- PowerShell 5.1 doesn't + # auto-load the enum type, so the literal string form is more portable. + $zip = [System.IO.Compression.ZipFile]::Open($jarPath, 'Create') + try { + $sourceLen = $dir.FullName.Length + Get-ChildItem -Path $dir.FullName -Recurse -File | ForEach-Object { + $relPath = $_.FullName.Substring($sourceLen).TrimStart('\','/').Replace('\','/') + $entry = $zip.CreateEntry($relPath, [System.IO.Compression.CompressionLevel]::Optimal) + $entryStream = $entry.Open() + try { + $bytes = [System.IO.File]::ReadAllBytes($_.FullName) + $entryStream.Write($bytes, 0, $bytes.Length) + } finally { $entryStream.Dispose() } + } + } finally { $zip.Dispose() } $size = (Get-Item $jarPath).Length Write-Host (" built {0,-40} {1,8:N0} bytes" -f $jarName, $size)