From 762aea41ecacff8c2b49d0bc0e3317c05fe802f4 Mon Sep 17 00:00:00 2001 From: endercodezz Date: Fri, 6 Nov 2026 17:07:18 +0200 Subject: [PATCH] feat(tools): compare loose mods and files inside containers with diff The first real translation showed two gaps in p3p-cpk diff: it is loose files, not a mod.cpk, and all 336 files reported as added lie inside game containers. diff now takes a directory, and such a file is in-container with the path of its container. Verified on the Russian translation v0.8.3 against umd0 and umd1: 1,369 changed as before, 336 in-container, 128 added (package and texture files only). tools/cpk/check.py: 28/28 CLI tests. --- .agents/skills/p3p-modding-vfs/SKILL.md | 2 +- .claude/skills/p3p-modding-vfs/SKILL.md | 2 +- README.md | 5 +- docs/CURRENT_STATE.md | 9 ++ docs/P3P_RESEARCH.md | 2 +- docs/VERIFICATION.md | 2 +- tools/cpk/src/cpk.zig | 11 ++ tools/cpk/src/main.zig | 161 ++++++++++++++++++------ tools/cpk/test_cli.py | 48 ++++++- 9 files changed, 197 insertions(+), 45 deletions(-) diff --git a/.agents/skills/p3p-modding-vfs/SKILL.md b/.agents/skills/p3p-modding-vfs/SKILL.md index 75027133..4b5a93b3 100644 --- a/.agents/skills/p3p-modding-vfs/SKILL.md +++ b/.agents/skills/p3p-modding-vfs/SKILL.md @@ -31,7 +31,7 @@ Do **not** assume all mods are purely asset replacements. For every modification - `p3p/p3p-patches/ULUS10512.ini` — Verified memory offsets for intro skip and mod loader string pointers. - `p3p/Persona-3-Portable-Mod-Menu/` — Field script hooks (`.flow` / `.bf`) and menu initialization. -- `tools/cpk/` — Our Zig CLI: lists and extracts a CPK from the ISO or a loose `mod.cpk`, which also checks that the archive is readable, and `diff` shows which game files a mod replaces (`build/cpk/bin/p3p-cpk --help`). +- `tools/cpk/` — Our Zig CLI: lists and extracts a CPK from the ISO or a loose `mod.cpk`, which also checks that the archive is readable, and `diff` shows which game files a mod, a `bind/` folder or an Aemulus package replaces (`build/cpk/bin/p3p-cpk --help`). - `tools/CriFsV2Lib/` — Modern C# library for reading and parsing CriWare CPK archives. - `tools/CriPakTools/` — C# CLI tool for unpacking and repacking CPK files with CRILAYLA compression. - `tools/AtlusFileSystemLibrary/` — Comprehensive library for Atlus PAC, BIN, GIM, and TMX containers. diff --git a/.claude/skills/p3p-modding-vfs/SKILL.md b/.claude/skills/p3p-modding-vfs/SKILL.md index 75027133..4b5a93b3 100644 --- a/.claude/skills/p3p-modding-vfs/SKILL.md +++ b/.claude/skills/p3p-modding-vfs/SKILL.md @@ -31,7 +31,7 @@ Do **not** assume all mods are purely asset replacements. For every modification - `p3p/p3p-patches/ULUS10512.ini` — Verified memory offsets for intro skip and mod loader string pointers. - `p3p/Persona-3-Portable-Mod-Menu/` — Field script hooks (`.flow` / `.bf`) and menu initialization. -- `tools/cpk/` — Our Zig CLI: lists and extracts a CPK from the ISO or a loose `mod.cpk`, which also checks that the archive is readable, and `diff` shows which game files a mod replaces (`build/cpk/bin/p3p-cpk --help`). +- `tools/cpk/` — Our Zig CLI: lists and extracts a CPK from the ISO or a loose `mod.cpk`, which also checks that the archive is readable, and `diff` shows which game files a mod, a `bind/` folder or an Aemulus package replaces (`build/cpk/bin/p3p-cpk --help`). - `tools/CriFsV2Lib/` — Modern C# library for reading and parsing CriWare CPK archives. - `tools/CriPakTools/` — C# CLI tool for unpacking and repacking CPK files with CRILAYLA compression. - `tools/AtlusFileSystemLibrary/` — Comprehensive library for Atlus PAC, BIN, GIM, and TMX containers. diff --git a/README.md b/README.md index 7b1ab718..d4cc8fe5 100644 --- a/README.md +++ b/README.md @@ -374,15 +374,16 @@ build/cpk/bin/p3p-cpk list game.iso /PSP_GAME/USRDIR/umd0.cpk .bmd build/cpk/bin/p3p-cpk list mods/mod.cpk build/cpk/bin/p3p-cpk extract game.iso /PSP_GAME/USRDIR/umd0.cpk data/battle .tmp/extract build/cpk/bin/p3p-cpk diff mods/mod.cpk game.iso /PSP_GAME/USRDIR/umd0.cpk /PSP_GAME/USRDIR/umd1.cpk +build/cpk/bin/p3p-cpk diff mods/bind game.iso /PSP_GAME/USRDIR/umd0.cpk /PSP_GAME/USRDIR/umd1.cpk build/cpk/bin/p3p-cpk check-trace game.iso .tmp/io-trace.csv ms0:/PSP/P3P=.tmp/mods ``` - `list` prints directory and name, offset, stored and extracted size, and whether the file is CRILAYLA-compressed; the optional last argument is a case-insensitive substring of `dir/name`. An archive it can't read fully is an error, which makes it a quick check of a community `mod.cpk`. - `extract` writes files under their CPK directories and decompresses them. All output paths are checked before the first write: `..`, absolute paths and names that are unsafe on Windows stop the extraction. -- `diff` shows what a `mod.cpk` does to the game's archives: each of its files is `added`, `changed` or `same`, by extracted content, so a stored copy of a compressed file counts as the same. Names match without regard to case, and a match that differs in case is marked `case-differs`. +- `diff` shows what a `mod.cpk`, a `bind/` folder or an Aemulus package does to the game's archives: each file is `added`, `changed` or `same`, by extracted content, so a stored copy of a compressed file counts as the same. A file under a folder named after a game file, such as `data/init/a.tmx` for `data/init.bin`, is `in-container`: a mod manager has to build it into that file first. Names match without regard to case, and a match that differs in case is marked `case-differs`. - `check-trace` verifies `p3p_pc_bootstrap --io-trace`: each read of a `.cpk` must be metadata or lie inside one file with the same FNV-1a 64. -Exit codes: **0** success, **1** `check-trace` found differences or `diff` found a file added or changed, **2** usage/input/output error. On Windows use `p3p-cpk.exe`. Keep game files and extracts under `.tmp/`. +Exit codes: **0** success, **1** `check-trace` found differences or `diff` found anything but `same`, **2** usage/input/output error. On Windows use `p3p-cpk.exe`. Keep game files and extracts under `.tmp/`. ### Continuous integration and releases (GitHub Actions) diff --git a/docs/CURRENT_STATE.md b/docs/CURRENT_STATE.md index 16d69b1a..7e6dc8a1 100644 --- a/docs/CURRENT_STATE.md +++ b/docs/CURRENT_STATE.md @@ -2,6 +2,15 @@ This is the current source of truth, newest entries first. Evidence concerns ULUS-10512; each section says whether it was measured on the PC runner, in Azahar or on a real New 3DS. +## First real translation compared: Russian v0.8.3 (#80, #23, 2026-11-06) + +- [VERIFIED] [P3P Russian Translation (PSP Version)](https://gamebanana.com/mods/449730) v0.8.3 by Kotone Team, MD5 `5fc0fa81f932311d0988ec4385c0b3b6`: an Aemulus package (`Package.xml`, 1,705 files under `data/`), `texture_override/ULUS10512` (126 files) and an EBOOT patch (`rus_eboot_patch_v0.8.2.xdelta`, source `EBOOT_DEC.BIN`). Not a `mod.cpk`. Game data, kept under `.tmp/` only. +- `tools/cpk`: `diff` accepts a directory as the mod, and a file under a folder named after a game file is `in-container`, not `added`. +- [VERIFIED] `diff` of the package against `umd0.cpk` and `umd1.cpk`: 1,369 `changed` (1,258 `.bf`, 98 `.abin`), 336 `in-container` (229 `.bf`, 72 `.tmx`, 20 `.bmd`, `data/init/font/font0.fnt` under `data/init.bin`), 128 `added` (the texture folder, `Package.xml`, `Preview.png`). +- [INFERRED] The `in-container` files must first be built into their containers, which Aemulus does, so the package can't simply be copied to `mods/bind/`. Not yet checked against Aemulus or run. +- [WRONG] A translation needs no EBOOT patch: the mod's description says the menu text is in the EBOOT. P3P3DS generates its AOT code from the EBOOT, so a patch that touches code has to reach the Builder. [UNVERIFIED] What it changes: not applied yet, no xdelta tool here. +- [INFERRED] Cyrillic is drawn through a replaced font with Latin character codes: the patch holds `Kluwka dlq lakrossa` ("lacrosse stick" in Russian). One string only. + ## `p3p-cpk diff`: what a mod changes in the game's archives (#76, 2026-11-06) - `tools/cpk`: `diff ` or `diff ...` reports each file of the mod as `added`, `changed` or `same` by extracted content. It is the first step of #23: which files a fan translation replaces. diff --git a/docs/P3P_RESEARCH.md b/docs/P3P_RESEARCH.md index f2f284e2..b1204026 100644 --- a/docs/P3P_RESEARCH.md +++ b/docs/P3P_RESEARCH.md @@ -135,7 +135,7 @@ In **P3P3DS**, the HLE `IoFileMgr` subsystem will intercept all game file reques ``` ### 6.2. Russification & Font Handling -Russian fan translations for Persona 3 Portable (such as the translation by The Miracle / DniweTamp): +Russian fan translations for Persona 3 Portable (such as the translation by Kotone Team, measured in `docs/CURRENT_STATE.md`): 1. **Text Encoding:** `[UNVERIFIED]` expected to map Cyrillic onto a custom 1-byte table used by the replaced font; the real translation package has not been examined. 2. **Font Textures:** `[INFERRED]` modifies the game font; `umd0.cpk` contains exactly one `.fnt` file (CPK listing via `experiments/cpk-check`). 3. **Dialogue Scripts:** `[INFERRED]` modified `.bf` (1,272 in `umd0.cpk`, flow scripts with embedded messages) and `.bmd` files. diff --git a/docs/VERIFICATION.md b/docs/VERIFICATION.md index 6b405b24..a89a1b52 100644 --- a/docs/VERIFICATION.md +++ b/docs/VERIFICATION.md @@ -152,7 +152,7 @@ Local ULUS-10512 ISO, Windows, Zig 0.17.1 `-Doptimize=safe`, oracle `experiments | Execution frontier advances through ten proven guest functions to `0x08B1C594` | `[VERIFIED]` | `profiles/p3p/config/p3p_functions.csv`; `build/generated/p3p_generated.cpp`; `logs/p3p_bootstrap_latest.log`; executable disassembly at `0x08AB315C` and `0x08B1C594` | The final run reaches executable word `0x0E2C7165` (`jal 0x08B1C594`) at `0x08AB315C` with `$ra = 0x08AB3164`. The target is a distinct, currently unregistered function boundary. Runtime, HLE, and codegen semantics are unchanged; graphics counters remain zero. | | P3P is 100% viable for static recompilation | `[INFERRED]` | Clean relocation handling + entry point execution milestone | Bootstrap and entry point succeed; viability of remaining complex subsystems (VFPU, overlays, indirect jumps) requires incremental verification. | | A new PSP thread starts with VFPU source/target prefixes `0xE4` and destination prefix 0 | `[VERIFIED]` | pspautotests `cpu/vfpu/{callout,convert_scaled,minmax}.expected` match exactly only with this initial state (`tests/autotest_baseline.txt`, 2026-10-08) | Before: all-zero `vfpu_ctrl`, every lane read X on a thread's first prefixed VFPU op. | -| Russian fan translation is 100% asset-only with no EBOOT patches | `[UNVERIFIED]` | Community packaging analysis | While scripts (`.bmd`) and fonts are asset-level, potential EBOOT localization patches (character spacing, glyph width) need empirical testing. | +| Russian fan translation is 100% asset-only with no EBOOT patches | `[WRONG]`: v0.8.3 ships an EBOOT xdelta patch for the menu text (#80) | Community packaging analysis | While scripts (`.bmd`) and fonts are asset-level, potential EBOOT localization patches (character spacing, glyph width) need empirical testing. | --- diff --git a/tools/cpk/src/cpk.zig b/tools/cpk/src/cpk.zig index 470e10af..78849c0c 100644 --- a/tools/cpk/src/cpk.zig +++ b/tools/cpk/src/cpk.zig @@ -276,6 +276,17 @@ fn isCompressed(source: Source, file: File) !bool { return std.mem.eql(u8, &magic, "CRILAYLA"); } +/// A file outside any archive, such as one in a `bind/` folder: all of `source`. +pub fn looseFile(source: Source, dir: []const u8, name: []const u8) !File { + var file: File = .{ .dir = dir, .name = name, .offset = 0, .size = source.size, .extract_size = source.size }; + if (try isCompressed(source, file)) { + var header: [layla_header]u8 = undefined; + try source.read(0, &header); + file.extract_size = @as(u64, std.mem.readInt(u32, header[8..12], .little)) + layla_prefix; + } + return file; +} + /// The file's content, decompressed when it is CRILAYLA. Caller frees. pub fn extract(allocator: std.mem.Allocator, source: Source, file: File) ![]u8 { if (file.size == 0) return allocator.alloc(u8, 0); diff --git a/tools/cpk/src/main.zig b/tools/cpk/src/main.zig index f3eb1c05..1079e16c 100644 --- a/tools/cpk/src/main.zig +++ b/tools/cpk/src/main.zig @@ -8,8 +8,8 @@ const usage = \\ p3p-cpk list [substring] \\ p3p-cpk extract [substring] \\ p3p-cpk extract [substring] - \\ p3p-cpk diff - \\ p3p-cpk diff ... + \\ p3p-cpk diff + \\ p3p-cpk diff ... \\ p3p-cpk check-trace [prefix=hostdir ...] \\ p3p-cpk --help | --version \\list prints every file: dir/name, offset, stored and extracted size, compressed. @@ -18,14 +18,17 @@ const usage = \\paths and names unsafe on Windows are refused. Bytes above ASCII become %XX. \\diff prints what a mod does to the base archives, for each of its files: added, \\changed or same, comparing extracted content, so a stored and a compressed copy - \\of the same bytes are the same. Names match without regard to case; a match - \\that differs in case is marked case-differs. With several base archives the - \\first that has a file wins. + \\of the same bytes are the same. A mod dir holds paths like data/init.bin, as a + \\bind/ folder does. A file missing from the base but under a folder named after + \\a base file without its extension (data/init/a.tmx, data/init.bin) is + \\in-container: a mod manager has to build it into that file. Names match without + \\regard to case; a match that differs in case is marked case-differs. With + \\several base archives the first that has a file wins. \\check-trace verifies the reads of p3p_pc_bootstrap --io-trace: each read of a \\.cpk must be metadata or lie in one file with the same FNV-1a 64. prefix=hostdir \\maps traced paths to host files, e.g. ms0:/PSP/P3P=.tmp/mods. - \\Exit: 0 success, 1 check-trace or diff found differences (for diff: a file added - \\or changed), 2 usage/input/output error. + \\Exit: 0 success, 1 check-trace or diff found differences (for diff: anything but + \\same), 2 usage/input/output error. \\ ; @@ -239,14 +242,106 @@ fn sameContent(allocator: std.mem.Allocator, mod_source: cpk.Source, mod: cpk.Fi return std.mem.eql(u8, left, right); } +const Diff = struct { + base_files: *const std.StringHashMapUnmanaged(BaseFile), + /// Lower-case base paths without their extension -> the base file's path. + stems: *const std.StringHashMapUnmanaged([]const u8), + files: u64 = 0, + added: u64 = 0, + in_container: u64 = 0, + changed: u64 = 0, + same: u64 = 0, + case_differs: u64 = 0, + + /// The deepest folder of `key` that is named after a base file. + fn container(self: *const Diff, key: []const u8) ?[]const u8 { + var end = key.len; + while (std.mem.lastIndexOfScalar(u8, key[0..end], '/')) |slash| { + if (slash == 0) return null; + if (self.stems.get(key[0..slash])) |found| return found; + end = slash; + } + return null; + } + + fn compare(self: *Diff, allocator: std.mem.Allocator, writer: *std.Io.Writer, source: cpk.Source, file: cpk.File) !void { + self.files += 1; + const key = try lowerKey(allocator, file); + defer allocator.free(key); + const found = self.base_files.get(key) orelse { + if (self.container(key)) |container_path| { + self.in_container += 1; + try writer.print("in-container {s}/{s} container={s}\n", .{ file.dir, file.name, container_path }); + } else { + self.added += 1; + try writer.print("added {s}/{s} extract=0x{X}\n", .{ file.dir, file.name, file.extract_size }); + } + return; + }; + const exact = std.mem.eql(u8, file.dir, found.file.dir) and std.mem.eql(u8, file.name, found.file.name); + const mark: []const u8 = if (exact) "" else " case-differs"; + if (!exact) self.case_differs += 1; + if (try sameContent(allocator, source, file, found)) { + self.same += 1; + try writer.print("same {s}/{s}{s}\n", .{ file.dir, file.name, mark }); + } else { + self.changed += 1; + try writer.print("changed {s}/{s} extract=0x{X} -> 0x{X}{s}\n", .{ file.dir, file.name, found.file.extract_size, file.extract_size, mark }); + } + } +}; + +fn pathLessThan(_: void, a: []u8, b: []u8) bool { + return std.mem.lessThan(u8, a, b); +} + +fn diffDirectory(init: std.process.Init, writer: *std.Io.Writer, diff: *Diff, dir: std.Io.Dir) !void { + const allocator = init.gpa; + const io = init.io; + var arena_state: std.heap.ArenaAllocator = .init(allocator); + defer arena_state.deinit(); + const arena = arena_state.allocator(); + var paths: std.ArrayList([]u8) = .empty; + var walker = try dir.walk(allocator); + defer walker.deinit(); + while (try walker.next(io)) |entry| { + if (entry.kind != .file) continue; + const path = try arena.dupe(u8, entry.path); + std.mem.replaceScalar(u8, path, '\\', '/'); + try paths.append(arena, path); + } + // The order of a directory listing differs between systems. + std.mem.sort([]u8, paths.items, {}, pathLessThan); + for (paths.items) |path| { + const file = try dir.openFile(io, path, .{}); + defer file.close(io); + const view: View = .{ .io = io, .file = file, .base = 0 }; + const source = view.source(try file.length(io)); + const split = std.mem.lastIndexOfScalar(u8, path, '/'); + const parent = if (split) |slash| path[0..slash] else ""; + const name = if (split) |slash| path[slash + 1 ..] else path; + try diff.compare(allocator, writer, source, try cpk.looseFile(source, parent, name)); + } +} + fn diffCommand(init: std.process.Init, writer: *std.Io.Writer, args: []const []const u8) !u8 { const allocator = init.gpa; const io = init.io; if (args.len < 2) return error.ExpectedModAndBase; + const mod_dir: ?std.Io.Dir = std.Io.Dir.cwd().openDir(io, args[0], .{ .iterate = true }) catch |err| switch (err) { + error.NotDir => null, + else => return err, + }; + defer if (mod_dir) |dir| dir.close(io); var mod: Container = undefined; - try mod.open(io, args[0]); - defer mod.file.close(io); - if (!mod.is_cpk) return error.ModIsNotCpk; + if (mod_dir == null) { + try mod.open(io, args[0]); + if (!mod.is_cpk) { + mod.file.close(io); + return error.ModIsNotCpk; + } + } + defer if (mod_dir == null) mod.file.close(io); var base: Container = undefined; try base.open(io, args[1]); defer base.file.close(io); @@ -263,6 +358,8 @@ fn diffCommand(init: std.process.Init, writer: *std.Io.Writer, args: []const []c defer for (archives[0..opened]) |archive| archive.deinit(allocator); var base_files: std.StringHashMapUnmanaged(BaseFile) = .empty; defer base_files.deinit(allocator); + var stems: std.StringHashMapUnmanaged([]const u8) = .empty; + defer stems.deinit(allocator); for (views, archives, 0..) |*view, *archive, index| { view.* = base.view; var size = base.size; @@ -277,39 +374,27 @@ fn diffCommand(init: std.process.Init, writer: *std.Io.Writer, args: []const []c archive.* = try cpk.Archive.open(allocator, source); opened += 1; for (archive.files) |file| { - const slot = try base_files.getOrPut(allocator, try lowerKey(arena, file)); + const key = try lowerKey(arena, file); + const slot = try base_files.getOrPut(allocator, key); if (!slot.found_existing) slot.value_ptr.* = .{ .file = file, .source = source }; + const dot = std.mem.lastIndexOfScalar(u8, key, '.') orelse continue; + if (dot <= file.dir.len + 1) continue; // no extension, or a name like `.hidden` + const stem = try stems.getOrPut(allocator, key[0..dot]); + if (!stem.found_existing) stem.value_ptr.* = try std.fmt.allocPrint(arena, "{s}/{s}", .{ file.dir, file.name }); } } - const mod_source = mod.view.source(mod.size); - const archive = try cpk.Archive.open(allocator, mod_source); - defer archive.deinit(allocator); - var added: u64 = 0; - var changed: u64 = 0; - var same: u64 = 0; - var case_differs: u64 = 0; - for (archive.files) |file| { - const key = try lowerKey(allocator, file); - defer allocator.free(key); - const found = base_files.get(key) orelse { - added += 1; - try writer.print("added {s}/{s} extract=0x{X}\n", .{ file.dir, file.name, file.extract_size }); - continue; - }; - const exact = std.mem.eql(u8, file.dir, found.file.dir) and std.mem.eql(u8, file.name, found.file.name); - const mark: []const u8 = if (exact) "" else " case-differs"; - if (!exact) case_differs += 1; - if (try sameContent(allocator, mod_source, file, found)) { - same += 1; - try writer.print("same {s}/{s}{s}\n", .{ file.dir, file.name, mark }); - } else { - changed += 1; - try writer.print("changed {s}/{s} extract=0x{X} -> 0x{X}{s}\n", .{ file.dir, file.name, found.file.extract_size, file.extract_size, mark }); - } + var diff: Diff = .{ .base_files = &base_files, .stems = &stems }; + if (mod_dir) |dir| { + try diffDirectory(init, writer, &diff, dir); + } else { + const mod_source = mod.view.source(mod.size); + const archive = try cpk.Archive.open(allocator, mod_source); + defer archive.deinit(allocator); + for (archive.files) |file| try diff.compare(allocator, writer, mod_source, file); } - try writer.print("mod files={d} added={d} changed={d} same={d} case_differs={d} base files={d}\n", .{ archive.files.len, added, changed, same, case_differs, base_files.count() }); - return if (added == 0 and changed == 0) 0 else 1; + try writer.print("mod files={d} added={d} in_container={d} changed={d} same={d} case_differs={d} base files={d}\n", .{ diff.files, diff.added, diff.in_container, diff.changed, diff.same, diff.case_differs, base_files.count() }); + return if (diff.added == 0 and diff.in_container == 0 and diff.changed == 0) 0 else 1; } const TracedCpk = struct { diff --git a/tools/cpk/test_cli.py b/tools/cpk/test_cli.py index 86aa343b..5f284f86 100644 --- a/tools/cpk/test_cli.py +++ b/tools/cpk/test_cli.py @@ -334,7 +334,53 @@ def test_diff_kinds(self): self.assertEqual(lines[1], "added data/a/root2.txt extract=0x3") self.assertEqual(lines[2], "changed /root.txt extract=0x5 -> 0x6") self.assertEqual(lines[3], "same data/b/packed.bin") - self.assertEqual(lines[4], "mod files=4 added=1 changed=2 same=1 case_differs=0 base files=4") + self.assertEqual(lines[4], "mod files=4 added=1 in_container=0 changed=2 same=1 case_differs=0 base files=4") + + def mod_directory(self, files): + root = self.dir / "bind" + for path, data in files.items(): + (root / path).parent.mkdir(parents=True, exist_ok=True) + (root / path).write_bytes(data) + return root + + def test_diff_directory(self): + base = self.diff_fixture(ENTRIES, "base.cpk") + root = self.mod_directory({ + "data/a/plain.bin": PLAIN, + "data/b/packed.bin": COMPRESSED, # a compressed loose file is compared by content + "root.txt": b"HELLO", + "data/a/plain/inner/tex.tmx": b"inside plain.bin", + "data/new/file.bin": b"new", + }) + result = run("diff", root, base) + self.assertEqual(result.returncode, 1, result.stderr) + self.assertEqual(result.stdout.splitlines(), [ + "same data/a/plain.bin", + "in-container data/a/plain/inner/tex.tmx container=data/a/plain.bin", + "same data/b/packed.bin", + f"added data/new/file.bin extract=0x3", + "changed /root.txt extract=0x5 -> 0x5", + "mod files=5 added=1 in_container=1 changed=1 same=2 case_differs=0 base files=4", + ]) + + def test_diff_directory_without_changes(self): + base = self.diff_fixture(ENTRIES, "base.cpk") + result = run("diff", self.mod_directory({"data/a/plain.bin": PLAIN}), base) + self.assertEqual(result.returncode, 0, result.stdout + result.stderr) + + def test_diff_empty_directory(self): + base = self.diff_fixture(ENTRIES, "base.cpk") + (self.dir / "empty").mkdir() + result = run("diff", self.dir / "empty", base) + self.assertEqual(result.returncode, 0, result.stdout + result.stderr) + self.assertIn("mod files=0", result.stdout) + + def test_diff_in_container_from_a_cpk_counts_as_a_difference(self): + base = self.diff_fixture(ENTRIES, "base.cpk") + mod = self.diff_fixture([("DATA/A/PLAIN", "x.bin", b"x", 1)]) + result = run("diff", mod, base) + self.assertEqual(result.returncode, 1, result.stderr) + self.assertIn("in-container DATA/A/PLAIN/x.bin container=data/a/plain.bin", result.stdout) def test_diff_nothing_changed(self): base = self.diff_fixture(ENTRIES, "base.cpk")