fix(package): zip paths use / so the translation files survive extraction
Compress-Archive on Windows PowerShell 5.1 wrote the entries as Translations\English\items.json. The zip format only allows /, so on Linux and Steam Deck each text file came out as one flat file with backslashes in its name, Jotunn found no Translations folder and every mod text showed as [key]. The zips are now built by scripts/package.ps1.
This commit is contained in:
parent
19d331789a
commit
6b020fb80a
2 changed files with 61 additions and 11 deletions
58
scripts/package.ps1
Normal file
58
scripts/package.ps1
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
# Builds the Thunderstore and Nexus zips. Called by the PackageThunderstore target in
|
||||
# RacesOfValheim.csproj on a Release build.
|
||||
#
|
||||
# Compress-Archive is not used on purpose: on Windows PowerShell 5.1 it writes entry names with
|
||||
# backslashes (Translations\English\items.json). The zip format only allows "/", so extractors
|
||||
# on Linux and Steam Deck turned each text file into one flat file with backslashes in its name,
|
||||
# Jotunn found no Translations folder, and every text in the mod showed up as [key].
|
||||
param(
|
||||
[Parameter(Mandatory)] [string] $Dll,
|
||||
[Parameter(Mandatory)] [string] $Manifest,
|
||||
[Parameter(Mandatory)] [string] $Readme,
|
||||
[Parameter(Mandatory)] [string] $Icon,
|
||||
[Parameter(Mandatory)] [string] $Translations,
|
||||
[Parameter(Mandatory)] [string] $OutDir
|
||||
)
|
||||
|
||||
$ErrorActionPreference = 'Stop'
|
||||
Add-Type -AssemblyName System.IO.Compression
|
||||
Add-Type -AssemblyName System.IO.Compression.FileSystem
|
||||
|
||||
function New-ModZip([string] $zipPath, [object[]] $entries) {
|
||||
if (Test-Path $zipPath) { Remove-Item $zipPath -Force }
|
||||
$zip = [System.IO.Compression.ZipFile]::Open($zipPath, [System.IO.Compression.ZipArchiveMode]::Create)
|
||||
try {
|
||||
foreach ($e in $entries) {
|
||||
$name = $e.Name.Replace('\', '/')
|
||||
[System.IO.Compression.ZipFileExtensions]::CreateEntryFromFile($zip, $e.Source, $name) | Out-Null
|
||||
}
|
||||
} finally {
|
||||
$zip.Dispose()
|
||||
}
|
||||
}
|
||||
|
||||
# Every translation file, named by its path under the Translations folder.
|
||||
$root = (Resolve-Path $Translations).Path.TrimEnd('\')
|
||||
$texts = Get-ChildItem $root -Recurse -File -Filter *.json | ForEach-Object {
|
||||
[pscustomobject]@{ Source = $_.FullName; Rel = $_.FullName.Substring($root.Length + 1) }
|
||||
}
|
||||
|
||||
# The version is read back out of manifest.json, so manifest.json stays the single place a
|
||||
# release is numbered.
|
||||
$version = (Get-Content $Manifest -Raw | ConvertFrom-Json).version_number
|
||||
|
||||
# Thunderstore gives every package a folder of its own, so the texts sit at the zip root.
|
||||
$thunderstore = @(
|
||||
[pscustomobject]@{ Source = $Dll; Name = 'RacesOfValheim.dll' }
|
||||
[pscustomobject]@{ Source = $Manifest; Name = 'manifest.json' }
|
||||
[pscustomobject]@{ Source = $Readme; Name = 'README.md' }
|
||||
[pscustomobject]@{ Source = $Icon; Name = 'icon.png' }
|
||||
) + ($texts | ForEach-Object { [pscustomobject]@{ Source = $_.Source; Name = "Translations/$($_.Rel)" } })
|
||||
|
||||
# Nexus users unzip straight into plugins, so the texts travel inside a RacesOfValheim folder.
|
||||
$nexus = @(
|
||||
[pscustomobject]@{ Source = $Dll; Name = 'RacesOfValheim.dll' }
|
||||
) + ($texts | ForEach-Object { [pscustomobject]@{ Source = $_.Source; Name = "RacesOfValheim/Translations/$($_.Rel)" } })
|
||||
|
||||
New-ModZip (Join-Path $OutDir "RacesOfValheim_Thunderstore_$version.zip") $thunderstore
|
||||
New-ModZip (Join-Path $OutDir "RacesOfValheim_Nexus_$version.zip") $nexus
|
||||
Loading…
Add table
Add a link
Reference in a new issue