diff --git a/SabreTools.Library/DatFiles/AttractMode.cs b/SabreTools.Library/DatFiles/AttractMode.cs
index 657a65e7..fee5f34d 100644
--- a/SabreTools.Library/DatFiles/AttractMode.cs
+++ b/SabreTools.Library/DatFiles/AttractMode.cs
@@ -1,7 +1,7 @@
using System;
using System.Collections.Generic;
using System.IO;
-using System.Net;
+using System.Linq;
using System.Text;
using SabreTools.Library.Data;
@@ -30,13 +30,7 @@ namespace SabreTools.Library.DatFiles
/// Name of the file to be parsed
/// Index ID for the DAT
/// True if full pathnames are to be kept, false otherwise (default)
- protected override void ParseFile(
- // Standard Dat parsing
- string filename,
- int indexId,
-
- // Miscellaneous
- bool keep)
+ protected override void ParseFile(string filename, int indexId, bool keep)
{
// Open a file reader
Encoding enc = FileExtensions.GetEncoding(filename);
@@ -147,45 +141,24 @@ namespace SabreTools.Library.DatFiles
// Write out the header
WriteHeader(svw);
- // Write out each of the machines and roms
- string lastgame = null;
-
// Use a sorted list of games to output
foreach (string key in Items.SortedKeys)
{
- List roms = Items[key];
+ List datItems = Items.FilteredItems(key);
// Resolve the names in the block
- roms = DatItem.ResolveNames(roms);
+ datItems = DatItem.ResolveNames(datItems);
- for (int index = 0; index < roms.Count; index++)
+ for (int index = 0; index < datItems.Count; index++)
{
- DatItem item = roms[index];
+ DatItem datItem = datItems[index];
- // There are apparently times when a null rom can skip by, skip them
- if (item.Name == null || item.Machine.Name == null)
- {
- Globals.Logger.Warning("Null rom found!");
- continue;
- }
+ // Check for a "null" item
+ datItem = ProcessNullifiedItem(datItem);
- // If we have a new game, output the beginning of the new item
- if (lastgame == null || lastgame.ToLowerInvariant() != item.Machine.Name.ToLowerInvariant())
- WriteDatItem(svw, item, ignoreblanks);
-
- // If we have a "null" game (created by DATFromDir or something similar), log it to file
- if (item.ItemType == ItemType.Rom
- && (item as Rom).Size == -1
- && (item as Rom).CRC == "null")
- {
- Globals.Logger.Verbose($"Empty folder found: {item.Machine.Name}");
-
- item.Name = (item.Name == "null" ? "-" : item.Name);
- (item as Rom).Size = Constants.SizeZero;
- }
-
- // Set the new data to compare against
- lastgame = item.Machine.Name;
+ // Write out the item if we're not ignoring
+ if (!ShouldIgnore(datItem, ignoreblanks))
+ WriteDatItem(svw, datItem);
}
}
@@ -250,14 +223,9 @@ namespace SabreTools.Library.DatFiles
///
/// SeparatedValueWriter to output to
/// DatItem object to be output
- /// True if blank roms should be skipped on output, false otherwise (default)
/// True if the data was written, false on error
- private bool WriteDatItem(SeparatedValueWriter svw, DatItem datItem, bool ignoreblanks = false)
+ private bool WriteDatItem(SeparatedValueWriter svw, DatItem datItem)
{
- // If we are in ignore blanks mode AND we have a blank (0-size) rom, skip
- if (ignoreblanks && (datItem.ItemType == ItemType.Rom && ((datItem as Rom).Size == 0 || (datItem as Rom).Size == -1)))
- return true;
-
try
{
// No game should start with a path separator
diff --git a/SabreTools.Library/DatFiles/ClrMamePro.cs b/SabreTools.Library/DatFiles/ClrMamePro.cs
index 006f19f4..5655d364 100644
--- a/SabreTools.Library/DatFiles/ClrMamePro.cs
+++ b/SabreTools.Library/DatFiles/ClrMamePro.cs
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.IO;
+using System.Linq;
using System.Text;
using SabreTools.Library.Data;
@@ -30,13 +31,7 @@ namespace SabreTools.Library.DatFiles
/// Name of the file to be parsed
/// Index ID for the DAT
/// True if full pathnames are to be kept, false otherwise (default)
- protected override void ParseFile(
- // Standard Dat parsing
- string filename,
- int indexId,
-
- // Miscellaneous
- bool keep)
+ protected override void ParseFile(string filename, int indexId, bool keep)
{
// Open a file reader
Encoding enc = FileExtensions.GetEncoding(filename);
@@ -459,56 +454,32 @@ namespace SabreTools.Library.DatFiles
// Use a sorted list of games to output
foreach (string key in Items.SortedKeys)
{
- List roms = Items[key];
+ List datItems = Items.FilteredItems(key);
// Resolve the names in the block
- roms = DatItem.ResolveNames(roms);
+ datItems = DatItem.ResolveNames(datItems);
- for (int index = 0; index < roms.Count; index++)
+ for (int index = 0; index < datItems.Count; index++)
{
- DatItem rom = roms[index];
-
- // There are apparently times when a null rom can skip by, skip them
- if (rom.Name == null || rom.Machine.Name == null)
- {
- Globals.Logger.Warning("Null rom found!");
- continue;
- }
+ DatItem datItem = datItems[index];
// If we have a different game and we're not at the start of the list, output the end of last item
- if (lastgame != null && lastgame.ToLowerInvariant() != rom.Machine.Name.ToLowerInvariant())
- WriteEndGame(cmpw, rom);
+ if (lastgame != null && lastgame.ToLowerInvariant() != datItem.Machine.Name.ToLowerInvariant())
+ WriteEndGame(cmpw, datItem);
// If we have a new game, output the beginning of the new item
- if (lastgame == null || lastgame.ToLowerInvariant() != rom.Machine.Name.ToLowerInvariant())
- WriteStartGame(cmpw, rom);
+ if (lastgame == null || lastgame.ToLowerInvariant() != datItem.Machine.Name.ToLowerInvariant())
+ WriteStartGame(cmpw, datItem);
- // If we have a "null" game (created by DATFromDir or something similar), log it to file
- if (rom.ItemType == ItemType.Rom
- && ((Rom)rom).Size == -1
- && ((Rom)rom).CRC == "null")
- {
- Globals.Logger.Verbose($"Empty folder found: {rom.Machine.Name}");
+ // Check for a "null" item
+ datItem = ProcessNullifiedItem(datItem);
- // If we're in a mode that doesn't allow for actual empty folders, add the blank info
- rom.Name = (rom.Name == "null" ? "-" : rom.Name);
- ((Rom)rom).Size = Constants.SizeZero;
- ((Rom)rom).CRC = ((Rom)rom).CRC == "null" ? Constants.CRCZero : null;
- ((Rom)rom).MD5 = ((Rom)rom).MD5 == "null" ? Constants.MD5Zero : null;
-#if NET_FRAMEWORK
- ((Rom)rom).RIPEMD160 = ((Rom)rom).RIPEMD160 == "null" ? Constants.RIPEMD160Zero : null;
-#endif
- ((Rom)rom).SHA1 = ((Rom)rom).SHA1 == "null" ? Constants.SHA1Zero : null;
- ((Rom)rom).SHA256 = ((Rom)rom).SHA256 == "null" ? Constants.SHA256Zero : null;
- ((Rom)rom).SHA384 = ((Rom)rom).SHA384 == "null" ? Constants.SHA384Zero : null;
- ((Rom)rom).SHA512 = ((Rom)rom).SHA512 == "null" ? Constants.SHA512Zero : null;
- }
-
- // Now, output the rom data
- WriteDatItem(cmpw, rom, ignoreblanks);
+ // Write out the item if we're not ignoring
+ if (!ShouldIgnore(datItem, ignoreblanks))
+ WriteDatItem(cmpw, datItem);
// Set the new data to compare against
- lastgame = rom.Machine.Name;
+ lastgame = datItem.Machine.Name;
}
}
@@ -634,14 +605,9 @@ namespace SabreTools.Library.DatFiles
/// DatFile to write out from
/// ClrMameProWriter to output to
/// DatItem object to be output
- /// True if blank roms should be skipped on output, false otherwise (default)
/// True if the data was written, false on error
- private bool WriteDatItem(ClrMameProWriter cmpw, DatItem datItem, bool ignoreblanks = false)
+ private bool WriteDatItem(ClrMameProWriter cmpw, DatItem datItem)
{
- // If we are in ignore blanks mode AND we have a blank (0-size) rom, skip
- if (ignoreblanks && (datItem.ItemType == ItemType.Rom && ((datItem as Rom).Size == 0 || (datItem as Rom).Size == -1)))
- return true;
-
try
{
// Pre-process the item name
diff --git a/SabreTools.Library/DatFiles/DatFile.cs b/SabreTools.Library/DatFiles/DatFile.cs
index dea21d22..d33f5f21 100644
--- a/SabreTools.Library/DatFiles/DatFile.cs
+++ b/SabreTools.Library/DatFiles/DatFile.cs
@@ -3605,6 +3605,83 @@ namespace SabreTools.Library.DatFiles
/// True if the DAT was written correctly, false otherwise
public abstract bool WriteToFile(string outfile, bool ignoreblanks = false);
+ ///
+ /// Create a prefix or postfix from inputs
+ ///
+ /// DatItem to create a prefix/postfix for
+ /// True for prefix, false for postfix
+ /// Sanitized string representing the postfix or prefix
+ protected string CreatePrefixPostfix(DatItem item, bool prefix)
+ {
+ // Initialize strings
+ string fix = string.Empty,
+ game = item.Machine.Name,
+ name = item.Name,
+ crc = string.Empty,
+ md5 = string.Empty,
+ ripemd160 = string.Empty,
+ sha1 = string.Empty,
+ sha256 = string.Empty,
+ sha384 = string.Empty,
+ sha512 = string.Empty,
+ size = string.Empty;
+
+ // If we have a prefix
+ if (prefix)
+ fix = Header.Prefix + (Header.Quotes ? "\"" : string.Empty);
+
+ // If we have a postfix
+ else
+ fix = (Header.Quotes ? "\"" : string.Empty) + Header.Postfix;
+
+ // Ensure we have the proper values for replacement
+ if (item.ItemType == ItemType.Disk)
+ {
+ md5 = (item as Disk).MD5 ?? string.Empty;
+ sha1 = (item as Disk).SHA1 ?? string.Empty;
+ }
+ else if (item.ItemType == ItemType.Media)
+ {
+ md5 = (item as Media).MD5 ?? string.Empty;
+ sha1 = (item as Media).SHA1 ?? string.Empty;
+ sha256 = (item as Media).SHA256 ?? string.Empty;
+ }
+ else if (item.ItemType == ItemType.Rom)
+ {
+ crc = (item as Rom).CRC ?? string.Empty;
+ md5 = (item as Rom).MD5 ?? string.Empty;
+#if NET_FRAMEWORK
+ ripemd160 = (item as Rom).RIPEMD160 ?? string.Empty;
+#endif
+ sha1 = (item as Rom).SHA1 ?? string.Empty;
+ sha256 = (item as Rom).SHA256 ?? string.Empty;
+ sha384 = (item as Rom).SHA384 ?? string.Empty;
+ sha512 = (item as Rom).SHA512 ?? string.Empty;
+ size = (item as Rom).Size.ToString();
+ }
+
+ // Now do bulk replacement where possible
+ fix = fix
+ .Replace("%game%", game)
+ .Replace("%machine%", game)
+ .Replace("%name%", name)
+ .Replace("%manufacturer%", item.Machine.Manufacturer ?? string.Empty)
+ .Replace("%publisher%", item.Machine.Publisher ?? string.Empty)
+ .Replace("%category%", item.Machine.Category ?? string.Empty)
+ .Replace("%crc%", crc)
+ .Replace("%md5%", md5)
+ .Replace("%ripemd160%", ripemd160)
+ .Replace("%sha1%", sha1)
+ .Replace("%sha256%", sha256)
+ .Replace("%sha384%", sha384)
+ .Replace("%sha512%", sha512)
+ .Replace("%size%", size);
+
+ // TODO: Add GameName logic here too?
+
+ return fix;
+ }
+
///
/// Process an item and correctly set the item name
///
@@ -3696,80 +3773,67 @@ namespace SabreTools.Library.DatFiles
}
///
- /// Create a prefix or postfix from inputs
+ /// Process any DatItems that are "null", usually created from directory population
///
- /// DatItem to create a prefix/postfix for
- /// True for prefix, false for postfix
- /// Sanitized string representing the postfix or prefix
- protected string CreatePrefixPostfix(DatItem item, bool prefix)
+ /// DatItem to check for "null" status
+ /// Cleaned DatItem
+ protected DatItem ProcessNullifiedItem(DatItem datItem)
{
- // Initialize strings
- string fix = string.Empty,
- game = item.Machine.Name,
- name = item.Name,
- crc = string.Empty,
- md5 = string.Empty,
- ripemd160 = string.Empty,
- sha1 = string.Empty,
- sha256 = string.Empty,
- sha384 = string.Empty,
- sha512 = string.Empty,
- size = string.Empty;
+ // If we don't have a Rom, we can ignore it
+ if (datItem.ItemType != ItemType.Rom)
+ return datItem;
- // If we have a prefix
- if (prefix)
- fix = Header.Prefix + (Header.Quotes ? "\"" : string.Empty);
+ // Cast for easier parsing
+ Rom rom = datItem as Rom;
- // If we have a postfix
- else
- fix = (Header.Quotes ? "\"" : string.Empty) + Header.Postfix;
+ // If the Rom has "null" characteristics, ensure all fields
+ if (rom.Size == -1 && rom.CRC == "null")
+ {
+ Globals.Logger.Verbose($"Empty folder found: {datItem.Machine.Name}");
- // Ensure we have the proper values for replacement
- if (item.ItemType == ItemType.Disk)
- {
- md5 = (item as Disk).MD5 ?? string.Empty;
- sha1 = (item as Disk).SHA1 ?? string.Empty;
- }
- else if (item.ItemType == ItemType.Media)
- {
- md5 = (item as Media).MD5 ?? string.Empty;
- sha1 = (item as Media).SHA1 ?? string.Empty;
- sha256 = (item as Media).SHA256 ?? string.Empty;
- }
- else if (item.ItemType == ItemType.Rom)
- {
- crc = (item as Rom).CRC ?? string.Empty;
- md5 = (item as Rom).MD5 ?? string.Empty;
+ datItem.Name = (datItem.Name == "null" ? "-" : datItem.Name);
+ rom.Size = Constants.SizeZero;
+ rom.CRC = rom.CRC == "null" ? Constants.CRCZero : null;
+ rom.MD5 = rom.MD5 == "null" ? Constants.MD5Zero : null;
#if NET_FRAMEWORK
- ripemd160 = (item as Rom).RIPEMD160 ?? string.Empty;
+ rom.RIPEMD160 = rom.RIPEMD160 == "null" ? Constants.RIPEMD160Zero : null;
#endif
- sha1 = (item as Rom).SHA1 ?? string.Empty;
- sha256 = (item as Rom).SHA256 ?? string.Empty;
- sha384 = (item as Rom).SHA384 ?? string.Empty;
- sha512 = (item as Rom).SHA512 ?? string.Empty;
- size = (item as Rom).Size.ToString();
+ rom.SHA1 = rom.SHA1 == "null" ? Constants.SHA1Zero : null;
+ rom.SHA256 = rom.SHA256 == "null" ? Constants.SHA256Zero : null;
+ rom.SHA384 = rom.SHA384 == "null" ? Constants.SHA384Zero : null;
+ rom.SHA512 = rom.SHA512 == "null" ? Constants.SHA512Zero : null;
}
- // Now do bulk replacement where possible
- fix = fix
- .Replace("%game%", game)
- .Replace("%machine%", game)
- .Replace("%name%", name)
- .Replace("%manufacturer%", item.Machine.Manufacturer ?? string.Empty)
- .Replace("%publisher%", item.Machine.Publisher ?? string.Empty)
- .Replace("%category%", item.Machine.Category ?? string.Empty)
- .Replace("%crc%", crc)
- .Replace("%md5%", md5)
- .Replace("%ripemd160%", ripemd160)
- .Replace("%sha1%", sha1)
- .Replace("%sha256%", sha256)
- .Replace("%sha384%", sha384)
- .Replace("%sha512%", sha512)
- .Replace("%size%", size);
+ return rom;
+ }
- // TODO: Add GameName logic here too?
+ ///
+ /// Get if an item should be ignored on write
+ ///
+ /// DatItem to check
+ /// True if blank roms should be skipped on output, false otherwise
+ /// True if the item should be skipped on write, false otherwise
+ protected bool ShouldIgnore(DatItem datItem, bool ignoreBlanks)
+ {
+ // If the item is supposed to be removed, we ignore
+ if (datItem.Remove)
+ return true;
- return fix;
+ // If we have the Blank dat item, we ignore
+ if (datItem.ItemType == ItemType.Blank)
+ return true;
+
+ // If we're ignoring blanks and we have a Rom
+ if (ignoreBlanks && datItem.ItemType == ItemType.Rom)
+ {
+ Rom rom = datItem as Rom;
+
+ // If we have a 0-size or blank rom, then we ignore
+ if (rom.Size == 0 || rom.Size == -1)
+ return true;
+ }
+
+ return false;
}
#endregion
diff --git a/SabreTools.Library/DatFiles/DosCenter.cs b/SabreTools.Library/DatFiles/DosCenter.cs
index 79331f8f..6d8b2b5d 100644
--- a/SabreTools.Library/DatFiles/DosCenter.cs
+++ b/SabreTools.Library/DatFiles/DosCenter.cs
@@ -30,13 +30,7 @@ namespace SabreTools.Library.DatFiles
/// Name of the file to be parsed
/// Index ID for the DAT
/// True if full pathnames are to be kept, false otherwise (default)
- protected override void ParseFile(
- // Standard Dat parsing
- string filename,
- int indexId,
-
- // Miscellaneous
- bool keep)
+ protected override void ParseFile(string filename, int indexId, bool keep)
{
// Open a file reader
Encoding enc = FileExtensions.GetEncoding(filename);
@@ -138,12 +132,7 @@ namespace SabreTools.Library.DatFiles
/// ClrMameProReader to use to parse the header
/// Name of the file to be parsed
/// Index ID for the DAT
- private void ReadGame(
- ClrMameProReader cmpr,
-
- // Standard Dat parsing
- string filename,
- int indexId)
+ private void ReadGame(ClrMameProReader cmpr, string filename, int indexId)
{
// Prepare all internal variables
bool containsItems = false;
@@ -295,57 +284,34 @@ namespace SabreTools.Library.DatFiles
// Use a sorted list of games to output
foreach (string key in Items.SortedKeys)
{
- List roms = Items[key];
+ List datItems = Items.FilteredItems(key);
// Resolve the names in the block
- roms = DatItem.ResolveNames(roms);
+ datItems = DatItem.ResolveNames(datItems);
- for (int index = 0; index < roms.Count; index++)
+ for (int index = 0; index < datItems.Count; index++)
{
- DatItem rom = roms[index];
+ DatItem datItem = datItems[index];
- // There are apparently times when a null rom can skip by, skip them
- if (rom.Name == null || rom.Machine.Name == null)
- {
- Globals.Logger.Warning("Null rom found!");
- continue;
- }
-
- List newsplit = rom.Machine.Name.Split('\\').ToList();
+ List newsplit = datItem.Machine.Name.Split('\\').ToList();
// If we have a different game and we're not at the start of the list, output the end of last item
- if (lastgame != null && lastgame.ToLowerInvariant() != rom.Machine.Name.ToLowerInvariant())
+ if (lastgame != null && lastgame.ToLowerInvariant() != datItem.Machine.Name.ToLowerInvariant())
WriteEndGame(cmpw);
// If we have a new game, output the beginning of the new item
- if (lastgame == null || lastgame.ToLowerInvariant() != rom.Machine.Name.ToLowerInvariant())
- WriteStartGame(cmpw, rom);
+ if (lastgame == null || lastgame.ToLowerInvariant() != datItem.Machine.Name.ToLowerInvariant())
+ WriteStartGame(cmpw, datItem);
- // If we have a "null" game (created by DATFromDir or something similar), log it to file
- if (rom.ItemType == ItemType.Rom
- && (rom as Rom).Size == -1
- && (rom as Rom).CRC == "null")
- {
- Globals.Logger.Verbose($"Empty folder found: {rom.Machine.Name}");
+ // Check for a "null" item
+ datItem = ProcessNullifiedItem(datItem);
- rom.Name = (rom.Name == "null" ? "-" : rom.Name);
- (rom as Rom).Size = Constants.SizeZero;
- (rom as Rom).CRC = (rom as Rom).CRC == "null" ? Constants.CRCZero : null;
- (rom as Rom).MD5 = (rom as Rom).MD5 == "null" ? Constants.MD5Zero : null;
-#if NET_FRAMEWORK
- (rom as Rom).RIPEMD160 = (rom as Rom).RIPEMD160 == "null" ? Constants.RIPEMD160Zero : null;
-#endif
- (rom as Rom).SHA1 = (rom as Rom).SHA1 == "null" ? Constants.SHA1Zero : null;
- (rom as Rom).SHA256 = (rom as Rom).SHA256 == "null" ? Constants.SHA256Zero : null;
- (rom as Rom).SHA384 = (rom as Rom).SHA384 == "null" ? Constants.SHA384Zero : null;
- (rom as Rom).SHA512 = (rom as Rom).SHA512 == "null" ? Constants.SHA512Zero : null;
- }
-
- // Now, output the rom data
- WriteDatItem(cmpw, rom, ignoreblanks);
+ // Write out the item if we're not ignoring
+ if (!ShouldIgnore(datItem, ignoreblanks))
+ WriteDatItem(cmpw, datItem);
// Set the new data to compare against
- lastgame = rom.Machine.Name;
+ lastgame = datItem.Machine.Name;
}
}
@@ -454,14 +420,9 @@ namespace SabreTools.Library.DatFiles
///
/// ClrMameProWriter to output to
/// DatItem object to be output
- /// True if blank roms should be skipped on output, false otherwise (default)
/// True if the data was written, false on error
- private bool WriteDatItem(ClrMameProWriter cmpw, DatItem datItem, bool ignoreblanks = false)
+ private bool WriteDatItem(ClrMameProWriter cmpw, DatItem datItem)
{
- // If we are in ignore blanks mode AND we have a blank (0-size) rom, skip
- if (ignoreblanks && (datItem.ItemType == ItemType.Rom && ((datItem as Rom).Size == 0 || (datItem as Rom).Size == -1)))
- return true;
-
try
{
// Pre-process the item name
diff --git a/SabreTools.Library/DatFiles/EverdriveSmdb.cs b/SabreTools.Library/DatFiles/EverdriveSmdb.cs
index e6737502..26766754 100644
--- a/SabreTools.Library/DatFiles/EverdriveSmdb.cs
+++ b/SabreTools.Library/DatFiles/EverdriveSmdb.cs
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.IO;
+using System.Linq;
using System.Text;
using SabreTools.Library.Data;
@@ -29,13 +30,7 @@ namespace SabreTools.Library.DatFiles
/// Name of the file to be parsed
/// Index ID for the DAT
/// True if full pathnames are to be kept, false otherwise (default)
- protected override void ParseFile(
- // Standard Dat parsing
- string filename,
- int indexId,
-
- // Miscellaneous
- bool keep)
+ protected override void ParseFile(string filename, int indexId, bool keep)
{
// Open a file reader
Encoding enc = FileExtensions.GetEncoding(filename);
@@ -117,34 +112,21 @@ namespace SabreTools.Library.DatFiles
// Use a sorted list of games to output
foreach (string key in Items.SortedKeys)
{
- List roms = Items[key];
+ List datItems = Items.FilteredItems(key);
// Resolve the names in the block
- roms = DatItem.ResolveNames(roms);
+ datItems = DatItem.ResolveNames(datItems);
- for (int index = 0; index < roms.Count; index++)
+ for (int index = 0; index < datItems.Count; index++)
{
- DatItem item = roms[index];
+ DatItem datItem = datItems[index];
- // There are apparently times when a null rom can skip by, skip them
- if (item.Name == null || item.Machine.Name == null)
- {
- Globals.Logger.Warning("Null rom found!");
- continue;
- }
+ // Check for a "null" item
+ datItem = ProcessNullifiedItem(datItem);
- // If we have a "null" game (created by DATFromDir or something similar), log it to file
- if (item.ItemType == ItemType.Rom
- && ((Rom)item).Size == -1
- && ((Rom)item).CRC == "null")
- {
- Globals.Logger.Verbose($"Empty folder found: {item.Machine.Name}");
-
- item.Name = (item.Name == "null" ? "-" : item.Name);
- ((Rom)item).Size = Constants.SizeZero;
- }
-
- WriteDatItem(svw, item, ignoreblanks);
+ // Write out the item if we're not ignoring
+ if (!ShouldIgnore(datItem, ignoreblanks))
+ WriteDatItem(svw, datItem);
}
}
@@ -167,12 +149,8 @@ namespace SabreTools.Library.DatFiles
/// SeparatedValueWriter to output to
/// DatItem object to be output
/// True if the data was written, false on error
- private bool WriteDatItem(SeparatedValueWriter svw, DatItem datItem, bool ignoreblanks = false)
+ private bool WriteDatItem(SeparatedValueWriter svw, DatItem datItem)
{
- // If we are in ignore blanks mode AND we have a blank (0-size) rom, skip
- if (ignoreblanks && (datItem.ItemType == ItemType.Rom && ((datItem as Rom).Size == 0 || (datItem as Rom).Size == -1)))
- return true;
-
try
{
// No game should start with a path separator
diff --git a/SabreTools.Library/DatFiles/Hashfile.cs b/SabreTools.Library/DatFiles/Hashfile.cs
index 204f51e2..ce813b47 100644
--- a/SabreTools.Library/DatFiles/Hashfile.cs
+++ b/SabreTools.Library/DatFiles/Hashfile.cs
@@ -34,13 +34,7 @@ namespace SabreTools.Library.DatFiles
/// Name of the file to be parsed
/// Index ID for the DAT
/// True if full pathnames are to be kept, false otherwise (default)
- protected override void ParseFile(
- // Standard Dat parsing
- string filename,
- int indexId,
-
- // Miscellaneous
- bool keep)
+ protected override void ParseFile(string filename, int indexId, bool keep)
{
// Open a file reader
Encoding enc = FileExtensions.GetEncoding(filename);
@@ -132,32 +126,21 @@ namespace SabreTools.Library.DatFiles
// Use a sorted list of games to output
foreach (string key in Items.SortedKeys)
{
- List roms = Items[key];
+ List datItems = Items[key];
// Resolve the names in the block
- roms = DatItem.ResolveNames(roms);
+ datItems = DatItem.ResolveNames(datItems);
- for (int index = 0; index < roms.Count; index++)
+ for (int index = 0; index < datItems.Count; index++)
{
- DatItem rom = roms[index];
+ DatItem datItem = datItems[index];
- // There are apparently times when a null rom can skip by, skip them
- if (rom.Name == null || rom.Machine.Name == null)
- {
- Globals.Logger.Warning("Null rom found!");
- continue;
- }
+ // Check for a "null" item
+ datItem = ProcessNullifiedItem(datItem);
- // If we have a "null" game (created by DATFromDir or something similar), log it to file
- if (rom.ItemType == ItemType.Rom
- && ((Rom)rom).Size == -1
- && ((Rom)rom).CRC == "null")
- {
- Globals.Logger.Verbose($"Empty folder found: {rom.Machine.Name}");
- }
-
- // Now, output the rom data
- WriteDatItem(svw, rom, ignoreblanks);
+ // Write out the item if we're not ignoring
+ if (!ShouldIgnore(datItem, ignoreblanks))
+ WriteDatItem(svw, datItem);
}
}
@@ -179,14 +162,9 @@ namespace SabreTools.Library.DatFiles
///
/// SeparatedValueWriter to output to
/// DatItem object to be output
- /// True if blank roms should be skipped on output, false otherwise (default)
/// True if the data was written, false on error
- private bool WriteDatItem(SeparatedValueWriter svw, DatItem datItem, bool ignoreblanks = false)
+ private bool WriteDatItem(SeparatedValueWriter svw, DatItem datItem)
{
- // If we are in ignore blanks mode AND we have a blank (0-size) rom, skip
- if (ignoreblanks && (datItem.ItemType == ItemType.Rom && ((datItem as Rom).Size == 0 || (datItem as Rom).Size == -1)))
- return true;
-
try
{
// Build the state
diff --git a/SabreTools.Library/DatFiles/ItemDictionary.cs b/SabreTools.Library/DatFiles/ItemDictionary.cs
index a97bcf4a..60179f49 100644
--- a/SabreTools.Library/DatFiles/ItemDictionary.cs
+++ b/SabreTools.Library/DatFiles/ItemDictionary.cs
@@ -336,6 +336,31 @@ namespace SabreTools.Library.DatFiles
return false;
}
+ ///
+ /// Get a list of filtered items for a given key
+ ///
+ /// Key in the dictionary to retrieve
+ public List FilteredItems(string key)
+ {
+ lock (key)
+ {
+ // Get the list, if possible
+ List fi = items[key];
+ if (fi == null)
+ return new List();
+
+ // Filter the list
+ fi = fi.Where(i => i != null)
+ .Where(i => !i.Remove)
+ .Where(i => i.Name != null)
+ .Where(i => i.Machine?.Name != null)
+ .ToList();
+
+ // Return the list
+ return fi;
+ }
+ }
+
///
/// Remove a key from the file dictionary if it exists
///
diff --git a/SabreTools.Library/DatFiles/Json.cs b/SabreTools.Library/DatFiles/Json.cs
index d67237a1..6536563c 100644
--- a/SabreTools.Library/DatFiles/Json.cs
+++ b/SabreTools.Library/DatFiles/Json.cs
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.IO;
+using System.Linq;
using System.Text;
using SabreTools.Library.Data;
@@ -32,13 +33,7 @@ namespace SabreTools.Library.DatFiles
/// Name of the file to be parsed
/// Index ID for the DAT
/// True if full pathnames are to be kept, false otherwise (default)
- protected override void ParseFile(
- // Standard Dat parsing
- string filename,
- int indexId,
-
- // Miscellaneous
- bool keep)
+ protected override void ParseFile(string filename, int indexId, bool keep)
{
// Prepare all internal variables
StreamReader sr = new StreamReader(FileExtensions.TryOpenRead(filename), new UTF8Encoding(false));
@@ -112,12 +107,7 @@ namespace SabreTools.Library.DatFiles
/// JsonTextReader to use to parse the machine
/// Name of the file to be parsed
/// Index ID for the DAT
- private void ReadMachines(
- JsonTextReader jtr,
-
- // Standard Dat parsing
- string filename,
- int indexId)
+ private void ReadMachines(JsonTextReader jtr, string filename, int indexId)
{
// If the reader is invalid, skip
if (jtr == null)
@@ -141,12 +131,7 @@ namespace SabreTools.Library.DatFiles
/// JObject representing a single machine
/// Name of the file to be parsed
/// Index ID for the DAT
- private void ReadMachine(
- JObject machineObj,
-
- // Standard Dat parsing
- string filename,
- int indexId)
+ private void ReadMachine(JObject machineObj, string filename, int indexId)
{
// If object is invalid, skip it
if (machineObj == null)
@@ -299,55 +284,32 @@ namespace SabreTools.Library.DatFiles
// Use a sorted list of games to output
foreach (string key in Items.SortedKeys)
{
- List roms = Items[key];
+ List datItems = Items.FilteredItems(key);
// Resolve the names in the block
- roms = DatItem.ResolveNames(roms);
+ datItems = DatItem.ResolveNames(datItems);
- for (int index = 0; index < roms.Count; index++)
+ for (int index = 0; index < datItems.Count; index++)
{
- DatItem rom = roms[index];
-
- // There are apparently times when a null rom can skip by, skip them
- if (rom.Name == null || rom.Machine.Name == null)
- {
- Globals.Logger.Warning("Null rom found!");
- continue;
- }
+ DatItem datItem = datItems[index];
// If we have a different game and we're not at the start of the list, output the end of last item
- if (lastgame != null && lastgame.ToLowerInvariant() != rom.Machine.Name.ToLowerInvariant())
+ if (lastgame != null && lastgame.ToLowerInvariant() != datItem.Machine.Name.ToLowerInvariant())
WriteEndGame(jtw);
// If we have a new game, output the beginning of the new item
- if (lastgame == null || lastgame.ToLowerInvariant() != rom.Machine.Name.ToLowerInvariant())
- WriteStartGame(jtw, rom);
+ if (lastgame == null || lastgame.ToLowerInvariant() != datItem.Machine.Name.ToLowerInvariant())
+ WriteStartGame(jtw, datItem);
- // If we have a "null" game (created by DATFromDir or something similar), log it to file
- if (rom.ItemType == ItemType.Rom
- && (rom as Rom).Size == -1
- && (rom as Rom).CRC == "null")
- {
- Globals.Logger.Verbose($"Empty folder found: {rom.Machine.Name}");
+ // Check for a "null" item
+ datItem = ProcessNullifiedItem(datItem);
- rom.Name = (rom.Name == "null" ? "-" : rom.Name);
- (rom as Rom).Size = Constants.SizeZero;
- (rom as Rom).CRC = (rom as Rom).CRC == "null" ? Constants.CRCZero : null;
- (rom as Rom).MD5 = (rom as Rom).MD5 == "null" ? Constants.MD5Zero : null;
-#if NET_FRAMEWORK
- (rom as Rom).RIPEMD160 = (rom as Rom).RIPEMD160 == "null" ? Constants.RIPEMD160Zero : null;
-#endif
- (rom as Rom).SHA1 = (rom as Rom).SHA1 == "null" ? Constants.SHA1Zero : null;
- (rom as Rom).SHA256 = (rom as Rom).SHA256 == "null" ? Constants.SHA256Zero : null;
- (rom as Rom).SHA384 = (rom as Rom).SHA384 == "null" ? Constants.SHA384Zero : null;
- (rom as Rom).SHA512 = (rom as Rom).SHA512 == "null" ? Constants.SHA512Zero : null;
- }
-
- // Now, output the rom data
- WriteDatItem(jtw, rom, ignoreblanks);
+ // Write out the item if we're not ignoring
+ if (!ShouldIgnore(datItem, ignoreblanks))
+ WriteDatItem(jtw, datItem);
// Set the new data to compare against
- lastgame = rom.Machine.Name;
+ lastgame = datItem.Machine.Name;
}
}
@@ -463,18 +425,9 @@ namespace SabreTools.Library.DatFiles
///
/// JsonTextWriter to output to
/// DatItem object to be output
- /// True if blank roms should be skipped on output, false otherwise (default)
/// True if the data was written, false on error
- private bool WriteDatItem(JsonTextWriter jtw, DatItem datItem, bool ignoreblanks = false)
+ private bool WriteDatItem(JsonTextWriter jtw, DatItem datItem)
{
- // If we are in ignore blanks mode AND we have a blank (0-size) rom, skip
- if (ignoreblanks && (datItem.ItemType == ItemType.Rom && ((datItem as Rom).Size == 0 || (datItem as Rom).Size == -1)))
- return true;
-
- // If we have the blank item type somehow, skip
- if (datItem.ItemType == ItemType.Blank)
- return true;
-
try
{
// Pre-process the item name
diff --git a/SabreTools.Library/DatFiles/Listrom.cs b/SabreTools.Library/DatFiles/Listrom.cs
index 5828947d..6646d19a 100644
--- a/SabreTools.Library/DatFiles/Listrom.cs
+++ b/SabreTools.Library/DatFiles/Listrom.cs
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.IO;
+using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
@@ -40,13 +41,7 @@ namespace SabreTools.Library.DatFiles
/// 6331.sound-u8 32 BAD CRC(1d298cb0) SHA1(bb0bb62365402543e3154b9a77be9c75010e6abc) BAD_DUMP
/// 16v8h-blue.u24 279 NO GOOD DUMP KNOWN
///
- protected override void ParseFile(
- // Standard Dat parsing
- string filename,
- int indexId,
-
- // Miscellaneous
- bool keep)
+ protected override void ParseFile(string filename, int indexId, bool keep)
{
// Open a file reader
Encoding enc = FileExtensions.GetEncoding(filename);
@@ -292,52 +287,32 @@ namespace SabreTools.Library.DatFiles
// Use a sorted list of games to output
foreach (string key in Items.SortedKeys)
{
- List roms = Items[key];
+ List datItems = Items.FilteredItems(key);
// Resolve the names in the block
- roms = DatItem.ResolveNames(roms);
+ datItems = DatItem.ResolveNames(datItems);
- for (int index = 0; index < roms.Count; index++)
+ for (int index = 0; index < datItems.Count; index++)
{
- DatItem rom = roms[index];
-
- // There are apparently times when a null rom can skip by, skip them
- if (rom.Name == null || rom.Machine.Name == null)
- {
- Globals.Logger.Warning("Null rom found!");
- continue;
- }
+ DatItem datItem = datItems[index];
// If we have a different game and we're not at the start of the list, output the end of last item
- if (lastgame != null && lastgame.ToLowerInvariant() != rom.Machine.Name.ToLowerInvariant())
+ if (lastgame != null && lastgame.ToLowerInvariant() != datItem.Machine.Name.ToLowerInvariant())
WriteEndGame(sw);
// If we have a new game, output the beginning of the new item
- if (lastgame == null || lastgame.ToLowerInvariant() != rom.Machine.Name.ToLowerInvariant())
- WriteStartGame(sw, rom);
+ if (lastgame == null || lastgame.ToLowerInvariant() != datItem.Machine.Name.ToLowerInvariant())
+ WriteStartGame(sw, datItem);
- // If we have a "null" game (created by DATFromDir or something similar), log it to file
- if (rom.ItemType == ItemType.Rom
- && (rom as Rom).Size == -1
- && (rom as Rom).CRC == "null")
- {
- Globals.Logger.Verbose($"Empty folder found: {rom.Machine.Name}");
+ // Check for a "null" item
+ datItem = ProcessNullifiedItem(datItem);
- rom.Name = (rom.Name == "null" ? "-" : rom.Name);
- (rom as Rom).Size = Constants.SizeZero;
- (rom as Rom).CRC = (rom as Rom).CRC == "null" ? Constants.CRCZero : null;
- (rom as Rom).MD5 = (rom as Rom).MD5 == "null" ? Constants.MD5Zero : null;
- (rom as Rom).SHA1 = (rom as Rom).SHA1 == "null" ? Constants.SHA1Zero : null;
- (rom as Rom).SHA256 = (rom as Rom).SHA256 == "null" ? Constants.SHA256Zero : null;
- (rom as Rom).SHA384 = (rom as Rom).SHA384 == "null" ? Constants.SHA384Zero : null;
- (rom as Rom).SHA512 = (rom as Rom).SHA512 == "null" ? Constants.SHA512Zero : null;
- }
-
- // Now, output the rom data
- WriteDatItem(sw, rom, ignoreblanks);
+ // Write out the item if we're not ignoring
+ if (!ShouldIgnore(datItem, ignoreblanks))
+ WriteDatItem(sw, datItem);
// Set the new data to compare against
- lastgame = rom.Machine.Name;
+ lastgame = datItem.Machine.Name;
}
}
@@ -410,14 +385,9 @@ namespace SabreTools.Library.DatFiles
///
/// StreamWriter to output to
/// DatItem object to be output
- /// True if blank roms should be skipped on output, false otherwise (default)
/// True if the data was written, false on error
- private bool WriteDatItem(StreamWriter sw, DatItem datItem, bool ignoreblanks = false)
+ private bool WriteDatItem(StreamWriter sw, DatItem datItem)
{
- // If we are in ignore blanks mode AND we have a blank (0-size) rom, skip
- if (ignoreblanks && (datItem.ItemType == ItemType.Rom && ((datItem as Rom).Size == 0 || (datItem as Rom).Size == -1)))
- return true;
-
try
{
// Pre-process the item name
diff --git a/SabreTools.Library/DatFiles/Listxml.cs b/SabreTools.Library/DatFiles/Listxml.cs
index 6e264fa7..b78844b4 100644
--- a/SabreTools.Library/DatFiles/Listxml.cs
+++ b/SabreTools.Library/DatFiles/Listxml.cs
@@ -34,13 +34,7 @@ namespace SabreTools.Library.DatFiles
/// True if full pathnames are to be kept, false otherwise (default)
///
///
- protected override void ParseFile(
- // Standard Dat parsing
- string filename,
- int indexId,
-
- // Miscellaneous
- bool keep)
+ protected override void ParseFile(string filename, int indexId, bool keep)
{
// Prepare all internal variables
XmlReader xtr = filename.GetXmlTextReader();
@@ -112,12 +106,7 @@ namespace SabreTools.Library.DatFiles
/// XmlReader representing a machine block
/// Name of the file to be parsed
/// Index ID for the DAT
- private void ReadMachine(
- XmlReader reader,
-
- // Standard Dat parsing
- string filename,
- int indexId)
+ private void ReadMachine(XmlReader reader, string filename, int indexId)
{
// If we have an empty machine, skip it
if (reader == null)
@@ -499,7 +488,7 @@ namespace SabreTools.Library.DatFiles
slot.Name = reader.GetAttribute("name");
// Now read the internal tags
- ReadSlot(reader.ReadSubtree(), slot, machine);
+ ReadSlot(reader.ReadSubtree(), slot);
// Ensure the list exists
if (machine.Slots == null)
@@ -579,8 +568,7 @@ namespace SabreTools.Library.DatFiles
///
/// XmlReader representing a machine block
/// ListXmlSlot to populate
- /// Machine information to pass to contained items
- private void ReadSlot(XmlReader reader, ListXmlSlot slot, Machine machine)
+ private void ReadSlot(XmlReader reader, ListXmlSlot slot)
{
// If we have an empty machine, skip it
if (reader == null)
@@ -981,46 +969,32 @@ namespace SabreTools.Library.DatFiles
// Use a sorted list of games to output
foreach (string key in Items.SortedKeys)
{
- List roms = Items[key];
+ List datItems = Items.FilteredItems(key);
// Resolve the names in the block
- roms = DatItem.ResolveNames(roms);
+ datItems = DatItem.ResolveNames(datItems);
- for (int index = 0; index < roms.Count; index++)
+ for (int index = 0; index < datItems.Count; index++)
{
- DatItem rom = roms[index];
-
- // There are apparently times when a null rom can skip by, skip them
- if (rom.Name == null || rom.Machine.Name == null)
- {
- Globals.Logger.Warning("Null rom found!");
- continue;
- }
+ DatItem datItem = datItems[index];
// If we have a different game and we're not at the start of the list, output the end of last item
- if (lastgame != null && lastgame.ToLowerInvariant() != rom.Machine.Name.ToLowerInvariant())
- WriteEndGame(xtw, rom);
+ if (lastgame != null && lastgame.ToLowerInvariant() != datItem.Machine.Name.ToLowerInvariant())
+ WriteEndGame(xtw, datItem);
// If we have a new game, output the beginning of the new item
- if (lastgame == null || lastgame.ToLowerInvariant() != rom.Machine.Name.ToLowerInvariant())
- WriteStartGame(xtw, rom);
+ if (lastgame == null || lastgame.ToLowerInvariant() != datItem.Machine.Name.ToLowerInvariant())
+ WriteStartGame(xtw, datItem);
- // If we have a "null" game (created by DATFromDir or something similar), log it to file
- if (rom.ItemType == ItemType.Rom
- && ((Rom)rom).Size == -1
- && ((Rom)rom).CRC == "null")
- {
- Globals.Logger.Verbose($"Empty folder found: {rom.Machine.Name}");
+ // Check for a "null" item
+ datItem = ProcessNullifiedItem(datItem);
- lastgame = rom.Machine.Name;
- continue;
- }
-
- // Now, output the rom data
- WriteDatItem(xtw, rom, ignoreblanks);
+ // Write out the item if we're not ignoring
+ if (!ShouldIgnore(datItem, ignoreblanks))
+ WriteDatItem(xtw, datItem);
// Set the new data to compare against
- lastgame = rom.Machine.Name;
+ lastgame = datItem.Machine.Name;
}
}
@@ -1514,14 +1488,9 @@ namespace SabreTools.Library.DatFiles
///
/// XmlTextWriter to output to
/// DatItem object to be output
- /// True if blank roms should be skipped on output, false otherwise (default)
/// True if the data was written, false on error
- private bool WriteDatItem(XmlTextWriter xtw, DatItem datItem, bool ignoreblanks = false)
+ private bool WriteDatItem(XmlTextWriter xtw, DatItem datItem)
{
- // If we are in ignore blanks mode AND we have a blank (0-size) rom, skip
- if (ignoreblanks && (datItem.ItemType == ItemType.Rom && ((datItem as Rom).Size == 0 || (datItem as Rom).Size == -1)))
- return true;
-
try
{
// Pre-process the item name
diff --git a/SabreTools.Library/DatFiles/Logiqx.cs b/SabreTools.Library/DatFiles/Logiqx.cs
index b7366ab1..dac92795 100644
--- a/SabreTools.Library/DatFiles/Logiqx.cs
+++ b/SabreTools.Library/DatFiles/Logiqx.cs
@@ -39,13 +39,7 @@ namespace SabreTools.Library.DatFiles
/// Name of the file to be parsed
/// Index ID for the DAT
/// True if full pathnames are to be kept, false otherwise (default)
- protected override void ParseFile(
- // Standard Dat parsing
- string filename,
- int indexId,
-
- // Miscellaneous
- bool keep)
+ protected override void ParseFile(string filename, int indexId, bool keep)
{
// Prepare all internal variables
XmlReader xtr = filename.GetXmlTextReader();
@@ -722,55 +716,32 @@ namespace SabreTools.Library.DatFiles
// Use a sorted list of games to output
foreach (string key in Items.SortedKeys)
{
- List roms = Items[key];
+ List datItems = Items.FilteredItems(key);
// Resolve the names in the block
- roms = DatItem.ResolveNames(roms);
+ datItems = DatItem.ResolveNames(datItems);
- for (int index = 0; index < roms.Count; index++)
+ for (int index = 0; index < datItems.Count; index++)
{
- DatItem rom = roms[index];
-
- // There are apparently times when a null rom can skip by, skip them
- if (rom.Name == null || rom.Machine.Name == null)
- {
- Globals.Logger.Warning("Null rom found!");
- continue;
- }
+ DatItem datItem = datItems[index];
// If we have a different game and we're not at the start of the list, output the end of last item
- if (lastgame != null && lastgame.ToLowerInvariant() != rom.Machine.Name.ToLowerInvariant())
+ if (lastgame != null && lastgame.ToLowerInvariant() != datItem.Machine.Name.ToLowerInvariant())
WriteEndGame(xtw);
// If we have a new game, output the beginning of the new item
- if (lastgame == null || lastgame.ToLowerInvariant() != rom.Machine.Name.ToLowerInvariant())
- WriteStartGame(xtw, rom);
+ if (lastgame == null || lastgame.ToLowerInvariant() != datItem.Machine.Name.ToLowerInvariant())
+ WriteStartGame(xtw, datItem);
- // If we have a "null" game (created by DATFromDir or something similar), log it to file
- if (rom.ItemType == ItemType.Rom
- && (rom as Rom).Size == -1
- && (rom as Rom).CRC == "null")
- {
- Globals.Logger.Verbose($"Empty folder found: {rom.Machine.Name}");
+ // Check for a "null" item
+ datItem = ProcessNullifiedItem(datItem);
- rom.Name = (rom.Name == "null" ? "-" : rom.Name);
- (rom as Rom).Size = Constants.SizeZero;
- (rom as Rom).CRC = (rom as Rom).CRC == "null" ? Constants.CRCZero : null;
- (rom as Rom).MD5 = (rom as Rom).MD5 == "null" ? Constants.MD5Zero : null;
-#if NET_FRAMEWORK
- (rom as Rom).RIPEMD160 = (rom as Rom).RIPEMD160 == "null" ? Constants.RIPEMD160Zero : null;
-#endif
- (rom as Rom).SHA1 = (rom as Rom).SHA1 == "null" ? Constants.SHA1Zero : null;
- (rom as Rom).SHA256 = (rom as Rom).SHA256 == "null" ? Constants.SHA256Zero : null;
- (rom as Rom).SHA384 = (rom as Rom).SHA384 == "null" ? Constants.SHA384Zero : null;
- (rom as Rom).SHA512 = (rom as Rom).SHA512 == "null" ? Constants.SHA512Zero : null;
- }
-
- // Now, output the rom data
- WriteDatItem(xtw, rom, ignoreblanks);
+ // Write out the item if we're not ignoring
+ if (!ShouldIgnore(datItem, ignoreblanks))
+ WriteDatItem(xtw, datItem);
// Set the new data to compare against
- lastgame = rom.Machine.Name;
+ lastgame = datItem.Machine.Name;
}
}
@@ -981,14 +952,9 @@ namespace SabreTools.Library.DatFiles
///
/// XmlTextWriter to output to
/// DatItem object to be output
- /// True if blank roms should be skipped on output, false otherwise (default)
/// True if the data was written, false on error
- private bool WriteDatItem(XmlTextWriter xtw, DatItem datItem, bool ignoreblanks = false)
+ private bool WriteDatItem(XmlTextWriter xtw, DatItem datItem)
{
- // If we are in ignore blanks mode AND we have a blank (0-size) rom, skip
- if (ignoreblanks && (datItem.ItemType == ItemType.Rom && ((datItem as Rom).Size == 0 || (datItem as Rom).Size == -1)))
- return true;
-
try
{
// Pre-process the item name
diff --git a/SabreTools.Library/DatFiles/Missfile.cs b/SabreTools.Library/DatFiles/Missfile.cs
index 4a507cb1..445c7664 100644
--- a/SabreTools.Library/DatFiles/Missfile.cs
+++ b/SabreTools.Library/DatFiles/Missfile.cs
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.IO;
+using System.Linq;
using System.Text;
using SabreTools.Library.Data;
@@ -29,13 +30,7 @@ namespace SabreTools.Library.DatFiles
/// Name of the file to be parsed
/// Index ID for the DAT
/// True if full pathnames are to be kept, false otherwise (default)
- protected override void ParseFile(
- // Standard Dat parsing
- string filename,
- int indexId,
-
- // Miscellaneous
- bool keep)
+ protected override void ParseFile(string filename, int indexId, bool keep)
{
// There is no consistent way to parse a missfile...
throw new NotImplementedException();
@@ -69,37 +64,24 @@ namespace SabreTools.Library.DatFiles
// Use a sorted list of games to output
foreach (string key in Items.SortedKeys)
{
- List roms = Items[key];
+ List datItems = Items.FilteredItems(key);
// Resolve the names in the block
- roms = DatItem.ResolveNames(roms);
+ datItems = DatItem.ResolveNames(datItems);
- for (int index = 0; index < roms.Count; index++)
+ for (int index = 0; index < datItems.Count; index++)
{
- DatItem rom = roms[index];
+ DatItem datItem = datItems[index];
- // There are apparently times when a null rom can skip by, skip them
- if (rom.Name == null || rom.Machine.Name == null)
- {
- Globals.Logger.Warning("Null rom found!");
- continue;
- }
+ // Check for a "null" item
+ datItem = ProcessNullifiedItem(datItem);
- // If we have a "null" game (created by DATFromDir or something similar), log it to file
- if (rom.ItemType == ItemType.Rom
- && (rom as Rom).Size == -1
- && (rom as Rom).CRC == "null")
- {
- Globals.Logger.Verbose($"Empty folder found: {rom.Machine.Name}");
- lastgame = rom.Machine.Name;
- continue;
- }
-
- // Now, output the rom data
- WriteDatItem(sw, rom, lastgame, ignoreblanks);
+ // Write out the item if we're not ignoring
+ if (!ShouldIgnore(datItem, ignoreblanks))
+ WriteDatItem(sw, datItem, lastgame);
// Set the new data to compare against
- lastgame = rom.Machine.Name;
+ lastgame = datItem.Machine.Name;
}
}
@@ -122,14 +104,9 @@ namespace SabreTools.Library.DatFiles
/// StreamWriter to output to
/// DatItem object to be output
/// The name of the last game to be output
- /// True if blank roms should be skipped on output, false otherwise (default)
/// True if the data was written, false on error
- private bool WriteDatItem(StreamWriter sw, DatItem datItem, string lastgame, bool ignoreblanks = false)
+ private bool WriteDatItem(StreamWriter sw, DatItem datItem, string lastgame)
{
- // If we are in ignore blanks mode AND we have a blank (0-size) rom, skip
- if (ignoreblanks && (datItem.ItemType == ItemType.Rom && ((datItem as Rom).Size == 0 || (datItem as Rom).Size == -1)))
- return true;
-
try
{
// Process the item name
diff --git a/SabreTools.Library/DatFiles/OfflineList.cs b/SabreTools.Library/DatFiles/OfflineList.cs
index d6012cd8..938393b3 100644
--- a/SabreTools.Library/DatFiles/OfflineList.cs
+++ b/SabreTools.Library/DatFiles/OfflineList.cs
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.IO;
+using System.Linq;
using System.Text;
using System.Xml;
@@ -31,15 +32,7 @@ namespace SabreTools.Library.DatFiles
/// Name of the file to be parsed
/// Index ID for the DAT
/// True if full pathnames are to be kept, false otherwise (default)
- ///
- ///
- protected override void ParseFile(
- // Standard Dat parsing
- string filename,
- int indexId,
-
- // Miscellaneous
- bool keep)
+ protected override void ParseFile(string filename, int indexId, bool keep)
{
XmlReader xtr = filename.GetXmlTextReader();
@@ -427,12 +420,7 @@ namespace SabreTools.Library.DatFiles
/// XmlReader to use to parse the header
/// Name of the file to be parsed
/// Index ID for the DAT
- private void ReadGames(
- XmlReader reader,
-
- // Standard Dat parsing
- string filename,
- int indexId)
+ private void ReadGames(XmlReader reader, string filename, int indexId)
{
// If there's no subtree to the configuration, skip it
if (reader == null)
@@ -474,12 +462,7 @@ namespace SabreTools.Library.DatFiles
/// XmlReader to use to parse the header
/// Name of the file to be parsed
/// Index ID for the DAT
- private void ReadGame(
- XmlReader reader,
-
- // Standard Dat parsing
- string filename,
- int indexId)
+ private void ReadGame(XmlReader reader, string filename, int indexId)
{
// Prepare all internal variables
string releaseNumber = string.Empty, duplicateid;
@@ -707,47 +690,24 @@ namespace SabreTools.Library.DatFiles
// Use a sorted list of games to output
foreach (string key in Items.SortedKeys)
{
- List roms = Items[key];
+ List datItems = Items.FilteredItems(key);
// Resolve the names in the block
- roms = DatItem.ResolveNames(roms);
+ datItems = DatItem.ResolveNames(datItems);
- for (int index = 0; index < roms.Count; index++)
+ for (int index = 0; index < datItems.Count; index++)
{
- DatItem rom = roms[index];
+ DatItem datItem = datItems[index];
- // There are apparently times when a null rom can skip by, skip them
- if (rom.Name == null || rom.Machine.Name == null)
- {
- Globals.Logger.Warning("Null rom found!");
- continue;
- }
+ // Check for a "null" item
+ datItem = ProcessNullifiedItem(datItem);
- // If we have a "null" game (created by DATFromDir or something similar), log it to file
- if (rom.ItemType == ItemType.Rom
- && (rom as Rom).Size == -1
- && (rom as Rom).CRC == "null")
- {
- Globals.Logger.Verbose($"Empty folder found: {rom.Machine.Name}");
-
- rom.Name = (rom.Name == "null" ? "-" : rom.Name);
- (rom as Rom).Size = Constants.SizeZero;
- (rom as Rom).CRC = (rom as Rom).CRC == "null" ? Constants.CRCZero : null;
- (rom as Rom).MD5 = (rom as Rom).MD5 == "null" ? Constants.MD5Zero : null;
-#if NET_FRAMEWORK
- (rom as Rom).RIPEMD160 = (rom as Rom).RIPEMD160 == "null" ? Constants.RIPEMD160Zero : null;
-#endif
- (rom as Rom).SHA1 = (rom as Rom).SHA1 == "null" ? Constants.SHA1Zero : null;
- (rom as Rom).SHA256 = (rom as Rom).SHA256 == "null" ? Constants.SHA256Zero : null;
- (rom as Rom).SHA384 = (rom as Rom).SHA384 == "null" ? Constants.SHA384Zero : null;
- (rom as Rom).SHA512 = (rom as Rom).SHA512 == "null" ? Constants.SHA512Zero : null;
- }
-
- // Now, output the rom data
- WriteDatItem(xtw, rom, ignoreblanks);
+ // Write out the item if we're not ignoring
+ if (!ShouldIgnore(datItem, ignoreblanks))
+ WriteDatItem(xtw, datItem);
// Set the new data to compare against
- lastgame = rom.Machine.Name;
+ lastgame = datItem.Machine.Name;
}
}
@@ -896,14 +856,9 @@ namespace SabreTools.Library.DatFiles
///
/// XmlTextWriter to output to
/// DatItem object to be output
- /// True if blank roms should be skipped on output, false otherwise (default)
/// True if the data was written, false on error
- private bool WriteDatItem(XmlTextWriter xtw, DatItem datItem, bool ignoreblanks = false)
+ private bool WriteDatItem(XmlTextWriter xtw, DatItem datItem)
{
- // If we are in ignore blanks mode AND we have a blank (0-size) rom, skip
- if (ignoreblanks && (datItem.ItemType == ItemType.Rom && ((datItem as Rom).Size == 0 || (datItem as Rom).Size == -1)))
- return true;
-
try
{
// Pre-process the item name
diff --git a/SabreTools.Library/DatFiles/OpenMSX.cs b/SabreTools.Library/DatFiles/OpenMSX.cs
index 5296a9c8..3fa4ad11 100644
--- a/SabreTools.Library/DatFiles/OpenMSX.cs
+++ b/SabreTools.Library/DatFiles/OpenMSX.cs
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.IO;
+using System.Linq;
using System.Text;
using System.Xml;
@@ -31,13 +32,7 @@ namespace SabreTools.Library.DatFiles
/// Name of the file to be parsed
/// Index ID for the DAT
/// True if full pathnames are to be kept, false otherwise (default)
- protected override void ParseFile(
- // Standard Dat parsing
- string filename,
- int indexId,
-
- // Miscellaneous
- bool keep)
+ protected override void ParseFile(string filename, int indexId, bool keep)
{
// Prepare all internal variables
XmlReader xtr = filename.GetXmlTextReader();
@@ -99,12 +94,7 @@ namespace SabreTools.Library.DatFiles
/// XmlReader representing a machine block
/// Name of the file to be parsed
/// Index ID for the DAT
- private void ReadSoftware(
- XmlReader reader,
-
- // Standard Dat parsing
- string filename,
- int indexId)
+ private void ReadSoftware(XmlReader reader, string filename, int indexId)
{
// If we have an empty machine, skip it
if (reader == null)
@@ -546,46 +536,32 @@ namespace SabreTools.Library.DatFiles
// Use a sorted list of games to output
foreach (string key in Items.SortedKeys)
{
- List roms = Items[key];
+ List datItems = Items.FilteredItems(key);
// Resolve the names in the block
- roms = DatItem.ResolveNames(roms);
+ datItems = DatItem.ResolveNames(datItems);
- for (int index = 0; index < roms.Count; index++)
+ for (int index = 0; index < datItems.Count; index++)
{
- DatItem rom = roms[index];
-
- // There are apparently times when a null rom can skip by, skip them
- if (rom.Name == null || rom.Machine.Name == null)
- {
- Globals.Logger.Warning("Null rom found!");
- continue;
- }
+ DatItem datItem = datItems[index];
// If we have a different game and we're not at the start of the list, output the end of last item
- if (lastgame != null && lastgame.ToLowerInvariant() != rom.Machine.Name.ToLowerInvariant())
+ if (lastgame != null && lastgame.ToLowerInvariant() != datItem.Machine.Name.ToLowerInvariant())
WriteEndGame(xtw);
// If we have a new game, output the beginning of the new item
- if (lastgame == null || lastgame.ToLowerInvariant() != rom.Machine.Name.ToLowerInvariant())
- WriteStartGame(xtw, rom);
+ if (lastgame == null || lastgame.ToLowerInvariant() != datItem.Machine.Name.ToLowerInvariant())
+ WriteStartGame(xtw, datItem);
- // If we have a "null" game (created by DATFromDir or something similar), log it to file
- if (rom.ItemType == ItemType.Rom
- && (rom as Rom).Size == -1
- && (rom as Rom).CRC == "null")
- {
- Globals.Logger.Verbose($"Empty folder found: {rom.Machine.Name}");
+ // Check for a "null" item
+ datItem = ProcessNullifiedItem(datItem);
- lastgame = rom.Machine.Name;
- continue;
- }
-
- // Now, output the rom data
- WriteDatItem(xtw, rom, ignoreblanks);
+ // Write out the item if we're not ignoring
+ if (!ShouldIgnore(datItem, ignoreblanks))
+ WriteDatItem(xtw, datItem);
// Set the new data to compare against
- lastgame = rom.Machine.Name;
+ lastgame = datItem.Machine.Name;
}
}
@@ -706,14 +682,9 @@ namespace SabreTools.Library.DatFiles
///
/// XmlTextWriter to output to
/// DatItem object to be output
- /// True if blank roms should be skipped on output, false otherwise (default)
/// True if the data was written, false on error
- private bool WriteDatItem(XmlTextWriter xtw, DatItem datItem, bool ignoreblanks = false)
+ private bool WriteDatItem(XmlTextWriter xtw, DatItem datItem)
{
- // If we are in ignore blanks mode AND we have a blank (0-size) rom, skip
- if (ignoreblanks && (datItem.ItemType == ItemType.Rom && ((datItem as Rom).Size == 0 || (datItem as Rom).Size == -1)))
- return true;
-
try
{
// Pre-process the item name
diff --git a/SabreTools.Library/DatFiles/RomCenter.cs b/SabreTools.Library/DatFiles/RomCenter.cs
index 02326f54..c01b504a 100644
--- a/SabreTools.Library/DatFiles/RomCenter.cs
+++ b/SabreTools.Library/DatFiles/RomCenter.cs
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.IO;
+using System.Linq;
using System.Text;
using SabreTools.Library.Data;
@@ -29,13 +30,7 @@ namespace SabreTools.Library.DatFiles
/// Name of the file to be parsed
/// Index ID for the DAT
/// True if full pathnames are to be kept, false otherwise (default)
- protected override void ParseFile(
- // Standard Dat parsing
- string filename,
- int indexId,
-
- // Miscellaneous
- bool keep)
+ protected override void ParseFile(string filename, int indexId, bool keep)
{
// Prepare all intenral variables
IniReader ir = filename.GetIniReader(false);
@@ -401,47 +396,24 @@ namespace SabreTools.Library.DatFiles
// Use a sorted list of games to output
foreach (string key in Items.SortedKeys)
{
- List roms = Items[key];
+ List datItems = Items.FilteredItems(key);
// Resolve the names in the block
- roms = DatItem.ResolveNames(roms);
+ datItems = DatItem.ResolveNames(datItems);
- for (int index = 0; index < roms.Count; index++)
+ for (int index = 0; index < datItems.Count; index++)
{
- DatItem rom = roms[index];
+ DatItem datItem = datItems[index];
- // There are apparently times when a null rom can skip by, skip them
- if (rom.Name == null || rom.Machine.Name == null)
- {
- Globals.Logger.Warning("Null rom found!");
- continue;
- }
+ // Check for a "null" item
+ datItem = ProcessNullifiedItem(datItem);
- // If we have a "null" game (created by DATFromDir or something similar), log it to file
- if (rom.ItemType == ItemType.Rom
- && (rom as Rom).Size == -1
- && (rom as Rom).CRC == "null")
- {
- Globals.Logger.Verbose($"Empty folder found: {rom.Machine.Name}");
-
- rom.Name = (rom.Name == "null" ? "-" : rom.Name);
- (rom as Rom).Size = Constants.SizeZero;
- (rom as Rom).CRC = (rom as Rom).CRC == "null" ? Constants.CRCZero : null;
- (rom as Rom).MD5 = (rom as Rom).MD5 == "null" ? Constants.MD5Zero : null;
-#if NET_FRAMEWORK
- (rom as Rom).RIPEMD160 = (rom as Rom).RIPEMD160 == "null" ? Constants.RIPEMD160Zero : null;
-#endif
- (rom as Rom).SHA1 = (rom as Rom).SHA1 == "null" ? Constants.SHA1Zero : null;
- (rom as Rom).SHA256 = (rom as Rom).SHA256 == "null" ? Constants.SHA256Zero : null;
- (rom as Rom).SHA384 = (rom as Rom).SHA384 == "null" ? Constants.SHA384Zero : null;
- (rom as Rom).SHA512 = (rom as Rom).SHA512 == "null" ? Constants.SHA512Zero : null;
- }
-
- // Now, output the rom data
- WriteDatItem(iw, rom, ignoreblanks);
+ // Write out the item if we're not ignoring
+ if (!ShouldIgnore(datItem, ignoreblanks))
+ WriteDatItem(iw, datItem);
// Set the new data to compare against
- lastgame = rom.Machine.Name;
+ lastgame = datItem.Machine.Name;
}
}
@@ -500,14 +472,9 @@ namespace SabreTools.Library.DatFiles
///
/// IniWriter to output to
/// DatItem object to be output
- /// True if blank roms should be skipped on output, false otherwise (default)
/// True if the data was written, false on error
- private bool WriteDatItem(IniWriter iw, DatItem datItem, bool ignoreblanks = false)
+ private bool WriteDatItem(IniWriter iw, DatItem datItem)
{
- // If we are in ignore blanks mode AND we have a blank (0-size) rom, skip
- if (ignoreblanks && (datItem.ItemType == ItemType.Rom && ((datItem as Rom).Size == 0 || (datItem as Rom).Size == -1)))
- return true;
-
/*
The rominfo order is as follows:
1 - parent name
diff --git a/SabreTools.Library/DatFiles/SabreDat.cs b/SabreTools.Library/DatFiles/SabreDat.cs
index 7ee6e46d..6fe80fdc 100644
--- a/SabreTools.Library/DatFiles/SabreDat.cs
+++ b/SabreTools.Library/DatFiles/SabreDat.cs
@@ -32,13 +32,7 @@ namespace SabreTools.Library.DatFiles
/// Name of the file to be parsed
/// Index ID for the DAT
/// True if full pathnames are to be kept, false otherwise (default)
- protected override void ParseFile(
- // Standard Dat parsing
- string filename,
- int indexId,
-
- // Miscellaneous
- bool keep)
+ protected override void ParseFile(string filename, int indexId, bool keep)
{
// Prepare all internal variables
bool empty = true;
@@ -224,7 +218,8 @@ namespace SabreTools.Library.DatFiles
/// Name of the file to be parsed
/// Index ID for the DAT
/// True if full pathnames are to be kept, false otherwise (default)
- private bool ReadDirectory(XmlReader reader,
+ private bool ReadDirectory(
+ XmlReader reader,
List parent,
// Standard Dat parsing
@@ -610,50 +605,35 @@ namespace SabreTools.Library.DatFiles
// Use a sorted list of games to output
foreach (string key in Items.SortedKeys)
{
- List roms = Items[key];
+ List datItems = Items.FilteredItems(key);
// Resolve the names in the block
- roms = DatItem.ResolveNames(roms);
+ datItems = DatItem.ResolveNames(datItems);
- for (int index = 0; index < roms.Count; index++)
+ for (int index = 0; index < datItems.Count; index++)
{
- DatItem rom = roms[index];
+ DatItem datItem = datItems[index];
- // There are apparently times when a null rom can skip by, skip them
- if (rom.Name == null || rom.Machine.Name == null)
- {
- Globals.Logger.Warning("Null rom found!");
- continue;
- }
-
- List newsplit = rom.Machine.Name.Split('\\').ToList();
+ List newsplit = datItem.Machine.Name.Split('\\').ToList();
// If we have a different game and we're not at the start of the list, output the end of last item
- if (lastgame != null && lastgame.ToLowerInvariant() != rom.Machine.Name.ToLowerInvariant())
+ if (lastgame != null && lastgame.ToLowerInvariant() != datItem.Machine.Name.ToLowerInvariant())
depth = WriteEndGame(xtw, splitpath, newsplit, depth, out last);
// If we have a new game, output the beginning of the new item
- if (lastgame == null || lastgame.ToLowerInvariant() != rom.Machine.Name.ToLowerInvariant())
- depth = WriteStartGame(xtw, rom, newsplit, depth, last);
+ if (lastgame == null || lastgame.ToLowerInvariant() != datItem.Machine.Name.ToLowerInvariant())
+ depth = WriteStartGame(xtw, datItem, newsplit, depth, last);
- // If we have a "null" game (created by DATFromDir or something similar), log it to file
- if (rom.ItemType == ItemType.Rom
- && (rom as Rom).Size == -1
- && (rom as Rom).CRC == "null")
- {
- Globals.Logger.Verbose($"Empty folder found: {rom.Machine.Name}");
+ // Check for a "null" item
+ datItem = ProcessNullifiedItem(datItem);
- splitpath = newsplit;
- lastgame = rom.Machine.Name;
- continue;
- }
-
- // Now, output the rom data
- WriteDatItem(xtw, rom, depth, ignoreblanks);
+ // Write out the item if we're not ignoring
+ if (!ShouldIgnore(datItem, ignoreblanks))
+ WriteDatItem(xtw, datItem, depth);
// Set the new data to compare against
splitpath = newsplit;
- lastgame = rom.Machine.Name;
+ lastgame = datItem.Machine.Name;
}
}
@@ -848,14 +828,9 @@ namespace SabreTools.Library.DatFiles
/// XmlTextWriter to output to
/// DatItem object to be output
/// Current depth to output file at (SabreDAT only)
- /// True if blank roms should be skipped on output, false otherwise (default)
/// True if the data was written, false on error
- private bool WriteDatItem(XmlTextWriter xtw, DatItem datItem, int depth, bool ignoreblanks = false)
+ private bool WriteDatItem(XmlTextWriter xtw, DatItem datItem, int depth)
{
- // If we are in ignore blanks mode AND we have a blank (0-size) rom, skip
- if (ignoreblanks && (datItem.ItemType == ItemType.Rom && ((datItem as Rom).Size == 0 || (datItem as Rom).Size == -1)))
- return true;
-
try
{
// Pre-process the item name
diff --git a/SabreTools.Library/DatFiles/SeparatedValue.cs b/SabreTools.Library/DatFiles/SeparatedValue.cs
index 3b33b5ab..8d2cb279 100644
--- a/SabreTools.Library/DatFiles/SeparatedValue.cs
+++ b/SabreTools.Library/DatFiles/SeparatedValue.cs
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.IO;
+using System.Linq;
using System.Text;
using SabreTools.Library.Data;
@@ -35,13 +36,7 @@ namespace SabreTools.Library.DatFiles
/// Name of the file to be parsed
/// Index ID for the DAT
/// True if full pathnames are to be kept, false otherwise (default)
- protected override void ParseFile(
- // Standard Dat parsing
- string filename,
- int indexId,
-
- // Miscellaneous
- bool keep)
+ protected override void ParseFile(string filename, int indexId, bool keep)
{
// Open a file reader
Encoding enc = FileExtensions.GetEncoding(filename);
@@ -134,32 +129,21 @@ namespace SabreTools.Library.DatFiles
// Use a sorted list of games to output
foreach (string key in Items.SortedKeys)
{
- List roms = Items[key];
+ List datItems = Items.FilteredItems(key);
// Resolve the names in the block
- roms = DatItem.ResolveNames(roms);
+ datItems = DatItem.ResolveNames(datItems);
- for (int index = 0; index < roms.Count; index++)
+ for (int index = 0; index < datItems.Count; index++)
{
- DatItem rom = roms[index];
+ DatItem datItem = datItems[index];
- // There are apparently times when a null rom can skip by, skip them
- if (rom.Name == null || rom.Machine.Name == null)
- {
- Globals.Logger.Warning("Null rom found!");
- continue;
- }
+ // Check for a "null" item
+ datItem = ProcessNullifiedItem(datItem);
- // If we have a "null" game (created by DATFromDir or something similar), log it to file
- if (rom.ItemType == ItemType.Rom
- && (rom as Rom).Size == -1
- && (rom as Rom).CRC == "null")
- {
- Globals.Logger.Verbose($"Empty folder found: {rom.Machine.Name}");
- }
-
- // Now, output the rom data
- WriteDatItem(svw, rom, ignoreblanks);
+ // Write out the item if we're not ignoring
+ if (!ShouldIgnore(datItem, ignoreblanks))
+ WriteDatItem(svw, datItem);
}
}
@@ -224,14 +208,9 @@ namespace SabreTools.Library.DatFiles
///
/// SeparatedValueWriter to output to
/// DatItem object to be output
- /// True if blank roms should be skipped on output, false otherwise (default)
/// True if the data was written, false on error
- private bool WriteDatItem(SeparatedValueWriter svw, DatItem datItem, bool ignoreblanks = false)
+ private bool WriteDatItem(SeparatedValueWriter svw, DatItem datItem)
{
- // If we are in ignore blanks mode AND we have a blank (0-size) rom, skip
- if (ignoreblanks && (datItem.ItemType == ItemType.Rom && ((datItem as Rom).Size == 0 || (datItem as Rom).Size == -1)))
- return true;
-
try
{
// Separated values should only output Rom and Disk
diff --git a/SabreTools.Library/DatFiles/SoftwareList.cs b/SabreTools.Library/DatFiles/SoftwareList.cs
index d9676ad6..658e4654 100644
--- a/SabreTools.Library/DatFiles/SoftwareList.cs
+++ b/SabreTools.Library/DatFiles/SoftwareList.cs
@@ -32,13 +32,7 @@ namespace SabreTools.Library.DatFiles
/// Name of the file to be parsed
/// Index ID for the DAT
/// True if full pathnames are to be kept, false otherwise (default)
- protected override void ParseFile(
- // Standard Dat parsing
- string filename,
- int indexId,
-
- // Miscellaneous
- bool keep)
+ protected override void ParseFile(string filename, int indexId, bool keep)
{
// Prepare all internal variables
XmlReader xtr = filename.GetXmlTextReader();
@@ -109,15 +103,7 @@ namespace SabreTools.Library.DatFiles
/// 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 ReadSoftware(
- XmlReader reader,
-
- // Standard Dat parsing
- string filename,
- int indexId,
-
- // Miscellaneous
- bool keep)
+ private void ReadSoftware(XmlReader reader, string filename, int indexId, bool keep)
{
// If we have an empty software, skip it
if (reader == null)
@@ -339,8 +325,7 @@ namespace SabreTools.Library.DatFiles
List disks = ReadDiskArea(
reader.ReadSubtree(),
areaname,
- areasize,
- keep);
+ areasize);
// If we got valid disks, add them to the list
if (disks != null)
@@ -486,17 +471,8 @@ namespace SabreTools.Library.DatFiles
/// XmlReader representing a diskarea block
/// Name of the containing area
/// Size of the containing area
- /// True if full pathnames are to be kept, false otherwise (default)
- private List ReadDiskArea(
- XmlReader reader,
- string areaname,
- long? areasize,
-
- // Miscellaneous
- bool keep)
+ private List ReadDiskArea(XmlReader reader, string areaname, long? areasize)
{
- string key = string.Empty;
- string temptype = reader.Name;
List items = new List();
while (!reader.EOF)
@@ -620,46 +596,32 @@ namespace SabreTools.Library.DatFiles
// Use a sorted list of games to output
foreach (string key in Items.SortedKeys)
{
- List roms = Items[key];
+ List datItems = Items.FilteredItems(key);
// Resolve the names in the block
- roms = DatItem.ResolveNames(roms);
+ datItems = DatItem.ResolveNames(datItems);
- for (int index = 0; index < roms.Count; index++)
+ for (int index = 0; index < datItems.Count; index++)
{
- DatItem rom = roms[index];
-
- // There are apparently times when a null rom can skip by, skip them
- if (rom.Name == null || rom.Machine.Name == null)
- {
- Globals.Logger.Warning("Null rom found!");
- continue;
- }
+ DatItem datItem = datItems[index];
// If we have a different game and we're not at the start of the list, output the end of last item
- if (lastgame != null && lastgame.ToLowerInvariant() != rom.Machine.Name.ToLowerInvariant())
+ if (lastgame != null && lastgame.ToLowerInvariant() != datItem.Machine.Name.ToLowerInvariant())
WriteEndGame(xtw);
// If we have a new game, output the beginning of the new item
- if (lastgame == null || lastgame.ToLowerInvariant() != rom.Machine.Name.ToLowerInvariant())
- WriteStartGame(xtw, rom);
+ if (lastgame == null || lastgame.ToLowerInvariant() != datItem.Machine.Name.ToLowerInvariant())
+ WriteStartGame(xtw, datItem);
- // If we have a "null" game (created by DATFromDir or something similar), log it to file
- if (rom.ItemType == ItemType.Rom
- && (rom as Rom).Size == -1
- && (rom as Rom).CRC == "null")
- {
- Globals.Logger.Verbose($"Empty folder found: {rom.Machine.Name}");
+ // Check for a "null" item
+ datItem = ProcessNullifiedItem(datItem);
- lastgame = rom.Machine.Name;
- continue;
- }
-
- // Now, output the rom data
- WriteDatItem(xtw, rom, ignoreblanks);
+ // Write out the item if we're not ignoring
+ if (!ShouldIgnore(datItem, ignoreblanks))
+ WriteDatItem(xtw, datItem);
// Set the new data to compare against
- lastgame = rom.Machine.Name;
+ lastgame = datItem.Machine.Name;
}
}
@@ -820,14 +782,9 @@ namespace SabreTools.Library.DatFiles
///
/// XmlTextWriter to output to
/// DatItem object to be output
- /// True if blank roms should be skipped on output, false otherwise (default)
/// True if the data was written, false on error
- private bool WriteDatItem(XmlTextWriter xtw, DatItem datItem, bool ignoreblanks = false)
+ private bool WriteDatItem(XmlTextWriter xtw, DatItem datItem)
{
- // If we are in ignore blanks mode AND we have a blank (0-size) rom, skip
- if (ignoreblanks && (datItem.ItemType == ItemType.Rom && ((datItem as Rom).Size == 0 || (datItem as Rom).Size == -1)))
- return true;
-
try
{
// Pre-process the item name