Print filename for ISO info, remove trailing comma for JSON

This commit is contained in:
Deterous
2023-12-06 12:56:31 +13:00
parent a036481560
commit 8ccbc8430c
3 changed files with 40 additions and 18 deletions
+30 -14
View File
@@ -177,15 +177,21 @@ namespace IRDKit
} }
// Print info from all IRDs // Print info from all IRDs
bool noISO = !isoFiles.Any();
string lastIRD = irdFiles.Last();
foreach (string file in irdFiles) 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 // Print info from all ISOs
string lastISO = isoFiles.Last();
foreach (string file in isoFiles) foreach (string file in isoFiles)
{ {
try try
{ {
PrintISO(file, opt.Json, opt.OutPath); PrintISO(file, opt.Json, file.Equals(lastISO), opt.OutPath);
} }
catch (InvalidFileSystemException) catch (InvalidFileSystemException)
{ {
@@ -235,7 +241,7 @@ namespace IRDKit
{ {
try try
{ {
PrintISO(inPath, json, outPath); PrintISO(inPath, json, single, outPath);
return; return;
} }
catch (InvalidFileSystemException) catch (InvalidFileSystemException)
@@ -251,13 +257,13 @@ namespace IRDKit
{ {
IRD ird = IRD.Read(inPath); IRD ird = IRD.Read(inPath);
if (outPath != null) if (outPath != null)
File.AppendAllText(outPath, $"\"{inPath}\": "); File.AppendAllText(outPath, $"\"{Path.GetFileName(inPath)}\": ");
else else
Console.Write($"\"{inPath}\": "); Console.Write($"\"{Path.GetFileName(inPath)}\": ");
ird.PrintJson(outPath, single); ird.PrintJson(outPath, single);
} }
else else
IRD.Read(inPath).Print(outPath, inPath); IRD.Read(inPath).Print(outPath, Path.GetFileName(inPath));
if (json) if (json)
return; return;
@@ -283,7 +289,7 @@ namespace IRDKit
/// <param name="outPath">File to output info to</param> /// <param name="outPath">File to output info to</param>
/// <exception cref="FileNotFoundException"></exception> /// <exception cref="FileNotFoundException"></exception>
/// <exception cref="InvalidFileSystemException"></exception> /// <exception cref="InvalidFileSystemException"></exception>
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 // Open ISO file for reading
using FileStream fs = new FileStream(isoPath, FileMode.Open, FileAccess.Read) ?? throw new FileNotFoundException(isoPath); using FileStream fs = new FileStream(isoPath, FileMode.Open, FileAccess.Read) ?? throw new FileNotFoundException(isoPath);
@@ -304,9 +310,9 @@ namespace IRDKit
if (json) if (json)
{ {
if (outPath != null) if (outPath != null)
File.AppendAllText(outPath, $"\"{isoPath}\": {{\n"); File.AppendAllText(outPath, $"\"{Path.GetFileName(isoPath)}\": {{\n");
else else
Console.WriteLine($"\"{isoPath}\": {{"); Console.WriteLine($"\"{Path.GetFileName(isoPath)}\": {{");
} }
// Print PS3_DISC.SFB info // Print PS3_DISC.SFB info
@@ -321,7 +327,7 @@ namespace IRDKit
Console.WriteLine(','); Console.WriteLine(',');
} }
else else
ps3_DiscSFB.Print(outPath); ps3_DiscSFB.Print(outPath, Path.GetFileName(isoPath));
} }
catch (FileNotFoundException) catch (FileNotFoundException)
{ {
@@ -344,7 +350,7 @@ namespace IRDKit
paramSFO.PrintJson(outPath); paramSFO.PrintJson(outPath);
} }
else else
paramSFO.Print(outPath); paramSFO.Print(outPath, Path.GetFileName(isoPath));
} }
catch (FileNotFoundException) catch (FileNotFoundException)
{ {
@@ -355,10 +361,20 @@ namespace IRDKit
// End JSON object // End JSON object
if (json) if (json)
{ {
if (outPath != null) if (single)
File.AppendAllText(outPath, "\n},\n"); {
if (outPath != null)
File.AppendAllText(outPath, "\n}\n");
else
Console.WriteLine("\n}");
}
else else
Console.WriteLine("\n},"); {
if (outPath != null)
File.AppendAllText(outPath, "\n},\n");
else
Console.WriteLine("\n},");
}
} }
} }
+5 -2
View File
@@ -103,11 +103,14 @@ namespace LibIRD
/// Prints formatted parameters extracted from PS3_DISC.SFB to console /// Prints formatted parameters extracted from PS3_DISC.SFB to console
/// </summary> /// </summary>
/// <param name="printPath">Optionally print to text file</param> /// <param name="printPath">Optionally print to text file</param>
public void Print(string printPath = null) public void Print(string printPath = null, string isoName = null)
{ {
// Build string from parameters // Build string from parameters
StringBuilder printText = new(); 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("======================"); printText.AppendLine("======================");
// Loop through all parameters in PARAM.SFO // Loop through all parameters in PARAM.SFO
+5 -2
View File
@@ -127,11 +127,14 @@ namespace LibIRD
/// Prints formatted parameters extracted from PARAM.SFO to console /// Prints formatted parameters extracted from PARAM.SFO to console
/// </summary> /// </summary>
/// <param name="printPath">Optionally print to text file</param> /// <param name="printPath">Optionally print to text file</param>
public void Print(string printPath = null) public void Print(string printPath = null, string isoName = null)
{ {
// Build string from parameters // Build string from parameters
StringBuilder printText = new(); 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("==================="); printText.AppendLine("===================");
// Loop through all parameters in PARAM.SFO // Loop through all parameters in PARAM.SFO