diff --git a/docs/mission_logic.md b/docs/mission_logic.md index 67a15ebf1..d1ee15e51 100644 --- a/docs/mission_logic.md +++ b/docs/mission_logic.md @@ -166,6 +166,10 @@ at, from inflated PSIN streams or a directory of carved `.bin` streams: python -I tools/mission_tables.py [--json] [--limit N] ``` +A lone path is the PSIN file: a file without the `PSIN` magic is one `ERROR: : not a PSIN container` +line and exit 2, while a folder is the place for the bare carved streams and is scanned as before. A PSIN +file that holds no records is still a clean run. + It prints per-file record, chunk, state and entity counts, plus each resolved entity's archetype hash, link hash, position and rotation. Pointers are scored in three encodings: **file-absolute**, **linked pool** (`pool_block_base + (offset >> 4)`), and **block-indexed** (`kind` is a 1-based diff --git a/tests/test_mission_tables.py b/tests/test_mission_tables.py index 43879eff1..5cdad139d 100644 --- a/tests/test_mission_tables.py +++ b/tests/test_mission_tables.py @@ -413,6 +413,28 @@ class TestCli(unittest.TestCase): self.assertEqual(completed.stdout.count(" records="), 2) self.assertIn("2 files,", completed.stdout) + def test_a_single_file_without_the_magic_is_refused(self): + # A lone argument is a PSIN file; a folder is where the bare carved .bin streams live. Naming a file + # that is neither used to end in "1 files, 0 records" and exit 0, so a wrong path looked like a run. + with tempfile.TemporaryDirectory() as folder: + path = os.path.join(folder, "not-a-container.bin") + with open(path, "wb") as handle: + handle.write(b"\x01" * 64) + completed = subprocess.run([sys.executable, "-I", TOOL, path], capture_output=True, text=True) + self.assertEqual(completed.returncode, 2) + self.assertIn("not a PSIN container", completed.stderr) + self.assertEqual(completed.stdout, "") + + def test_a_folder_still_scans_a_stream_without_the_magic(self): + # Negative control: the same bytes in a folder are a carved stream and are still counted. + with tempfile.TemporaryDirectory() as folder: + with open(os.path.join(folder, "bare.bin"), "wb") as handle: + handle.write(b"\x01" * 64) + completed = subprocess.run([sys.executable, "-I", TOOL, folder], capture_output=True, text=True) + self.assertEqual(completed.returncode, 0, completed.stderr) + self.assertIn("1 files, 0 records", completed.stdout) + self.assertIn("skipped bytes 64", completed.stdout) + if __name__ == "__main__": unittest.main() diff --git a/tools/mission_tables.py b/tools/mission_tables.py index f093048a6..f8299a900 100644 --- a/tools/mission_tables.py +++ b/tools/mission_tables.py @@ -552,6 +552,17 @@ def main(argv=None): if not os.path.exists(args.src): print(f"ERROR: {args.src}: no such file or folder", file=sys.stderr) return 2 + if os.path.isfile(args.src): + # A lone argument is the inflated PSIN file; the bare carved streams are what a folder holds. + try: + with open(args.src, "rb") as handle: + magic = handle.read(4) + except OSError as error: + print(f"ERROR: {args.src}: {error}", file=sys.stderr) + return 2 + if magic != b"PSIN": + print(f"ERROR: {args.src}: not a PSIN container", file=sys.stderr) + return 2 try: files = collect(args.src, args.limit) except OSError as error: