upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/tools/rpf9dump/Program.cs
diff options
context:
space:
mode:
authorItsNotRexed <300290919+ItsNotRexed@users.noreply.github.com>2026-11-22 00:33:00 -0500
committerItsNotRexed <300290919+ItsNotRexed@users.noreply.github.com>2026-11-22 00:33:00 -0500
commitb7ec22e79892c4d99e6b35054db7e2700ba5b4a8 (patch)
treed4989fd572a625728678d118957cb209680f209e /tools/rpf9dump/Program.cs
parent7b51dbd9d8016be52a532d26db2d8727992b121b (diff)
parented784a23009049af46cb35343303332e56b36714 (diff)
Merge pull request #890 from nicolas
Diffstat (limited to 'tools/rpf9dump/Program.cs')
-rw-r--r--tools/rpf9dump/Program.cs34
1 files changed, 26 insertions, 8 deletions
diff --git a/tools/rpf9dump/Program.cs b/tools/rpf9dump/Program.cs
index 65e850b37..046e66b9f 100644
--- a/tools/rpf9dump/Program.cs
+++ b/tools/rpf9dump/Program.cs
@@ -20,15 +20,33 @@ if (mode == "ttpf")
20 foreach (var t in info.Textures) 20 foreach (var t in info.Textures)
21 { 21 {
22 string name = $"{t.Index:D6}_{Util.Safe(Path.GetFileNameWithoutExtension(t.Name))}.dds"; 22 string name = $"{t.Index:D6}_{Util.Safe(Path.GetFileNameWithoutExtension(t.Name))}.dds";
23 rows.Add(new { t.Index, t.Name, t.Id, AssetKey = t.AssetKey.ToString("X16"), t.Width, t.Height, t.DxgiFormat, t.Mips, t.SourceMips, t.BaseMipLevel, t.Limitation, File = t.CanExtract ? name : null });
24 if (!t.CanExtract) { skip++; continue; }
25 string path = Path.Combine(outDir, name); 23 string path = Path.Combine(outDir, name);
26 if (File.Exists(path)) { ok++; continue; } 24 string? file = t.CanExtract ? name : null, limitation = t.Limitation;
27 try { Util.WriteAllBytes(path, TtpfReader.CreateDds(src, t.Index)); ok++; } 25 if (!t.CanExtract) skip++;
28 catch (Exception e) { fail++; if (fail <= 5) Console.WriteLine($" fail {t.Index}: {e.GetType().Name} {e.Message}"); } 26 else if (File.Exists(path)) ok++;
29 if ((ok + fail) % 5000 == 0) Console.WriteLine($" {ok + fail}/{info.Textures.Count}"); 27 else
28 {
29 try
30 {
31 // Content the decoder cannot handle is a skip like !CanExtract. Pool read errors, DDS write errors,
32 // cancellation and anything unexpected stay failures.
33 byte[]? dds = null;
34 try { dds = TtpfReader.CreateDds(src, t.Index); }
35 catch (Exception e) when (e.GetType() == typeof(NotSupportedException) || e.GetType() == typeof(InvalidDataException))
36 { skip++; file = null; limitation = e.Message; }
37 if (dds != null) { Util.WriteAllBytes(path, dds); ok++; }
38 }
39 catch (Exception e) { fail++; if (fail <= 5) Console.WriteLine($" fail {t.Index}: {e.GetType().Name} {e.Message}"); }
40 if ((ok + fail) % 5000 == 0) Console.WriteLine($" {ok + fail}/{info.Textures.Count}");
41 }
42 rows.Add(new { t.Index, t.Name, t.Id, AssetKey = t.AssetKey.ToString("X16"), t.Width, t.Height, t.DxgiFormat, t.Mips, t.SourceMips, t.BaseMipLevel, Limitation = limitation, File = file });
30 } 43 }
31 Util.WriteAllText(Path.Combine(outDir, "manifest.json"), JsonSerializer.Serialize(new { src, info.Version, Count = info.Textures.Count, info.Metadata, Textures = rows }, json)); 44 // The manifest is the build's completion marker. Keep successful DDS for retry, but withdraw a stale marker.
45 string manifest = Path.Combine(outDir, "manifest.json");
46 if (fail == 0)
47 Util.WriteAllText(manifest, JsonSerializer.Serialize(new { src, info.Version, Count = info.Textures.Count, info.Metadata, Textures = rows }, json));
48 else
49 File.Delete(manifest);
32} 50}
33else if (mode == "audio") 51else if (mode == "audio")
34{ 52{
@@ -199,4 +217,4 @@ else if (mode is "models" or "textures")
199 File.Move(partial, manifestPath, true); 217 File.Move(partial, manifestPath, true);
200} 218}
201Console.WriteLine($"{mode} {baseName}: ok={ok} fail={fail} skip={skip} in {sw.Elapsed.TotalSeconds:0}s"); 219Console.WriteLine($"{mode} {baseName}: ok={ok} fail={fail} skip={skip} in {sw.Elapsed.TotalSeconds:0}s");
202return 0; 220return mode == "ttpf" && fail != 0 ? 1 : 0;