From 8ccbc8430c988f1cde7a9cd0ef31469fcbec726d Mon Sep 17 00:00:00 2001 From: Deterous <138427222+Deterous@users.noreply.github.com> Date: Wed, 6 Dec 2023 12:56:31 +1300 Subject: [PATCH] Print filename for ISO info, remove trailing comma for JSON --- IRDKit/Program.cs | 44 +++++++++++++++++++++++++++++-------------- LibIRD/PS3_DiscSFB.cs | 7 +++++-- LibIRD/ParamSFO.cs | 7 +++++-- 3 files changed, 40 insertions(+), 18 deletions(-) diff --git a/IRDKit/Program.cs b/IRDKit/Program.cs index 325e312..ce4830d 100644 --- a/IRDKit/Program.cs +++ b/IRDKit/Program.cs @@ -177,15 +177,21 @@ namespace IRDKit } // Print info from all IRDs + bool noISO = !isoFiles.Any(); + string lastIRD = irdFiles.Last(); foreach (string file in irdFiles) - PrintInfo(file, opt.Json, false, opt.OutPath); + { + PrintInfo(file, opt.Json, (noISO && file.Equals(lastIRD)), opt.OutPath); + } + // Print info from all ISOs + string lastISO = isoFiles.Last(); foreach (string file in isoFiles) { try { - PrintISO(file, opt.Json, opt.OutPath); + PrintISO(file, opt.Json, file.Equals(lastISO), opt.OutPath); } catch (InvalidFileSystemException) { @@ -235,7 +241,7 @@ namespace IRDKit { try { - PrintISO(inPath, json, outPath); + PrintISO(inPath, json, single, outPath); return; } catch (InvalidFileSystemException) @@ -251,13 +257,13 @@ namespace IRDKit { IRD ird = IRD.Read(inPath); if (outPath != null) - File.AppendAllText(outPath, $"\"{inPath}\": "); + File.AppendAllText(outPath, $"\"{Path.GetFileName(inPath)}\": "); else - Console.Write($"\"{inPath}\": "); + Console.Write($"\"{Path.GetFileName(inPath)}\": "); ird.PrintJson(outPath, single); } else - IRD.Read(inPath).Print(outPath, inPath); + IRD.Read(inPath).Print(outPath, Path.GetFileName(inPath)); if (json) return; @@ -283,7 +289,7 @@ namespace IRDKit /// File to output info to /// /// - public static void PrintISO(string isoPath, bool json, string outPath = null) + public static void PrintISO(string isoPath, bool json, bool single = true, string outPath = null) { // Open ISO file for reading using FileStream fs = new FileStream(isoPath, FileMode.Open, FileAccess.Read) ?? throw new FileNotFoundException(isoPath); @@ -304,9 +310,9 @@ namespace IRDKit if (json) { if (outPath != null) - File.AppendAllText(outPath, $"\"{isoPath}\": {{\n"); + File.AppendAllText(outPath, $"\"{Path.GetFileName(isoPath)}\": {{\n"); else - Console.WriteLine($"\"{isoPath}\": {{"); + Console.WriteLine($"\"{Path.GetFileName(isoPath)}\": {{"); } // Print PS3_DISC.SFB info @@ -321,7 +327,7 @@ namespace IRDKit Console.WriteLine(','); } else - ps3_DiscSFB.Print(outPath); + ps3_DiscSFB.Print(outPath, Path.GetFileName(isoPath)); } catch (FileNotFoundException) { @@ -344,7 +350,7 @@ namespace IRDKit paramSFO.PrintJson(outPath); } else - paramSFO.Print(outPath); + paramSFO.Print(outPath, Path.GetFileName(isoPath)); } catch (FileNotFoundException) { @@ -355,10 +361,20 @@ namespace IRDKit // End JSON object if (json) { - if (outPath != null) - File.AppendAllText(outPath, "\n},\n"); + if (single) + { + if (outPath != null) + File.AppendAllText(outPath, "\n}\n"); + else + Console.WriteLine("\n}"); + } else - Console.WriteLine("\n},"); + { + if (outPath != null) + File.AppendAllText(outPath, "\n},\n"); + else + Console.WriteLine("\n},"); + } } } diff --git a/LibIRD/PS3_DiscSFB.cs b/LibIRD/PS3_DiscSFB.cs index d86cf66..c3e059f 100644 --- a/LibIRD/PS3_DiscSFB.cs +++ b/LibIRD/PS3_DiscSFB.cs @@ -103,11 +103,14 @@ namespace LibIRD /// Prints formatted parameters extracted from PS3_DISC.SFB to console /// /// Optionally print to text file - public void Print(string printPath = null) + public void Print(string printPath = null, string isoName = null) { // Build string from parameters StringBuilder printText = new(); - printText.AppendLine("PS3_DISC.SFB Contents:"); + if (isoName != null) + printText.AppendLine($"PS3_DISC.SFB Contents: {isoName}"); + else + printText.AppendLine("PS3_DISC.SFB Contents:"); printText.AppendLine("======================"); // Loop through all parameters in PARAM.SFO diff --git a/LibIRD/ParamSFO.cs b/LibIRD/ParamSFO.cs index 28fbc13..b216dd7 100644 --- a/LibIRD/ParamSFO.cs +++ b/LibIRD/ParamSFO.cs @@ -127,11 +127,14 @@ namespace LibIRD /// Prints formatted parameters extracted from PARAM.SFO to console /// /// Optionally print to text file - public void Print(string printPath = null) + public void Print(string printPath = null, string isoName = null) { // Build string from parameters StringBuilder printText = new(); - printText.AppendLine("PARAM.SFO Contents:"); + if (isoName != null) + printText.AppendLine($"PARAM.SFO Contents: {isoName}"); + else + printText.AppendLine("PARAM.SFO Contents:"); printText.AppendLine("==================="); // Loop through all parameters in PARAM.SFO