Wire through "stats only" parsing, version 1 (nw)

This commit is contained in:
Matt Nadareski
2020-12-23 13:55:09 -08:00
parent 5253ca05ab
commit 0f4a4ed585
19 changed files with 116 additions and 90 deletions

View File

@@ -152,16 +152,17 @@ namespace SabreTools.DatFiles
/// <param name="filename">Name of the file to be parsed</param>
/// <param name="indexId">Index ID for the DAT</param>
/// <param name="keep">True if full pathnames are to be kept, false otherwise (default)</param>
/// <param name="statsOnly">True to only add item statistics while parsing, false otherwise</param>
/// <param name="throwOnError">True if the error that is thrown should be thrown back to the caller, false otherwise</param>
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);
/// <summary>
/// Add a rom to the Dat after checking
/// </summary>
/// <param name="item">Item data to check against</param>
/// <param name="statsOnly">Only add item statistics, full item otherwise</param>
/// <param name="statsOnly">True to only add item statistics while parsing, false otherwise</param>
/// <returns>The key for the item</returns>
protected string ParseAddHelper(DatItem item, bool statsOnly = false)
protected string ParseAddHelper(DatItem item, bool statsOnly)
{
string key;

View File

@@ -26,7 +26,7 @@ namespace SabreTools.DatFiles.Formats
}
/// <inheritdoc/>
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)
{

View File

@@ -38,7 +38,7 @@ namespace SabreTools.DatFiles.Formats
}
/// <inheritdoc/>
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
/// </summary>
/// <param name="cmpr">ClrMameProReader to use to parse the header</param>
/// <param name="resource">True if the item is a resource (bios), false otherwise</param>
/// <param name="statsOnly">True to only add item statistics while parsing, false otherwise</param>
/// <param name="filename">Name of the file to be parsed</param>
/// <param name="indexId">Index ID for the DAT</param>
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);
}
}

View File

@@ -28,7 +28,7 @@ namespace SabreTools.DatFiles.Formats
}
/// <inheritdoc/>
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
/// </summary>
/// <param name="cmpr">ClrMameProReader to use to parse the header</param>
/// <param name="statsOnly">True to only add item statistics while parsing, false otherwise</param>
/// <param name="filename">Name of the file to be parsed</param>
/// <param name="indexId">Index ID for the DAT</param>
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);
}
}

View File

@@ -26,7 +26,7 @@ namespace SabreTools.DatFiles.Formats
}
/// <inheritdoc/>
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)
{

View File

@@ -30,7 +30,7 @@ namespace SabreTools.DatFiles.Formats
}
/// <inheritdoc/>
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)
{

View File

@@ -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
/// </remarks>
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

View File

@@ -191,7 +191,7 @@ namespace SabreTools.DatFiles.Formats
}
/// <inheritdoc/>
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
/// </summary>
/// <param name="reader">XmlReader representing a machine block</param>
/// <param name="statsOnly">True to only add item statistics while parsing, false otherwise</param>
/// <param name="filename">Name of the file to be parsed</param>
/// <param name="indexId">Index ID for the DAT</param>
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);
}
}

View File

@@ -133,7 +133,7 @@ namespace SabreTools.DatFiles.Formats
}
/// <inheritdoc/>
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
/// </summary>
/// <param name="reader">XmlReader to use to parse the machine</param>
/// <param name="dirs">List of dirs to prepend to the game name</param>
/// <param name="statsOnly">True to only add item statistics while parsing, false otherwise</param>
/// <param name="filename">Name of the file to be parsed</param>
/// <param name="indexId">Index ID for the DAT</param>
/// <param name="keep">True if full pathnames are to be kept, false otherwise (default)</param>
private void ReadMachine(
XmlReader reader,
List<string> 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);
}
}

View File

@@ -22,7 +22,7 @@ namespace SabreTools.DatFiles.Formats
}
/// <inheritdoc/>
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();

View File

@@ -27,7 +27,7 @@ namespace SabreTools.DatFiles.Formats
}
/// <inheritdoc/>
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
/// </summary>
/// <param name="reader">XmlReader to use to parse the header</param>
/// <param name="statsOnly">True to only add item statistics while parsing, false otherwise</param>
/// <param name="filename">Name of the file to be parsed</param>
/// <param name="indexId">Index ID for the DAT</param>
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
/// </summary>
/// <param name="reader">XmlReader to use to parse the header</param>
/// <param name="statsOnly">True to only add item statistics while parsing, false otherwise</param>
/// <param name="filename">Name of the file to be parsed</param>
/// <param name="indexId">Index ID for the DAT</param>
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);
}
}

View File

@@ -41,7 +41,7 @@ namespace SabreTools.DatFiles.Formats
}
/// <inheritdoc/>
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
/// </summary>
/// <param name="reader">XmlReader representing a machine block</param>
/// <param name="statsOnly">True to only add item statistics while parsing, false otherwise</param>
/// <param name="filename">Name of the file to be parsed</param>
/// <param name="indexId">Index ID for the DAT</param>
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
/// <param name="reader">XmlReader representing a part block</param>
/// <param name="machine">Machine information to pass to contained items</param>
/// <param name="diskno">Disk number to use when outputting to other DAT formats</param>
/// <param name="statsOnly">True to only add item statistics while parsing, false otherwise</param>
/// <param name="filename">Name of the file to be parsed</param>
/// <param name="indexId">Index ID for the DAT</param>
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;

