Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion scripts/meta_to_xml.ps1
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
# Converts carved PSO ('PSIN') and RBF ('RBF0') metadata blobs to XML with CodeWalker.Core's parsers.
# Run in Windows PowerShell 5.1.
# .\meta_to_xml.ps1 -Carve <work>\carve -Out <work>\meta [-Limit N]
# -Limit N converts the first N blobs; 0 or no -Limit converts every blob.
# Each blob becomes <Out>\<archive>\<offset>.xml. Failures go to <Out>\failures.txt (UTF-8 with BOM) with the error message.
param(
[string]$Carve = "<work>\carve",
[string]$Out = "<work>\meta",
[string]$CodeWalker = "<ref>\codewalker-gen9",
[int]$Limit = 0
# A negative limit used to stop before the first blob: `$Limit` is true for any non-zero value, so the loop
# broke at once and the run ended with 'pso ok 0 failed 0' and an empty failures.txt.
[ValidateRange(0, 2147483647)][int]$Limit = 0
)
$ErrorActionPreference = "Stop"
try { (Get-Process -Id $PID).PriorityClass = "BelowNormal" } catch {}
Expand Down
66 changes: 60 additions & 6 deletions tests/test_meta_to_xml_paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,35 @@
"""


def build_stub_deps(deps):
"""Compile stand-ins for the three CodeWalker DLLs with PowerShell's own compiler."""
deps.mkdir(parents=True, exist_ok=True)
return subprocess.run(
[*POWERSHELL, "-Command", "-"], cwd=deps, input=BUILD_STUB + "\n",
capture_output=True, text=True, timeout=60,
)


def write_two_pso_blobs(carve):
"""Two synthetic PSIN blobs in a carve folder: <carve>/archive/index.json plus the two .bin files."""
archive = carve / "archive"
archive.mkdir(parents=True)
(archive / "index.json").write_text(json.dumps({"files": [
{"head": "5053494e", "off": 0},
{"head": "5053494e", "off": 16},
]}), encoding="utf-8")
(archive / "000000000000.bin").write_bytes(b"PSIN\x00")
(archive / "000000000010.bin").write_bytes(b"PSIN\x00")
return archive


@unittest.skipUnless(os.name == "nt", "Windows PowerShell 5.1 script")
class MetaToXmlPathsTest(unittest.TestCase):
def test_plain_bracketed_and_unicode_paths(self):
with tempfile.TemporaryDirectory() as tmp:
root = Path(tmp)
deps = root / "deps"
deps.mkdir()
# Use PowerShell's built-in compiler to stand in for the three DLLs.
build = subprocess.run(
[*POWERSHELL, "-Command", "-"], cwd=deps, input=BUILD_STUB + "\n",
capture_output=True, text=True, timeout=30,
)
build = build_stub_deps(deps)
self.assertEqual(build.returncode, 0, build.stdout + build.stderr)

cases = (
Expand Down Expand Up @@ -80,6 +97,43 @@ def test_plain_bracketed_and_unicode_paths(self):
self.assertTrue(failures[1].startswith(f"{archive_name}\\000000000008 pso : "), failures[1])
self.assertEqual(failures[2], f"{archive_name}\\000000000010 pso : synthetic parser failure")

def test_negative_limit_is_refused_before_anything_is_converted(self):
with tempfile.TemporaryDirectory() as tmp:
root = Path(tmp)
deps = build_stub_deps(root / "deps")
self.assertEqual(deps.returncode, 0, deps.stdout + deps.stderr)
carve, out = root / "carve", root / "out"
write_two_pso_blobs(carve)

result = subprocess.run(
[*POWERSHELL, "-File", str(SCRIPT), "-Carve", str(carve), "-Out", str(out),
"-CodeWalker", str(root / "deps"), "-Limit", "-5"],
capture_output=True, text=True, timeout=60,
)
# A negative limit is true in PowerShell, so the old guard broke out before the first blob and the run
# ended with "pso ok 0 failed 0" and an empty failures.txt.
self.assertNotEqual(result.returncode, 0, result.stdout)
self.assertIn("Limit", result.stderr)
self.assertNotIn("pso ok", result.stdout)
self.assertFalse(out.exists(), "the value is refused before the output folder is made")

def test_zero_limit_still_converts_every_blob(self):
with tempfile.TemporaryDirectory() as tmp:
root = Path(tmp)
deps = build_stub_deps(root / "deps")
self.assertEqual(deps.returncode, 0, deps.stdout + deps.stderr)
carve, out = root / "carve", root / "out"
write_two_pso_blobs(carve)

result = subprocess.run(
[*POWERSHELL, "-File", str(SCRIPT), "-Carve", str(carve), "-Out", str(out),
"-CodeWalker", str(root / "deps"), "-Limit", "0"],
capture_output=True, text=True, timeout=60,
)
# 0 is the default and means "every blob"; the new range must not turn it into a refusal.
self.assertEqual(result.returncode, 0, result.stdout + result.stderr)
self.assertIn("pso ok 2 failed 0", result.stdout)


if __name__ == "__main__":
unittest.main()