mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
Wire through "stats only" parsing, version 1 (nw)
This commit is contained in:
@@ -152,16 +152,17 @@ namespace SabreTools.DatFiles
|
|||||||
/// <param name="filename">Name of the file to be parsed</param>
|
/// <param name="filename">Name of the file to be parsed</param>
|
||||||
/// <param name="indexId">Index ID for the DAT</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="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>
|
/// <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>
|
/// <summary>
|
||||||
/// Add a rom to the Dat after checking
|
/// Add a rom to the Dat after checking
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="item">Item data to check against</param>
|
/// <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>
|
/// <returns>The key for the item</returns>
|
||||||
protected string ParseAddHelper(DatItem item, bool statsOnly = false)
|
protected string ParseAddHelper(DatItem item, bool statsOnly)
|
||||||
{
|
{
|
||||||
string key;
|
string key;
|
||||||
|
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ namespace SabreTools.DatFiles.Formats
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <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
|
// Open a file reader
|
||||||
Encoding enc = filename.GetEncoding();
|
Encoding enc = filename.GetEncoding();
|
||||||
@@ -94,7 +94,7 @@ namespace SabreTools.DatFiles.Formats
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Now process and add the rom
|
// Now process and add the rom
|
||||||
ParseAddHelper(rom);
|
ParseAddHelper(rom, statsOnly);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ namespace SabreTools.DatFiles.Formats
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <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
|
// Open a file reader
|
||||||
Encoding enc = filename.GetEncoding();
|
Encoding enc = filename.GetEncoding();
|
||||||
@@ -71,10 +71,10 @@ namespace SabreTools.DatFiles.Formats
|
|||||||
case "set": // Used by the most ancient DATs
|
case "set": // Used by the most ancient DATs
|
||||||
case "game": // Used by most CMP DATs
|
case "game": // Used by most CMP DATs
|
||||||
case "machine": // Possibly used by MAME CMP DATs
|
case "machine": // Possibly used by MAME CMP DATs
|
||||||
ReadSet(cmpr, false, filename, indexId);
|
ReadSet(cmpr, false, statsOnly, filename, indexId);
|
||||||
break;
|
break;
|
||||||
case "resource": // Used by some other DATs to denote a BIOS set
|
case "resource": // Used by some other DATs to denote a BIOS set
|
||||||
ReadSet(cmpr, true, filename, indexId);
|
ReadSet(cmpr, true, statsOnly, filename, indexId);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@@ -201,11 +201,13 @@ namespace SabreTools.DatFiles.Formats
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="cmpr">ClrMameProReader to use to parse the header</param>
|
/// <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="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="filename">Name of the file to be parsed</param>
|
||||||
/// <param name="indexId">Index ID for the DAT</param>
|
/// <param name="indexId">Index ID for the DAT</param>
|
||||||
private void ReadSet(
|
private void ReadSet(
|
||||||
ClrMameProReader cmpr,
|
ClrMameProReader cmpr,
|
||||||
bool resource,
|
bool resource,
|
||||||
|
bool statsOnly,
|
||||||
|
|
||||||
// Standard Dat parsing
|
// Standard Dat parsing
|
||||||
string filename,
|
string filename,
|
||||||
@@ -398,7 +400,7 @@ namespace SabreTools.DatFiles.Formats
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Now process and add the rom
|
// Now process and add the rom
|
||||||
ParseAddHelper(item);
|
ParseAddHelper(item, statsOnly);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -417,7 +419,7 @@ namespace SabreTools.DatFiles.Formats
|
|||||||
blank.CopyMachineInformation(machine);
|
blank.CopyMachineInformation(machine);
|
||||||
|
|
||||||
// Now process and add the rom
|
// Now process and add the rom
|
||||||
ParseAddHelper(blank);
|
ParseAddHelper(blank, statsOnly);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ namespace SabreTools.DatFiles.Formats
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <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
|
// Open a file reader
|
||||||
Encoding enc = filename.GetEncoding();
|
Encoding enc = filename.GetEncoding();
|
||||||
@@ -57,7 +57,7 @@ namespace SabreTools.DatFiles.Formats
|
|||||||
|
|
||||||
// Sets
|
// Sets
|
||||||
case "game":
|
case "game":
|
||||||
ReadGame(cmpr, filename, indexId);
|
ReadGame(cmpr, statsOnly, filename, indexId);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@@ -141,9 +141,10 @@ namespace SabreTools.DatFiles.Formats
|
|||||||
/// Read set information
|
/// Read set information
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="cmpr">ClrMameProReader to use to parse the header</param>
|
/// <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="filename">Name of the file to be parsed</param>
|
||||||
/// <param name="indexId">Index ID for the DAT</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
|
// Prepare all internal variables
|
||||||
bool containsItems = false;
|
bool containsItems = false;
|
||||||
@@ -233,7 +234,7 @@ namespace SabreTools.DatFiles.Formats
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Now process and add the rom
|
// Now process and add the rom
|
||||||
ParseAddHelper(item);
|
ParseAddHelper(item, statsOnly);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -252,7 +253,7 @@ namespace SabreTools.DatFiles.Formats
|
|||||||
blank.CopyMachineInformation(machine);
|
blank.CopyMachineInformation(machine);
|
||||||
|
|
||||||
// Now process and add the rom
|
// Now process and add the rom
|
||||||
ParseAddHelper(blank);
|
ParseAddHelper(blank, statsOnly);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ namespace SabreTools.DatFiles.Formats
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <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
|
// Open a file reader
|
||||||
Encoding enc = filename.GetEncoding();
|
Encoding enc = filename.GetEncoding();
|
||||||
@@ -85,7 +85,7 @@ namespace SabreTools.DatFiles.Formats
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Now process and add the rom
|
// Now process and add the rom
|
||||||
ParseAddHelper(rom);
|
ParseAddHelper(rom, statsOnly);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ namespace SabreTools.DatFiles.Formats
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <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
|
// Open a file reader
|
||||||
Encoding enc = filename.GetEncoding();
|
Encoding enc = filename.GetEncoding();
|
||||||
@@ -86,7 +86,7 @@ namespace SabreTools.DatFiles.Formats
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Now process and add the rom
|
// Now process and add the rom
|
||||||
ParseAddHelper(rom);
|
ParseAddHelper(rom, statsOnly);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ namespace SabreTools.DatFiles.Formats
|
|||||||
/// 6331.sound-u8 32 BAD CRC(1d298cb0) SHA1(bb0bb62365402543e3154b9a77be9c75010e6abc) BAD_DUMP
|
/// 6331.sound-u8 32 BAD CRC(1d298cb0) SHA1(bb0bb62365402543e3154b9a77be9c75010e6abc) BAD_DUMP
|
||||||
/// 16v8h-blue.u24 279 NO GOOD DUMP KNOWN
|
/// 16v8h-blue.u24 279 NO GOOD DUMP KNOWN
|
||||||
/// </remarks>
|
/// </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
|
// Open a file reader
|
||||||
Encoding enc = filename.GetEncoding();
|
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)
|
// 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)
|
// 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)
|
// 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)
|
// 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)
|
// 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
|
// If we have something else, it's invalid
|
||||||
|
|||||||
@@ -191,7 +191,7 @@ namespace SabreTools.DatFiles.Formats
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <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
|
// Prepare all internal variables
|
||||||
XmlReader xtr = XmlReader.Create(filename, new XmlReaderSettings
|
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
|
// We want to process the entire subtree of the machine
|
||||||
case "game": // Some older DATs still use "game"
|
case "game": // Some older DATs still use "game"
|
||||||
case "machine":
|
case "machine":
|
||||||
ReadMachine(xtr.ReadSubtree(), filename, indexId);
|
ReadMachine(xtr.ReadSubtree(), statsOnly, filename, indexId);
|
||||||
|
|
||||||
// Skip the machine now that we've processed it
|
// Skip the machine now that we've processed it
|
||||||
xtr.Skip();
|
xtr.Skip();
|
||||||
@@ -274,9 +274,10 @@ namespace SabreTools.DatFiles.Formats
|
|||||||
/// Read machine information
|
/// Read machine information
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="reader">XmlReader representing a machine block</param>
|
/// <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="filename">Name of the file to be parsed</param>
|
||||||
/// <param name="indexId">Index ID for the DAT</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 we have an empty machine, skip it
|
||||||
if (reader == null)
|
if (reader == null)
|
||||||
@@ -761,7 +762,7 @@ namespace SabreTools.DatFiles.Formats
|
|||||||
foreach (DatItem datItem in datItems)
|
foreach (DatItem datItem in datItems)
|
||||||
{
|
{
|
||||||
datItem.CopyMachineInformation(machine);
|
datItem.CopyMachineInformation(machine);
|
||||||
ParseAddHelper(datItem);
|
ParseAddHelper(datItem, statsOnly);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -780,7 +781,7 @@ namespace SabreTools.DatFiles.Formats
|
|||||||
blank.CopyMachineInformation(machine);
|
blank.CopyMachineInformation(machine);
|
||||||
|
|
||||||
// Now process and add the rom
|
// Now process and add the rom
|
||||||
ParseAddHelper(blank);
|
ParseAddHelper(blank, statsOnly);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -133,7 +133,7 @@ namespace SabreTools.DatFiles.Formats
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <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
|
// Prepare all internal variables
|
||||||
XmlReader xtr = XmlReader.Create(filename, new XmlReaderSettings
|
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
|
// We want to process the entire subtree of the game
|
||||||
case "machine": // New-style Logiqx
|
case "machine": // New-style Logiqx
|
||||||
case "game": // Old-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
|
// Skip the machine now that we've processed it
|
||||||
xtr.Skip();
|
xtr.Skip();
|
||||||
@@ -371,12 +371,14 @@ namespace SabreTools.DatFiles.Formats
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="reader">XmlReader to use to parse the machine</param>
|
/// <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="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="filename">Name of the file to be parsed</param>
|
||||||
/// <param name="indexId">Index ID for the DAT</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="keep">True if full pathnames are to be kept, false otherwise (default)</param>
|
||||||
private void ReadMachine(
|
private void ReadMachine(
|
||||||
XmlReader reader,
|
XmlReader reader,
|
||||||
List<string> dirs,
|
List<string> dirs,
|
||||||
|
bool statsOnly,
|
||||||
|
|
||||||
// Standard Dat parsing
|
// Standard Dat parsing
|
||||||
string filename,
|
string filename,
|
||||||
@@ -489,7 +491,7 @@ namespace SabreTools.DatFiles.Formats
|
|||||||
archive.CopyMachineInformation(machine);
|
archive.CopyMachineInformation(machine);
|
||||||
|
|
||||||
// Now process and add the archive
|
// Now process and add the archive
|
||||||
ParseAddHelper(archive);
|
ParseAddHelper(archive, statsOnly);
|
||||||
|
|
||||||
reader.Read();
|
reader.Read();
|
||||||
break;
|
break;
|
||||||
@@ -513,7 +515,7 @@ namespace SabreTools.DatFiles.Formats
|
|||||||
biosSet.CopyMachineInformation(machine);
|
biosSet.CopyMachineInformation(machine);
|
||||||
|
|
||||||
// Now process and add the biosSet
|
// Now process and add the biosSet
|
||||||
ParseAddHelper(biosSet);
|
ParseAddHelper(biosSet, statsOnly);
|
||||||
|
|
||||||
reader.Read();
|
reader.Read();
|
||||||
break;
|
break;
|
||||||
@@ -539,7 +541,7 @@ namespace SabreTools.DatFiles.Formats
|
|||||||
disk.CopyMachineInformation(machine);
|
disk.CopyMachineInformation(machine);
|
||||||
|
|
||||||
// Now process and add the disk
|
// Now process and add the disk
|
||||||
ParseAddHelper(disk);
|
ParseAddHelper(disk, statsOnly);
|
||||||
|
|
||||||
reader.Read();
|
reader.Read();
|
||||||
break;
|
break;
|
||||||
@@ -565,7 +567,7 @@ namespace SabreTools.DatFiles.Formats
|
|||||||
media.CopyMachineInformation(machine);
|
media.CopyMachineInformation(machine);
|
||||||
|
|
||||||
// Now process and add the media
|
// Now process and add the media
|
||||||
ParseAddHelper(media);
|
ParseAddHelper(media, statsOnly);
|
||||||
|
|
||||||
reader.Read();
|
reader.Read();
|
||||||
break;
|
break;
|
||||||
@@ -585,7 +587,7 @@ namespace SabreTools.DatFiles.Formats
|
|||||||
release.CopyMachineInformation(machine);
|
release.CopyMachineInformation(machine);
|
||||||
|
|
||||||
// Now process and add the release
|
// Now process and add the release
|
||||||
ParseAddHelper(release);
|
ParseAddHelper(release, statsOnly);
|
||||||
|
|
||||||
reader.Read();
|
reader.Read();
|
||||||
break;
|
break;
|
||||||
@@ -619,7 +621,7 @@ namespace SabreTools.DatFiles.Formats
|
|||||||
rom.CopyMachineInformation(machine);
|
rom.CopyMachineInformation(machine);
|
||||||
|
|
||||||
// Now process and add the rom
|
// Now process and add the rom
|
||||||
ParseAddHelper(rom);
|
ParseAddHelper(rom, statsOnly);
|
||||||
|
|
||||||
reader.Read();
|
reader.Read();
|
||||||
break;
|
break;
|
||||||
@@ -641,7 +643,7 @@ namespace SabreTools.DatFiles.Formats
|
|||||||
sample.CopyMachineInformation(machine);
|
sample.CopyMachineInformation(machine);
|
||||||
|
|
||||||
// Now process and add the sample
|
// Now process and add the sample
|
||||||
ParseAddHelper(sample);
|
ParseAddHelper(sample, statsOnly);
|
||||||
|
|
||||||
reader.Read();
|
reader.Read();
|
||||||
break;
|
break;
|
||||||
@@ -667,7 +669,7 @@ namespace SabreTools.DatFiles.Formats
|
|||||||
blank.CopyMachineInformation(machine);
|
blank.CopyMachineInformation(machine);
|
||||||
|
|
||||||
// Now process and add the rom
|
// Now process and add the rom
|
||||||
ParseAddHelper(blank);
|
ParseAddHelper(blank, statsOnly);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ namespace SabreTools.DatFiles.Formats
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <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...
|
// There is no consistent way to parse a missfile...
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ namespace SabreTools.DatFiles.Formats
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <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
|
XmlReader xtr = XmlReader.Create(filename, new XmlReaderSettings
|
||||||
{
|
{
|
||||||
@@ -66,7 +66,7 @@ namespace SabreTools.DatFiles.Formats
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case "games":
|
case "games":
|
||||||
ReadGames(xtr.ReadSubtree(), filename, indexId);
|
ReadGames(xtr.ReadSubtree(), statsOnly, filename, indexId);
|
||||||
|
|
||||||
// Skip the games node now that we've processed it
|
// Skip the games node now that we've processed it
|
||||||
xtr.Skip();
|
xtr.Skip();
|
||||||
@@ -424,9 +424,10 @@ namespace SabreTools.DatFiles.Formats
|
|||||||
/// Read games information
|
/// Read games information
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="reader">XmlReader to use to parse the header</param>
|
/// <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="filename">Name of the file to be parsed</param>
|
||||||
/// <param name="indexId">Index ID for the DAT</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 there's no subtree to the configuration, skip it
|
||||||
if (reader == null)
|
if (reader == null)
|
||||||
@@ -449,7 +450,7 @@ namespace SabreTools.DatFiles.Formats
|
|||||||
switch (reader.Name.ToLowerInvariant())
|
switch (reader.Name.ToLowerInvariant())
|
||||||
{
|
{
|
||||||
case "game":
|
case "game":
|
||||||
ReadGame(reader.ReadSubtree(), filename, indexId);
|
ReadGame(reader.ReadSubtree(), statsOnly, filename, indexId);
|
||||||
|
|
||||||
// Skip the game node now that we've processed it
|
// Skip the game node now that we've processed it
|
||||||
reader.Skip();
|
reader.Skip();
|
||||||
@@ -466,9 +467,10 @@ namespace SabreTools.DatFiles.Formats
|
|||||||
/// Read game information
|
/// Read game information
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="reader">XmlReader to use to parse the header</param>
|
/// <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="filename">Name of the file to be parsed</param>
|
||||||
/// <param name="indexId">Index ID for the DAT</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
|
// Prepare all internal variables
|
||||||
string releaseNumber = string.Empty, duplicateid;
|
string releaseNumber = string.Empty, duplicateid;
|
||||||
@@ -579,7 +581,7 @@ namespace SabreTools.DatFiles.Formats
|
|||||||
datItems[i].CopyMachineInformation(machine);
|
datItems[i].CopyMachineInformation(machine);
|
||||||
|
|
||||||
// Now process and add the rom
|
// Now process and add the rom
|
||||||
ParseAddHelper(datItems[i]);
|
ParseAddHelper(datItems[i], statsOnly);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ namespace SabreTools.DatFiles.Formats
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <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
|
// Prepare all internal variables
|
||||||
XmlReader xtr = XmlReader.Create(filename, new XmlReaderSettings
|
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
|
// We want to process the entire subtree of the software
|
||||||
case "software":
|
case "software":
|
||||||
ReadSoftware(xtr.ReadSubtree(), filename, indexId);
|
ReadSoftware(xtr.ReadSubtree(), statsOnly, filename, indexId);
|
||||||
|
|
||||||
// Skip the software now that we've processed it
|
// Skip the software now that we've processed it
|
||||||
xtr.Skip();
|
xtr.Skip();
|
||||||
@@ -114,9 +114,10 @@ namespace SabreTools.DatFiles.Formats
|
|||||||
/// Read software information
|
/// Read software information
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="reader">XmlReader representing a machine block</param>
|
/// <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="filename">Name of the file to be parsed</param>
|
||||||
/// <param name="indexId">Index ID for the DAT</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 we have an empty machine, skip it
|
||||||
if (reader == null)
|
if (reader == null)
|
||||||
@@ -168,7 +169,7 @@ namespace SabreTools.DatFiles.Formats
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case "dump":
|
case "dump":
|
||||||
containsItems = ReadDump(reader.ReadSubtree(), machine, diskno, filename, indexId);
|
containsItems = ReadDump(reader.ReadSubtree(), machine, diskno, statsOnly, filename, indexId);
|
||||||
diskno++;
|
diskno++;
|
||||||
|
|
||||||
// Skip the dump now that we've processed it
|
// Skip the dump now that we've processed it
|
||||||
@@ -196,7 +197,7 @@ namespace SabreTools.DatFiles.Formats
|
|||||||
blank.CopyMachineInformation(machine);
|
blank.CopyMachineInformation(machine);
|
||||||
|
|
||||||
// Now process and add the rom
|
// 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="reader">XmlReader representing a part block</param>
|
||||||
/// <param name="machine">Machine information to pass to contained items</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="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="filename">Name of the file to be parsed</param>
|
||||||
/// <param name="indexId">Index ID for the DAT</param>
|
/// <param name="indexId">Index ID for the DAT</param>
|
||||||
private bool ReadDump(
|
private bool ReadDump(
|
||||||
XmlReader reader,
|
XmlReader reader,
|
||||||
Machine machine,
|
Machine machine,
|
||||||
int diskno,
|
int diskno,
|
||||||
|
bool statsOnly,
|
||||||
|
|
||||||
// Standard Dat parsing
|
// Standard Dat parsing
|
||||||
string filename,
|
string filename,
|
||||||
@@ -284,7 +287,7 @@ namespace SabreTools.DatFiles.Formats
|
|||||||
}
|
}
|
||||||
|
|
||||||
item.CopyMachineInformation(machine);
|
item.CopyMachineInformation(machine);
|
||||||
ParseAddHelper(item);
|
ParseAddHelper(item, statsOnly);
|
||||||
}
|
}
|
||||||
|
|
||||||
return items.Count > 0;
|
return items.Count > 0;
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ namespace SabreTools.DatFiles.Formats
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <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
|
// Prepare all intenral variables
|
||||||
IniReader ir = new IniReader(filename) { ValidateRows = false };
|
IniReader ir = new IniReader(filename) { ValidateRows = false };
|
||||||
@@ -66,7 +66,7 @@ namespace SabreTools.DatFiles.Formats
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case "games":
|
case "games":
|
||||||
ReadGamesSection(ir, filename, indexId);
|
ReadGamesSection(ir, statsOnly, filename, indexId);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// Unknown section so we ignore it
|
// Unknown section so we ignore it
|
||||||
@@ -284,9 +284,10 @@ namespace SabreTools.DatFiles.Formats
|
|||||||
/// Read games information
|
/// Read games information
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="reader">IniReader to use to parse the credits</param>
|
/// <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="filename">Name of the file to be parsed</param>
|
||||||
/// <param name="indexId">Index ID for the DAT</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 the reader is somehow null, skip it
|
||||||
if (reader == null)
|
if (reader == null)
|
||||||
@@ -355,7 +356,7 @@ namespace SabreTools.DatFiles.Formats
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Now process and add the rom
|
// Now process and add the rom
|
||||||
ParseAddHelper(rom);
|
ParseAddHelper(rom, statsOnly);
|
||||||
|
|
||||||
reader.ReadNextLine();
|
reader.ReadNextLine();
|
||||||
} while (!reader.EndOfStream && reader.Section.ToLowerInvariant() == "games");
|
} while (!reader.EndOfStream && reader.Section.ToLowerInvariant() == "games");
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ namespace SabreTools.DatFiles.Formats
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <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
|
// Prepare all internal variables
|
||||||
StreamReader sr = new StreamReader(File.OpenRead(filename), new UTF8Encoding(false));
|
StreamReader sr = new StreamReader(File.OpenRead(filename), new UTF8Encoding(false));
|
||||||
@@ -61,7 +61,7 @@ namespace SabreTools.DatFiles.Formats
|
|||||||
|
|
||||||
// Machine array
|
// Machine array
|
||||||
case "machines":
|
case "machines":
|
||||||
ReadMachines(jtr, filename, indexId);
|
ReadMachines(jtr, statsOnly, filename, indexId);
|
||||||
jtr.Read();
|
jtr.Read();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -101,9 +101,10 @@ namespace SabreTools.DatFiles.Formats
|
|||||||
/// Read machine array information
|
/// Read machine array information
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="itr">JsonTextReader to use to parse the machine</param>
|
/// <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="filename">Name of the file to be parsed</param>
|
||||||
/// <param name="indexId">Index ID for the DAT</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 the reader is invalid, skip
|
||||||
if (jtr == null)
|
if (jtr == null)
|
||||||
@@ -117,7 +118,7 @@ namespace SabreTools.DatFiles.Formats
|
|||||||
// Loop through each machine object and process
|
// Loop through each machine object and process
|
||||||
foreach (JObject machineObj in machineArray)
|
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
|
/// Read machine object information
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="machineObj">JObject representing a single machine</param>
|
/// <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="filename">Name of the file to be parsed</param>
|
||||||
/// <param name="indexId">Index ID for the DAT</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 object is invalid, skip it
|
||||||
if (machineObj == null)
|
if (machineObj == null)
|
||||||
@@ -142,18 +144,20 @@ namespace SabreTools.DatFiles.Formats
|
|||||||
|
|
||||||
// Read items, if possible
|
// Read items, if possible
|
||||||
if (machineObj.ContainsKey("items"))
|
if (machineObj.ContainsKey("items"))
|
||||||
ReadItems(machineObj["items"] as JArray, filename, indexId, machine);
|
ReadItems(machineObj["items"] as JArray, statsOnly, filename, indexId, machine);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Read item array information
|
/// Read item array information
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="itemsArr">JArray representing the items list</param>
|
/// <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="filename">Name of the file to be parsed</param>
|
||||||
/// <param name="indexId">Index ID for the DAT</param>
|
/// <param name="indexId">Index ID for the DAT</param>
|
||||||
/// <param name="machine">Machine information to add to the parsed items</param>
|
/// <param name="machine">Machine information to add to the parsed items</param>
|
||||||
private void ReadItems(
|
private void ReadItems(
|
||||||
JArray itemsArr,
|
JArray itemsArr,
|
||||||
|
bool statsOnly,
|
||||||
|
|
||||||
// Standard Dat parsing
|
// Standard Dat parsing
|
||||||
string filename,
|
string filename,
|
||||||
@@ -169,7 +173,7 @@ namespace SabreTools.DatFiles.Formats
|
|||||||
// Loop through each datitem object and process
|
// Loop through each datitem object and process
|
||||||
foreach (JObject itemObj in itemsArr)
|
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
|
/// Read item information
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="machineObj">JObject representing a single datitem</param>
|
/// <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="filename">Name of the file to be parsed</param>
|
||||||
/// <param name="indexId">Index ID for the DAT</param>
|
/// <param name="indexId">Index ID for the DAT</param>
|
||||||
/// <param name="machine">Machine information to add to the parsed items</param>
|
/// <param name="machine">Machine information to add to the parsed items</param>
|
||||||
private void ReadItem(
|
private void ReadItem(
|
||||||
JObject itemObj,
|
JObject itemObj,
|
||||||
|
bool statsOnly,
|
||||||
|
|
||||||
// Standard Dat parsing
|
// Standard Dat parsing
|
||||||
string filename,
|
string filename,
|
||||||
@@ -322,7 +328,7 @@ namespace SabreTools.DatFiles.Formats
|
|||||||
{
|
{
|
||||||
datItem.CopyMachineInformation(machine);
|
datItem.CopyMachineInformation(machine);
|
||||||
datItem.Source = new Source { Index = indexId, Name = filename };
|
datItem.Source = new Source { Index = indexId, Name = filename };
|
||||||
ParseAddHelper(datItem);
|
ParseAddHelper(datItem, statsOnly);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ namespace SabreTools.DatFiles.Formats
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <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
|
// Prepare all internal variables
|
||||||
XmlReader xtr = XmlReader.Create(filename, new XmlReaderSettings
|
XmlReader xtr = XmlReader.Create(filename, new XmlReaderSettings
|
||||||
@@ -65,7 +65,7 @@ namespace SabreTools.DatFiles.Formats
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case "directory":
|
case "directory":
|
||||||
ReadDirectory(xtr.ReadSubtree(), filename, indexId);
|
ReadDirectory(xtr.ReadSubtree(), statsOnly, filename, indexId);
|
||||||
|
|
||||||
// Skip the directory node now that we've processed it
|
// Skip the directory node now that we've processed it
|
||||||
xtr.Read();
|
xtr.Read();
|
||||||
@@ -96,9 +96,10 @@ namespace SabreTools.DatFiles.Formats
|
|||||||
/// Read directory information
|
/// Read directory information
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="xtr">XmlReader to use to parse the header</param>
|
/// <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="filename">Name of the file to be parsed</param>
|
||||||
/// <param name="indexId">Index ID for the DAT</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 the reader is invalid, skip
|
||||||
if (xtr == null)
|
if (xtr == null)
|
||||||
@@ -127,7 +128,7 @@ namespace SabreTools.DatFiles.Formats
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case "files":
|
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
|
// Skip the directory node now that we've processed it
|
||||||
xtr.Read();
|
xtr.Read();
|
||||||
@@ -144,9 +145,10 @@ namespace SabreTools.DatFiles.Formats
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="xtr">XmlReader to use to parse the header</param>
|
/// <param name="xtr">XmlReader to use to parse the header</param>
|
||||||
/// <param name="machine">Machine to copy information from</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="filename">Name of the file to be parsed</param>
|
||||||
/// <param name="indexId">Index ID for the DAT</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 the reader is invalid, skip
|
||||||
if (xtr == null)
|
if (xtr == null)
|
||||||
@@ -170,7 +172,7 @@ namespace SabreTools.DatFiles.Formats
|
|||||||
DatItem item = xs.Deserialize(xtr.ReadSubtree()) as DatItem;
|
DatItem item = xs.Deserialize(xtr.ReadSubtree()) as DatItem;
|
||||||
item.CopyMachineInformation(machine);
|
item.CopyMachineInformation(machine);
|
||||||
item.Source = new Source { Name = filename, Index = indexId };
|
item.Source = new Source { Name = filename, Index = indexId };
|
||||||
ParseAddHelper(item);
|
ParseAddHelper(item, statsOnly);
|
||||||
xtr.Skip();
|
xtr.Skip();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ namespace SabreTools.DatFiles.Formats
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <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
|
// Open a file reader
|
||||||
Encoding enc = filename.GetEncoding();
|
Encoding enc = filename.GetEncoding();
|
||||||
@@ -101,7 +101,7 @@ namespace SabreTools.DatFiles.Formats
|
|||||||
DatItem datItem = DatItem.Create(datItemMappings[DatItemField.Type].AsItemType());
|
DatItem datItem = DatItem.Create(datItemMappings[DatItemField.Type].AsItemType());
|
||||||
DatItemTool.SetFields(datItem, datItemMappings, machineMappings);
|
DatItemTool.SetFields(datItem, datItemMappings, machineMappings);
|
||||||
datItem.Source = new Source(indexId, filename);
|
datItem.Source = new Source(indexId, filename);
|
||||||
ParseAddHelper(datItem);
|
ParseAddHelper(datItem, statsOnly);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
|
|||||||
@@ -91,7 +91,7 @@ namespace SabreTools.DatFiles.Formats
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <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
|
// Prepare all internal variables
|
||||||
XmlReader xtr = XmlReader.Create(filename, new XmlReaderSettings
|
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
|
// We want to process the entire subtree of the machine
|
||||||
case "software":
|
case "software":
|
||||||
ReadSoftware(xtr.ReadSubtree(), filename, indexId);
|
ReadSoftware(xtr.ReadSubtree(), statsOnly, filename, indexId);
|
||||||
|
|
||||||
// Skip the software now that we've processed it
|
// Skip the software now that we've processed it
|
||||||
xtr.Skip();
|
xtr.Skip();
|
||||||
@@ -164,9 +164,10 @@ namespace SabreTools.DatFiles.Formats
|
|||||||
/// Read software information
|
/// Read software information
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="reader">XmlReader representing a software block</param>
|
/// <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="filename">Name of the file to be parsed</param>
|
||||||
/// <param name="indexId">Index ID for the DAT</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 we have an empty software, skip it
|
||||||
if (reader == null)
|
if (reader == null)
|
||||||
@@ -220,7 +221,7 @@ namespace SabreTools.DatFiles.Formats
|
|||||||
Index = indexId,
|
Index = indexId,
|
||||||
Name = filename,
|
Name = filename,
|
||||||
},
|
},
|
||||||
});
|
}, statsOnly);
|
||||||
|
|
||||||
reader.Read();
|
reader.Read();
|
||||||
break;
|
break;
|
||||||
@@ -236,7 +237,7 @@ namespace SabreTools.DatFiles.Formats
|
|||||||
Index = indexId,
|
Index = indexId,
|
||||||
Name = filename,
|
Name = filename,
|
||||||
},
|
},
|
||||||
});
|
}, statsOnly);
|
||||||
|
|
||||||
reader.Read();
|
reader.Read();
|
||||||
break;
|
break;
|
||||||
@@ -249,7 +250,7 @@ namespace SabreTools.DatFiles.Formats
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Now read the internal tags
|
// 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
|
// Skip the part now that we've processed it
|
||||||
reader.Skip();
|
reader.Skip();
|
||||||
@@ -276,7 +277,7 @@ namespace SabreTools.DatFiles.Formats
|
|||||||
blank.CopyMachineInformation(machine);
|
blank.CopyMachineInformation(machine);
|
||||||
|
|
||||||
// Now process and add the rom
|
// 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="reader">XmlReader representing a part block</param>
|
||||||
/// <param name="machine">Machine information to pass to contained items</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="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="filename">Name of the file to be parsed</param>
|
||||||
/// <param name="indexId">Index ID for the DAT</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 we have an empty port, skip it
|
||||||
if (reader == null)
|
if (reader == null)
|
||||||
@@ -422,7 +424,7 @@ namespace SabreTools.DatFiles.Formats
|
|||||||
item.CopyMachineInformation(machine);
|
item.CopyMachineInformation(machine);
|
||||||
|
|
||||||
// Finally add each item
|
// Finally add each item
|
||||||
key = ParseAddHelper(item);
|
key = ParseAddHelper(item, statsOnly);
|
||||||
}
|
}
|
||||||
|
|
||||||
return items.Any();
|
return items.Any();
|
||||||
|
|||||||
@@ -28,11 +28,12 @@ namespace SabreTools.DatTools
|
|||||||
/// Create a DatFile and parse a file into it
|
/// Create a DatFile and parse a file into it
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="filename">Name of the file to be parsed</param>
|
/// <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>
|
/// <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();
|
DatFile datFile = DatFile.Create();
|
||||||
ParseInto(datFile, new ParentablePath(filename), throwOnError: throwOnError);
|
ParseInto(datFile, new ParentablePath(filename), statsOnly: statsOnly, throwOnError: throwOnError);
|
||||||
return datFile;
|
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="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="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="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>
|
/// <param name="throwOnError">True if the error that is thrown should be thrown back to the caller, false otherwise</param>
|
||||||
public static void ParseInto(
|
public static void ParseInto(
|
||||||
DatFile datFile,
|
DatFile datFile,
|
||||||
@@ -53,10 +55,11 @@ namespace SabreTools.DatTools
|
|||||||
bool keep = false,
|
bool keep = false,
|
||||||
bool keepext = false,
|
bool keepext = false,
|
||||||
bool quotes = true,
|
bool quotes = true,
|
||||||
|
bool statsOnly = false,
|
||||||
bool throwOnError = false)
|
bool throwOnError = false)
|
||||||
{
|
{
|
||||||
ParentablePath path = new ParentablePath(filename.Trim('"'));
|
ParentablePath path = new ParentablePath(filename.Trim('"'));
|
||||||
ParseInto(datFile, path, indexId, keep, keepext, quotes, throwOnError);
|
ParseInto(datFile, path, indexId, keep, keepext, quotes, statsOnly, throwOnError);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <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="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="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="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>
|
/// <param name="throwOnError">True if the error that is thrown should be thrown back to the caller, false otherwise</param>
|
||||||
public static void ParseInto(
|
public static void ParseInto(
|
||||||
DatFile datFile,
|
DatFile datFile,
|
||||||
@@ -76,6 +80,7 @@ namespace SabreTools.DatTools
|
|||||||
bool keep = false,
|
bool keep = false,
|
||||||
bool keepext = false,
|
bool keepext = false,
|
||||||
bool quotes = true,
|
bool quotes = true,
|
||||||
|
bool statsOnly = false,
|
||||||
bool throwOnError = true)
|
bool throwOnError = true)
|
||||||
{
|
{
|
||||||
// Get the current path from the filename
|
// Get the current path from the filename
|
||||||
@@ -100,7 +105,8 @@ namespace SabreTools.DatTools
|
|||||||
// Now parse the correct type of DAT
|
// Now parse the correct type of DAT
|
||||||
try
|
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)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -129,9 +129,6 @@ namespace SabreTools.DatTools
|
|||||||
totalStats.AddStatistics(datdata.Items);
|
totalStats.AddStatistics(datdata.Items);
|
||||||
totalStats.GameCount += datdata.Items.Keys.Count();
|
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
|
// Make sure to assign the new directory
|
||||||
lastdir = thisdir;
|
lastdir = thisdir;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user