diff --git a/SabreTools.DatFiles/DatFile.cs b/SabreTools.DatFiles/DatFile.cs
index 63eeedbc..7a2ffdc1 100644
--- a/SabreTools.DatFiles/DatFile.cs
+++ b/SabreTools.DatFiles/DatFile.cs
@@ -152,16 +152,17 @@ namespace SabreTools.DatFiles
/// Name of the file to be parsed
/// Index ID for the DAT
/// True if full pathnames are to be kept, false otherwise (default)
+ /// True to only add item statistics while parsing, false otherwise
/// True if the error that is thrown should be thrown back to the caller, false otherwise
- public abstract void ParseFile(string filename, int indexId, bool keep, bool throwOnError = false);
+ public abstract void ParseFile(string filename, int indexId, bool keep, bool statsOnly = false, bool throwOnError = false);
///
/// Add a rom to the Dat after checking
///
/// Item data to check against
- /// Only add item statistics, full item otherwise
+ /// True to only add item statistics while parsing, false otherwise
/// The key for the item
- protected string ParseAddHelper(DatItem item, bool statsOnly = false)
+ protected string ParseAddHelper(DatItem item, bool statsOnly)
{
string key;
diff --git a/SabreTools.DatFiles/Formats/AttractMode.cs b/SabreTools.DatFiles/Formats/AttractMode.cs
index d66ba175..5142b2b9 100644
--- a/SabreTools.DatFiles/Formats/AttractMode.cs
+++ b/SabreTools.DatFiles/Formats/AttractMode.cs
@@ -26,7 +26,7 @@ namespace SabreTools.DatFiles.Formats
}
///
- public override void ParseFile(string filename, int indexId, bool keep, bool throwOnError = false)
+ public override void ParseFile(string filename, int indexId, bool keep, bool statsOnly = false, bool throwOnError = false)
{
// Open a file reader
Encoding enc = filename.GetEncoding();
@@ -94,7 +94,7 @@ namespace SabreTools.DatFiles.Formats
};
// Now process and add the rom
- ParseAddHelper(rom);
+ ParseAddHelper(rom, statsOnly);
}
catch (Exception ex)
{
diff --git a/SabreTools.DatFiles/Formats/ClrMamePro.cs b/SabreTools.DatFiles/Formats/ClrMamePro.cs
index 98d868dd..22dc9cd4 100644
--- a/SabreTools.DatFiles/Formats/ClrMamePro.cs
+++ b/SabreTools.DatFiles/Formats/ClrMamePro.cs
@@ -38,7 +38,7 @@ namespace SabreTools.DatFiles.Formats
}
///
- public override void ParseFile(string filename, int indexId, bool keep, bool throwOnError = false)
+ public override void ParseFile(string filename, int indexId, bool keep, bool statsOnly = false, bool throwOnError = false)
{
// Open a file reader
Encoding enc = filename.GetEncoding();
@@ -71,10 +71,10 @@ namespace SabreTools.DatFiles.Formats
case "set": // Used by the most ancient DATs
case "game": // Used by most CMP DATs
case "machine": // Possibly used by MAME CMP DATs
- ReadSet(cmpr, false, filename, indexId);
+ ReadSet(cmpr, false, statsOnly, filename, indexId);
break;
case "resource": // Used by some other DATs to denote a BIOS set
- ReadSet(cmpr, true, filename, indexId);
+ ReadSet(cmpr, true, statsOnly, filename, indexId);
break;
default:
@@ -201,11 +201,13 @@ namespace SabreTools.DatFiles.Formats
///
/// ClrMameProReader to use to parse the header
/// True if the item is a resource (bios), false otherwise
+ /// True to only add item statistics while parsing, false otherwise
/// Name of the file to be parsed
/// Index ID for the DAT
private void ReadSet(
ClrMameProReader cmpr,
bool resource,
+ bool statsOnly,
// Standard Dat parsing
string filename,
@@ -398,7 +400,7 @@ namespace SabreTools.DatFiles.Formats
}
// Now process and add the rom
- ParseAddHelper(item);
+ ParseAddHelper(item, statsOnly);
}
}
@@ -417,7 +419,7 @@ namespace SabreTools.DatFiles.Formats
blank.CopyMachineInformation(machine);
// Now process and add the rom
- ParseAddHelper(blank);
+ ParseAddHelper(blank, statsOnly);
}
}
diff --git a/SabreTools.DatFiles/Formats/DosCenter.cs b/SabreTools.DatFiles/Formats/DosCenter.cs
index 2036c5f2..c77ac021 100644
--- a/SabreTools.DatFiles/Formats/DosCenter.cs
+++ b/SabreTools.DatFiles/Formats/DosCenter.cs
@@ -28,7 +28,7 @@ namespace SabreTools.DatFiles.Formats
}
///
- public override void ParseFile(string filename, int indexId, bool keep, bool throwOnError = false)
+ public override void ParseFile(string filename, int indexId, bool keep, bool statsOnly = false, bool throwOnError = false)
{
// Open a file reader
Encoding enc = filename.GetEncoding();
@@ -57,7 +57,7 @@ namespace SabreTools.DatFiles.Formats
// Sets
case "game":
- ReadGame(cmpr, filename, indexId);
+ ReadGame(cmpr, statsOnly, filename, indexId);
break;
default:
@@ -141,9 +141,10 @@ namespace SabreTools.DatFiles.Formats
/// Read set information
///
/// ClrMameProReader to use to parse the header
+ /// True to only add item statistics while parsing, false otherwise
/// Name of the file to be parsed
/// Index ID for the DAT
- private void ReadGame(ClrMameProReader cmpr, string filename, int indexId)
+ private void ReadGame(ClrMameProReader cmpr, bool statsOnly, string filename, int indexId)
{
// Prepare all internal variables
bool containsItems = false;
@@ -233,7 +234,7 @@ namespace SabreTools.DatFiles.Formats
}
// Now process and add the rom
- ParseAddHelper(item);
+ ParseAddHelper(item, statsOnly);
}
}
@@ -252,7 +253,7 @@ namespace SabreTools.DatFiles.Formats
blank.CopyMachineInformation(machine);
// Now process and add the rom
- ParseAddHelper(blank);
+ ParseAddHelper(blank, statsOnly);
}
}
diff --git a/SabreTools.DatFiles/Formats/EverdriveSmdb.cs b/SabreTools.DatFiles/Formats/EverdriveSmdb.cs
index 865bdb14..87820a1a 100644
--- a/SabreTools.DatFiles/Formats/EverdriveSmdb.cs
+++ b/SabreTools.DatFiles/Formats/EverdriveSmdb.cs
@@ -26,7 +26,7 @@ namespace SabreTools.DatFiles.Formats
}
///
- public override void ParseFile(string filename, int indexId, bool keep, bool throwOnError = false)
+ public override void ParseFile(string filename, int indexId, bool keep, bool statsOnly = false, bool throwOnError = false)
{
// Open a file reader
Encoding enc = filename.GetEncoding();
@@ -85,7 +85,7 @@ namespace SabreTools.DatFiles.Formats
};
// Now process and add the rom
- ParseAddHelper(rom);
+ ParseAddHelper(rom, statsOnly);
}
catch (Exception ex)
{
diff --git a/SabreTools.DatFiles/Formats/Hashfile.cs b/SabreTools.DatFiles/Formats/Hashfile.cs
index e665f121..8cf6bb22 100644
--- a/SabreTools.DatFiles/Formats/Hashfile.cs
+++ b/SabreTools.DatFiles/Formats/Hashfile.cs
@@ -30,7 +30,7 @@ namespace SabreTools.DatFiles.Formats
}
///
- public override void ParseFile(string filename, int indexId, bool keep, bool throwOnError = false)
+ public override void ParseFile(string filename, int indexId, bool keep, bool statsOnly = false, bool throwOnError = false)
{
// Open a file reader
Encoding enc = filename.GetEncoding();
@@ -86,7 +86,7 @@ namespace SabreTools.DatFiles.Formats
};
// Now process and add the rom
- ParseAddHelper(rom);
+ ParseAddHelper(rom, statsOnly);
}
catch (Exception ex)
{
diff --git a/SabreTools.DatFiles/Formats/Listrom.cs b/SabreTools.DatFiles/Formats/Listrom.cs
index 02b73253..c46d4ea1 100644
--- a/SabreTools.DatFiles/Formats/Listrom.cs
+++ b/SabreTools.DatFiles/Formats/Listrom.cs
@@ -35,7 +35,7 @@ namespace SabreTools.DatFiles.Formats
/// 6331.sound-u8 32 BAD CRC(1d298cb0) SHA1(bb0bb62365402543e3154b9a77be9c75010e6abc) BAD_DUMP
/// 16v8h-blue.u24 279 NO GOOD DUMP KNOWN
///
- public override void ParseFile(string filename, int indexId, bool keep, bool throwOnError = false)
+ public override void ParseFile(string filename, int indexId, bool keep, bool statsOnly = false, bool throwOnError = false)
{
// Open a file reader
Encoding enc = filename.GetEncoding();
@@ -112,7 +112,7 @@ namespace SabreTools.DatFiles.Formats
},
};
- ParseAddHelper(disk);
+ ParseAddHelper(disk, statsOnly);
}
// Baddump Disks have 4 pieces (name, BAD, sha1, BAD_DUMP)
@@ -136,7 +136,7 @@ namespace SabreTools.DatFiles.Formats
},
};
- ParseAddHelper(disk);
+ ParseAddHelper(disk, statsOnly);
}
// Standard ROMs have 4 pieces (name, size, crc, sha1)
@@ -161,7 +161,7 @@ namespace SabreTools.DatFiles.Formats
},
};
- ParseAddHelper(rom);
+ ParseAddHelper(rom, statsOnly);
}
// Nodump Disks have 5 pieces (name, NO, GOOD, DUMP, KNOWN)
@@ -184,7 +184,7 @@ namespace SabreTools.DatFiles.Formats
},
};
- ParseAddHelper(disk);
+ ParseAddHelper(disk, statsOnly);
}
// Baddump ROMs have 6 pieces (name, size, BAD, crc, sha1, BAD_DUMP)
@@ -210,7 +210,7 @@ namespace SabreTools.DatFiles.Formats
},
};
- ParseAddHelper(rom);
+ ParseAddHelper(rom, statsOnly);
}
// Nodump ROMs have 6 pieces (name, size, NO, GOOD, DUMP, KNOWN)
@@ -234,7 +234,7 @@ namespace SabreTools.DatFiles.Formats
},
};
- ParseAddHelper(rom);
+ ParseAddHelper(rom, statsOnly);
}
// If we have something else, it's invalid
diff --git a/SabreTools.DatFiles/Formats/Listxml.cs b/SabreTools.DatFiles/Formats/Listxml.cs
index e860ef96..c068d220 100644
--- a/SabreTools.DatFiles/Formats/Listxml.cs
+++ b/SabreTools.DatFiles/Formats/Listxml.cs
@@ -191,7 +191,7 @@ namespace SabreTools.DatFiles.Formats
}
///
- public override void ParseFile(string filename, int indexId, bool keep, bool throwOnError = false)
+ public override void ParseFile(string filename, int indexId, bool keep, bool statsOnly = false, bool throwOnError = false)
{
// Prepare all internal variables
XmlReader xtr = XmlReader.Create(filename, new XmlReaderSettings
@@ -242,7 +242,7 @@ namespace SabreTools.DatFiles.Formats
// We want to process the entire subtree of the machine
case "game": // Some older DATs still use "game"
case "machine":
- ReadMachine(xtr.ReadSubtree(), filename, indexId);
+ ReadMachine(xtr.ReadSubtree(), statsOnly, filename, indexId);
// Skip the machine now that we've processed it
xtr.Skip();
@@ -274,9 +274,10 @@ namespace SabreTools.DatFiles.Formats
/// Read machine information
///
/// XmlReader representing a machine block
+ /// True to only add item statistics while parsing, false otherwise
/// Name of the file to be parsed
/// Index ID for the DAT
- private void ReadMachine(XmlReader reader, string filename, int indexId)
+ private void ReadMachine(XmlReader reader, bool statsOnly, string filename, int indexId)
{
// If we have an empty machine, skip it
if (reader == null)
@@ -761,7 +762,7 @@ namespace SabreTools.DatFiles.Formats
foreach (DatItem datItem in datItems)
{
datItem.CopyMachineInformation(machine);
- ParseAddHelper(datItem);
+ ParseAddHelper(datItem, statsOnly);
}
}
@@ -780,7 +781,7 @@ namespace SabreTools.DatFiles.Formats
blank.CopyMachineInformation(machine);
// Now process and add the rom
- ParseAddHelper(blank);
+ ParseAddHelper(blank, statsOnly);
}
}
diff --git a/SabreTools.DatFiles/Formats/Logiqx.cs b/SabreTools.DatFiles/Formats/Logiqx.cs
index ca9a1b29..aaeb2a17 100644
--- a/SabreTools.DatFiles/Formats/Logiqx.cs
+++ b/SabreTools.DatFiles/Formats/Logiqx.cs
@@ -133,7 +133,7 @@ namespace SabreTools.DatFiles.Formats
}
///
- public override void ParseFile(string filename, int indexId, bool keep, bool throwOnError = false)
+ public override void ParseFile(string filename, int indexId, bool keep, bool statsOnly = false, bool throwOnError = false)
{
// Prepare all internal variables
XmlReader xtr = XmlReader.Create(filename, new XmlReaderSettings
@@ -196,7 +196,7 @@ namespace SabreTools.DatFiles.Formats
// We want to process the entire subtree of the game
case "machine": // New-style Logiqx
case "game": // Old-style Logiqx
- ReadMachine(xtr.ReadSubtree(), dirs, filename, indexId, keep);
+ ReadMachine(xtr.ReadSubtree(), dirs, statsOnly, filename, indexId, keep);
// Skip the machine now that we've processed it
xtr.Skip();
@@ -371,12 +371,14 @@ namespace SabreTools.DatFiles.Formats
///
/// XmlReader to use to parse the machine
/// List of dirs to prepend to the game name
+ /// True to only add item statistics while parsing, false otherwise
/// Name of the file to be parsed
/// Index ID for the DAT
/// True if full pathnames are to be kept, false otherwise (default)
private void ReadMachine(
XmlReader reader,
List dirs,
+ bool statsOnly,
// Standard Dat parsing
string filename,
@@ -489,7 +491,7 @@ namespace SabreTools.DatFiles.Formats
archive.CopyMachineInformation(machine);
// Now process and add the archive
- ParseAddHelper(archive);
+ ParseAddHelper(archive, statsOnly);
reader.Read();
break;
@@ -513,7 +515,7 @@ namespace SabreTools.DatFiles.Formats
biosSet.CopyMachineInformation(machine);
// Now process and add the biosSet
- ParseAddHelper(biosSet);
+ ParseAddHelper(biosSet, statsOnly);
reader.Read();
break;
@@ -539,7 +541,7 @@ namespace SabreTools.DatFiles.Formats
disk.CopyMachineInformation(machine);
// Now process and add the disk
- ParseAddHelper(disk);
+ ParseAddHelper(disk, statsOnly);
reader.Read();
break;
@@ -565,7 +567,7 @@ namespace SabreTools.DatFiles.Formats
media.CopyMachineInformation(machine);
// Now process and add the media
- ParseAddHelper(media);
+ ParseAddHelper(media, statsOnly);
reader.Read();
break;
@@ -585,7 +587,7 @@ namespace SabreTools.DatFiles.Formats
release.CopyMachineInformation(machine);
// Now process and add the release
- ParseAddHelper(release);
+ ParseAddHelper(release, statsOnly);
reader.Read();
break;
@@ -619,7 +621,7 @@ namespace SabreTools.DatFiles.Formats
rom.CopyMachineInformation(machine);
// Now process and add the rom
- ParseAddHelper(rom);
+ ParseAddHelper(rom, statsOnly);
reader.Read();
break;
@@ -641,7 +643,7 @@ namespace SabreTools.DatFiles.Formats
sample.CopyMachineInformation(machine);
// Now process and add the sample
- ParseAddHelper(sample);
+ ParseAddHelper(sample, statsOnly);
reader.Read();
break;
@@ -667,7 +669,7 @@ namespace SabreTools.DatFiles.Formats
blank.CopyMachineInformation(machine);
// Now process and add the rom
- ParseAddHelper(blank);
+ ParseAddHelper(blank, statsOnly);
}
}
diff --git a/SabreTools.DatFiles/Formats/Missfile.cs b/SabreTools.DatFiles/Formats/Missfile.cs
index 75a0265a..c1614627 100644
--- a/SabreTools.DatFiles/Formats/Missfile.cs
+++ b/SabreTools.DatFiles/Formats/Missfile.cs
@@ -22,7 +22,7 @@ namespace SabreTools.DatFiles.Formats
}
///
- public override void ParseFile(string filename, int indexId, bool keep, bool throwOnError = false)
+ public override void ParseFile(string filename, int indexId, bool keep, bool statsOnly = false, bool throwOnError = false)
{
// There is no consistent way to parse a missfile...
throw new NotImplementedException();
diff --git a/SabreTools.DatFiles/Formats/OfflineList.cs b/SabreTools.DatFiles/Formats/OfflineList.cs
index 978acb73..66c393c8 100644
--- a/SabreTools.DatFiles/Formats/OfflineList.cs
+++ b/SabreTools.DatFiles/Formats/OfflineList.cs
@@ -27,7 +27,7 @@ namespace SabreTools.DatFiles.Formats
}
///
- public override void ParseFile(string filename, int indexId, bool keep, bool throwOnError = false)
+ public override void ParseFile(string filename, int indexId, bool keep, bool statsOnly = false, bool throwOnError = false)
{
XmlReader xtr = XmlReader.Create(filename, new XmlReaderSettings
{
@@ -66,7 +66,7 @@ namespace SabreTools.DatFiles.Formats
break;
case "games":
- ReadGames(xtr.ReadSubtree(), filename, indexId);
+ ReadGames(xtr.ReadSubtree(), statsOnly, filename, indexId);
// Skip the games node now that we've processed it
xtr.Skip();
@@ -424,9 +424,10 @@ namespace SabreTools.DatFiles.Formats
/// Read games information
///
/// XmlReader to use to parse the header
+ /// True to only add item statistics while parsing, false otherwise
/// Name of the file to be parsed
/// Index ID for the DAT
- private void ReadGames(XmlReader reader, string filename, int indexId)
+ private void ReadGames(XmlReader reader, bool statsOnly, string filename, int indexId)
{
// If there's no subtree to the configuration, skip it
if (reader == null)
@@ -449,7 +450,7 @@ namespace SabreTools.DatFiles.Formats
switch (reader.Name.ToLowerInvariant())
{
case "game":
- ReadGame(reader.ReadSubtree(), filename, indexId);
+ ReadGame(reader.ReadSubtree(), statsOnly, filename, indexId);
// Skip the game node now that we've processed it
reader.Skip();
@@ -466,9 +467,10 @@ namespace SabreTools.DatFiles.Formats
/// Read game information
///
/// XmlReader to use to parse the header
+ /// True to only add item statistics while parsing, false otherwise
/// Name of the file to be parsed
/// Index ID for the DAT
- private void ReadGame(XmlReader reader, string filename, int indexId)
+ private void ReadGame(XmlReader reader, bool statsOnly, string filename, int indexId)
{
// Prepare all internal variables
string releaseNumber = string.Empty, duplicateid;
@@ -579,7 +581,7 @@ namespace SabreTools.DatFiles.Formats
datItems[i].CopyMachineInformation(machine);
// Now process and add the rom
- ParseAddHelper(datItems[i]);
+ ParseAddHelper(datItems[i], statsOnly);
}
}
diff --git a/SabreTools.DatFiles/Formats/OpenMSX.cs b/SabreTools.DatFiles/Formats/OpenMSX.cs
index 5e334109..71f0b49d 100644
--- a/SabreTools.DatFiles/Formats/OpenMSX.cs
+++ b/SabreTools.DatFiles/Formats/OpenMSX.cs
@@ -41,7 +41,7 @@ namespace SabreTools.DatFiles.Formats
}
///
- public override void ParseFile(string filename, int indexId, bool keep, bool throwOnError = false)
+ public override void ParseFile(string filename, int indexId, bool keep, bool statsOnly = false, bool throwOnError = false)
{
// Prepare all internal variables
XmlReader xtr = XmlReader.Create(filename, new XmlReaderSettings
@@ -82,7 +82,7 @@ namespace SabreTools.DatFiles.Formats
// We want to process the entire subtree of the software
case "software":
- ReadSoftware(xtr.ReadSubtree(), filename, indexId);
+ ReadSoftware(xtr.ReadSubtree(), statsOnly, filename, indexId);
// Skip the software now that we've processed it
xtr.Skip();
@@ -114,9 +114,10 @@ namespace SabreTools.DatFiles.Formats
/// Read software information
///
/// XmlReader representing a machine block
+ /// True to only add item statistics while parsing, false otherwise
/// Name of the file to be parsed
/// Index ID for the DAT
- private void ReadSoftware(XmlReader reader, string filename, int indexId)
+ private void ReadSoftware(XmlReader reader, bool statsOnly, string filename, int indexId)
{
// If we have an empty machine, skip it
if (reader == null)
@@ -168,7 +169,7 @@ namespace SabreTools.DatFiles.Formats
break;
case "dump":
- containsItems = ReadDump(reader.ReadSubtree(), machine, diskno, filename, indexId);
+ containsItems = ReadDump(reader.ReadSubtree(), machine, diskno, statsOnly, filename, indexId);
diskno++;
// Skip the dump now that we've processed it
@@ -196,7 +197,7 @@ namespace SabreTools.DatFiles.Formats
blank.CopyMachineInformation(machine);
// Now process and add the rom
- ParseAddHelper(blank);
+ ParseAddHelper(blank, statsOnly);
}
}
@@ -206,12 +207,14 @@ namespace SabreTools.DatFiles.Formats
/// XmlReader representing a part block
/// Machine information to pass to contained items
/// Disk number to use when outputting to other DAT formats
+ /// True to only add item statistics while parsing, false otherwise
/// Name of the file to be parsed
/// Index ID for the DAT
private bool ReadDump(
XmlReader reader,
Machine machine,
int diskno,
+ bool statsOnly,
// Standard Dat parsing
string filename,
@@ -284,7 +287,7 @@ namespace SabreTools.DatFiles.Formats
}
item.CopyMachineInformation(machine);
- ParseAddHelper(item);
+ ParseAddHelper(item, statsOnly);
}
return items.Count > 0;
diff --git a/SabreTools.DatFiles/Formats/RomCenter.cs b/SabreTools.DatFiles/Formats/RomCenter.cs
index 97abfafa..ebf71438 100644
--- a/SabreTools.DatFiles/Formats/RomCenter.cs
+++ b/SabreTools.DatFiles/Formats/RomCenter.cs
@@ -26,7 +26,7 @@ namespace SabreTools.DatFiles.Formats
}
///
- public override void ParseFile(string filename, int indexId, bool keep, bool throwOnError = false)
+ public override void ParseFile(string filename, int indexId, bool keep, bool statsOnly = false, bool throwOnError = false)
{
// Prepare all intenral variables
IniReader ir = new IniReader(filename) { ValidateRows = false };
@@ -66,7 +66,7 @@ namespace SabreTools.DatFiles.Formats
break;
case "games":
- ReadGamesSection(ir, filename, indexId);
+ ReadGamesSection(ir, statsOnly, filename, indexId);
break;
// Unknown section so we ignore it
@@ -284,9 +284,10 @@ namespace SabreTools.DatFiles.Formats
/// Read games information
///
/// IniReader to use to parse the credits
+ /// True to only add item statistics while parsing, false otherwise
/// Name of the file to be parsed
/// Index ID for the DAT
- private void ReadGamesSection(IniReader reader, string filename, int indexId)
+ private void ReadGamesSection(IniReader reader, bool statsOnly, string filename, int indexId)
{
// If the reader is somehow null, skip it
if (reader == null)
@@ -355,7 +356,7 @@ namespace SabreTools.DatFiles.Formats
};
// Now process and add the rom
- ParseAddHelper(rom);
+ ParseAddHelper(rom, statsOnly);
reader.ReadNextLine();
} while (!reader.EndOfStream && reader.Section.ToLowerInvariant() == "games");
diff --git a/SabreTools.DatFiles/Formats/SabreJSON.cs b/SabreTools.DatFiles/Formats/SabreJSON.cs
index 5e4705c3..d3e99463 100644
--- a/SabreTools.DatFiles/Formats/SabreJSON.cs
+++ b/SabreTools.DatFiles/Formats/SabreJSON.cs
@@ -28,7 +28,7 @@ namespace SabreTools.DatFiles.Formats
}
///
- public override void ParseFile(string filename, int indexId, bool keep, bool throwOnError = false)
+ public override void ParseFile(string filename, int indexId, bool keep, bool statsOnly = false, bool throwOnError = false)
{
// Prepare all internal variables
StreamReader sr = new StreamReader(File.OpenRead(filename), new UTF8Encoding(false));
@@ -61,7 +61,7 @@ namespace SabreTools.DatFiles.Formats
// Machine array
case "machines":
- ReadMachines(jtr, filename, indexId);
+ ReadMachines(jtr, statsOnly, filename, indexId);
jtr.Read();
break;
@@ -101,9 +101,10 @@ namespace SabreTools.DatFiles.Formats
/// Read machine array information
///
/// JsonTextReader to use to parse the machine
+ /// True to only add item statistics while parsing, false otherwise
/// Name of the file to be parsed
/// Index ID for the DAT
- private void ReadMachines(JsonTextReader jtr, string filename, int indexId)
+ private void ReadMachines(JsonTextReader jtr, bool statsOnly, string filename, int indexId)
{
// If the reader is invalid, skip
if (jtr == null)
@@ -117,7 +118,7 @@ namespace SabreTools.DatFiles.Formats
// Loop through each machine object and process
foreach (JObject machineObj in machineArray)
{
- ReadMachine(machineObj, filename, indexId);
+ ReadMachine(machineObj, statsOnly, filename, indexId);
}
}
@@ -125,9 +126,10 @@ namespace SabreTools.DatFiles.Formats
/// Read machine object information
///
/// JObject representing a single machine
+ /// True to only add item statistics while parsing, false otherwise
/// Name of the file to be parsed
/// Index ID for the DAT
- private void ReadMachine(JObject machineObj, string filename, int indexId)
+ private void ReadMachine(JObject machineObj, bool statsOnly, string filename, int indexId)
{
// If object is invalid, skip it
if (machineObj == null)
@@ -142,18 +144,20 @@ namespace SabreTools.DatFiles.Formats
// Read items, if possible
if (machineObj.ContainsKey("items"))
- ReadItems(machineObj["items"] as JArray, filename, indexId, machine);
+ ReadItems(machineObj["items"] as JArray, statsOnly, filename, indexId, machine);
}
///
/// Read item array information
///
/// JArray representing the items list
+ /// True to only add item statistics while parsing, false otherwise
/// Name of the file to be parsed
/// Index ID for the DAT
/// Machine information to add to the parsed items
private void ReadItems(
JArray itemsArr,
+ bool statsOnly,
// Standard Dat parsing
string filename,
@@ -169,7 +173,7 @@ namespace SabreTools.DatFiles.Formats
// Loop through each datitem object and process
foreach (JObject itemObj in itemsArr)
{
- ReadItem(itemObj, filename, indexId, machine);
+ ReadItem(itemObj, statsOnly, filename, indexId, machine);
}
}
@@ -177,11 +181,13 @@ namespace SabreTools.DatFiles.Formats
/// Read item information
///
/// JObject representing a single datitem
+ /// True to only add item statistics while parsing, false otherwise
/// Name of the file to be parsed
/// Index ID for the DAT
/// Machine information to add to the parsed items
private void ReadItem(
JObject itemObj,
+ bool statsOnly,
// Standard Dat parsing
string filename,
@@ -322,7 +328,7 @@ namespace SabreTools.DatFiles.Formats
{
datItem.CopyMachineInformation(machine);
datItem.Source = new Source { Index = indexId, Name = filename };
- ParseAddHelper(datItem);
+ ParseAddHelper(datItem, statsOnly);
}
}
diff --git a/SabreTools.DatFiles/Formats/SabreXML.cs b/SabreTools.DatFiles/Formats/SabreXML.cs
index 763b18a5..93e6d651 100644
--- a/SabreTools.DatFiles/Formats/SabreXML.cs
+++ b/SabreTools.DatFiles/Formats/SabreXML.cs
@@ -25,7 +25,7 @@ namespace SabreTools.DatFiles.Formats
}
///
- public override void ParseFile(string filename, int indexId, bool keep, bool throwOnError = false)
+ public override void ParseFile(string filename, int indexId, bool keep, bool statsOnly = false, bool throwOnError = false)
{
// Prepare all internal variables
XmlReader xtr = XmlReader.Create(filename, new XmlReaderSettings
@@ -65,7 +65,7 @@ namespace SabreTools.DatFiles.Formats
break;
case "directory":
- ReadDirectory(xtr.ReadSubtree(), filename, indexId);
+ ReadDirectory(xtr.ReadSubtree(), statsOnly, filename, indexId);
// Skip the directory node now that we've processed it
xtr.Read();
@@ -96,9 +96,10 @@ namespace SabreTools.DatFiles.Formats
/// Read directory information
///
/// XmlReader to use to parse the header
+ /// True to only add item statistics while parsing, false otherwise
/// Name of the file to be parsed
/// Index ID for the DAT
- private void ReadDirectory(XmlReader xtr, string filename, int indexId)
+ private void ReadDirectory(XmlReader xtr, bool statsOnly, string filename, int indexId)
{
// If the reader is invalid, skip
if (xtr == null)
@@ -127,7 +128,7 @@ namespace SabreTools.DatFiles.Formats
break;
case "files":
- ReadFiles(xtr.ReadSubtree(), machine, filename, indexId);
+ ReadFiles(xtr.ReadSubtree(), machine, statsOnly, filename, indexId);
// Skip the directory node now that we've processed it
xtr.Read();
@@ -144,9 +145,10 @@ namespace SabreTools.DatFiles.Formats
///
/// XmlReader to use to parse the header
/// Machine to copy information from
+ /// True to only add item statistics while parsing, false otherwise
/// Name of the file to be parsed
/// Index ID for the DAT
- private void ReadFiles(XmlReader xtr, Machine machine, string filename, int indexId)
+ private void ReadFiles(XmlReader xtr, Machine machine, bool statsOnly, string filename, int indexId)
{
// If the reader is invalid, skip
if (xtr == null)
@@ -170,7 +172,7 @@ namespace SabreTools.DatFiles.Formats
DatItem item = xs.Deserialize(xtr.ReadSubtree()) as DatItem;
item.CopyMachineInformation(machine);
item.Source = new Source { Name = filename, Index = indexId };
- ParseAddHelper(item);
+ ParseAddHelper(item, statsOnly);
xtr.Skip();
break;
default:
diff --git a/SabreTools.DatFiles/Formats/SeparatedValue.cs b/SabreTools.DatFiles/Formats/SeparatedValue.cs
index a89a1be6..70636b18 100644
--- a/SabreTools.DatFiles/Formats/SeparatedValue.cs
+++ b/SabreTools.DatFiles/Formats/SeparatedValue.cs
@@ -32,7 +32,7 @@ namespace SabreTools.DatFiles.Formats
}
///
- public override void ParseFile(string filename, int indexId, bool keep, bool throwOnError = false)
+ public override void ParseFile(string filename, int indexId, bool keep, bool statsOnly = false, bool throwOnError = false)
{
// Open a file reader
Encoding enc = filename.GetEncoding();
@@ -101,7 +101,7 @@ namespace SabreTools.DatFiles.Formats
DatItem datItem = DatItem.Create(datItemMappings[DatItemField.Type].AsItemType());
DatItemTool.SetFields(datItem, datItemMappings, machineMappings);
datItem.Source = new Source(indexId, filename);
- ParseAddHelper(datItem);
+ ParseAddHelper(datItem, statsOnly);
}
}
catch (Exception ex)
diff --git a/SabreTools.DatFiles/Formats/SoftwareList.cs b/SabreTools.DatFiles/Formats/SoftwareList.cs
index f31aa295..d66dc114 100644
--- a/SabreTools.DatFiles/Formats/SoftwareList.cs
+++ b/SabreTools.DatFiles/Formats/SoftwareList.cs
@@ -91,7 +91,7 @@ namespace SabreTools.DatFiles.Formats
}
///
- public override void ParseFile(string filename, int indexId, bool keep, bool throwOnError = false)
+ public override void ParseFile(string filename, int indexId, bool keep, bool statsOnly = false, bool throwOnError = false)
{
// Prepare all internal variables
XmlReader xtr = XmlReader.Create(filename, new XmlReaderSettings
@@ -132,7 +132,7 @@ namespace SabreTools.DatFiles.Formats
// We want to process the entire subtree of the machine
case "software":
- ReadSoftware(xtr.ReadSubtree(), filename, indexId);
+ ReadSoftware(xtr.ReadSubtree(), statsOnly, filename, indexId);
// Skip the software now that we've processed it
xtr.Skip();
@@ -164,9 +164,10 @@ namespace SabreTools.DatFiles.Formats
/// Read software information
///
/// XmlReader representing a software block
+ /// True to only add item statistics while parsing, false otherwise
/// Name of the file to be parsed
/// Index ID for the DAT
- private void ReadSoftware(XmlReader reader, string filename, int indexId)
+ private void ReadSoftware(XmlReader reader, bool statsOnly, string filename, int indexId)
{
// If we have an empty software, skip it
if (reader == null)
@@ -220,7 +221,7 @@ namespace SabreTools.DatFiles.Formats
Index = indexId,
Name = filename,
},
- });
+ }, statsOnly);
reader.Read();
break;
@@ -236,7 +237,7 @@ namespace SabreTools.DatFiles.Formats
Index = indexId,
Name = filename,
},
- });
+ }, statsOnly);
reader.Read();
break;
@@ -249,7 +250,7 @@ namespace SabreTools.DatFiles.Formats
};
// Now read the internal tags
- containsItems = ReadPart(reader.ReadSubtree(), machine, part, filename, indexId);
+ containsItems = ReadPart(reader.ReadSubtree(), machine, part, statsOnly, filename, indexId);
// Skip the part now that we've processed it
reader.Skip();
@@ -276,7 +277,7 @@ namespace SabreTools.DatFiles.Formats
blank.CopyMachineInformation(machine);
// Now process and add the rom
- ParseAddHelper(blank);
+ ParseAddHelper(blank, statsOnly);
}
}
@@ -286,9 +287,10 @@ namespace SabreTools.DatFiles.Formats
/// XmlReader representing a part block
/// Machine information to pass to contained items
/// Part information to pass to contained items
+ /// True to only add item statistics while parsing, false otherwise
/// Name of the file to be parsed
/// Index ID for the DAT
- private bool ReadPart(XmlReader reader, Machine machine, Part part, string filename, int indexId)
+ private bool ReadPart(XmlReader reader, Machine machine, Part part, bool statsOnly, string filename, int indexId)
{
// If we have an empty port, skip it
if (reader == null)
@@ -422,7 +424,7 @@ namespace SabreTools.DatFiles.Formats
item.CopyMachineInformation(machine);
// Finally add each item
- key = ParseAddHelper(item);
+ key = ParseAddHelper(item, statsOnly);
}
return items.Any();
diff --git a/SabreTools.DatTools/Parser.cs b/SabreTools.DatTools/Parser.cs
index 93f8948b..2dc52a3d 100644
--- a/SabreTools.DatTools/Parser.cs
+++ b/SabreTools.DatTools/Parser.cs
@@ -28,11 +28,12 @@ namespace SabreTools.DatTools
/// Create a DatFile and parse a file into it
///
/// Name of the file to be parsed
+ /// True to only add item statistics while parsing, false otherwise
/// True if the error that is thrown should be thrown back to the caller, false otherwise
- public static DatFile CreateAndParse(string filename, bool throwOnError = false)
+ public static DatFile CreateAndParse(string filename, bool statsOnly = false, bool throwOnError = false)
{
DatFile datFile = DatFile.Create();
- ParseInto(datFile, new ParentablePath(filename), throwOnError: throwOnError);
+ ParseInto(datFile, new ParentablePath(filename), statsOnly: statsOnly, throwOnError: throwOnError);
return datFile;
}
@@ -45,6 +46,7 @@ namespace SabreTools.DatTools
/// True if full pathnames are to be kept, false otherwise (default)
/// True if original extension should be kept, false otherwise (default)
/// True if quotes are assumed in supported types (default), false otherwise
+ /// True to only add item statistics while parsing, false otherwise
/// True if the error that is thrown should be thrown back to the caller, false otherwise
public static void ParseInto(
DatFile datFile,
@@ -53,10 +55,11 @@ namespace SabreTools.DatTools
bool keep = false,
bool keepext = false,
bool quotes = true,
+ bool statsOnly = false,
bool throwOnError = false)
{
ParentablePath path = new ParentablePath(filename.Trim('"'));
- ParseInto(datFile, path, indexId, keep, keepext, quotes, throwOnError);
+ ParseInto(datFile, path, indexId, keep, keepext, quotes, statsOnly, throwOnError);
}
///
@@ -68,6 +71,7 @@ namespace SabreTools.DatTools
/// True if full pathnames are to be kept, false otherwise (default)
/// True if original extension should be kept, false otherwise (default)
/// True if quotes are assumed in supported types (default), false otherwise
+ /// True to only add item statistics while parsing, false otherwise
/// True if the error that is thrown should be thrown back to the caller, false otherwise
public static void ParseInto(
DatFile datFile,
@@ -76,6 +80,7 @@ namespace SabreTools.DatTools
bool keep = false,
bool keepext = false,
bool quotes = true,
+ bool statsOnly = false,
bool throwOnError = true)
{
// Get the current path from the filename
@@ -100,7 +105,8 @@ namespace SabreTools.DatTools
// Now parse the correct type of DAT
try
{
- DatFile.Create(currentPathFormat, datFile, quotes)?.ParseFile(currentPath, indexId, keep, throwOnError);
+ var parsingDatFile = DatFile.Create(currentPathFormat, datFile, quotes);
+ parsingDatFile?.ParseFile(currentPath, indexId, keep, statsOnly: statsOnly, throwOnError: throwOnError);
}
catch (Exception ex)
{
diff --git a/SabreTools.DatTools/Statistics.cs b/SabreTools.DatTools/Statistics.cs
index f2e73f15..036dad93 100644
--- a/SabreTools.DatTools/Statistics.cs
+++ b/SabreTools.DatTools/Statistics.cs
@@ -129,9 +129,6 @@ namespace SabreTools.DatTools
totalStats.AddStatistics(datdata.Items);
totalStats.GameCount += datdata.Items.Keys.Count();
- // Clear out the item dictionary so it doesn't linger
- datdata.Items.Clear();
-
// Make sure to assign the new directory
lastdir = thisdir;
}