View File

@@ -26,7 +26,7 @@ namespace SabreTools.DatFiles.Formats
}
/// <inheritdoc/>
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
/// </summary>
/// <param name="reader">IniReader to use to parse the credits</param>
/// <param name="statsOnly">True to only add item statistics while parsing, false otherwise</param>
/// <param name="filename">Name of the file to be parsed</param>
/// <param name="indexId">Index ID for the DAT</param>
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");

View File

@@ -28,7 +28,7 @@ namespace SabreTools.DatFiles.Formats
}
/// <inheritdoc/>
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
/// </summary>
/// <param name="itr">JsonTextReader to use to parse the machine</param>
/// <param name="statsOnly">True to only add item statistics while parsing, false otherwise</param>
/// <param name="filename">Name of the file to be parsed</param>
/// <param name="indexId">Index ID for the DAT</param>
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
/// </summary>
/// <param name="machineObj">JObject representing a single machine</param>
/// <param name="statsOnly">True to only add item statistics while parsing, false otherwise</param>
/// <param name="filename">Name of the file to be parsed</param>
/// <param name="indexId">Index ID for the DAT</param>
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);
}
/// <summary>
/// Read item array information
/// </summary>
/// <param name="itemsArr">JArray representing the items list</param>
/// <param name="statsOnly">True to only add item statistics while parsing, false otherwise</param>
/// <param name="filename">Name of the file to be parsed</param>
/// <param name="indexId">Index ID for the DAT</param>
/// <param name="machine">Machine information to add to the parsed items</param>
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
/// </summary>
/// <param name="machineObj">JObject representing a single datitem</param>
/// <param name="statsOnly">True to only add item statistics while parsing, false otherwise</param>
/// <param name="filename">Name of the file to be parsed</param>
/// <param name="indexId">Index ID for the DAT</param>
/// <param name="machine">Machine information to add to the parsed items</param>
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);
}
}

View File

@@ -25,7 +25,7 @@ namespace SabreTools.DatFiles.Formats
}
/// <inheritdoc/>
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
/// </summary>
/// <param name="xtr">XmlReader to use to parse the header</param>
/// <param name="statsOnly">True to only add item statistics while parsing, false otherwise</param>
/// <param name="filename">Name of the file to be parsed</param>
/// <param name="indexId">Index ID for the DAT</param>
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
/// </summary>
/// <param name="xtr">XmlReader to use to parse the header</param>
/// <param name="machine">Machine to copy information from</param>
/// <param name="statsOnly">True to only add item statistics while parsing, false otherwise</param>
/// <param name="filename">Name of the file to be parsed</param>
/// <param name="indexId">Index ID for the DAT</param>
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:

View File

@@ -32,7 +32,7 @@ namespace SabreTools.DatFiles.Formats
}
/// <inheritdoc/>
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)

View File

@@ -91,7 +91,7 @@ namespace SabreTools.DatFiles.Formats
}
/// <inheritdoc/>
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
/// </summary>
/// <param name="reader">XmlReader representing a software block</param>
/// <param name="statsOnly">True to only add item statistics while parsing, false otherwise</param>
/// <param name="filename">Name of the file to be parsed</param>
/// <param name="indexId">Index ID for the DAT</param>
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
/// <param name="reader">XmlReader representing a part block</param>
/// <param name="machine">Machine information to pass to contained items</param>
/// <param name="part">Part information to pass to contained items</param>
/// <param name="statsOnly">True to only add item statistics while parsing, false otherwise</param>
/// <param name="filename">Name of the file to be parsed</param>
/// <param name="indexId">Index ID for the DAT</param>
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();

View File

@@ -28,11 +28,12 @@ namespace SabreTools.DatTools
/// Create a DatFile and parse a file into it
/// </summary>
/// <param name="filename">Name of the file to be parsed</param>
/// <param name="statsOnly">True to only add item statistics while parsing, false otherwise</param>
/// <param name="throwOnError">True if the error that is thrown should be thrown back to the caller, false otherwise</param>
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
/// <param name="keep">True if full pathnames are to be kept, false otherwise (default)</param>
/// <param name="keepext">True if original extension should be kept, false otherwise (default)</param>
/// <param name="quotes">True if quotes are assumed in supported types (default), false otherwise</param>
/// <param name="statsOnly">True to only add item statistics while parsing, false otherwise</param>
/// <param name="throwOnError">True if the error that is thrown should be thrown back to the caller, false otherwise</param>
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);
}
/// <summary>
@@ -68,6 +71,7 @@ namespace SabreTools.DatTools
/// <param name="keep">True if full pathnames are to be kept, false otherwise (default)</param>
/// <param name="keepext">True if original extension should be kept, false otherwise (default)</param>
/// <param name="quotes">True if quotes are assumed in supported types (default), false otherwise</param>
/// <param name="statsOnly">True to only add item statistics while parsing, false otherwise</param>
/// <param name="throwOnError">True if the error that is thrown should be thrown back to the caller, false otherwise</param>
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)
{

View File

@@ -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;
}