diff --git a/README.md b/README.md index 9dfdf6b..fbc7a28 100644 --- a/README.md +++ b/README.md @@ -76,7 +76,7 @@ RimWorld 1.7 no longer runs on Unity/Mono. It runs on .NET 10 (CoreCLR) with Lud It stages only what players need (About, 1.7, Defs, Patches, Languages) in `%TEMP%`, sets the tags the game would (Mod plus the supported versions), and writes every CHANGELOG.md entry since the version in `Tools/workshop-published.txt` as the change note. `-Publish` refuses unless the shipped files are committed and pushed, the top CHANGELOG entry matches `modVersion`, and the last test run passed after the last build. It leaves the title and preview alone; the game's uploader resets the title from About.xml and never updates the description. The in-game route still works: `Tools/workshop-stage.ps1` swaps the junction for a clean copy, upload from Mods > Blax Slaves > More actions (dev mode), then `workshop-stage.ps1 -Done`. -The Workshop description is `docs/workshop-description.txt` (Steam BBCode). Its images load from this repo's `docs/art/` over Forgejo's raw URLs, so push them before you upload a description that uses them. `Source/Art/README.md` has the render commands. +The Workshop description is `docs/workshop-description.txt` (Steam BBCode); `-DescriptionOnly -DescriptionFile docs\workshop-description.txt` replaces just the text, with no build, no content upload and no change note. Steam loads description images as cross-origin requests, so every `[img]` host must send an `Access-Control-Allow-Origin` header or the image shows broken; the script checks each one and `-Publish` refuses otherwise. Forgejo's raw URLs send no such header. `Source/Art/README.md` has the render commands for the art in `docs/art/`. ### Tests diff --git a/Tools/WorkshopUpload/Program.cs b/Tools/WorkshopUpload/Program.cs index 48e7703..4aaa67d 100644 --- a/Tools/WorkshopUpload/Program.cs +++ b/Tools/WorkshopUpload/Program.cs @@ -96,9 +96,10 @@ internal static class Program return 0; } - if (o.Content == null || note == null) + bool descriptionOnly = o.Content == null && note == null && description != null; + if (!descriptionOnly && (o.Content == null || note == null)) { - Console.Error.WriteLine("--publish needs --content and --note-file."); + Console.Error.WriteLine("--publish needs --content and --note-file, or only --description-file."); return 64; } return Submit(item, o, note, description); @@ -107,7 +108,8 @@ internal static class Program private static int Submit(PublishedFileId_t item, Options o, string note, string description) { UGCUpdateHandle_t h = SteamUGC.StartItemUpdate(new AppId_t(RimWorldAppId), item); - if (!SteamUGC.SetItemContent(h, o.Content)) return Fail("SetItemContent refused the content folder."); + // Description-only updates send no content and no change note (null), so Steam lists no new change note. + if (o.Content != null && !SteamUGC.SetItemContent(h, o.Content)) return Fail("SetItemContent refused the content folder."); if (o.Tags != null && !SteamUGC.SetItemTags(h, o.Tags)) return Fail("SetItemTags refused the tags."); if (description != null && !SteamUGC.SetItemDescription(h, description)) return Fail("SetItemDescription refused the text."); @@ -230,7 +232,8 @@ internal static class Program public const string Usage = "Usage: WorkshopUpload --item [--content ] [--note-file ] [--tags Mod,1.7]\n" + " [--description-file ] [--timeout ] [--publish]\n" + - "Without --publish it only reads the item and checks ownership."; + "Without --publish it only reads the item and checks ownership. With only --description-file it\n" + + "replaces the description and nothing else."; public ulong Item; public string Content, NoteFile, DescriptionFile; diff --git a/Tools/workshop-upload.ps1 b/Tools/workshop-upload.ps1 index a0a9d18..146da24 100644 --- a/Tools/workshop-upload.ps1 +++ b/Tools/workshop-upload.ps1 @@ -7,6 +7,12 @@ no game window, no dev mode. RimWorld may stay open. .\Tools\workshop-upload.ps1 -Publish uploads the staged copy. The change note is the CHANGELOG.md entry for the version in About.xml. -DescriptionFile docs\workshop-description.txt also replaces the Workshop description (BBCode) + -DescriptionOnly with -DescriptionFile: replaces only the description. No build, + no content upload, no change note. + +Every [img] in the description must load with an Access-Control-Allow-Origin header: Steam loads +description images as cross-origin requests and shows a broken image otherwise. -Publish refuses +when one doesn't. -Publish refuses unless the shipped files are committed and pushed, the top CHANGELOG.md entry matches About.xml's modVersion, and the last Tests\run-tests.ps1 run passed after the last build. @@ -16,6 +22,7 @@ param( [string]$RimWorldDir = 'E:\SteamLibrary\steamapps\common\RimWorld', [switch]$Publish, [string]$DescriptionFile, + [switch]$DescriptionOnly, [string]$TestResults = (Join-Path $env:TEMP 'BlaxSlavesTest\BlaxSlavesTestResults.txt'), [switch]$SkipChecks ) @@ -24,6 +31,26 @@ $repo = Split-Path -Parent $PSScriptRoot $ship = 'About', '1.7', 'Defs', 'Patches', 'Languages', 'Textures', 'Sounds' $toolProj = Join-Path $PSScriptRoot 'WorkshopUpload\WorkshopUpload.csproj' $toolExe = Join-Path $PSScriptRoot 'WorkshopUpload\bin\Release\WorkshopUpload.exe' +if ($DescriptionOnly -and -not $DescriptionFile) { throw '-DescriptionOnly needs -DescriptionFile.' } + +# Steam adds crossorigin to description images, so a host without Access-Control-Allow-Origin shows a broken image. +function Test-DescriptionImages([string]$file) { + [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 + $found = @() + $text = [IO.File]::ReadAllText((Resolve-Path $file).Path, [Text.Encoding]::UTF8) + foreach ($m in [regex]::Matches($text, '\[img\](.*?)\[/img\]')) { + $url = $m.Groups[1].Value.Trim() + try { + $r = Invoke-WebRequest -Uri $url -UseBasicParsing -Headers @{ Origin = 'https://steamcommunity.com' } + $type = "$($r.Headers['Content-Type'])" + $acao = "$($r.Headers['Access-Control-Allow-Origin'])" + if ($type -notlike 'image/*') { $found += "$url is not an image ($type)." } + elseif ($acao -ne '*' -and $acao -ne 'https://steamcommunity.com') { $found += "$url sends no Access-Control-Allow-Origin header; Steam would show it broken." } + } + catch { $found += "$url does not load: $($_.Exception.Message)" } + } + $found +} $itemId = (Get-Content -LiteralPath (Join-Path $repo 'About\PublishedFileId.txt') -Raw).Trim() $about = [xml](Get-Content -LiteralPath (Join-Path $repo 'About\About.xml') -Raw -Encoding UTF8) @@ -53,47 +80,66 @@ foreach ($v in $sections.Keys) { if (-not $noteLines) { $noteLines = @("$($about.ModMetaData.name) $topVersion") + $sections[$topVersion] } $note = ($noteLines -join "`n").Trim() -foreach ($proj in Get-ChildItem (Join-Path $repo 'Source\*\*.csproj')) { - & dotnet build $proj.FullName -c Release -nologo -v q "-p:RimWorldDir=$RimWorldDir" - if ($LASTEXITCODE -ne 0) { throw "build failed: $($proj.Name)" } +if (-not $DescriptionOnly) { + foreach ($proj in Get-ChildItem (Join-Path $repo 'Source\*\*.csproj')) { + & dotnet build $proj.FullName -c Release -nologo -v q "-p:RimWorldDir=$RimWorldDir" + if ($LASTEXITCODE -ne 0) { throw "build failed: $($proj.Name)" } + } } & dotnet build $toolProj -c Release -nologo -v q "-p:RimWorldDir=$RimWorldDir" if ($LASTEXITCODE -ne 0) { throw 'build failed: WorkshopUpload' } +$imageProblems = @() +if ($DescriptionFile) { + $imageProblems = @(Test-DescriptionImages $DescriptionFile) + foreach ($p in $imageProblems) { Write-Warning $p } +} + if ($Publish -and -not $SkipChecks) { - $problems = @() - if ($topVersion -ne $modVersion) { $problems += "CHANGELOG.md's top entry is $topVersion, About.xml says $modVersion." } - $dirty = & git -C $repo status --porcelain -- $ship - if ($dirty) { $problems += "Uncommitted changes in shipped files:`n$($dirty -join "`n")" } + $problems = @() + $imageProblems $ahead = & git -C $repo rev-list --count '@{u}..HEAD' 2>$null if ($LASTEXITCODE -ne 0) { $problems += 'The branch has no upstream to compare with.' } - elseif ([int]$ahead -gt 0) { $problems += "$ahead commit(s) not pushed yet, so the Workshop would ship code the repo doesn't show." } - $dll = Get-ChildItem (Join-Path $repo '1.7\Assemblies\*.dll') | Sort-Object LastWriteTime -Descending | Select-Object -First 1 - if (-not (Test-Path $TestResults)) { $problems += "No test results at $TestResults. Run .\Tests\run-tests.ps1 first." } + elseif ([int]$ahead -gt 0) { $problems += "$ahead commit(s) not pushed yet, so the Workshop would show what the repo doesn't." } + if ($DescriptionOnly) { + $dirty = & git -C $repo status --porcelain -- (Resolve-Path $DescriptionFile).Path + if ($dirty) { $problems += "The description file has uncommitted changes: $dirty" } + } else { - $res = Get-Item $TestResults - $lines = Get-Content -LiteralPath $TestResults -Encoding UTF8 - if (-not ($lines -match '^END$') -or ($lines -match '^FAIL ')) { $problems += 'The last test run failed or did not finish.' } - elseif ($dll -and $res.LastWriteTime -lt $dll.LastWriteTime) { $problems += "The last test run ($($res.LastWriteTime)) is older than the build ($($dll.LastWriteTime)). Run .\Tests\run-tests.ps1 again." } + if ($topVersion -ne $modVersion) { $problems += "CHANGELOG.md's top entry is $topVersion, About.xml says $modVersion." } + $dirty = & git -C $repo status --porcelain -- $ship + if ($dirty) { $problems += "Uncommitted changes in shipped files:`n$($dirty -join "`n")" } + $dll = Get-ChildItem (Join-Path $repo '1.7\Assemblies\*.dll') | Sort-Object LastWriteTime -Descending | Select-Object -First 1 + if (-not (Test-Path $TestResults)) { $problems += "No test results at $TestResults. Run .\Tests\run-tests.ps1 first." } + else { + $res = Get-Item $TestResults + $lines = Get-Content -LiteralPath $TestResults -Encoding UTF8 + if (-not ($lines -match '^END$') -or ($lines -match '^FAIL ')) { $problems += 'The last test run failed or did not finish.' } + elseif ($dll -and $res.LastWriteTime -lt $dll.LastWriteTime) { $problems += "The last test run ($($res.LastWriteTime)) is older than the build ($($dll.LastWriteTime)). Run .\Tests\run-tests.ps1 again." } + } } if ($problems) { throw ("Not publishing:`n- " + ($problems -join "`n- ")) } } -# Clean copy outside the repo: only what players need, no PDBs. TEMP has no spaces in its path. -$root = Join-Path $env:TEMP 'BlaxWorkshopUpload' -$stage = Join-Path $root $packageId -if (Test-Path $stage) { Remove-Item $stage -Recurse -Force } -New-Item -ItemType Directory $stage -Force | Out-Null -foreach ($name in $ship) { - $src = Join-Path $repo $name - if (Test-Path $src) { Copy-Item $src (Join-Path $stage $name) -Recurse } +if ($DescriptionOnly) { + $toolArgs = @('--item', $itemId, '--description-file', (Resolve-Path $DescriptionFile).Path) } -Get-ChildItem $stage -Recurse -File -Filter *.pdb | Remove-Item -$noteFile = Join-Path $root "$packageId.note.txt" -[IO.File]::WriteAllText($noteFile, $note, (New-Object Text.UTF8Encoding $false)) +else { + # Clean copy outside the repo: only what players need, no PDBs. TEMP has no spaces in its path. + $root = Join-Path $env:TEMP 'BlaxWorkshopUpload' + $stage = Join-Path $root $packageId + if (Test-Path $stage) { Remove-Item $stage -Recurse -Force } + New-Item -ItemType Directory $stage -Force | Out-Null + foreach ($name in $ship) { + $src = Join-Path $repo $name + if (Test-Path $src) { Copy-Item $src (Join-Path $stage $name) -Recurse } + } + Get-ChildItem $stage -Recurse -File -Filter *.pdb | Remove-Item + $noteFile = Join-Path $root "$packageId.note.txt" + [IO.File]::WriteAllText($noteFile, $note, (New-Object Text.UTF8Encoding $false)) -$toolArgs = @('--item', $itemId, '--content', $stage, '--note-file', $noteFile, '--tags', ($tags -join ',')) -if ($DescriptionFile) { $toolArgs += @('--description-file', (Resolve-Path $DescriptionFile).Path) } + $toolArgs = @('--item', $itemId, '--content', $stage, '--note-file', $noteFile, '--tags', ($tags -join ',')) + if ($DescriptionFile) { $toolArgs += @('--description-file', (Resolve-Path $DescriptionFile).Path) } +} if ($Publish) { $toolArgs += '--publish' } # steam_api writes status lines to stderr; under 'Stop' PowerShell 5.1 would turn them into errors. @@ -104,7 +150,7 @@ try { $code = $LASTEXITCODE } finally { Pop-Location } -if ($Publish -and $code -eq 0) { +if ($Publish -and $code -eq 0 -and -not $DescriptionOnly) { [IO.File]::WriteAllText($publishedFile, "$topVersion`n") Write-Host "Recorded $topVersion in Tools\workshop-published.txt. Commit it." }