diff --git a/RombaSharp/RombaSharp.Helpers.cs b/RombaSharp/RombaSharp.Helpers.cs index ca0269af..abd2b518 100644 --- a/RombaSharp/RombaSharp.Helpers.cs +++ b/RombaSharp/RombaSharp.Helpers.cs @@ -296,7 +296,7 @@ namespace RombaSharp { Globals.Logger.Verbose("Checking and adding file '{0}'", datItem.Name); - if (datItem.Type == ItemType.Rom) + if (datItem.ItemType == ItemType.Rom) { Rom rom = (Rom)datItem; @@ -322,7 +322,7 @@ namespace RombaSharp } } } - else if (datItem.Type == ItemType.Disk) + else if (datItem.ItemType == ItemType.Disk) { Disk disk = (Disk)datItem; diff --git a/SabreTools.Library/DatFiles/AttractMode.cs b/SabreTools.Library/DatFiles/AttractMode.cs index 0320c4a9..31f76f0b 100644 --- a/SabreTools.Library/DatFiles/AttractMode.cs +++ b/SabreTools.Library/DatFiles/AttractMode.cs @@ -165,7 +165,7 @@ namespace SabreTools.Library.DatFiles } // If we have a "null" game (created by DATFromDir or something similar), log it to file - if (item.Type == ItemType.Rom + if (item.ItemType == ItemType.Rom && ((Rom)item).Size == -1 && ((Rom)item).CRC == "null") { diff --git a/SabreTools.Library/DatFiles/ClrMamePro.cs b/SabreTools.Library/DatFiles/ClrMamePro.cs index 897f4654..5dd0c8c2 100644 --- a/SabreTools.Library/DatFiles/ClrMamePro.cs +++ b/SabreTools.Library/DatFiles/ClrMamePro.cs @@ -433,11 +433,11 @@ namespace SabreTools.Library.DatFiles case "nodump": case "verified": ItemStatus tempStandaloneStatus = Utilities.GetItemStatus(quoteless); - if (item.Type == ItemType.Rom) + if (item.ItemType == ItemType.Rom) { ((Rom)item).ItemStatus = tempStandaloneStatus; } - else if (item.Type == ItemType.Disk) + else if (item.ItemType == ItemType.Disk) { ((Disk)item).ItemStatus = tempStandaloneStatus; } @@ -449,7 +449,7 @@ namespace SabreTools.Library.DatFiles item.Name = quoteless; break; case "size": - if (item.Type == ItemType.Rom) + if (item.ItemType == ItemType.Rom) { quoteless = linegc[++i].Replace("\"", ""); if (Int64.TryParse(quoteless, out long size)) @@ -463,19 +463,19 @@ namespace SabreTools.Library.DatFiles } break; case "crc": - if (item.Type == ItemType.Rom) + if (item.ItemType == ItemType.Rom) { quoteless = linegc[++i].Replace("\"", ""); ((Rom)item).CRC = Utilities.CleanHashData(quoteless, Constants.CRCLength); } break; case "md5": - if (item.Type == ItemType.Rom) + if (item.ItemType == ItemType.Rom) { quoteless = linegc[++i].Replace("\"", ""); ((Rom)item).MD5 = Utilities.CleanHashData(quoteless, Constants.MD5Length); } - else if (item.Type == ItemType.Disk) + else if (item.ItemType == ItemType.Disk) { i++; quoteless = linegc[i].Replace("\"", ""); @@ -483,48 +483,48 @@ namespace SabreTools.Library.DatFiles } break; case "sha1": - if (item.Type == ItemType.Rom) + if (item.ItemType == ItemType.Rom) { quoteless = linegc[++i].Replace("\"", ""); ((Rom)item).SHA1 = Utilities.CleanHashData(quoteless, Constants.SHA1Length); } - else if (item.Type == ItemType.Disk) + else if (item.ItemType == ItemType.Disk) { quoteless = linegc[++i].Replace("\"", ""); ((Disk)item).SHA1 = Utilities.CleanHashData(quoteless, Constants.SHA1Length); } break; case "sha256": - if (item.Type == ItemType.Rom) + if (item.ItemType == ItemType.Rom) { quoteless = linegc[++i].Replace("\"", ""); ((Rom)item).SHA256 = Utilities.CleanHashData(quoteless, Constants.SHA256Length); } - else if (item.Type == ItemType.Disk) + else if (item.ItemType == ItemType.Disk) { quoteless = linegc[++i].Replace("\"", ""); ((Disk)item).SHA256 = Utilities.CleanHashData(quoteless, Constants.SHA256Length); } break; case "sha384": - if (item.Type == ItemType.Rom) + if (item.ItemType == ItemType.Rom) { quoteless = linegc[++i].Replace("\"", ""); ((Rom)item).SHA384 = Utilities.CleanHashData(quoteless, Constants.SHA384Length); } - else if (item.Type == ItemType.Disk) + else if (item.ItemType == ItemType.Disk) { quoteless = linegc[++i].Replace("\"", ""); ((Disk)item).SHA384 = Utilities.CleanHashData(quoteless, Constants.SHA384Length); } break; case "sha512": - if (item.Type == ItemType.Rom) + if (item.ItemType == ItemType.Rom) { quoteless = linegc[++i].Replace("\"", ""); ((Rom)item).SHA512 = Utilities.CleanHashData(quoteless, Constants.SHA512Length); } - else if (item.Type == ItemType.Disk) + else if (item.ItemType == ItemType.Disk) { quoteless = linegc[++i].Replace("\"", ""); ((Disk)item).SHA512 = Utilities.CleanHashData(quoteless, Constants.SHA512Length); @@ -534,17 +534,17 @@ namespace SabreTools.Library.DatFiles case "flags": quoteless = linegc[++i].Replace("\"", ""); ItemStatus tempFlagStatus = Utilities.GetItemStatus(quoteless); - if (item.Type == ItemType.Rom) + if (item.ItemType == ItemType.Rom) { ((Rom)item).ItemStatus = tempFlagStatus; } - else if (item.Type == ItemType.Disk) + else if (item.ItemType == ItemType.Disk) { ((Disk)item).ItemStatus = tempFlagStatus; } break; case "date": - if (item.Type == ItemType.Rom) + if (item.ItemType == ItemType.Rom) { // If we have quotes in the next item, assume only one item if (linegc[i + 1].Contains("\"")) @@ -558,7 +558,7 @@ namespace SabreTools.Library.DatFiles } ((Rom)item).Date = quoteless; } - else if (item.Type == ItemType.Release) + else if (item.ItemType == ItemType.Release) { // If we have quotes in the next item, assume only one item if (linegc[i + 1].Contains("\"")) @@ -574,33 +574,33 @@ namespace SabreTools.Library.DatFiles } break; case "default": - if (item.Type == ItemType.BiosSet) + if (item.ItemType == ItemType.BiosSet) { quoteless = linegc[++i].Replace("\"", ""); ((BiosSet)item).Default = Utilities.GetYesNo(quoteless.ToLowerInvariant()); } - else if (item.Type == ItemType.Release) + else if (item.ItemType == ItemType.Release) { quoteless = linegc[++i].Replace("\"", ""); ((Release)item).Default = Utilities.GetYesNo(quoteless.ToLowerInvariant()); } break; case "description": - if (item.Type == ItemType.BiosSet) + if (item.ItemType == ItemType.BiosSet) { quoteless = linegc[++i].Replace("\"", ""); ((BiosSet)item).Description = quoteless.ToLowerInvariant(); } break; case "region": - if (item.Type == ItemType.Release) + if (item.ItemType == ItemType.Release) { quoteless = linegc[++i].Replace("\"", ""); ((Release)item).Region = quoteless.ToLowerInvariant(); } break; case "language": - if (item.Type == ItemType.Release) + if (item.ItemType == ItemType.Release) { quoteless = linegc[++i].Replace("\"", ""); ((Release)item).Language = quoteless.ToLowerInvariant(); @@ -728,7 +728,7 @@ namespace SabreTools.Library.DatFiles } // If we have a "null" game (created by DATFromDir or something similar), log it to file - if (rom.Type == ItemType.Rom + if (rom.ItemType == ItemType.Rom && ((Rom)rom).Size == -1 && ((Rom)rom).CRC == "null") { @@ -882,7 +882,7 @@ namespace SabreTools.Library.DatFiles { // If we are in ignore blanks mode AND we have a blank (0-size) rom, skip if (ignoreblanks - && (rom.Type == ItemType.Rom + && (rom.ItemType == ItemType.Rom && (((Rom)rom).Size == 0 || ((Rom)rom).Size == -1))) { return true; @@ -895,7 +895,7 @@ namespace SabreTools.Library.DatFiles // Pre-process the item name ProcessItemName(rom, true); - switch (rom.Type) + switch (rom.ItemType) { case ItemType.Archive: state += "\tarchive ( name\"" + (!ExcludeFields[(int)Field.Name] ? rom.Name : "") + "\"" diff --git a/SabreTools.Library/DatFiles/DatFile.cs b/SabreTools.Library/DatFiles/DatFile.cs index 27fe8e42..3c8951bd 100644 --- a/SabreTools.Library/DatFiles/DatFile.cs +++ b/SabreTools.Library/DatFiles/DatFile.cs @@ -1671,7 +1671,7 @@ namespace SabreTools.Library.DatFiles foreach (DatItem datItem in datItems) { // If we have something other than a Rom or Disk, then this doesn't do anything - if (datItem.Type != ItemType.Disk && datItem.Type != ItemType.Rom) + if (datItem.ItemType != ItemType.Disk && datItem.ItemType != ItemType.Rom) { newDatItems.Add((DatItem)datItem.Clone()); continue; @@ -1691,7 +1691,7 @@ namespace SabreTools.Library.DatFiles // If we're updating hashes, only replace if the current item doesn't have them if ((replaceMode & ReplaceMode.Hash) != 0) { - if (newDatItem.Type == ItemType.Rom) + if (newDatItem.ItemType == ItemType.Rom) { Rom newRomItem = (Rom)newDatItem; if (String.IsNullOrEmpty(newRomItem.CRC) && !String.IsNullOrEmpty(((Rom)dupes[0]).CRC)) @@ -1721,7 +1721,7 @@ namespace SabreTools.Library.DatFiles newDatItem = (Rom)newRomItem.Clone(); } - else if (newDatItem.Type == ItemType.Disk) + else if (newDatItem.ItemType == ItemType.Disk) { Disk newDiskItem = (Disk)newDatItem; if (String.IsNullOrEmpty(newDiskItem.MD5) && !String.IsNullOrEmpty(((Disk)dupes[0]).MD5)) @@ -2072,7 +2072,7 @@ namespace SabreTools.Library.DatFiles // No duplicates if ((diff & UpdateMode.DiffNoDupesOnly) != 0 || (diff & UpdateMode.DiffIndividualsOnly) != 0) { - if ((item.Dupe & DupeType.Internal) != 0 || item.Dupe == 0x00) + if ((item.DupeType & DupeType.Internal) != 0 || item.DupeType == 0x00) { // Individual DATs that are output if ((diff & UpdateMode.DiffIndividualsOnly) != 0) @@ -2094,7 +2094,7 @@ namespace SabreTools.Library.DatFiles // Duplicates only if ((diff & UpdateMode.DiffDupesOnly) != 0) { - if ((item.Dupe & DupeType.External) != 0) + if ((item.DupeType & DupeType.External) != 0) { DatItem newrom = item.Clone() as DatItem; newrom.MachineName += " (" + Path.GetFileNameWithoutExtension(inputs[item.SystemID].Split('¬')[0]) + ")"; @@ -2786,14 +2786,14 @@ namespace SabreTools.Library.DatFiles foreach (DatItem item in items) { // If the disk doesn't have a valid merge tag OR the merged file doesn't exist in the parent, then add it - if (item.Type == ItemType.Disk && (((Disk)item).MergeTag == null || !this[parent].Select(i => i.Name).Contains(((Disk)item).MergeTag))) + if (item.ItemType == ItemType.Disk && (((Disk)item).MergeTag == null || !this[parent].Select(i => i.Name).Contains(((Disk)item).MergeTag))) { item.CopyMachineInformation(copyFrom); Add(parent, item); } // Otherwise, if the parent doesn't already contain the non-disk (or a merge-equivalent), add it - else if (item.Type != ItemType.Disk && !this[parent].Contains(item)) + else if (item.ItemType != ItemType.Disk && !this[parent].Contains(item)) { // Rename the child so it's in a subfolder item.Name = item.MachineName + "\\" + item.Name; @@ -3080,7 +3080,7 @@ namespace SabreTools.Library.DatFiles List newitems = new List(); foreach (DatItem item in items) { - if (item.Type != ItemType.Blank) + if (item.ItemType != ItemType.Blank) { newitems.Add(item); } @@ -3122,7 +3122,7 @@ namespace SabreTools.Library.DatFiles } // If we have a Rom or a Disk, clean the hash data - if (item.Type == ItemType.Rom) + if (item.ItemType == ItemType.Rom) { Rom itemRom = (Rom)item; @@ -3190,7 +3190,7 @@ namespace SabreTools.Library.DatFiles item = itemRom; } - else if (item.Type == ItemType.Disk) + else if (item.ItemType == ItemType.Disk) { Disk itemDisk = (Disk)item; @@ -3527,7 +3527,7 @@ namespace SabreTools.Library.DatFiles private void ProcessFileHelper(string item, DatItem datItem, string basepath, string parent) { // If we somehow got something other than a Rom or Disk, cancel out - if (datItem.Type != ItemType.Rom && datItem.Type != ItemType.Disk) + if (datItem.ItemType != ItemType.Rom && datItem.ItemType != ItemType.Disk) { return; } @@ -3641,7 +3641,7 @@ namespace SabreTools.Library.DatFiles datItem.MachineDescription = gamename; // If we have a Disk, then the ".chd" extension needs to be removed - if (datItem.Type == ItemType.Disk) + if (datItem.ItemType == ItemType.Disk) { datItem.Name = datItem.Name.Replace(".chd", ""); } @@ -3800,7 +3800,7 @@ namespace SabreTools.Library.DatFiles } // Otherwise, we rebuild that file to all locations that we need to - if (this[hash][0].Type == ItemType.Disk) + if (this[hash][0].ItemType == ItemType.Disk) { RebuildIndividualFile(new Disk(fileinfo), foundpath, outDir, date, inverse, outputFormat, romba, updateDat, false /* isZip */, headerToCheckAgainst); @@ -4091,7 +4091,7 @@ namespace SabreTools.Library.DatFiles bool rebuilt = true; // If the DatItem is a Disk, force rebuilding to a folder except if TGZ - if (datItem.Type == ItemType.Disk && outputFormat != OutputFormat.TorrentGzip) + if (datItem.ItemType == ItemType.Disk && outputFormat != OutputFormat.TorrentGzip) { outputFormat = OutputFormat.Folder; } @@ -4099,12 +4099,12 @@ namespace SabreTools.Library.DatFiles // Prepopluate a few key strings based on DatItem type string crc = null; string sha1 = null; - if (datItem.Type == ItemType.Rom) + if (datItem.ItemType == ItemType.Rom) { crc = ((Rom)datItem).CRC; sha1 = ((Rom)datItem).SHA1; } - else if (datItem.Type == ItemType.Disk) + else if (datItem.ItemType == ItemType.Disk) { crc = ""; sha1 = ((Disk)datItem).SHA1; @@ -4560,7 +4560,7 @@ namespace SabreTools.Library.DatFiles { if (rom.SourceID == 99) { - if (rom.Type == ItemType.Disk || rom.Type == ItemType.Rom) + if (rom.ItemType == ItemType.Disk || rom.ItemType == ItemType.Rom) { matched.Add(((Disk)rom).SHA1, rom); } @@ -4937,49 +4937,49 @@ namespace SabreTools.Library.DatFiles foreach (DatItem item in items) { // If the file is not a Rom or Disk, continue - if (item.Type != ItemType.Disk && item.Type != ItemType.Rom) + if (item.ItemType != ItemType.Disk && item.ItemType != ItemType.Rom) { return; } // If the file is a nodump - if ((item.Type == ItemType.Rom && ((Rom)item).ItemStatus == ItemStatus.Nodump) - || (item.Type == ItemType.Disk && ((Disk)item).ItemStatus == ItemStatus.Nodump)) + if ((item.ItemType == ItemType.Rom && ((Rom)item).ItemStatus == ItemStatus.Nodump) + || (item.ItemType == ItemType.Disk && ((Disk)item).ItemStatus == ItemStatus.Nodump)) { nodump.Add(key, item); } // If the file has a SHA-512 - else if ((item.Type == ItemType.Rom && !String.IsNullOrWhiteSpace(((Rom)item).SHA512)) - || (item.Type == ItemType.Disk && !String.IsNullOrWhiteSpace(((Disk)item).SHA512))) + else if ((item.ItemType == ItemType.Rom && !String.IsNullOrWhiteSpace(((Rom)item).SHA512)) + || (item.ItemType == ItemType.Disk && !String.IsNullOrWhiteSpace(((Disk)item).SHA512))) { sha512.Add(key, item); } // If the file has a SHA-384 - else if ((item.Type == ItemType.Rom && !String.IsNullOrWhiteSpace(((Rom)item).SHA384)) - || (item.Type == ItemType.Disk && !String.IsNullOrWhiteSpace(((Disk)item).SHA384))) + else if ((item.ItemType == ItemType.Rom && !String.IsNullOrWhiteSpace(((Rom)item).SHA384)) + || (item.ItemType == ItemType.Disk && !String.IsNullOrWhiteSpace(((Disk)item).SHA384))) { sha384.Add(key, item); } // If the file has a SHA-256 - else if ((item.Type == ItemType.Rom && !String.IsNullOrWhiteSpace(((Rom)item).SHA256)) - || (item.Type == ItemType.Disk && !String.IsNullOrWhiteSpace(((Disk)item).SHA256))) + else if ((item.ItemType == ItemType.Rom && !String.IsNullOrWhiteSpace(((Rom)item).SHA256)) + || (item.ItemType == ItemType.Disk && !String.IsNullOrWhiteSpace(((Disk)item).SHA256))) { sha256.Add(key, item); } // If the file has a SHA-1 - else if ((item.Type == ItemType.Rom && !String.IsNullOrWhiteSpace(((Rom)item).SHA1)) - || (item.Type == ItemType.Disk && !String.IsNullOrWhiteSpace(((Disk)item).SHA1))) + else if ((item.ItemType == ItemType.Rom && !String.IsNullOrWhiteSpace(((Rom)item).SHA1)) + || (item.ItemType == ItemType.Disk && !String.IsNullOrWhiteSpace(((Disk)item).SHA1))) { sha1.Add(key, item); } // If the file has no SHA-1 but has an MD5 - else if ((item.Type == ItemType.Rom && !String.IsNullOrWhiteSpace(((Rom)item).MD5)) - || (item.Type == ItemType.Disk && !String.IsNullOrWhiteSpace(((Disk)item).MD5))) + else if ((item.ItemType == ItemType.Rom && !String.IsNullOrWhiteSpace(((Rom)item).MD5)) + || (item.ItemType == ItemType.Disk && !String.IsNullOrWhiteSpace(((Disk)item).MD5))) { md5.Add(key, item); } // If the file has no MD5 but a CRC - else if ((item.Type == ItemType.Rom && !String.IsNullOrWhiteSpace(((Rom)item).CRC))) + else if ((item.ItemType == ItemType.Rom && !String.IsNullOrWhiteSpace(((Rom)item).CRC))) { crc.Add(key, item); } @@ -5164,17 +5164,17 @@ namespace SabreTools.Library.DatFiles foreach (DatItem item in items) { // If the file is not a Rom, it automatically goes in the "lesser" dat - if (item.Type != ItemType.Rom) + if (item.ItemType != ItemType.Rom) { lessDat.Add(key, item); } // If the file is a Rom and less than the radix, put it in the "lesser" dat - else if (item.Type == ItemType.Rom && ((Rom)item).Size < radix) + else if (item.ItemType == ItemType.Rom && ((Rom)item).Size < radix) { lessDat.Add(key, item); } // If the file is a Rom and greater than or equal to the radix, put it in the "greater" dat - else if (item.Type == ItemType.Rom && ((Rom)item).Size >= radix) + else if (item.ItemType == ItemType.Rom && ((Rom)item).Size >= radix) { greaterEqualDat.Add(key, item); } @@ -5271,17 +5271,17 @@ namespace SabreTools.Library.DatFiles foreach (DatItem item in items) { // If the file is a Rom - if (item.Type == ItemType.Rom) + if (item.ItemType == ItemType.Rom) { romdat.Add(key, item); } // If the file is a Disk - else if (item.Type == ItemType.Disk) + else if (item.ItemType == ItemType.Disk) { diskdat.Add(key, item); } // If the file is a Sample - else if (item.Type == ItemType.Sample) + else if (item.ItemType == ItemType.Sample) { sampledat.Add(key, item); } @@ -5799,7 +5799,7 @@ namespace SabreTools.Library.DatFiles // If we're in Romba mode, take care of that instead if (Romba) { - if (item.Type == ItemType.Rom) + if (item.ItemType == ItemType.Rom) { // We can only write out if there's a SHA-1 if (!String.IsNullOrWhiteSpace(((Rom)item).SHA1)) @@ -5812,7 +5812,7 @@ namespace SabreTools.Library.DatFiles item.Name = pre + name + post; } } - else if (item.Type == ItemType.Disk) + else if (item.ItemType == ItemType.Disk) { // We can only write out if there's a SHA-1 if (!String.IsNullOrWhiteSpace(((Disk)item).SHA1)) @@ -5898,7 +5898,7 @@ namespace SabreTools.Library.DatFiles } // Ensure we have the proper values for replacement - if (item.Type == ItemType.Rom) + if (item.ItemType == ItemType.Rom) { crc = ((Rom)item).CRC; md5 = ((Rom)item).MD5; @@ -5908,7 +5908,7 @@ namespace SabreTools.Library.DatFiles sha512 = ((Rom)item).SHA512; size = ((Rom)item).Size.ToString(); } - else if (item.Type == ItemType.Disk) + else if (item.ItemType == ItemType.Disk) { md5 = ((Disk)item).MD5; sha1 = ((Disk)item).SHA1; diff --git a/SabreTools.Library/DatFiles/DatStats.cs b/SabreTools.Library/DatFiles/DatStats.cs index bbb6a6c8..b8c46aa4 100644 --- a/SabreTools.Library/DatFiles/DatStats.cs +++ b/SabreTools.Library/DatFiles/DatStats.cs @@ -138,7 +138,7 @@ namespace SabreTools.Library.DatFiles // Now we do different things for each item type - switch (item.Type) + switch (item.ItemType) { case ItemType.Archive: this.ArchiveCount += 1; @@ -237,7 +237,7 @@ namespace SabreTools.Library.DatFiles // Now we do different things for each item type - switch (item.Type) + switch (item.ItemType) { case ItemType.Archive: this.ArchiveCount -= 1; diff --git a/SabreTools.Library/DatFiles/DosCenter.cs b/SabreTools.Library/DatFiles/DosCenter.cs index 80a1b64a..5d475489 100644 --- a/SabreTools.Library/DatFiles/DosCenter.cs +++ b/SabreTools.Library/DatFiles/DosCenter.cs @@ -124,7 +124,7 @@ namespace SabreTools.Library.DatFiles } // If we have a "null" game (created by DATFromDir or something similar), log it to file - if (rom.Type == ItemType.Rom + if (rom.ItemType == ItemType.Rom && ((Rom)rom).Size == -1 && ((Rom)rom).CRC == "null") { @@ -261,7 +261,7 @@ namespace SabreTools.Library.DatFiles { // If we are in ignore blanks mode AND we have a blank (0-size) rom, skip if (ignoreblanks - && (rom.Type == ItemType.Rom + && (rom.ItemType == ItemType.Rom && (((Rom)rom).Size == 0 || ((Rom)rom).Size == -1))) { return true; @@ -274,7 +274,7 @@ namespace SabreTools.Library.DatFiles // Pre-process the item name ProcessItemName(rom, true); - switch (rom.Type) + switch (rom.ItemType) { case ItemType.Archive: case ItemType.BiosSet: diff --git a/SabreTools.Library/DatFiles/Filter.cs b/SabreTools.Library/DatFiles/Filter.cs index 56f94e13..3ed01fb5 100644 --- a/SabreTools.Library/DatFiles/Filter.cs +++ b/SabreTools.Library/DatFiles/Filter.cs @@ -389,7 +389,7 @@ namespace SabreTools.Library.DatFiles } // Take care of Rom and Disk specific differences - if (item.Type == ItemType.Rom) + if (item.ItemType == ItemType.Rom) { Rom rom = (Rom)item; @@ -528,7 +528,7 @@ namespace SabreTools.Library.DatFiles } } } - else if (item.Type == ItemType.Disk) + else if (item.ItemType == ItemType.Disk) { Disk rom = (Disk)item; @@ -710,14 +710,14 @@ namespace SabreTools.Library.DatFiles } // Filter on rom type - if (_romTypes.Count == 0 && _notRomTypes.Count == 0 && item.Type != ItemType.Rom && item.Type != ItemType.Disk && item.Type != ItemType.Blank) + if (_romTypes.Count == 0 && _notRomTypes.Count == 0 && item.ItemType != ItemType.Rom && item.ItemType != ItemType.Disk && item.ItemType != ItemType.Blank) { return false; } if (_romTypes.Count > 0) { // If the rom type was not found in the list, return false - if (!FindValueInList(_romTypes, item.Type.ToString())) + if (!FindValueInList(_romTypes, item.ItemType.ToString())) { return false; } @@ -725,7 +725,7 @@ namespace SabreTools.Library.DatFiles if (_notRomTypes.Count > 0) { // If the rom type was found in the list, return false - if (FindValueInList(_notRomTypes, item.Type.ToString())) + if (FindValueInList(_notRomTypes, item.ItemType.ToString())) { return false; } diff --git a/SabreTools.Library/DatFiles/Hashfile.cs b/SabreTools.Library/DatFiles/Hashfile.cs index eb8ae0d5..0fa1920d 100644 --- a/SabreTools.Library/DatFiles/Hashfile.cs +++ b/SabreTools.Library/DatFiles/Hashfile.cs @@ -154,7 +154,7 @@ namespace SabreTools.Library.DatFiles } // If we have a "null" game (created by DATFromDir or something similar), log it to file - if (rom.Type == ItemType.Rom + if (rom.ItemType == ItemType.Rom && ((Rom)rom).Size == -1 && ((Rom)rom).CRC == "null") { @@ -190,7 +190,7 @@ namespace SabreTools.Library.DatFiles { // If we are in ignore blanks mode AND we have a blank (0-size) rom, skip if (ignoreblanks - && (rom.Type == ItemType.Rom + && (rom.ItemType == ItemType.Rom && (((Rom)rom).Size == 0 || ((Rom)rom).Size == -1))) { return true; @@ -206,13 +206,13 @@ namespace SabreTools.Library.DatFiles switch (_hash) { case Hash.MD5: - if (rom.Type == ItemType.Rom) + if (rom.ItemType == ItemType.Rom) { state += (!ExcludeFields[(int)Field.MD5] ? ((Rom)rom).MD5 : "") + " *" + (!ExcludeFields[(int)Field.MachineName] && GameName ? rom.MachineName + Path.DirectorySeparatorChar : "") + (!ExcludeFields[(int)Field.Name] ? rom.Name : "") + "\n"; } - else if (rom.Type == ItemType.Disk) + else if (rom.ItemType == ItemType.Disk) { state += (!ExcludeFields[(int)Field.MD5] ? ((Disk)rom).MD5 : "") + " *" + (!ExcludeFields[(int)Field.MachineName] && GameName ? rom.MachineName + Path.DirectorySeparatorChar : "") @@ -220,7 +220,7 @@ namespace SabreTools.Library.DatFiles } break; case Hash.CRC: - if (rom.Type == ItemType.Rom) + if (rom.ItemType == ItemType.Rom) { state += (!ExcludeFields[(int)Field.MachineName] && GameName ? rom.MachineName + Path.DirectorySeparatorChar : "") + (!ExcludeFields[(int)Field.Name] ? rom.Name : "") @@ -228,13 +228,13 @@ namespace SabreTools.Library.DatFiles } break; case Hash.SHA1: - if (rom.Type == ItemType.Rom) + if (rom.ItemType == ItemType.Rom) { state += (!ExcludeFields[(int)Field.SHA1] ? ((Rom)rom).SHA1 : "") + " *" + (!ExcludeFields[(int)Field.MachineName] && GameName ? rom.MachineName + Path.DirectorySeparatorChar : "") + (!ExcludeFields[(int)Field.Name] ? rom.Name : "") + "\n"; } - else if (rom.Type == ItemType.Disk) + else if (rom.ItemType == ItemType.Disk) { state += (!ExcludeFields[(int)Field.SHA1] ? ((Disk)rom).SHA1 : "") + " *" + (!ExcludeFields[(int)Field.MachineName] && GameName ? rom.MachineName + Path.DirectorySeparatorChar : "") @@ -242,13 +242,13 @@ namespace SabreTools.Library.DatFiles } break; case Hash.SHA256: - if (rom.Type == ItemType.Rom) + if (rom.ItemType == ItemType.Rom) { state += (!ExcludeFields[(int)Field.SHA256] ? ((Rom)rom).SHA256 : "") + " *" + (!ExcludeFields[(int)Field.MachineName] && GameName ? rom.MachineName + Path.DirectorySeparatorChar : "") + (!ExcludeFields[(int)Field.Name] ? rom.Name : "") + "\n"; } - else if (rom.Type == ItemType.Disk) + else if (rom.ItemType == ItemType.Disk) { state += (!ExcludeFields[(int)Field.SHA256] ? ((Disk)rom).SHA256 : "") + " *" + (!ExcludeFields[(int)Field.MachineName] && GameName ? rom.MachineName + Path.DirectorySeparatorChar : "") @@ -256,13 +256,13 @@ namespace SabreTools.Library.DatFiles } break; case Hash.SHA384: - if (rom.Type == ItemType.Rom) + if (rom.ItemType == ItemType.Rom) { state += (!ExcludeFields[(int)Field.SHA384] ? ((Rom)rom).SHA384 : "") + " *" + (!ExcludeFields[(int)Field.MachineName] && GameName ? rom.MachineName + Path.DirectorySeparatorChar : "") + (!ExcludeFields[(int)Field.Name] ? rom.Name : "") + "\n"; } - else if (rom.Type == ItemType.Disk) + else if (rom.ItemType == ItemType.Disk) { state += (!ExcludeFields[(int)Field.SHA384] ? ((Disk)rom).SHA384 : "") + " *" + (!ExcludeFields[(int)Field.MachineName] && GameName ? rom.MachineName + Path.DirectorySeparatorChar : "") @@ -270,13 +270,13 @@ namespace SabreTools.Library.DatFiles } break; case Hash.SHA512: - if (rom.Type == ItemType.Rom) + if (rom.ItemType == ItemType.Rom) { state += (!ExcludeFields[(int)Field.SHA512] ? ((Rom)rom).SHA512 : "") + " *" + (!ExcludeFields[(int)Field.MachineName] && GameName ? rom.MachineName + Path.DirectorySeparatorChar : "") + (!ExcludeFields[(int)Field.Name] ? rom.Name : "") + "\n"; } - else if (rom.Type == ItemType.Disk) + else if (rom.ItemType == ItemType.Disk) { state += (!ExcludeFields[(int)Field.SHA512] ? ((Disk)rom).SHA512 : "") + " *" + (!ExcludeFields[(int)Field.MachineName] && GameName ? rom.MachineName + Path.DirectorySeparatorChar : "") diff --git a/SabreTools.Library/DatFiles/Listrom.cs b/SabreTools.Library/DatFiles/Listrom.cs index b86c257e..bf68455e 100644 --- a/SabreTools.Library/DatFiles/Listrom.cs +++ b/SabreTools.Library/DatFiles/Listrom.cs @@ -297,7 +297,7 @@ namespace SabreTools.Library.DatFiles } // If we have a "null" game (created by DATFromDir or something similar), log it to file - if (rom.Type == ItemType.Rom + if (rom.ItemType == ItemType.Rom && ((Rom)rom).Size == -1 && ((Rom)rom).CRC == "null") { @@ -399,7 +399,7 @@ namespace SabreTools.Library.DatFiles { // If we are in ignore blanks mode AND we have a blank (0-size) rom, skip if (ignoreblanks - && (rom.Type == ItemType.Rom + && (rom.ItemType == ItemType.Rom && (((Rom)rom).Size == 0 || ((Rom)rom).Size == -1))) { return true; @@ -412,7 +412,7 @@ namespace SabreTools.Library.DatFiles // Pre-process the item name ProcessItemName(rom, true); - switch (rom.Type) + switch (rom.ItemType) { case ItemType.Archive: case ItemType.BiosSet: diff --git a/SabreTools.Library/DatFiles/Listxml.cs b/SabreTools.Library/DatFiles/Listxml.cs index 073e6403..0675d740 100644 --- a/SabreTools.Library/DatFiles/Listxml.cs +++ b/SabreTools.Library/DatFiles/Listxml.cs @@ -617,7 +617,7 @@ namespace SabreTools.Library.DatFiles } // If we have a "null" game (created by DATFromDir or something similar), log it to file - if (rom.Type == ItemType.Rom + if (rom.ItemType == ItemType.Rom && ((Rom)rom).Size == -1 && ((Rom)rom).CRC == "null") { @@ -771,7 +771,7 @@ namespace SabreTools.Library.DatFiles { // If we are in ignore blanks mode AND we have a blank (0-size) rom, skip if (ignoreblanks - && (rom.Type == ItemType.Rom + && (rom.ItemType == ItemType.Rom && (((Rom)rom).Size == 0 || ((Rom)rom).Size == -1))) { return true; @@ -784,7 +784,7 @@ namespace SabreTools.Library.DatFiles // Pre-process the item name ProcessItemName(rom, true); - switch (rom.Type) + switch (rom.ItemType) { case ItemType.Archive: break; diff --git a/SabreTools.Library/DatFiles/Logiqx.cs b/SabreTools.Library/DatFiles/Logiqx.cs index e4af9693..dde0801b 100644 --- a/SabreTools.Library/DatFiles/Logiqx.cs +++ b/SabreTools.Library/DatFiles/Logiqx.cs @@ -700,7 +700,7 @@ namespace SabreTools.Library.DatFiles } // If we have a "null" game (created by DATFromDir or something similar), log it to file - if (rom.Type == ItemType.Rom + if (rom.ItemType == ItemType.Rom && ((Rom)rom).Size == -1 && ((Rom)rom).CRC == "null") { @@ -879,7 +879,7 @@ namespace SabreTools.Library.DatFiles { // If we are in ignore blanks mode AND we have a blank (0-size) rom, skip if (ignoreblanks - && (rom.Type == ItemType.Rom + && (rom.ItemType == ItemType.Rom && (((Rom)rom).Size == 0 || ((Rom)rom).Size == -1))) { return true; @@ -892,7 +892,7 @@ namespace SabreTools.Library.DatFiles // Pre-process the item name ProcessItemName(rom, true); - switch (rom.Type) + switch (rom.ItemType) { case ItemType.Archive: state += "\t\t" + (!ExcludeFields[(int)Field.Name] ? HttpUtility.HtmlEncode(rom.Name) : "") + "\n" + "\t\t\tNone\n"; - if (rom.Type == ItemType.Rom) + if (rom.ItemType == ItemType.Rom) { state += "\t\t\t" + (!ExcludeFields[(int)Field.Size] ? ((Rom)rom).Size.ToString() : "") + "\n"; } @@ -974,7 +974,7 @@ namespace SabreTools.Library.DatFiles + "\t\t\tNone\n" + "\t\t\t0\n"; - if (rom.Type == ItemType.Disk) + if (rom.ItemType == ItemType.Disk) { state += "\t\t\t\n" + (((Disk)rom).MD5 != null @@ -982,7 +982,7 @@ namespace SabreTools.Library.DatFiles : "\t\t\t\t" + (!ExcludeFields[(int)Field.SHA1] ? ((Disk)rom).SHA1.ToUpperInvariant() : "") + "\n") + "\t\t\t\n"; } - else if (rom.Type == ItemType.Rom) + else if (rom.ItemType == ItemType.Rom) { string tempext = "." + Utilities.GetExtension(((Rom)rom).Name); diff --git a/SabreTools.Library/DatFiles/OpenMSX.cs b/SabreTools.Library/DatFiles/OpenMSX.cs index a1706ca6..3d0f30b5 100644 --- a/SabreTools.Library/DatFiles/OpenMSX.cs +++ b/SabreTools.Library/DatFiles/OpenMSX.cs @@ -572,7 +572,7 @@ namespace SabreTools.Library.DatFiles } // If we have a "null" game (created by DATFromDir or something similar), log it to file - if (rom.Type == ItemType.Rom + if (rom.ItemType == ItemType.Rom && ((Rom)rom).Size == -1 && ((Rom)rom).CRC == "null") { @@ -715,7 +715,7 @@ Generation MSXIDs by www.generation-msx.nl { // If we are in ignore blanks mode AND we have a blank (0-size) rom, skip if (ignoreblanks - && (rom.Type == ItemType.Rom + && (rom.ItemType == ItemType.Rom && (((Rom)rom).Size == 0 || ((Rom)rom).Size == -1))) { return true; @@ -728,7 +728,7 @@ Generation MSXIDs by www.generation-msx.nl // Pre-process the item name ProcessItemName(rom, true); - switch (rom.Type) + switch (rom.ItemType) { case ItemType.Archive: break; diff --git a/SabreTools.Library/DatFiles/RomCenter.cs b/SabreTools.Library/DatFiles/RomCenter.cs index a04192c8..107e2fd7 100644 --- a/SabreTools.Library/DatFiles/RomCenter.cs +++ b/SabreTools.Library/DatFiles/RomCenter.cs @@ -247,7 +247,7 @@ namespace SabreTools.Library.DatFiles } // If we have a "null" game (created by DATFromDir or something similar), log it to file - if (rom.Type == ItemType.Rom + if (rom.ItemType == ItemType.Rom && ((Rom)rom).Size == -1 && ((Rom)rom).CRC == "null") { @@ -330,7 +330,7 @@ namespace SabreTools.Library.DatFiles { // If we are in ignore blanks mode AND we have a blank (0-size) rom, skip if (ignoreblanks - && (rom.Type == ItemType.Rom + && (rom.ItemType == ItemType.Rom && (((Rom)rom).Size == 0 || ((Rom)rom).Size == -1))) { return true; @@ -343,7 +343,7 @@ namespace SabreTools.Library.DatFiles // Pre-process the item name ProcessItemName(rom, true); - if (rom.Type == ItemType.Rom) + if (rom.ItemType == ItemType.Rom) { state += "¬" + (!ExcludeFields[(int)Field.CloneOf] && String.IsNullOrWhiteSpace(rom.CloneOf) ? HttpUtility.HtmlEncode(rom.CloneOf) : "") + "¬" + (!ExcludeFields[(int)Field.CloneOf] && String.IsNullOrWhiteSpace(rom.CloneOf) ? HttpUtility.HtmlEncode(rom.CloneOf) : "") + @@ -353,7 +353,7 @@ namespace SabreTools.Library.DatFiles "¬" + (!ExcludeFields[(int)Field.CRC] ? ((Rom)rom).CRC.ToLowerInvariant() : "") + "¬" + (!ExcludeFields[(int)Field.Size] && ((Rom)rom).Size != -1 ? ((Rom)rom).Size.ToString() : "") + "¬¬¬\n"; } - else if (rom.Type == ItemType.Disk) + else if (rom.ItemType == ItemType.Disk) { state += "¬" + (!ExcludeFields[(int)Field.CloneOf] && String.IsNullOrWhiteSpace(rom.CloneOf) ? HttpUtility.HtmlEncode(rom.CloneOf) : "") + "¬" + (!ExcludeFields[(int)Field.CloneOf] && String.IsNullOrWhiteSpace(rom.CloneOf) ? HttpUtility.HtmlEncode(rom.CloneOf) : "") + diff --git a/SabreTools.Library/DatFiles/SabreDat.cs b/SabreTools.Library/DatFiles/SabreDat.cs index a14187cb..75f4189b 100644 --- a/SabreTools.Library/DatFiles/SabreDat.cs +++ b/SabreTools.Library/DatFiles/SabreDat.cs @@ -613,7 +613,7 @@ namespace SabreTools.Library.DatFiles } // If we have a "null" game (created by DATFromDir or something similar), log it to file - if (rom.Type == ItemType.Rom + if (rom.ItemType == ItemType.Rom && ((Rom)rom).Size == -1 && ((Rom)rom).CRC == "null") { @@ -813,7 +813,7 @@ namespace SabreTools.Library.DatFiles { // If we are in ignore blanks mode AND we have a blank (0-size) rom, skip if (ignoreblanks - && (rom.Type == ItemType.Rom + && (rom.ItemType == ItemType.Rom && (((Rom)rom).Size == 0 || ((Rom)rom).Size == -1))) { return true; @@ -832,7 +832,7 @@ namespace SabreTools.Library.DatFiles } state += prefix; - switch (rom.Type) + switch (rom.ItemType) { case ItemType.Archive: state += " - /// Base class for all items included in a set - /// - public abstract class DatItem : IEquatable, IComparable, ICloneable - { - #region Protected instance variables - - // Standard item information - protected string _name; - protected ItemType _itemType; - protected DupeType _dupeType; - - // Machine information - protected Machine _machine = new Machine(); - - // Software list information - protected bool? _supported; - protected string _partName; - protected string _partInterface; - protected List> _features; - protected string _areaName; - protected long? _areaSize; - - // Source metadata information - protected int _systemId; - protected string _systemName; - protected int _sourceId; - protected string _sourceName; - protected bool _remove; - - #endregion - - #region Publicly facing variables - - // Standard item information - public string Name - { - get { return _name; } - set { _name = value; } - } - public ItemType Type - { - get { return _itemType; } - set { _itemType = value; } - } - public DupeType Dupe - { - get { return _dupeType; } - set { _dupeType = value; } - } - - // Machine information - public string MachineName - { - get - { - if (_machine == null) - { - _machine = new Machine(); - } - - return _machine.Name; - } - set - { - if (_machine == null) - { - _machine = new Machine(); - } - - _machine.Name = value; - } - } - public string Comment - { - get - { - if (_machine == null) - { - _machine = new Machine(); - } - - return _machine.Comment; - } - set - { - if (_machine == null) - { - _machine = new Machine(); - } - - _machine.Comment = value; - } - } - public string MachineDescription - { - get - { - if (_machine == null) - { - _machine = new Machine(); - } - - return _machine.Description; - } - set - { - if (_machine == null) - { - _machine = new Machine(); - } - - _machine.Description = value; - } - } - public string Year - { - get - { - if (_machine == null) - { - _machine = new Machine(); - } - - return _machine.Year; - } - set - { - if (_machine == null) - { - _machine = new Machine(); - } - - _machine.Year = value; - } - } - public string Manufacturer - { - get - { - if (_machine == null) - { - _machine = new Machine(); - } - - return _machine.Manufacturer; - } - set - { - if (_machine == null) - { - _machine = new Machine(); - } - - _machine.Manufacturer = value; - } - } - public string RomOf - { - get - { - if (_machine == null) - { - _machine = new Machine(); - } - - return _machine.RomOf; - } - set - { - if (_machine == null) - { - _machine = new Machine(); - } - - _machine.RomOf = value; - } - } - public string CloneOf - { - get - { - if (_machine == null) - { - _machine = new Machine(); - } - - return _machine.CloneOf; - } - set - { - if (_machine == null) - { - _machine = new Machine(); - } - - _machine.CloneOf = value; - } - } - public string SampleOf - { - get - { - if (_machine == null) - { - _machine = new Machine(); - } - - return _machine.SampleOf; - } - set - { - if (_machine == null) - { - _machine = new Machine(); - } - - _machine.SampleOf = value; - } - } - public string SourceFile - { - get - { - if (_machine == null) - { - _machine = new Machine(); - } - - return _machine.SourceFile; - } - set - { - if (_machine == null) - { - _machine = new Machine(); - } - - _machine.SourceFile = value; - } - } - public bool? Runnable - { - get - { - if (_machine == null) - { - _machine = new Machine(); - } - - return _machine.Runnable; - } - set - { - if (_machine == null) - { - _machine = new Machine(); - } - - _machine.Runnable = value; - } - } - public string Board - { - get - { - if (_machine == null) - { - _machine = new Machine(); - } - - return _machine.Board; - } - set - { - if (_machine == null) - { - _machine = new Machine(); - } - - _machine.Board = value; - } - } - public string RebuildTo - { - get - { - if (_machine == null) - { - _machine = new Machine(); - } - - return _machine.RebuildTo; - } - set - { - if (_machine == null) - { - _machine = new Machine(); - } - - _machine.RebuildTo = value; - } - } - public List Devices - { - get - { - if (_machine == null) - { - _machine = new Machine(); - } - - return _machine.Devices; - } - set - { - if (_machine == null) - { - _machine = new Machine(); - } - - _machine.Devices = value; - } - } - public List SlotOptions - { - get - { - if (_machine == null) - { - _machine = new Machine(); - } - - return _machine.SlotOptions; - } - set - { - if (_machine == null) - { - _machine = new Machine(); - } - - _machine.SlotOptions = value; - } - } - public MachineType MachineType - { - get - { - if (_machine == null) - { - _machine = new Machine(); - } - - return _machine.MachineType; - } - set - { - if (_machine == null) - { - _machine = new Machine(); - } - - _machine.MachineType = value; - } - } - - // Software list information - public bool? Supported // yes = true, partial = null, no = false - { - get { return _machine.Supported; } - set { _machine.Supported = value; } - } - public string Publisher - { - get { return _machine.Publisher; } - set { _machine.Publisher = value; } - } - public List> Infos - { - get { return _machine.Infos; } - set { _machine.Infos = value; } - } - public string PartName - { - get { return _partName; } - set { _partName = value; } - } - public string PartInterface - { - get { return _partInterface; } - set { _partInterface = value; } - } - public List> Features - { - get { return _features; } - set { _features = value; } - } - public string AreaName - { - get { return _areaName; } - set { _areaName = value; } - } - public long? AreaSize - { - get { return _areaSize; } - set { _areaSize = value; } - } - - // Source metadata information - public int SystemID - { - get { return _systemId; } - set { _systemId = value; } - } - public string System - { - get { return _systemName; } - set { _systemName = value; } - } - public int SourceID - { - get { return _sourceId; } - set { _sourceId = value; } - } - public string Source - { - get { return _sourceName; } - set { _sourceName = value; } - } - public bool Remove - { - get { return _remove; } - set { _remove = value; } - } - - #endregion - - #region Instance Methods - - #region Cloning Methods - - /// - /// Clone the DatItem - /// - /// Clone of the DatItem - public abstract object Clone(); - - /// - /// Copy all machine information over in one shot - /// - /// Existing item to copy information from - public void CopyMachineInformation(DatItem item) - { - _machine = (Machine)item._machine.Clone(); - } - - /// - /// Copy all machine information over in one shot - /// - /// Existing machine to copy information from - public void CopyMachineInformation(Machine machine) - { - _machine = (Machine)machine.Clone(); - } - - #endregion - - #region Comparision Methods - - public int CompareTo(DatItem other) - { - int ret = 0; - - try - { - if (_name == other.Name) - { - ret = (this.Equals(other) ? 0 : 1); - } - ret = String.Compare(_name, other.Name); - } - catch - { - ret = 1; - } - - return ret; - } - - /// - /// Determine if an item is a duplicate using partial matching logic - /// - /// DatItem to use as a baseline - /// True if the roms are duplicates, false otherwise - public abstract bool Equals(DatItem other); - - /// - /// Return the duplicate status of two items - /// - /// DatItem to check against - /// The DupeType corresponding to the relationship between the two - public DupeType GetDuplicateStatus(DatItem lastItem) - { - DupeType output = 0x00; - - // If we don't have a duplicate at all, return none - if (!this.Equals(lastItem)) - { - return output; - } - - // If the duplicate is external already or should be, set it - if ((lastItem.Dupe & DupeType.External) != 0 || lastItem.SystemID != this.SystemID || lastItem.SourceID != this.SourceID) - { - if (lastItem.MachineName == this.MachineName && lastItem.Name == this.Name) - { - output = DupeType.External | DupeType.All; - } - else - { - output = DupeType.External | DupeType.Hash; - } - } - - // Otherwise, it's considered an internal dupe - else - { - if (lastItem.MachineName == this.MachineName && lastItem.Name == this.Name) - { - output = DupeType.Internal | DupeType.All; - } - else - { - output = DupeType.Internal | DupeType.Hash; - } - } - - return output; - } - - #endregion - - #region Sorting and Merging - - /// - /// Check if a DAT contains the given rom - /// - /// Dat to match against - /// True if the DAT is already sorted accordingly, false otherwise (default) - /// True if it contains the rom, false otherwise - public bool HasDuplicates(DatFile datdata, bool sorted = false) - { - // Check for an empty rom list first - if (datdata.Count == 0) - { - return false; - } - - // We want to get the proper key for the DatItem - string key = SortAndGetKey(datdata, sorted); - - // If the key doesn't exist, return the empty list - if (!datdata.Contains(key)) - { - return false; - } - - // Try to find duplicates - List roms = datdata[key]; - - foreach (DatItem rom in roms) - { - if (this.Equals(rom)) - { - return true; - } - } - - return false; - } - - /// - /// List all duplicates found in a DAT based on a rom - /// - /// Dat to match against - /// True to mark matched roms for removal from the input, false otherwise (default) - /// True if the DAT is already sorted accordingly, false otherwise (default) - /// List of matched DatItem objects - public List GetDuplicates(DatFile datdata, bool remove = false, bool sorted = false) - { - List output = new List(); - - // Check for an empty rom list first - if (datdata.Count == 0) - { - return output; - } - - // We want to get the proper key for the DatItem - string key = SortAndGetKey(datdata, sorted); - - // If the key doesn't exist, return the empty list - if (!datdata.Contains(key)) - { - return output; - } - - // Try to find duplicates - List roms = datdata[key]; - List left = new List(); - for (int i = 0; i < roms.Count; i++) - { - DatItem datItem = roms[i]; - - if (this.Equals(datItem)) - { - datItem.Remove = true; - output.Add(datItem); - } - else - { - left.Add(datItem); - } - } - - // If we're in removal mode, add back all roms with the proper flags - if (remove) - { - datdata.Remove(key); - datdata.AddRange(key, output); - datdata.AddRange(key, left); - } - - return output; - } - - /// - /// Sort the input DAT and get the key to be used by the item - /// - /// Dat to match against - /// True if the DAT is already sorted accordingly, false otherwise (default) - /// Key to try to use - private string SortAndGetKey(DatFile datdata, bool sorted = false) - { - // If we're not already sorted, take care of it - if (!sorted) - { - datdata.BucketByBestAvailable(); - } - - // Now that we have the sorted type, we get the proper key - return Utilities.GetKeyFromDatItem(this, datdata.SortedBy); - } - - #endregion - - #endregion // Instance Methods - - #region Static Methods - - #region Sorting and Merging - - /// - /// Merge an arbitrary set of ROMs based on the supplied information - /// - /// List of File objects representing the roms to be merged - /// A List of DatItem objects representing the merged roms - public static List Merge(List infiles) - { - // Check for null or blank roms first - if (infiles == null || infiles.Count == 0) - { - return new List(); - } - - // Create output list - List outfiles = new List(); - - // Then deduplicate them by checking to see if data matches previous saved roms - int nodumpCount = 0; - foreach (DatItem file in infiles) - { - // If we don't have a Rom or a Disk, we skip checking for duplicates - if (file.Type != ItemType.Rom && file.Type != ItemType.Disk) - { - continue; - } - - // If it's a nodump, add and skip - if (file.Type == ItemType.Rom && ((Rom)file).ItemStatus == ItemStatus.Nodump) - { - outfiles.Add(file); - nodumpCount++; - continue; - } - else if (file.Type == ItemType.Disk && ((Disk)file).ItemStatus == ItemStatus.Nodump) - { - outfiles.Add(file); - nodumpCount++; - continue; - } - // If it's the first non-nodump rom in the list, don't touch it - else if (outfiles.Count == 0 || outfiles.Count == nodumpCount) - { - outfiles.Add(file); - continue; - } - - // Check if the rom is a duplicate - DupeType dupetype = 0x00; - DatItem saveditem = new Rom(); - int pos = -1; - for (int i = 0; i < outfiles.Count; i++) - { - DatItem lastrom = outfiles[i]; - - // Get the duplicate status - dupetype = file.GetDuplicateStatus(lastrom); - - // If it's a duplicate, skip adding it to the output but add any missing information - if (dupetype != 0x00) - { - saveditem = lastrom; - pos = i; - - // Roms have more infomration to save - if (file.Type == ItemType.Rom) - { - ((Rom)saveditem).Size = (((Rom)saveditem).Size == -1 && ((Rom)file).Size != -1 - ? ((Rom)file).Size - : ((Rom)saveditem).Size); - ((Rom)saveditem).CRC = (String.IsNullOrWhiteSpace(((Rom)saveditem).CRC) && !String.IsNullOrWhiteSpace(((Rom)file).CRC) - ? ((Rom)file).CRC - : ((Rom)saveditem).CRC); - ((Rom)saveditem).MD5 = (String.IsNullOrWhiteSpace(((Rom)saveditem).MD5) && !String.IsNullOrWhiteSpace(((Rom)file).MD5) - ? ((Rom)file).MD5 - : ((Rom)saveditem).MD5); - ((Rom)saveditem).SHA1 = (String.IsNullOrWhiteSpace(((Rom)saveditem).SHA1) && !String.IsNullOrWhiteSpace(((Rom)file).SHA1) - ? ((Rom)file).SHA1 - : ((Rom)saveditem).SHA1); - ((Rom)saveditem).SHA256 = (String.IsNullOrWhiteSpace(((Rom)saveditem).SHA256) && !String.IsNullOrWhiteSpace(((Rom)file).SHA256) - ? ((Rom)file).SHA256 - : ((Rom)saveditem).SHA256); - ((Rom)saveditem).SHA384 = (String.IsNullOrWhiteSpace(((Rom)saveditem).SHA384) && !String.IsNullOrWhiteSpace(((Rom)file).SHA384) - ? ((Rom)file).SHA384 - : ((Rom)saveditem).SHA384); - ((Rom)saveditem).SHA512 = (String.IsNullOrWhiteSpace(((Rom)saveditem).SHA512) && !String.IsNullOrWhiteSpace(((Rom)file).SHA512) - ? ((Rom)file).SHA512 - : ((Rom)saveditem).SHA512); - } - else if (file.Type == ItemType.Disk) - { - ((Disk)saveditem).MD5 = (String.IsNullOrWhiteSpace(((Disk)saveditem).MD5) && !String.IsNullOrWhiteSpace(((Disk)file).MD5) - ? ((Disk)file).MD5 - : ((Disk)saveditem).MD5); - ((Disk)saveditem).SHA1 = (String.IsNullOrWhiteSpace(((Disk)saveditem).SHA1) && !String.IsNullOrWhiteSpace(((Disk)file).SHA1) - ? ((Disk)file).SHA1 - : ((Disk)saveditem).SHA1); - ((Disk)saveditem).SHA256 = (String.IsNullOrWhiteSpace(((Disk)saveditem).SHA256) && !String.IsNullOrWhiteSpace(((Disk)file).SHA256) - ? ((Disk)file).SHA256 - : ((Disk)saveditem).SHA256); - ((Disk)saveditem).SHA384 = (String.IsNullOrWhiteSpace(((Disk)saveditem).SHA384) && !String.IsNullOrWhiteSpace(((Disk)file).SHA384) - ? ((Disk)file).SHA384 - : ((Disk)saveditem).SHA384); - ((Disk)saveditem).SHA512 = (String.IsNullOrWhiteSpace(((Disk)saveditem).SHA512) && !String.IsNullOrWhiteSpace(((Disk)file).SHA512) - ? ((Disk)file).SHA512 - : ((Disk)saveditem).SHA512); - } - - saveditem.Dupe = dupetype; - - // If the current system has a lower ID than the previous, set the system accordingly - if (file.SystemID < saveditem.SystemID) - { - saveditem.SystemID = file.SystemID; - saveditem.System = file.System; - saveditem.CopyMachineInformation(file); - saveditem.Name = file.Name; - } - - // If the current source has a lower ID than the previous, set the source accordingly - if (file.SourceID < saveditem.SourceID) - { - saveditem.SourceID = file.SourceID; - saveditem.Source = file.Source; - saveditem.CopyMachineInformation(file); - saveditem.Name = file.Name; - } - - // If the current machine is a child of the new machine, use the new machine instead - if (saveditem.CloneOf == file.MachineName || saveditem.RomOf == file.MachineName) - { - saveditem.CopyMachineInformation(file); - saveditem.Name = file.Name; - } - - break; - } - } - - // If no duplicate is found, add it to the list - if (dupetype == 0x00) - { - outfiles.Add(file); - } - // Otherwise, if a new rom information is found, add that - else - { - outfiles.RemoveAt(pos); - outfiles.Insert(pos, saveditem); - } - } - - // Then return the result - return outfiles; - } - - /// - /// Resolve name duplicates in an arbitrary set of ROMs based on the supplied information - /// - /// List of File objects representing the roms to be merged - /// A List of DatItem objects representing the renamed roms - public static List ResolveNames(List infiles) - { - // Create the output list - List output = new List(); - - // First we want to make sure the list is in alphabetical order - Sort(ref infiles, true); - - // Now we want to loop through and check names - DatItem lastItem = null; - string lastrenamed = null; - int lastid = 0; - for (int i = 0; i < infiles.Count; i++) - { - DatItem datItem = infiles[i]; - - // If we have the first item, we automatically add it - if (lastItem == null) - { - output.Add(datItem); - lastItem = datItem; - continue; - } - - // If the current item exactly matches the last item, then we don't add it - if ((datItem.GetDuplicateStatus(lastItem) & DupeType.All) != 0) - { - Globals.Logger.Verbose("Exact duplicate found for '{0}'", datItem.Name); - continue; - } - - // If the current name matches the previous name, rename the current item - else if (datItem.Name == lastItem.Name) - { - Globals.Logger.Verbose("Name duplicate found for '{0}'", datItem.Name); - - if (datItem.Type == ItemType.Disk) - { - Disk disk = (Disk)datItem; - disk.Name += "_" + (!String.IsNullOrWhiteSpace(disk.MD5) - ? disk.MD5 - : !String.IsNullOrWhiteSpace(disk.SHA1) - ? disk.SHA1 - : "1"); - datItem = disk; - lastrenamed = lastrenamed ?? datItem.Name; - } - else if (datItem.Type == ItemType.Rom) - { - Rom rom = (Rom)datItem; - rom.Name += "_" + (!String.IsNullOrWhiteSpace(rom.CRC) - ? rom.CRC - : !String.IsNullOrWhiteSpace(rom.MD5) - ? rom.MD5 - : !String.IsNullOrWhiteSpace(rom.SHA1) - ? rom.SHA1 - : "1"); - datItem = rom; - lastrenamed = lastrenamed ?? datItem.Name; - } - - // If we have a conflict with the last renamed item, do the right thing - if (datItem.Name == lastrenamed) - { - lastrenamed = datItem.Name; - datItem.Name += (lastid == 0 ? "" : "_" + lastid); - lastid++; - } - // If we have no conflict, then we want to reset the lastrenamed and id - else - { - lastrenamed = null; - lastid = 0; - } - - output.Add(datItem); - } - - // Otherwise, we say that we have a valid named file - else - { - output.Add(datItem); - lastItem = datItem; - lastrenamed = null; - lastid = 0; - } - } - - // One last sort to make sure this is ordered - Sort(ref output, true); - - return output; - } - - /// - /// Sort a list of File objects by SystemID, SourceID, Game, and Name (in order) - /// - /// List of File objects representing the roms to be sorted - /// True if files are not renamed, false otherwise - /// True if it sorted correctly, false otherwise - public static bool Sort(ref List roms, bool norename) - { - roms.Sort(delegate (DatItem x, DatItem y) - { - try - { - NaturalComparer nc = new NaturalComparer(); - if (x.SystemID == y.SystemID) - { - if (x.SourceID == y.SourceID) - { - if (x.MachineName == y.MachineName) - { - if ((x.Type == ItemType.Rom || x.Type == ItemType.Disk) && (y.Type == ItemType.Rom || y.Type == ItemType.Disk)) - { - if (Path.GetDirectoryName(Utilities.RemovePathUnsafeCharacters(x.Name)) == Path.GetDirectoryName(Utilities.RemovePathUnsafeCharacters(y.Name))) - { - return nc.Compare(Path.GetFileName(Utilities.RemovePathUnsafeCharacters(x.Name)), Path.GetFileName(Utilities.RemovePathUnsafeCharacters(y.Name))); - } - return nc.Compare(Path.GetDirectoryName(Utilities.RemovePathUnsafeCharacters(x.Name)), Path.GetDirectoryName(Utilities.RemovePathUnsafeCharacters(y.Name))); - } - else if ((x.Type == ItemType.Rom || x.Type == ItemType.Disk) && (y.Type != ItemType.Rom && y.Type != ItemType.Disk)) - { - return -1; - } - else if ((x.Type != ItemType.Rom && x.Type != ItemType.Disk) && (y.Type == ItemType.Rom || y.Type == ItemType.Disk)) - { - return 1; - } - else - { - if (Path.GetDirectoryName(x.Name) == Path.GetDirectoryName(y.Name)) - { - return nc.Compare(Path.GetFileName(x.Name), Path.GetFileName(y.Name)); - } - return nc.Compare(Path.GetDirectoryName(x.Name), Path.GetDirectoryName(y.Name)); - } - } - return nc.Compare(x.MachineName, y.MachineName); - } - return (norename ? nc.Compare(x.MachineName, y.MachineName) : x.SourceID - y.SourceID); - } - return (norename ? nc.Compare(x.MachineName, y.MachineName) : x.SystemID - y.SystemID); - } - catch (Exception) - { - // Absorb the error - return 0; - } - }); - - return true; - } - - #endregion - - #endregion // Static Methods - } + /// + /// Base class for all items included in a set + /// + public abstract class DatItem : IEquatable, IComparable, ICloneable + { + #region Protected instance variables + + // Machine information + protected Machine _machine = new Machine(); + + #endregion + + #region Publicly facing variables + + #region Standard item information + + /// + /// Name of the item + /// + public string Name { get; set; } + + /// + /// Item type for outputting + /// + public ItemType ItemType { get; set; } + + /// + /// Duplicate type when compared to another item + /// + public DupeType DupeType { get; set; } + + #endregion + + #region Machine information + + /// + /// Name of the machine associated with the item + /// + public string MachineName + { + get + { + if (_machine == null) + { + _machine = new Machine(); + } + + return _machine.Name; + } + set + { + if (_machine == null) + { + _machine = new Machine(); + } + + _machine.Name = value; + } + } + + /// + /// Additional notes on the machine + /// + public string Comment + { + get + { + if (_machine == null) + { + _machine = new Machine(); + } + + return _machine.Comment; + } + set + { + if (_machine == null) + { + _machine = new Machine(); + } + + _machine.Comment = value; + } + } + + /// + /// Extended description of the machine + /// + public string MachineDescription + { + get + { + if (_machine == null) + { + _machine = new Machine(); + } + + return _machine.Description; + } + set + { + if (_machine == null) + { + _machine = new Machine(); + } + + _machine.Description = value; + } + } + + /// + /// Machine year(s) of release/manufacture + /// + public string Year + { + get + { + if (_machine == null) + { + _machine = new Machine(); + } + + return _machine.Year; + } + set + { + if (_machine == null) + { + _machine = new Machine(); + } + + _machine.Year = value; + } + } + + /// + /// Machine manufacturer, if available + /// + public string Manufacturer + { + get + { + if (_machine == null) + { + _machine = new Machine(); + } + + return _machine.Manufacturer; + } + set + { + if (_machine == null) + { + _machine = new Machine(); + } + + _machine.Manufacturer = value; + } + } + + /// + /// Machine publisher, if available + /// + public string Publisher + { + get { return _machine.Publisher; } + set { _machine.Publisher = value; } + } + + /// + /// Machine romof parent + /// + public string RomOf + { + get + { + if (_machine == null) + { + _machine = new Machine(); + } + + return _machine.RomOf; + } + set + { + if (_machine == null) + { + _machine = new Machine(); + } + + _machine.RomOf = value; + } + } + + /// + /// Machine cloneof parent + /// + public string CloneOf + { + get + { + if (_machine == null) + { + _machine = new Machine(); + } + + return _machine.CloneOf; + } + set + { + if (_machine == null) + { + _machine = new Machine(); + } + + _machine.CloneOf = value; + } + } + + /// + /// Machine sampleof parent + /// + public string SampleOf + { + get + { + if (_machine == null) + { + _machine = new Machine(); + } + + return _machine.SampleOf; + } + set + { + if (_machine == null) + { + _machine = new Machine(); + } + + _machine.SampleOf = value; + } + } + + /// + /// Machine support status + /// + /// yes = true, partial = null, no = false + public bool? Supported + { + get { return _machine.Supported; } + set { _machine.Supported = value; } + } + + /// + /// Emulator source file related to the machine + /// + public string SourceFile + { + get + { + if (_machine == null) + { + _machine = new Machine(); + } + + return _machine.SourceFile; + } + set + { + if (_machine == null) + { + _machine = new Machine(); + } + + _machine.SourceFile = value; + } + } + + /// + /// Machine runnable status + /// + /// yes = true, partial = null, no = false + public bool? Runnable + { + get + { + if (_machine == null) + { + _machine = new Machine(); + } + + return _machine.Runnable; + } + set + { + if (_machine == null) + { + _machine = new Machine(); + } + + _machine.Runnable = value; + } + } + + /// + /// Machine board name + /// + public string Board + { + get + { + if (_machine == null) + { + _machine = new Machine(); + } + + return _machine.Board; + } + set + { + if (_machine == null) + { + _machine = new Machine(); + } + + _machine.Board = value; + } + } + + /// + /// Rebuild location if different than machine name + /// + public string RebuildTo + { + get + { + if (_machine == null) + { + _machine = new Machine(); + } + + return _machine.RebuildTo; + } + set + { + if (_machine == null) + { + _machine = new Machine(); + } + + _machine.RebuildTo = value; + } + } + + /// + /// List of associated device names + /// + public List Devices + { + get + { + if (_machine == null) + { + _machine = new Machine(); + } + + return _machine.Devices; + } + set + { + if (_machine == null) + { + _machine = new Machine(); + } + + _machine.Devices = value; + } + } + + /// + /// List of slot options + /// + public List SlotOptions + { + get + { + if (_machine == null) + { + _machine = new Machine(); + } + + return _machine.SlotOptions; + } + set + { + if (_machine == null) + { + _machine = new Machine(); + } + + _machine.SlotOptions = value; + } + } + + /// + /// List of info items + /// + public List> Infos + { + get + { + if (_machine == null) + { + _machine = new Machine(); + } + + return _machine.Infos; + } + set + { + if (_machine == null) + { + _machine = new Machine(); + } + + _machine.Infos = value; + } + } + + /// + /// Type of the associated machine + /// + public MachineType MachineType + { + get + { + if (_machine == null) + { + _machine = new Machine(); + } + + return _machine.MachineType; + } + set + { + if (_machine == null) + { + _machine = new Machine(); + } + + _machine.MachineType = value; + } + } + + #endregion + + #region Software list information + + /// + /// Original hardware part associated with the item + /// + public string PartName { get; set; } + + /// + /// Original hardware interface associated with the item + /// + public string PartInterface { get; set; } + + /// + /// Features provided to/by the item + /// + public List> Features { get; set; } + + /// + /// Original hardware part name within an item + /// + public string AreaName { get; set; } + + /// + /// Original hardware size within the part + /// + public long? AreaSize { get; set; } + + #endregion + + #region Source metadata information + + /// + /// Internal system ID for organization + /// + public int SystemID { get; set; } + + /// + /// Internal system name for organization + /// + public string System { get; set; } + + /// + /// Internal source ID for organization + /// + public int SourceID { get; set; } + + /// + /// Internal source name for organization + /// + public string Source { get; set; } + + /// + /// Flag if item should be removed + /// + public bool Remove { get; set; } + + #endregion + + #endregion + + #region Instance Methods + + #region Cloning Methods + + /// + /// Clone the DatItem + /// + /// Clone of the DatItem + public abstract object Clone(); + + /// + /// Copy all machine information over in one shot + /// + /// Existing item to copy information from + public void CopyMachineInformation(DatItem item) + { + _machine = (Machine)item._machine.Clone(); + } + + /// + /// Copy all machine information over in one shot + /// + /// Existing machine to copy information from + public void CopyMachineInformation(Machine machine) + { + _machine = (Machine)machine.Clone(); + } + + #endregion + + #region Comparision Methods + + public int CompareTo(DatItem other) + { + int ret = 0; + + try + { + if (this.Name == other.Name) + { + ret = (this.Equals(other) ? 0 : 1); + } + ret = String.Compare(this.Name, other.Name); + } + catch + { + ret = 1; + } + + return ret; + } + + /// + /// Determine if an item is a duplicate using partial matching logic + /// + /// DatItem to use as a baseline + /// True if the roms are duplicates, false otherwise + public abstract bool Equals(DatItem other); + + /// + /// Return the duplicate status of two items + /// + /// DatItem to check against + /// The DupeType corresponding to the relationship between the two + public DupeType GetDuplicateStatus(DatItem lastItem) + { + DupeType output = 0x00; + + // If we don't have a duplicate at all, return none + if (!this.Equals(lastItem)) + { + return output; + } + + // If the duplicate is external already or should be, set it + if ((lastItem.DupeType & DupeType.External) != 0 || lastItem.SystemID != this.SystemID || lastItem.SourceID != this.SourceID) + { + if (lastItem.MachineName == this.MachineName && lastItem.Name == this.Name) + { + output = DupeType.External | DupeType.All; + } + else + { + output = DupeType.External | DupeType.Hash; + } + } + + // Otherwise, it's considered an internal dupe + else + { + if (lastItem.MachineName == this.MachineName && lastItem.Name == this.Name) + { + output = DupeType.Internal | DupeType.All; + } + else + { + output = DupeType.Internal | DupeType.Hash; + } + } + + return output; + } + + #endregion + + #region Sorting and Merging + + /// + /// Check if a DAT contains the given rom + /// + /// Dat to match against + /// True if the DAT is already sorted accordingly, false otherwise (default) + /// True if it contains the rom, false otherwise + public bool HasDuplicates(DatFile datdata, bool sorted = false) + { + // Check for an empty rom list first + if (datdata.Count == 0) + { + return false; + } + + // We want to get the proper key for the DatItem + string key = SortAndGetKey(datdata, sorted); + + // If the key doesn't exist, return the empty list + if (!datdata.Contains(key)) + { + return false; + } + + // Try to find duplicates + List roms = datdata[key]; + + foreach (DatItem rom in roms) + { + if (this.Equals(rom)) + { + return true; + } + } + + return false; + } + + /// + /// List all duplicates found in a DAT based on a rom + /// + /// Dat to match against + /// True to mark matched roms for removal from the input, false otherwise (default) + /// True if the DAT is already sorted accordingly, false otherwise (default) + /// List of matched DatItem objects + public List GetDuplicates(DatFile datdata, bool remove = false, bool sorted = false) + { + List output = new List(); + + // Check for an empty rom list first + if (datdata.Count == 0) + { + return output; + } + + // We want to get the proper key for the DatItem + string key = SortAndGetKey(datdata, sorted); + + // If the key doesn't exist, return the empty list + if (!datdata.Contains(key)) + { + return output; + } + + // Try to find duplicates + List roms = datdata[key]; + List left = new List(); + for (int i = 0; i < roms.Count; i++) + { + DatItem datItem = roms[i]; + + if (this.Equals(datItem)) + { + datItem.Remove = true; + output.Add(datItem); + } + else + { + left.Add(datItem); + } + } + + // If we're in removal mode, add back all roms with the proper flags + if (remove) + { + datdata.Remove(key); + datdata.AddRange(key, output); + datdata.AddRange(key, left); + } + + return output; + } + + /// + /// Sort the input DAT and get the key to be used by the item + /// + /// Dat to match against + /// True if the DAT is already sorted accordingly, false otherwise (default) + /// Key to try to use + private string SortAndGetKey(DatFile datdata, bool sorted = false) + { + // If we're not already sorted, take care of it + if (!sorted) + { + datdata.BucketByBestAvailable(); + } + + // Now that we have the sorted type, we get the proper key + return Utilities.GetKeyFromDatItem(this, datdata.SortedBy); + } + + #endregion + + #endregion // Instance Methods + + #region Static Methods + + #region Sorting and Merging + + /// + /// Merge an arbitrary set of ROMs based on the supplied information + /// + /// List of File objects representing the roms to be merged + /// A List of DatItem objects representing the merged roms + public static List Merge(List infiles) + { + // Check for null or blank roms first + if (infiles == null || infiles.Count == 0) + { + return new List(); + } + + // Create output list + List outfiles = new List(); + + // Then deduplicate them by checking to see if data matches previous saved roms + int nodumpCount = 0; + foreach (DatItem file in infiles) + { + // If we don't have a Rom or a Disk, we skip checking for duplicates + if (file.ItemType != ItemType.Rom && file.ItemType != ItemType.Disk) + { + continue; + } + + // If it's a nodump, add and skip + if (file.ItemType == ItemType.Rom && ((Rom)file).ItemStatus == ItemStatus.Nodump) + { + outfiles.Add(file); + nodumpCount++; + continue; + } + else if (file.ItemType == ItemType.Disk && ((Disk)file).ItemStatus == ItemStatus.Nodump) + { + outfiles.Add(file); + nodumpCount++; + continue; + } + // If it's the first non-nodump rom in the list, don't touch it + else if (outfiles.Count == 0 || outfiles.Count == nodumpCount) + { + outfiles.Add(file); + continue; + } + + // Check if the rom is a duplicate + DupeType dupetype = 0x00; + DatItem saveditem = new Rom(); + int pos = -1; + for (int i = 0; i < outfiles.Count; i++) + { + DatItem lastrom = outfiles[i]; + + // Get the duplicate status + dupetype = file.GetDuplicateStatus(lastrom); + + // If it's a duplicate, skip adding it to the output but add any missing information + if (dupetype != 0x00) + { + saveditem = lastrom; + pos = i; + + // Roms have more infomration to save + if (file.ItemType == ItemType.Rom) + { + ((Rom)saveditem).Size = (((Rom)saveditem).Size == -1 && ((Rom)file).Size != -1 + ? ((Rom)file).Size + : ((Rom)saveditem).Size); + ((Rom)saveditem).CRC = (String.IsNullOrWhiteSpace(((Rom)saveditem).CRC) && !String.IsNullOrWhiteSpace(((Rom)file).CRC) + ? ((Rom)file).CRC + : ((Rom)saveditem).CRC); + ((Rom)saveditem).MD5 = (String.IsNullOrWhiteSpace(((Rom)saveditem).MD5) && !String.IsNullOrWhiteSpace(((Rom)file).MD5) + ? ((Rom)file).MD5 + : ((Rom)saveditem).MD5); + ((Rom)saveditem).SHA1 = (String.IsNullOrWhiteSpace(((Rom)saveditem).SHA1) && !String.IsNullOrWhiteSpace(((Rom)file).SHA1) + ? ((Rom)file).SHA1 + : ((Rom)saveditem).SHA1); + ((Rom)saveditem).SHA256 = (String.IsNullOrWhiteSpace(((Rom)saveditem).SHA256) && !String.IsNullOrWhiteSpace(((Rom)file).SHA256) + ? ((Rom)file).SHA256 + : ((Rom)saveditem).SHA256); + ((Rom)saveditem).SHA384 = (String.IsNullOrWhiteSpace(((Rom)saveditem).SHA384) && !String.IsNullOrWhiteSpace(((Rom)file).SHA384) + ? ((Rom)file).SHA384 + : ((Rom)saveditem).SHA384); + ((Rom)saveditem).SHA512 = (String.IsNullOrWhiteSpace(((Rom)saveditem).SHA512) && !String.IsNullOrWhiteSpace(((Rom)file).SHA512) + ? ((Rom)file).SHA512 + : ((Rom)saveditem).SHA512); + } + else if (file.ItemType == ItemType.Disk) + { + ((Disk)saveditem).MD5 = (String.IsNullOrWhiteSpace(((Disk)saveditem).MD5) && !String.IsNullOrWhiteSpace(((Disk)file).MD5) + ? ((Disk)file).MD5 + : ((Disk)saveditem).MD5); + ((Disk)saveditem).SHA1 = (String.IsNullOrWhiteSpace(((Disk)saveditem).SHA1) && !String.IsNullOrWhiteSpace(((Disk)file).SHA1) + ? ((Disk)file).SHA1 + : ((Disk)saveditem).SHA1); + ((Disk)saveditem).SHA256 = (String.IsNullOrWhiteSpace(((Disk)saveditem).SHA256) && !String.IsNullOrWhiteSpace(((Disk)file).SHA256) + ? ((Disk)file).SHA256 + : ((Disk)saveditem).SHA256); + ((Disk)saveditem).SHA384 = (String.IsNullOrWhiteSpace(((Disk)saveditem).SHA384) && !String.IsNullOrWhiteSpace(((Disk)file).SHA384) + ? ((Disk)file).SHA384 + : ((Disk)saveditem).SHA384); + ((Disk)saveditem).SHA512 = (String.IsNullOrWhiteSpace(((Disk)saveditem).SHA512) && !String.IsNullOrWhiteSpace(((Disk)file).SHA512) + ? ((Disk)file).SHA512 + : ((Disk)saveditem).SHA512); + } + + saveditem.DupeType = dupetype; + + // If the current system has a lower ID than the previous, set the system accordingly + if (file.SystemID < saveditem.SystemID) + { + saveditem.SystemID = file.SystemID; + saveditem.System = file.System; + saveditem.CopyMachineInformation(file); + saveditem.Name = file.Name; + } + + // If the current source has a lower ID than the previous, set the source accordingly + if (file.SourceID < saveditem.SourceID) + { + saveditem.SourceID = file.SourceID; + saveditem.Source = file.Source; + saveditem.CopyMachineInformation(file); + saveditem.Name = file.Name; + } + + // If the current machine is a child of the new machine, use the new machine instead + if (saveditem.CloneOf == file.MachineName || saveditem.RomOf == file.MachineName) + { + saveditem.CopyMachineInformation(file); + saveditem.Name = file.Name; + } + + break; + } + } + + // If no duplicate is found, add it to the list + if (dupetype == 0x00) + { + outfiles.Add(file); + } + // Otherwise, if a new rom information is found, add that + else + { + outfiles.RemoveAt(pos); + outfiles.Insert(pos, saveditem); + } + } + + // Then return the result + return outfiles; + } + + /// + /// Resolve name duplicates in an arbitrary set of ROMs based on the supplied information + /// + /// List of File objects representing the roms to be merged + /// A List of DatItem objects representing the renamed roms + public static List ResolveNames(List infiles) + { + // Create the output list + List output = new List(); + + // First we want to make sure the list is in alphabetical order + Sort(ref infiles, true); + + // Now we want to loop through and check names + DatItem lastItem = null; + string lastrenamed = null; + int lastid = 0; + for (int i = 0; i < infiles.Count; i++) + { + DatItem datItem = infiles[i]; + + // If we have the first item, we automatically add it + if (lastItem == null) + { + output.Add(datItem); + lastItem = datItem; + continue; + } + + // If the current item exactly matches the last item, then we don't add it + if ((datItem.GetDuplicateStatus(lastItem) & DupeType.All) != 0) + { + Globals.Logger.Verbose("Exact duplicate found for '{0}'", datItem.Name); + continue; + } + + // If the current name matches the previous name, rename the current item + else if (datItem.Name == lastItem.Name) + { + Globals.Logger.Verbose("Name duplicate found for '{0}'", datItem.Name); + + if (datItem.ItemType == ItemType.Disk) + { + Disk disk = (Disk)datItem; + disk.Name += "_" + (!String.IsNullOrWhiteSpace(disk.MD5) + ? disk.MD5 + : !String.IsNullOrWhiteSpace(disk.SHA1) + ? disk.SHA1 + : "1"); + datItem = disk; + lastrenamed = lastrenamed ?? datItem.Name; + } + else if (datItem.ItemType == ItemType.Rom) + { + Rom rom = (Rom)datItem; + rom.Name += "_" + (!String.IsNullOrWhiteSpace(rom.CRC) + ? rom.CRC + : !String.IsNullOrWhiteSpace(rom.MD5) + ? rom.MD5 + : !String.IsNullOrWhiteSpace(rom.SHA1) + ? rom.SHA1 + : "1"); + datItem = rom; + lastrenamed = lastrenamed ?? datItem.Name; + } + + // If we have a conflict with the last renamed item, do the right thing + if (datItem.Name == lastrenamed) + { + lastrenamed = datItem.Name; + datItem.Name += (lastid == 0 ? "" : "_" + lastid); + lastid++; + } + // If we have no conflict, then we want to reset the lastrenamed and id + else + { + lastrenamed = null; + lastid = 0; + } + + output.Add(datItem); + } + + // Otherwise, we say that we have a valid named file + else + { + output.Add(datItem); + lastItem = datItem; + lastrenamed = null; + lastid = 0; + } + } + + // One last sort to make sure this is ordered + Sort(ref output, true); + + return output; + } + + /// + /// Sort a list of File objects by SystemID, SourceID, Game, and Name (in order) + /// + /// List of File objects representing the roms to be sorted + /// True if files are not renamed, false otherwise + /// True if it sorted correctly, false otherwise + public static bool Sort(ref List roms, bool norename) + { + roms.Sort(delegate (DatItem x, DatItem y) + { + try + { + NaturalComparer nc = new NaturalComparer(); + if (x.SystemID == y.SystemID) + { + if (x.SourceID == y.SourceID) + { + if (x.MachineName == y.MachineName) + { + if ((x.ItemType == ItemType.Rom || x.ItemType == ItemType.Disk) && (y.ItemType == ItemType.Rom || y.ItemType == ItemType.Disk)) + { + if (Path.GetDirectoryName(Utilities.RemovePathUnsafeCharacters(x.Name)) == Path.GetDirectoryName(Utilities.RemovePathUnsafeCharacters(y.Name))) + { + return nc.Compare(Path.GetFileName(Utilities.RemovePathUnsafeCharacters(x.Name)), Path.GetFileName(Utilities.RemovePathUnsafeCharacters(y.Name))); + } + return nc.Compare(Path.GetDirectoryName(Utilities.RemovePathUnsafeCharacters(x.Name)), Path.GetDirectoryName(Utilities.RemovePathUnsafeCharacters(y.Name))); + } + else if ((x.ItemType == ItemType.Rom || x.ItemType == ItemType.Disk) && (y.ItemType != ItemType.Rom && y.ItemType != ItemType.Disk)) + { + return -1; + } + else if ((x.ItemType != ItemType.Rom && x.ItemType != ItemType.Disk) && (y.ItemType == ItemType.Rom || y.ItemType == ItemType.Disk)) + { + return 1; + } + else + { + if (Path.GetDirectoryName(x.Name) == Path.GetDirectoryName(y.Name)) + { + return nc.Compare(Path.GetFileName(x.Name), Path.GetFileName(y.Name)); + } + return nc.Compare(Path.GetDirectoryName(x.Name), Path.GetDirectoryName(y.Name)); + } + } + return nc.Compare(x.MachineName, y.MachineName); + } + return (norename ? nc.Compare(x.MachineName, y.MachineName) : x.SourceID - y.SourceID); + } + return (norename ? nc.Compare(x.MachineName, y.MachineName) : x.SystemID - y.SystemID); + } + catch (Exception) + { + // Absorb the error + return 0; + } + }); + + return true; + } + + #endregion + + #endregion // Static Methods + } } diff --git a/SabreTools.Library/DatItems/Disk.cs b/SabreTools.Library/DatItems/Disk.cs index 6a67732f..1d51bb72 100644 --- a/SabreTools.Library/DatItems/Disk.cs +++ b/SabreTools.Library/DatItems/Disk.cs @@ -129,8 +129,8 @@ namespace SabreTools.Library.DatItems return new Disk() { Name = this.Name, - Type = this.Type, - Dupe = this.Dupe, + ItemType = this.ItemType, + DupeType = this.DupeType, Supported = this.Supported, Publisher = this.Publisher, @@ -179,7 +179,7 @@ namespace SabreTools.Library.DatItems bool dupefound = false; // If we don't have a rom, return false - if (_itemType != other.Type) + if (_itemType != other.ItemType) { return dupefound; } diff --git a/SabreTools.Library/DatItems/Machine.cs b/SabreTools.Library/DatItems/Machine.cs index 61268a70..7c427fc2 100644 --- a/SabreTools.Library/DatItems/Machine.cs +++ b/SabreTools.Library/DatItems/Machine.cs @@ -1,126 +1,197 @@ using System; using System.Collections.Generic; - using SabreTools.Library.Data; namespace SabreTools.Library.DatItems { - /// - /// Represents the information specific to a set/game/machine - /// - public class Machine : ICloneable - { - #region Publicly facing variables + /// + /// Represents the information specific to a set/game/machine + /// + public class Machine : ICloneable + { + #region Publicly facing variables - // Machine information - public string Name; - public string Comment; - public string Description; - public string Year; - public string Manufacturer; - public string Publisher; - public string RomOf; - public string CloneOf; - public string SampleOf; - public bool? Supported; - public string SourceFile; - public bool? Runnable; - public string Board; - public string RebuildTo; - public List Devices; - public List SlotOptions; - public List> Infos; - public MachineType MachineType; + /// + /// Name of the machine + /// + public string Name { get; set; } - #endregion + /// + /// Additional notes + /// + public string Comment { get; set; } - #region Constructors + /// + /// Extended description + /// + public string Description { get; set; } - /// - /// Create a new Machine object - /// - public Machine() - { - Name = null; - Comment = null; - Description = null; - Year = null; - Manufacturer = null; - Publisher = null; - RomOf = null; - CloneOf = null; - SampleOf = null; - Supported = true; - SourceFile = null; - Runnable = null; - Board = null; - RebuildTo = null; - Devices = null; - SlotOptions = null; - Infos = null; - MachineType = MachineType.NULL; - } + /// + /// Year(s) of release/manufacture + /// + public string Year { get; set; } - /// - /// Create a new Machine object with the included information - /// - /// Name of the machine - /// Description of the machine - public Machine(string name, string description) - { - Name = name; - Comment = null; - Description = description; - Year = null; - Manufacturer = null; - Publisher = null; - RomOf = null; - CloneOf = null; - SampleOf = null; - Supported = true; - SourceFile = null; - Runnable = null; - Board = null; - RebuildTo = null; - Devices = null; - SlotOptions = null; - Infos = null; - MachineType = MachineType.NULL; - } + /// + /// Manufacturer, if available + /// + public string Manufacturer { get; set; } - #endregion + /// + /// Publisher, if available + /// + public string Publisher { get; set; } - #region Cloning methods + /// + /// fomof parent + /// + public string RomOf { get; set; } - /// - /// Create a clone of the current machine - /// - /// New machine with the same values as the current one - public object Clone() - { - return new Machine() - { - Name = this.Name, - Comment = this.Comment, - Description = this.Description, - Year = this.Year, - Manufacturer = this.Manufacturer, - Publisher = this.Publisher, - RomOf = this.RomOf, - CloneOf = this.CloneOf, - SampleOf = this.SampleOf, - Supported = this.Supported, - SourceFile = this.SourceFile, - Runnable = this.Runnable, - Board = this.Board, - RebuildTo = this.RebuildTo, - Devices = this.Devices, - SlotOptions = this.SlotOptions, - Infos = this.Infos, - MachineType = this.MachineType, - }; - } + /// + /// cloneof parent + /// + public string CloneOf { get; set; } - #endregion - } + /// + /// sampleof parent + /// + public string SampleOf { get; set; } + + /// + /// Support status + /// + /// yes = true, partial = null, no = false + public bool? Supported { get; set; } + + /// + /// Emulator source file related to the machine + /// + public string SourceFile { get; set; } + + /// + /// Machine runnable status + /// + /// yes = true, partial = null, no = false + public bool? Runnable { get; set; } + + /// + /// Machine board name + /// + public string Board { get; set; } + + /// + /// Rebuild location if different than machine name + /// + public string RebuildTo { get; set; } + + /// + /// List of associated device names + /// + public List Devices { get; set; } + + /// + /// List of slot options + /// + public List SlotOptions { get; set; } + + /// + /// List of info items + /// + public List> Infos { get; set; } + + /// + /// Type of the machine + /// + public MachineType MachineType { get; set; } + + #endregion + + #region Constructors + + /// + /// Create a new Machine object + /// + public Machine() + { + Name = null; + Comment = null; + Description = null; + Year = null; + Manufacturer = null; + Publisher = null; + RomOf = null; + CloneOf = null; + SampleOf = null; + Supported = true; + SourceFile = null; + Runnable = null; + Board = null; + RebuildTo = null; + Devices = null; + SlotOptions = null; + Infos = null; + MachineType = MachineType.NULL; + } + + /// + /// Create a new Machine object with the included information + /// + /// Name of the machine + /// Description of the machine + public Machine(string name, string description) + { + Name = name; + Comment = null; + Description = description; + Year = null; + Manufacturer = null; + Publisher = null; + RomOf = null; + CloneOf = null; + SampleOf = null; + Supported = true; + SourceFile = null; + Runnable = null; + Board = null; + RebuildTo = null; + Devices = null; + SlotOptions = null; + Infos = null; + MachineType = MachineType.NULL; + } + + #endregion + + #region Cloning methods + + /// + /// Create a clone of the current machine + /// + /// New machine with the same values as the current one + public object Clone() + { + return new Machine() + { + Name = this.Name, + Comment = this.Comment, + Description = this.Description, + Year = this.Year, + Manufacturer = this.Manufacturer, + Publisher = this.Publisher, + RomOf = this.RomOf, + CloneOf = this.CloneOf, + SampleOf = this.SampleOf, + Supported = this.Supported, + SourceFile = this.SourceFile, + Runnable = this.Runnable, + Board = this.Board, + RebuildTo = this.RebuildTo, + Devices = this.Devices, + SlotOptions = this.SlotOptions, + Infos = this.Infos, + MachineType = this.MachineType, + }; + } + + #endregion + } } diff --git a/SabreTools.Library/DatItems/Release.cs b/SabreTools.Library/DatItems/Release.cs index fd44acd8..e02b7c6e 100644 --- a/SabreTools.Library/DatItems/Release.cs +++ b/SabreTools.Library/DatItems/Release.cs @@ -65,8 +65,8 @@ namespace SabreTools.Library.DatItems return new Release() { Name = this.Name, - Type = this.Type, - Dupe = this.Dupe, + ItemType = this.ItemType, + DupeType = this.DupeType, Supported = this.Supported, Publisher = this.Publisher, @@ -111,7 +111,7 @@ namespace SabreTools.Library.DatItems public override bool Equals(DatItem other) { // If we don't have a release return false - if (_itemType != other.Type) + if (_itemType != other.ItemType) { return false; } diff --git a/SabreTools.Library/DatItems/Rom.cs b/SabreTools.Library/DatItems/Rom.cs index 33e832d5..ba39dd78 100644 --- a/SabreTools.Library/DatItems/Rom.cs +++ b/SabreTools.Library/DatItems/Rom.cs @@ -196,8 +196,8 @@ namespace SabreTools.Library.DatItems return new Rom() { Name = this.Name, - Type = this.Type, - Dupe = this.Dupe, + ItemType = this.ItemType, + DupeType = this.DupeType, Supported = this.Supported, Publisher = this.Publisher, @@ -249,7 +249,7 @@ namespace SabreTools.Library.DatItems bool dupefound = false; // If we don't have a rom, return false - if (_itemType != other.Type) + if (_itemType != other.ItemType) { return dupefound; } diff --git a/SabreTools.Library/DatItems/Sample.cs b/SabreTools.Library/DatItems/Sample.cs index 5e1749a3..2dc4a7a2 100644 --- a/SabreTools.Library/DatItems/Sample.cs +++ b/SabreTools.Library/DatItems/Sample.cs @@ -27,8 +27,8 @@ namespace SabreTools.Library.DatItems return new Sample() { Name = this.Name, - Type = this.Type, - Dupe = this.Dupe, + ItemType = this.ItemType, + DupeType = this.DupeType, Supported = this.Supported, Publisher = this.Publisher, @@ -68,7 +68,7 @@ namespace SabreTools.Library.DatItems public override bool Equals(DatItem other) { // If we don't have a sample, return false - if (_itemType != other.Type) + if (_itemType != other.ItemType) { return false; } diff --git a/SabreTools.Library/FileTypes/Folder.cs b/SabreTools.Library/FileTypes/Folder.cs index 9b75f005..973c3719 100644 --- a/SabreTools.Library/FileTypes/Folder.cs +++ b/SabreTools.Library/FileTypes/Folder.cs @@ -283,7 +283,7 @@ namespace SabreTools.Library.FileTypes } outputStream.Dispose(); - if (rom.Type == ItemType.Rom) + if (rom.ItemType == ItemType.Rom) { if (date && !String.IsNullOrWhiteSpace(((Rom)rom).Date)) { diff --git a/SabreTools.Library/Tools/Utilities.cs b/SabreTools.Library/Tools/Utilities.cs index a23be8d5..762efd15 100644 --- a/SabreTools.Library/Tools/Utilities.cs +++ b/SabreTools.Library/Tools/Utilities.cs @@ -2617,7 +2617,7 @@ namespace SabreTools.Library.Tools switch (sortedBy) { case SortedBy.CRC: - key = (item.Type == ItemType.Rom ? ((Rom)item).CRC : Constants.CRCZero); + key = (item.ItemType == ItemType.Rom ? ((Rom)item).CRC : Constants.CRCZero); break; case SortedBy.Game: key = (norename ? "" @@ -2639,37 +2639,37 @@ namespace SabreTools.Library.Tools key = HttpUtility.HtmlEncode(key); break; case SortedBy.MD5: - key = (item.Type == ItemType.Rom + key = (item.ItemType == ItemType.Rom ? ((Rom)item).MD5 - : (item.Type == ItemType.Disk + : (item.ItemType == ItemType.Disk ? ((Disk)item).MD5 : Constants.MD5Zero)); break; case SortedBy.SHA1: - key = (item.Type == ItemType.Rom + key = (item.ItemType == ItemType.Rom ? ((Rom)item).SHA1 - : (item.Type == ItemType.Disk + : (item.ItemType == ItemType.Disk ? ((Disk)item).SHA1 : Constants.SHA1Zero)); break; case SortedBy.SHA256: - key = (item.Type == ItemType.Rom + key = (item.ItemType == ItemType.Rom ? ((Rom)item).SHA256 - : (item.Type == ItemType.Disk + : (item.ItemType == ItemType.Disk ? ((Disk)item).SHA256 : Constants.SHA256Zero)); break; case SortedBy.SHA384: - key = (item.Type == ItemType.Rom + key = (item.ItemType == ItemType.Rom ? ((Rom)item).SHA384 - : (item.Type == ItemType.Disk + : (item.ItemType == ItemType.Disk ? ((Disk)item).SHA384 : Constants.SHA384Zero)); break; case SortedBy.SHA512: - key = (item.Type == ItemType.Rom + key = (item.ItemType == ItemType.Rom ? ((Rom)item).SHA512 - : (item.Type == ItemType.Disk + : (item.ItemType == ItemType.Disk ? ((Disk)item).SHA512 : Constants.SHA512Zero)); break;