Merge branch 'fix-package-zip-paths'

This commit is contained in:
kanym 2026-09-29 04:25:04 +02:00
commit 7b425c69c2
2 changed files with 61 additions and 11 deletions

View file

@ -153,18 +153,10 @@
<PackageOutputDir>$(REPO_ROOT)dist\</PackageOutputDir>
</PropertyGroup>
<MakeDir Directories="$(PackageOutputDir)" Condition="!Exists('$(PackageOutputDir)')" />
<!-- Nexus users unzip straight into plugins, so the texts travel inside a RacesOfValheim
folder there; Thunderstore already gives every package a folder of its own. -->
<PropertyGroup>
<NexusStaging>$(IntermediateOutputPath)nexus\</NexusStaging>
</PropertyGroup>
<RemoveDir Directories="$(NexusStaging)" />
<Copy SourceFiles="@(TranslationFile)" DestinationFiles="@(TranslationFile->'$(NexusStaging)RacesOfValheim\Translations\%(RecursiveDir)%(Filename)%(Extension)')" />
<Message Text="Packaging Thunderstore and Nexus zips into $(PackageOutputDir)" Importance="high" />
<!-- The version is read back out of manifest.json rather than duplicated here, so
manifest.json stays the single place a release is numbered. Written with string
concatenation because MSBuild would eat a PowerShell $(...) subexpression. -->
<Exec Command="powershell -NoProfile -Command &quot;$v = (Get-Content '$(ProjectDir)..\manifest.json' -Raw | ConvertFrom-Json).version_number; Compress-Archive -Path '$(TargetDir)$(TargetName).dll', '$(ProjectDir)..\manifest.json', '$(ProjectDir)..\README.md', '$(ProjectDir)Package\icon.png', '$(ProjectDir)Translations' -DestinationPath ('$(PackageOutputDir)RacesOfValheim_Thunderstore_' + $v + '.zip') -Force; Compress-Archive -Path '$(TargetDir)$(TargetName).dll', '$(NexusStaging)RacesOfValheim' -DestinationPath ('$(PackageOutputDir)RacesOfValheim_Nexus_' + $v + '.zip') -Force&quot;" />
<!-- A script rather than Compress-Archive, which writes zip paths with backslashes: see
scripts\package.ps1. -->
<Exec Command="powershell -NoProfile -ExecutionPolicy Bypass -File &quot;$(ProjectDir)..\scripts\package.ps1&quot; -Dll &quot;$(TargetDir)$(TargetName).dll&quot; -Manifest &quot;$(ProjectDir)..\manifest.json&quot; -Readme &quot;$(ProjectDir)..\README.md&quot; -Icon &quot;$(ProjectDir)Package\icon.png&quot; -Translations &quot;$(ProjectDir)Translations&quot; -OutDir &quot;$(REPO_ROOT)dist&quot;" />
</Target>

58
scripts/package.ps1 Normal file
View 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