diff --git a/SabreTools.DatFiles/DatFile.ToMetadata.cs b/SabreTools.DatFiles/DatFile.ToMetadata.cs index 7fe4c0ef..b2135818 100644 --- a/SabreTools.DatFiles/DatFile.ToMetadata.cs +++ b/SabreTools.DatFiles/DatFile.ToMetadata.cs @@ -71,7 +71,7 @@ namespace SabreTools.DatFiles // Loop through the sorted items and create games for them foreach (string key in Items.SortedKeys) { - var items = Items.FilteredItems(key); + var items = Items.GetItemsForBucket(key, filter: true); if (items == null || items.Count == 0) continue; @@ -494,7 +494,7 @@ namespace SabreTools.DatFiles // Loop through the sorted items and create games for them foreach (string key in ItemsDB.SortedKeys) { - var items = ItemsDB.GetItemsForBucket(key, filter: true); + var items = GetItemsForBucketDB(key, filter: true); if (items == null || items.Count == 0) continue; diff --git a/SabreTools.DatFiles/DatFile.cs b/SabreTools.DatFiles/DatFile.cs index 90a094a3..dd09be9e 100644 --- a/SabreTools.DatFiles/DatFile.cs +++ b/SabreTools.DatFiles/DatFile.cs @@ -38,6 +38,13 @@ namespace SabreTools.DatFiles [JsonProperty("items"), XmlElement("items")] public ItemDictionaryDB ItemsDB { get; private set; } = new ItemDictionaryDB(); + /// + /// DAT statistics + /// + [JsonIgnore, XmlIgnore] + public DatStatistics DatStatistics => Items.DatStatistics; + //public DatStatistics DatStatistics => ItemsDB.DatStatistics; + /// /// List of supported types for writing /// @@ -134,21 +141,7 @@ namespace SabreTools.DatFiles #endregion - #region Filtering - - /// - /// Execute all filters in a filter runner on the items in the dictionary - /// - /// Preconfigured filter runner to use - public void ExecuteFilters(FilterRunner filterRunner) - { - Items.ExecuteFilters(filterRunner); - ItemsDB.ExecuteFilters(filterRunner); - } - - #endregion - - #region Item Dictionary Manipulation + #region Item Dictionary Passthrough - Accessors /// /// Add a value to the file dictionary @@ -228,6 +221,18 @@ namespace SabreTools.DatFiles ItemsDB.ClearMarked(); } + /// + /// Get the items associated with a bucket name + /// + public List GetItemsForBucket(string bucketName, bool filter = false) + => Items.GetItemsForBucket(bucketName, filter); + + /// + /// Get the indices and items associated with a bucket name + /// + public Dictionary GetItemsForBucketDB(string bucketName, bool filter = false) + => ItemsDB.GetItemsForBucket(bucketName, filter); + /// /// Remove a key from the file dictionary if it exists /// @@ -248,6 +253,203 @@ namespace SabreTools.DatFiles #endregion + #region Item Dictionary Passthrough - Bucketing + + /// + /// Take the arbitrarily bucketed Files Dictionary and convert to one bucketed by a user-defined method + /// + /// ItemKey enum representing how to bucket the individual items + /// Dedupe type that should be used + /// True if the key should be lowercased (default), false otherwise + /// True if games should only be compared on game and file name, false if system and source are counted + public void BucketBy(ItemKey bucketBy, DedupeType dedupeType, bool lower = true, bool norename = true) + { + Items.BucketBy(bucketBy, dedupeType, lower, norename); + ItemsDB.BucketBy(bucketBy, dedupeType, lower, norename); + } + + /// + /// List all duplicates found in a DAT based on a DatItem + /// + /// Item to try to match + /// True if the DAT is already sorted accordingly, false otherwise (default) + /// List of matched DatItem objects + public List GetDuplicates(DatItem datItem, bool sorted = false) + => Items.GetDuplicates(datItem, sorted); + + /// + /// List all duplicates found in a DAT based on a DatItem + /// + /// Item to try to match + /// True if the DAT is already sorted accordingly, false otherwise (default) + /// List of matched DatItem objects + public Dictionary GetDuplicatesDB(KeyValuePair datItem, bool sorted = false) + => ItemsDB.GetDuplicates(datItem, sorted); + + /// + /// Check if a DAT contains the given DatItem + /// + /// Item to try to match + /// True if the DAT is already sorted accordingly, false otherwise (default) + /// True if it contains the rom, false otherwise + public bool HasDuplicates(DatItem datItem, bool sorted = false) + => Items.HasDuplicates(datItem, sorted); + + /// + /// Check if a DAT contains the given DatItem + /// + /// Item to try to match + /// True if the DAT is already sorted accordingly, false otherwise (default) + /// True if it contains the rom, false otherwise + public bool HasDuplicates(KeyValuePair datItem, bool sorted = false) + => ItemsDB.HasDuplicates(datItem, sorted); + + #endregion + + #region Item Dictionary Passthrough - Filtering + + /// + /// Execute all filters in a filter runner on the items in the dictionary + /// + /// Preconfigured filter runner to use + public void ExecuteFilters(FilterRunner filterRunner) + { + Items.ExecuteFilters(filterRunner); + ItemsDB.ExecuteFilters(filterRunner); + } + + /// + /// Use game descriptions as names, updating cloneof/romof/sampleof + /// + /// True if the error that is thrown should be thrown back to the caller, false otherwise + public void MachineDescriptionToName(bool throwOnError = false) + { + Items.MachineDescriptionToName(throwOnError); + ItemsDB.MachineDescriptionToName(throwOnError); + } + + /// + /// Ensure that all roms are in their own game (or at least try to ensure) + /// + public void SetOneRomPerGame() + { + Items.SetOneRomPerGame(); + ItemsDB.SetOneRomPerGame(); + } + + /// + /// Filter a DAT using 1G1R logic given an ordered set of regions + /// + /// List of regions in order of priority + /// + /// In the most technical sense, the way that the region list is being used does not + /// confine its values to be just regions. Since it's essentially acting like a + /// specialized version of the machine name filter, anything that is usually encapsulated + /// in parenthesis would be matched on, including disc numbers, languages, editions, + /// and anything else commonly used. Please note that, unlike other existing 1G1R + /// solutions, this does not have the ability to contain custom mappings of parent + /// to clone sets based on name, nor does it have the ability to match on the + /// Release DatItem type. + /// + public void SetOneGamePerRegion(List regionList) + { + Items.SetOneGamePerRegion(regionList); + ItemsDB.SetOneGamePerRegion(regionList); + } + + /// + /// Strip the dates from the beginning of scene-style set names + /// + public void StripSceneDatesFromItems() + { + Items.StripSceneDatesFromItems(); + ItemsDB.StripSceneDatesFromItems(); + } + + #endregion + + #region Item Dictionary Passthrough - Splitting + + /// + /// Use romof tags to add roms to the children + /// + public void AddRomsFromBios() + { + Items.AddRomsFromBios(); + ItemsDB.AddRomsFromBios(); + } + + /// + /// Use device_ref and optionally slotoption tags to add roms to the children + /// + /// True if only child device sets are touched, false for non-device sets + /// True if slotoptions tags are used as well, false otherwise + public bool AddRomsFromDevices(bool dev, bool useSlotOptions) + { + bool foundnew = Items.AddRomsFromDevices(dev, useSlotOptions); + foundnew |= ItemsDB.AddRomsFromDevices(dev, useSlotOptions); + return foundnew; + } + + /// + /// Use cloneof tags to add roms to the parents, removing the child sets in the process + /// + /// True to add DatItems to subfolder of parent (not including Disk), false otherwise + /// True to skip checking for duplicate ROMs in parent, false otherwise + public void AddRomsFromChildren(bool subfolder, bool skipDedup) + { + Items.AddRomsFromChildren(subfolder, skipDedup); + ItemsDB.AddRomsFromChildren(subfolder, skipDedup); + } + + /// + /// Use cloneof tags to add roms to the children, setting the new romof tag in the process + /// + public void AddRomsFromParent() + { + Items.AddRomsFromParent(); + ItemsDB.AddRomsFromParent(); + } + + /// + /// Remove all BIOS and device sets + /// + public void RemoveBiosAndDeviceSets() + { + Items.RemoveBiosAndDeviceSets(); + ItemsDB.RemoveBiosAndDeviceSets(); + } + + /// + /// Use romof tags to remove bios roms from children + /// + /// True if only child Bios sets are touched, false for non-bios sets + public void RemoveBiosRomsFromChild(bool bios) + { + Items.RemoveBiosRomsFromChild(bios); + ItemsDB.RemoveBiosRomsFromChild(bios); + } + + /// + /// Use cloneof tags to remove roms from the children + /// + public void RemoveRomsFromChild() + { + Items.RemoveRomsFromChild(); + ItemsDB.RemoveRomsFromChild(); + } + + /// + /// Remove all romof and cloneof tags from all games + /// + public void RemoveTagsFromChild() + { + Items.RemoveTagsFromChild(); + ItemsDB.RemoveTagsFromChild(); + } + + #endregion + #region Parsing /// diff --git a/SabreTools.DatFiles/DatFileTool.cs b/SabreTools.DatFiles/DatFileTool.cs index 68138af4..2cdf5627 100644 --- a/SabreTools.DatFiles/DatFileTool.cs +++ b/SabreTools.DatFiles/DatFileTool.cs @@ -320,7 +320,7 @@ namespace SabreTools.DatFiles foreach (var key in keys) #endif { - List? items = datFile.Items[key]; + List? items = datFile.GetItemsForBucket(key); if (items == null) #if NET40_OR_GREATER || NETCOREAPP return; @@ -391,7 +391,7 @@ namespace SabreTools.DatFiles foreach (var key in keys) #endif { - var items = datFile.ItemsDB.GetItemsForBucket(key); + var items = datFile.GetItemsForBucketDB(key); if (items == null) #if NET40_OR_GREATER || NETCOREAPP return; @@ -462,8 +462,8 @@ namespace SabreTools.DatFiles if (itemFieldNames.Count > 0) { // For comparison's sake, we want to use CRC as the base bucketing - datFile.Items.BucketBy(ItemKey.CRC, DedupeType.Full); - intDat.Items.BucketBy(ItemKey.CRC, DedupeType.None); + datFile.BucketBy(ItemKey.CRC, DedupeType.Full); + intDat.BucketBy(ItemKey.CRC, DedupeType.None); // Then we do a hashwise comparison against the base DAT #if NET452_OR_GREATER || NETCOREAPP @@ -474,7 +474,7 @@ namespace SabreTools.DatFiles foreach (var key in intDat.Items.Keys) #endif { - List? datItems = intDat.Items[key]; + List? datItems = intDat.GetItemsForBucket(key); if (datItems == null) #if NET40_OR_GREATER || NETCOREAPP return; @@ -510,8 +510,8 @@ namespace SabreTools.DatFiles if (machineFieldNames.Count > 0) { // For comparison's sake, we want to use Machine Name as the base bucketing - datFile.Items.BucketBy(ItemKey.Machine, DedupeType.Full); - intDat.Items.BucketBy(ItemKey.Machine, DedupeType.None); + datFile.BucketBy(ItemKey.Machine, DedupeType.Full); + intDat.BucketBy(ItemKey.Machine, DedupeType.None); // Then we do a namewise comparison against the base DAT #if NET452_OR_GREATER || NETCOREAPP @@ -522,7 +522,7 @@ namespace SabreTools.DatFiles foreach (var key in intDat.Items.Keys) #endif { - List? datItems = intDat.Items[key]; + List? datItems = intDat.GetItemsForBucket(key); if (datItems == null) #if NET40_OR_GREATER || NETCOREAPP return; @@ -579,8 +579,8 @@ namespace SabreTools.DatFiles if (itemFieldNames.Count > 0) { // For comparison's sake, we want to use CRC as the base bucketing - datFile.ItemsDB.BucketBy(ItemKey.CRC, DedupeType.Full); - intDat.ItemsDB.BucketBy(ItemKey.CRC, DedupeType.None); + datFile.BucketBy(ItemKey.CRC, DedupeType.Full); + intDat.BucketBy(ItemKey.CRC, DedupeType.None); // Then we do a hashwise comparison against the base DAT #if NET452_OR_GREATER || NETCOREAPP @@ -591,7 +591,7 @@ namespace SabreTools.DatFiles foreach (var key in intDat.ItemsDB.SortedKeys) #endif { - var datItems = intDat.ItemsDB.GetItemsForBucket(key); + var datItems = intDat.GetItemsForBucketDB(key); if (datItems == null) #if NET40_OR_GREATER || NETCOREAPP return; @@ -601,7 +601,7 @@ namespace SabreTools.DatFiles foreach (var datItem in datItems) { - var dupes = datFile.ItemsDB.GetDuplicates(datItem, sorted: true); + var dupes = datFile.GetDuplicatesDB(datItem, sorted: true); if (datItem.Value.Clone() is not DatItem newDatItem) continue; @@ -620,8 +620,8 @@ namespace SabreTools.DatFiles if (machineFieldNames.Count > 0) { // For comparison's sake, we want to use Machine Name as the base bucketing - datFile.ItemsDB.BucketBy(ItemKey.Machine, DedupeType.Full); - intDat.ItemsDB.BucketBy(ItemKey.Machine, DedupeType.None); + datFile.BucketBy(ItemKey.Machine, DedupeType.Full); + intDat.BucketBy(ItemKey.Machine, DedupeType.None); // Then we do a namewise comparison against the base DAT #if NET452_OR_GREATER || NETCOREAPP @@ -632,7 +632,7 @@ namespace SabreTools.DatFiles foreach (var key in intDat.ItemsDB.SortedKeys) #endif { - var datItems = intDat.ItemsDB.GetItemsForBucket(key); + var datItems = intDat.GetItemsForBucketDB(key); if (datItems == null) #if NET40_OR_GREATER || NETCOREAPP return; @@ -642,7 +642,7 @@ namespace SabreTools.DatFiles foreach (var datItem in datItems) { - var datMachine = datFile.ItemsDB.GetMachineForItem(datFile.ItemsDB.GetItemsForBucket(key)!.First().Key); + var datMachine = datFile.ItemsDB.GetMachineForItem(datFile.GetItemsForBucketDB(key)!.First().Key); var intMachine = intDat.ItemsDB.GetMachineForItem(datItem.Key); if (datMachine.Value != null && intMachine.Value != null) Replacer.ReplaceFields(intMachine.Value, datMachine.Value, machineFieldNames, onlySame); @@ -671,17 +671,17 @@ namespace SabreTools.DatFiles { // For comparison's sake, we want to use a base ordering if (useGames) - datFile.Items.BucketBy(ItemKey.Machine, DedupeType.None); + datFile.BucketBy(ItemKey.Machine, DedupeType.None); else - datFile.Items.BucketBy(ItemKey.CRC, DedupeType.None); + datFile.BucketBy(ItemKey.CRC, DedupeType.None); InternalStopwatch watch = new($"Comparing '{intDat.Header.GetStringFieldValue(DatHeader.FileNameKey)}' to base DAT"); // For comparison's sake, we want to a the base bucketing if (useGames) - intDat.Items.BucketBy(ItemKey.Machine, DedupeType.None); + intDat.BucketBy(ItemKey.Machine, DedupeType.None); else - intDat.Items.BucketBy(ItemKey.CRC, DedupeType.Full); + intDat.BucketBy(ItemKey.CRC, DedupeType.Full); // Then we compare against the base DAT List keys = [.. intDat.Items.Keys]; @@ -740,7 +740,7 @@ namespace SabreTools.DatFiles // Standard Against uses hashes else { - List? datItems = intDat.Items[key]; + List? datItems = intDat.GetItemsForBucket(key); if (datItems == null) #if NET40_OR_GREATER || NETCOREAPP return; @@ -751,7 +751,7 @@ namespace SabreTools.DatFiles List keepDatItems = []; foreach (DatItem datItem in datItems) { - if (!datFile.Items.HasDuplicates(datItem, true)) + if (!datFile.HasDuplicates(datItem, true)) keepDatItems.Add(datItem); } @@ -780,7 +780,7 @@ namespace SabreTools.DatFiles List outDats = []; // Ensure the current DatFile is sorted optimally - datFile.Items.BucketBy(ItemKey.CRC, DedupeType.None); + datFile.BucketBy(ItemKey.CRC, DedupeType.None); // Loop through each of the inputs and get or create a new DatData object InternalStopwatch watch = new("Initializing and filling all output DATs"); @@ -795,10 +795,10 @@ namespace SabreTools.DatFiles for (int j = 0; j < datHeaders.Count; j++) #endif { - DatFile diffData = DatFileTool.CreateDatFile(datHeaders[j]); + DatFile diffData = CreateDatFile(datHeaders[j]); diffData.ResetDictionary(); FillWithSourceIndex(datFile, diffData, j); - //FillWithSourceIndexDB(datFile, diffData, j); + FillWithSourceIndexDB(datFile, diffData, j); outDatsArray[j] = diffData; #if NET40_OR_GREATER || NETCOREAPP }); @@ -844,7 +844,7 @@ namespace SabreTools.DatFiles datFile.Header.SetFieldValue(Models.Metadata.Header.DescriptionKey, "datFile.All DATs"); string post = " (Duplicates)"; - DatFile dupeData = DatFileTool.CreateDatFile(datFile.Header); + DatFile dupeData = CreateDatFile(datFile.Header); dupeData.Header.SetFieldValue(DatHeader.FileNameKey, dupeData.Header.GetStringFieldValue(DatHeader.FileNameKey) + post); dupeData.Header.SetFieldValue(Models.Metadata.Header.NameKey, dupeData.Header.GetStringFieldValue(Models.Metadata.Header.NameKey) + post); dupeData.Header.SetFieldValue(Models.Metadata.Header.DescriptionKey, dupeData.Header.GetStringFieldValue(Models.Metadata.Header.DescriptionKey) + post); @@ -863,7 +863,7 @@ namespace SabreTools.DatFiles foreach (var key in datFile.Items.Keys) #endif { - List items = Merge(datFile.Items[key]); + List items = Merge(datFile.GetItemsForBucket(key)); // If the rom list is empty or null, just skip it if (items == null || items.Count == 0) @@ -922,7 +922,7 @@ namespace SabreTools.DatFiles datFile.Header.SetFieldValue(Models.Metadata.Header.DescriptionKey, "datFile.All DATs"); string post = " (Duplicates)"; - DatFile dupeData = DatFileTool.CreateDatFile(datFile.Header); + DatFile dupeData = CreateDatFile(datFile.Header); dupeData.Header.SetFieldValue(DatHeader.FileNameKey, dupeData.Header.GetStringFieldValue(DatHeader.FileNameKey) + post); dupeData.Header.SetFieldValue(Models.Metadata.Header.NameKey, dupeData.Header.GetStringFieldValue(Models.Metadata.Header.NameKey) + post); dupeData.Header.SetFieldValue(Models.Metadata.Header.DescriptionKey, dupeData.Header.GetStringFieldValue(Models.Metadata.Header.DescriptionKey) + post); @@ -1060,7 +1060,7 @@ namespace SabreTools.DatFiles #endif { string innerpost = $" ({j} - {inputs[j].GetNormalizedFileName(true)} Only)"; - DatFile diffData = DatFileTool.CreateDatFile(datFile.Header); + DatFile diffData = CreateDatFile(datFile.Header); diffData.Header.SetFieldValue(DatHeader.FileNameKey, diffData.Header.GetStringFieldValue(DatHeader.FileNameKey) + innerpost); diffData.Header.SetFieldValue(Models.Metadata.Header.NameKey, diffData.Header.GetStringFieldValue(Models.Metadata.Header.NameKey) + innerpost); diffData.Header.SetFieldValue(Models.Metadata.Header.DescriptionKey, diffData.Header.GetStringFieldValue(Models.Metadata.Header.DescriptionKey) + innerpost); @@ -1088,7 +1088,7 @@ namespace SabreTools.DatFiles foreach (var key in datFile.Items.Keys) #endif { - List items = Merge(datFile.Items[key]); + List items = Merge(datFile.GetItemsForBucket(key)); // If the rom list is empty or null, just skip it if (items == null || items.Count == 0) @@ -1153,7 +1153,7 @@ namespace SabreTools.DatFiles #endif { string innerpost = $" ({j} - {inputs[j].GetNormalizedFileName(true)} Only)"; - DatFile diffData = DatFileTool.CreateDatFile(datFile.Header); + DatFile diffData = CreateDatFile(datFile.Header); diffData.Header.SetFieldValue(DatHeader.FileNameKey, diffData.Header.GetStringFieldValue(DatHeader.FileNameKey) + innerpost); diffData.Header.SetFieldValue(Models.Metadata.Header.NameKey, diffData.Header.GetStringFieldValue(Models.Metadata.Header.NameKey) + innerpost); diffData.Header.SetFieldValue(Models.Metadata.Header.DescriptionKey, diffData.Header.GetStringFieldValue(Models.Metadata.Header.DescriptionKey) + innerpost); @@ -1279,7 +1279,7 @@ namespace SabreTools.DatFiles datFile.Header.SetFieldValue(Models.Metadata.Header.DescriptionKey, "All DATs"); string post = " (No Duplicates)"; - DatFile outerDiffData = DatFileTool.CreateDatFile(datFile.Header); + DatFile outerDiffData = CreateDatFile(datFile.Header); outerDiffData.Header.SetFieldValue(DatHeader.FileNameKey, outerDiffData.Header.GetStringFieldValue(DatHeader.FileNameKey) + post); outerDiffData.Header.SetFieldValue(Models.Metadata.Header.NameKey, outerDiffData.Header.GetStringFieldValue(Models.Metadata.Header.NameKey) + post); outerDiffData.Header.SetFieldValue(Models.Metadata.Header.DescriptionKey, outerDiffData.Header.GetStringFieldValue(Models.Metadata.Header.DescriptionKey) + post); @@ -1298,7 +1298,7 @@ namespace SabreTools.DatFiles foreach (var key in datFile.Items.Keys) #endif { - List items = Merge(datFile.Items[key]); + List items = Merge(datFile.GetItemsForBucket(key)); // If the rom list is empty or null, just skip it if (items == null || items.Count == 0) @@ -1355,7 +1355,7 @@ namespace SabreTools.DatFiles datFile.Header.SetFieldValue(Models.Metadata.Header.DescriptionKey, "All DATs"); string post = " (No Duplicates)"; - DatFile outerDiffData = DatFileTool.CreateDatFile(datFile.Header); + DatFile outerDiffData = CreateDatFile(datFile.Header); outerDiffData.Header.SetFieldValue(DatHeader.FileNameKey, outerDiffData.Header.GetStringFieldValue(DatHeader.FileNameKey) + post); outerDiffData.Header.SetFieldValue(Models.Metadata.Header.NameKey, outerDiffData.Header.GetStringFieldValue(Models.Metadata.Header.NameKey) + post); outerDiffData.Header.SetFieldValue(Models.Metadata.Header.DescriptionKey, outerDiffData.Header.GetStringFieldValue(Models.Metadata.Header.DescriptionKey) + post); @@ -1488,7 +1488,7 @@ namespace SabreTools.DatFiles { var input = inputs[i]; _staticLogger.User($"Adding DAT: {input.CurrentPath}"); - datFiles[i] = DatFileTool.CreateDatFile(datFile.Header.CloneFiltering()); + datFiles[i] = CreateDatFile(datFile.Header.CloneFiltering()); Parser.ParseInto(datFiles[i], input, i, keep: true); #if NET40_OR_GREATER || NETCOREAPP }); @@ -1523,7 +1523,7 @@ namespace SabreTools.DatFiles foreach (string key in keys) { // Add everything from the key to the internal DAT - addTo.Add(key, addFrom.Items[key]); + addTo.Add(key, addFrom.GetItemsForBucket(key)); // Now remove the key from the source DAT if (delete) @@ -1616,7 +1616,7 @@ namespace SabreTools.DatFiles foreach (var key in datFile.Items.Keys) #endif { - List items = Merge(datFile.Items[key]); + List items = Merge(datFile.GetItemsForBucket(key)); // If the rom list is empty or null, just skip it if (items == null || items.Count == 0) diff --git a/SabreTools.DatFiles/Formats/Missfile.cs b/SabreTools.DatFiles/Formats/Missfile.cs index ea7a69ed..5b7855d2 100644 --- a/SabreTools.DatFiles/Formats/Missfile.cs +++ b/SabreTools.DatFiles/Formats/Missfile.cs @@ -60,7 +60,7 @@ namespace SabreTools.DatFiles.Formats // Use a sorted list of games to output foreach (string key in Items.SortedKeys) { - List datItems = Items.FilteredItems(key); + List datItems = GetItemsForBucket(key, filter: true); // If this machine doesn't contain any writable items, skip if (!ContainsWritable(datItems)) @@ -122,7 +122,7 @@ namespace SabreTools.DatFiles.Formats foreach (string key in ItemsDB.SortedKeys) { // If this machine doesn't contain any writable items, skip - var itemsDict = ItemsDB.GetItemsForBucket(key, filter: true); + var itemsDict = GetItemsForBucketDB(key, filter: true); if (itemsDict == null || !ContainsWritable([.. itemsDict.Values])) continue; diff --git a/SabreTools.DatFiles/Formats/SabreJSON.cs b/SabreTools.DatFiles/Formats/SabreJSON.cs index cced0bb5..88677c21 100644 --- a/SabreTools.DatFiles/Formats/SabreJSON.cs +++ b/SabreTools.DatFiles/Formats/SabreJSON.cs @@ -396,7 +396,7 @@ namespace SabreTools.DatFiles.Formats // Use a sorted list of games to output foreach (string key in Items.SortedKeys) { - List datItems = Items.FilteredItems(key); + List datItems = GetItemsForBucket(key, filter: true); // If this machine doesn't contain any writable items, skip if (!ContainsWritable(datItems)) @@ -478,7 +478,7 @@ namespace SabreTools.DatFiles.Formats foreach (string key in ItemsDB.SortedKeys) { // If this machine doesn't contain any writable items, skip - var itemsDict = ItemsDB.GetItemsForBucket(key, filter: true); + var itemsDict = GetItemsForBucketDB(key, filter: true); if (itemsDict == null || !ContainsWritable([.. itemsDict.Values])) continue; diff --git a/SabreTools.DatFiles/Formats/SabreXML.cs b/SabreTools.DatFiles/Formats/SabreXML.cs index 78abda2b..4e315384 100644 --- a/SabreTools.DatFiles/Formats/SabreXML.cs +++ b/SabreTools.DatFiles/Formats/SabreXML.cs @@ -224,7 +224,7 @@ namespace SabreTools.DatFiles.Formats // Use a sorted list of games to output foreach (string key in Items.SortedKeys) { - List datItems = Items.FilteredItems(key); + List datItems = GetItemsForBucket(key, filter: true); // If this machine doesn't contain any writable items, skip if (!ContainsWritable(datItems)) @@ -307,7 +307,7 @@ namespace SabreTools.DatFiles.Formats foreach (string key in ItemsDB.SortedKeys) { // If this machine doesn't contain any writable items, skip - var itemsDict = ItemsDB.GetItemsForBucket(key, filter: true); + var itemsDict = GetItemsForBucketDB(key, filter: true); if (itemsDict == null || !ContainsWritable([.. itemsDict.Values])) continue; diff --git a/SabreTools.DatFiles/ItemDictionary.cs b/SabreTools.DatFiles/ItemDictionary.cs index 4a327b4d..baa93a8b 100644 --- a/SabreTools.DatFiles/ItemDictionary.cs +++ b/SabreTools.DatFiles/ItemDictionary.cs @@ -44,7 +44,7 @@ namespace SabreTools.DatFiles /// Internal dictionary for the class /// #if NET40_OR_GREATER || NETCOREAPP - private readonly ConcurrentDictionary?> items = []; + private readonly ConcurrentDictionary?> _items = []; #else private readonly Dictionary?> items = []; #endif @@ -67,7 +67,7 @@ namespace SabreTools.DatFiles [JsonIgnore, XmlIgnore] public ICollection Keys { - get { return items.Keys; } + get { return _items.Keys; } } /// @@ -79,7 +79,7 @@ namespace SabreTools.DatFiles { get { - List keys = [.. items.Keys]; + List keys = [.. _items.Keys]; keys.Sort(new NaturalComparer()); return keys; } @@ -130,14 +130,14 @@ namespace SabreTools.DatFiles EnsureKey(key); // Now return the value - return items[key]; + return _items[key]; } } set { Remove(key); if (value == null) - items[key] = null; + _items[key] = null; else Add(key, value); } @@ -161,7 +161,7 @@ namespace SabreTools.DatFiles return; // Now add the value - items[key]!.Add(value); + _items[key]!.Add(value); // Now update the statistics DatStatistics.AddItemStatistics(value); @@ -186,7 +186,7 @@ namespace SabreTools.DatFiles EnsureKey(key); // Now add the value - items[key]!.AddRange(value); + _items[key]!.AddRange(value); // Now update the statistics foreach (DatItem item in value) @@ -299,23 +299,23 @@ namespace SabreTools.DatFiles /// /// Remove any keys that have null or empty values /// - public void ClearEmpty() + internal void ClearEmpty() { string[] keys = [.. Keys]; foreach (string key in keys) { #if NET40_OR_GREATER || NETCOREAPP // If the key doesn't exist, skip - if (!items.TryGetValue(key, out var value)) + if (!_items.TryGetValue(key, out var value)) continue; // If the value is null, remove else if (value == null) - items.TryRemove(key, out _); + _items.TryRemove(key, out _); // If there are no non-blank items, remove else if (value!.FindIndex(i => i != null && i is not Blank) == -1) - items.TryRemove(key, out _); + _items.TryRemove(key, out _); #else // If the key doesn't exist, skip if (!items.ContainsKey(key)) @@ -335,7 +335,7 @@ namespace SabreTools.DatFiles /// /// Remove all items marked for removal /// - public void ClearMarked() + internal void ClearMarked() { string[] keys = [.. Keys]; foreach (string key in keys) @@ -366,7 +366,7 @@ namespace SabreTools.DatFiles // Explicit lock for some weird corner cases lock (key) { - return items.ContainsKey(key); + return _items.ContainsKey(key); } } @@ -386,7 +386,7 @@ namespace SabreTools.DatFiles lock (key) { #if NET40_OR_GREATER || NETCOREAPP - if (items.TryGetValue(key, out var list) && list != null) + if (_items.TryGetValue(key, out var list) && list != null) return list.Contains(value); #else if (items.ContainsKey(key) && items[key] != null) @@ -404,32 +404,34 @@ namespace SabreTools.DatFiles public void EnsureKey(string key) { // If the key is missing from the dictionary, add it - if (!items.ContainsKey(key)) + if (!_items.ContainsKey(key)) #if NET40_OR_GREATER || NETCOREAPP - items.TryAdd(key, []); + _items.TryAdd(key, []); #else items[key] = []; #endif } /// - /// Get a list of filtered items for a given key + /// Get the items associated with a bucket name /// - /// Key in the dictionary to retrieve - public List FilteredItems(string key) + public List GetItemsForBucket(string bucketName, bool filter = false) { - lock (key) - { - // Get the list, if possible - List? fi = items[key]; - if (fi == null) - return []; + if (!_items.ContainsKey(bucketName)) + return []; - // Filter the list - return fi.FindAll(i => i != null) - .FindAll(i => i.GetBoolFieldValue(DatItem.RemoveKey) != true) - .FindAll(i => i.GetFieldValue(DatItem.MachineKey) != null); + var items = _items[bucketName]; + if (items == null) + return []; + + var datItems = new List(); + foreach (DatItem item in items) + { + if (!filter || item.GetBoolFieldValue(DatItem.RemoveKey) != true) + datItems.Add(item); } + + return datItems; } /// @@ -442,18 +444,18 @@ namespace SabreTools.DatFiles lock (key) { // If the key doesn't exist, return - if (!ContainsKey(key) || items[key] == null) + if (!ContainsKey(key) || _items[key] == null) return false; // Remove the statistics first - foreach (DatItem item in items[key]!) + foreach (DatItem item in _items[key]!) { DatStatistics.RemoveItemStatistics(item); } // Remove the key from the dictionary #if NET40_OR_GREATER || NETCOREAPP - return items.TryRemove(key, out _); + return _items.TryRemove(key, out _); #else return items.Remove(key); #endif @@ -471,13 +473,13 @@ namespace SabreTools.DatFiles lock (key) { // If the key and value doesn't exist, return - if (!Contains(key, value) || items[key] == null) + if (!Contains(key, value) || _items[key] == null) return false; // Remove the statistics first DatStatistics.RemoveItemStatistics(value); - return items[key]!.Remove(value); + return _items[key]!.Remove(value); } } @@ -488,17 +490,17 @@ namespace SabreTools.DatFiles public bool Reset(string key) { // If the key doesn't exist, return - if (!ContainsKey(key) || items[key] == null) + if (!ContainsKey(key) || _items[key] == null) return false; // Remove the statistics first - foreach (DatItem item in items[key]!) + foreach (DatItem item in _items[key]!) { DatStatistics.RemoveItemStatistics(item); } // Remove the key from the dictionary - items[key] = []; + _items[key] = []; return true; } @@ -522,10 +524,10 @@ namespace SabreTools.DatFiles /// Dedupe type that should be used /// True if the key should be lowercased (default), false otherwise /// True if games should only be compared on game and file name, false if system and source are counted - public void BucketBy(ItemKey bucketBy, DedupeType dedupeType, bool lower = true, bool norename = true) + internal void BucketBy(ItemKey bucketBy, DedupeType dedupeType, bool lower = true, bool norename = true) { // If we have a situation where there's no dictionary or no keys at all, we skip - if (items == null || items.Count == 0) + if (_items == null || _items.Count == 0) return; // If the sorted type isn't the same, we want to sort the dictionary accordingly @@ -555,7 +557,7 @@ namespace SabreTools.DatFiles /// Item to try to match /// True if the DAT is already sorted accordingly, false otherwise (default) /// List of matched DatItem objects - public List GetDuplicates(DatItem datItem, bool sorted = false) + internal List GetDuplicates(DatItem datItem, bool sorted = false) { List output = []; @@ -607,7 +609,7 @@ namespace SabreTools.DatFiles /// Item to try to match /// True if the DAT is already sorted accordingly, false otherwise (default) /// True if it contains the rom, false otherwise - public bool HasDuplicates(DatItem datItem, bool sorted = false) + internal bool HasDuplicates(DatItem datItem, bool sorted = false) { // Check for an empty rom list first if (DatStatistics.TotalCount == 0) @@ -820,13 +822,14 @@ namespace SabreTools.DatFiles #endregion + // TODO: All internal, can this be put into a better location? #region Filtering /// /// Execute all filters in a filter runner on the items in the dictionary /// /// Preconfigured filter runner to use - public void ExecuteFilters(FilterRunner filterRunner) + internal void ExecuteFilters(FilterRunner filterRunner) { List keys = [.. Keys]; #if NET452_OR_GREATER || NETCOREAPP @@ -867,7 +870,7 @@ namespace SabreTools.DatFiles /// Use game descriptions as names, updating cloneof/romof/sampleof /// /// True if the error that is thrown should be thrown back to the caller, false otherwise - public void MachineDescriptionToName(bool throwOnError = false) + internal void MachineDescriptionToName(bool throwOnError = false) { try { @@ -883,6 +886,39 @@ namespace SabreTools.DatFiles } } + /// + /// Ensure that all roms are in their own game (or at least try to ensure) + /// + internal void SetOneRomPerGame() + { + // For each rom, we want to update the game to be "/" +#if NET452_OR_GREATER || NETCOREAPP + Parallel.ForEach(Keys, Core.Globals.ParallelOptions, key => +#elif NET40_OR_GREATER + Parallel.ForEach(Keys, key => +#else + foreach (var key in Keys) +#endif + { + var items = this[key]; + if (items == null) +#if NET40_OR_GREATER || NETCOREAPP + return; +#else + continue; +#endif + + for (int i = 0; i < items.Count; i++) + { + SetOneRomPerGame(items[i]); + } +#if NET40_OR_GREATER || NETCOREAPP + }); +#else + } +#endif + } + /// /// Filter a DAT using 1G1R logic given an ordered set of regions /// @@ -897,7 +933,7 @@ namespace SabreTools.DatFiles /// to clone sets based on name, nor does it have the ability to match on the /// Release DatItem type. /// - public void SetOneGamePerRegion(List regionList) + internal void SetOneGamePerRegion(List regionList) { // If we have null region list, make it empty regionList ??= []; @@ -976,43 +1012,10 @@ namespace SabreTools.DatFiles RemoveTagsFromChild(); } - /// - /// Ensure that all roms are in their own game (or at least try to ensure) - /// - public void SetOneRomPerGame() - { - // For each rom, we want to update the game to be "/" -#if NET452_OR_GREATER || NETCOREAPP - Parallel.ForEach(Keys, Core.Globals.ParallelOptions, key => -#elif NET40_OR_GREATER - Parallel.ForEach(Keys, key => -#else - foreach (var key in Keys) -#endif - { - var items = this[key]; - if (items == null) -#if NET40_OR_GREATER || NETCOREAPP - return; -#else - continue; -#endif - - for (int i = 0; i < items.Count; i++) - { - SetOneRomPerGame(items[i]); - } -#if NET40_OR_GREATER || NETCOREAPP - }); -#else - } -#endif - } - /// /// Strip the dates from the beginning of scene-style set names /// - public void StripSceneDatesFromItems() + internal void StripSceneDatesFromItems() { // Set the regex pattern to use string pattern = @"([0-9]{2}\.[0-9]{2}\.[0-9]{2}-)(.*?-.*?)"; @@ -1184,12 +1187,13 @@ namespace SabreTools.DatFiles #endregion + // TODO: All internal, can this be put into a better location? #region Splitting /// /// Use romof tags to add roms to the children /// - public void AddRomsFromBios() + internal void AddRomsFromBios() { List games = [.. Keys]; games.Sort(); @@ -1233,7 +1237,7 @@ namespace SabreTools.DatFiles /// /// True if only child device sets are touched, false for non-device sets (default) /// True if slotoptions tags are used as well, false otherwise - public bool AddRomsFromDevices(bool dev, bool useSlotOptions) + internal bool AddRomsFromDevices(bool dev, bool useSlotOptions) { bool foundnew = false; List machines = [.. Keys]; @@ -1382,7 +1386,7 @@ namespace SabreTools.DatFiles /// /// Use cloneof tags to add roms to the children, setting the new romof tag in the process /// - public void AddRomsFromParent() + internal void AddRomsFromParent() { List games = [.. Keys]; games.Sort(); @@ -1437,7 +1441,7 @@ namespace SabreTools.DatFiles /// /// True to add DatItems to subfolder of parent (not including Disk), false otherwise /// True to skip checking for duplicate ROMs in parent, false otherwise - public void AddRomsFromChildren(bool subfolder, bool skipDedup) + internal void AddRomsFromChildren(bool subfolder, bool skipDedup) { List games = [.. Keys]; games.Sort(); @@ -1563,7 +1567,7 @@ namespace SabreTools.DatFiles /// /// Remove all BIOS and device sets /// - public void RemoveBiosAndDeviceSets() + internal void RemoveBiosAndDeviceSets() { List games = [.. Keys]; games.Sort(); @@ -1593,7 +1597,7 @@ namespace SabreTools.DatFiles /// Use romof tags to remove bios roms from children /// /// True if only child Bios sets are touched, false for non-bios sets - public void RemoveBiosRomsFromChild(bool bios) + internal void RemoveBiosRomsFromChild(bool bios) { // Loop through the romof tags List games = [.. Keys]; @@ -1640,7 +1644,7 @@ namespace SabreTools.DatFiles /// /// Use cloneof tags to remove roms from the children /// - public void RemoveRomsFromChild() + internal void RemoveRomsFromChild() { List games = [.. Keys]; games.Sort(); @@ -1690,7 +1694,7 @@ namespace SabreTools.DatFiles /// /// Remove all romof and cloneof tags from all games /// - public void RemoveTagsFromChild() + internal void RemoveTagsFromChild() { List games = [.. Keys]; games.Sort(); @@ -1724,13 +1728,13 @@ namespace SabreTools.DatFiles DatStatistics.ResetStatistics(); // If we have a blank Dat in any way, return - if (items == null) + if (_items == null) return; // Loop through and add - foreach (string key in items.Keys) + foreach (string key in _items.Keys) { - List? datItems = items[key]; + List? datItems = _items[key]; if (datItems == null) continue; @@ -1745,50 +1749,50 @@ namespace SabreTools.DatFiles #region IDictionary Implementations - public ICollection?> Values => ((IDictionary?>)items).Values; + public ICollection?> Values => ((IDictionary?>)_items).Values; - public int Count => ((ICollection?>>)items).Count; + public int Count => ((ICollection?>>)_items).Count; - public bool IsReadOnly => ((ICollection?>>)items).IsReadOnly; + public bool IsReadOnly => ((ICollection?>>)_items).IsReadOnly; public bool TryGetValue(string key, out List? value) { - return ((IDictionary?>)items).TryGetValue(key, out value); + return ((IDictionary?>)_items).TryGetValue(key, out value); } public void Add(KeyValuePair?> item) { - ((ICollection?>>)items).Add(item); + ((ICollection?>>)_items).Add(item); } public void Clear() { - ((ICollection?>>)items).Clear(); + ((ICollection?>>)_items).Clear(); } public bool Contains(KeyValuePair?> item) { - return ((ICollection?>>)items).Contains(item); + return ((ICollection?>>)_items).Contains(item); } public void CopyTo(KeyValuePair?>[] array, int arrayIndex) { - ((ICollection?>>)items).CopyTo(array, arrayIndex); + ((ICollection?>>)_items).CopyTo(array, arrayIndex); } public bool Remove(KeyValuePair?> item) { - return ((ICollection?>>)items).Remove(item); + return ((ICollection?>>)_items).Remove(item); } public IEnumerator?>> GetEnumerator() { - return ((IEnumerable?>>)items).GetEnumerator(); + return ((IEnumerable?>>)_items).GetEnumerator(); } IEnumerator IEnumerable.GetEnumerator() { - return ((IEnumerable)items).GetEnumerator(); + return ((IEnumerable)_items).GetEnumerator(); } #endregion diff --git a/SabreTools.DatFiles/ItemDictionaryDB.cs b/SabreTools.DatFiles/ItemDictionaryDB.cs index bd1c232e..65d2f4c5 100644 --- a/SabreTools.DatFiles/ItemDictionaryDB.cs +++ b/SabreTools.DatFiles/ItemDictionaryDB.cs @@ -286,7 +286,7 @@ namespace SabreTools.DatFiles /// /// Remove any keys that have null or empty values /// - public void ClearEmpty() + internal void ClearEmpty() { var keys = Array.FindAll(SortedKeys, k => k != null); foreach (string key in keys) @@ -308,7 +308,7 @@ namespace SabreTools.DatFiles /// /// Remove all items marked for removal /// - public void ClearMarked() + internal void ClearMarked() { var itemIndices = _items.Keys; foreach (long itemIndex in itemIndices) @@ -594,7 +594,7 @@ namespace SabreTools.DatFiles /// True if the key should be lowercased (default), false otherwise /// True if games should only be compared on game and file name, false if system and source are counted /// - public void BucketBy(ItemKey bucketBy, DedupeType dedupeType, bool lower = true, bool norename = true) + internal void BucketBy(ItemKey bucketBy, DedupeType dedupeType, bool lower = true, bool norename = true) { // If the sorted type isn't the same, we want to sort the dictionary accordingly if (_bucketedBy != bucketBy && bucketBy != ItemKey.NULL) @@ -618,7 +618,7 @@ namespace SabreTools.DatFiles /// Item to try to match /// True if the DAT is already sorted accordingly, false otherwise (default) /// List of matched DatItem objects - public Dictionary GetDuplicates(DatItem datItem, bool sorted = false) + internal Dictionary GetDuplicates(DatItem datItem, bool sorted = false) { Dictionary output = []; @@ -663,7 +663,7 @@ namespace SabreTools.DatFiles /// Item to try to match /// True if the DAT is already sorted accordingly, false otherwise (default) /// List of matched DatItem objects - public Dictionary GetDuplicates(KeyValuePair datItem, bool sorted = false) + internal Dictionary GetDuplicates(KeyValuePair datItem, bool sorted = false) { Dictionary output = []; @@ -708,7 +708,7 @@ namespace SabreTools.DatFiles /// Item to try to match /// True if the DAT is already sorted accordingly, false otherwise (default) /// True if it contains the rom, false otherwise - public bool HasDuplicates(KeyValuePair datItem, bool sorted = false) + internal bool HasDuplicates(KeyValuePair datItem, bool sorted = false) { // Check for an empty rom list first if (DatStatistics.TotalCount == 0) @@ -1206,13 +1206,14 @@ namespace SabreTools.DatFiles #endregion + // TODO: All internal, can this be put into a better location? #region Filtering /// /// Execute all filters in a filter runner on the items in the dictionary /// /// Preconfigured filter runner to use - public void ExecuteFilters(FilterRunner filterRunner) + internal void ExecuteFilters(FilterRunner filterRunner) { List keys = [.. SortedKeys]; #if NET452_OR_GREATER || NETCOREAPP @@ -1235,7 +1236,7 @@ namespace SabreTools.DatFiles /// Use game descriptions as names, updating cloneof/romof/sampleof /// /// True if the error that is thrown should be thrown back to the caller, false otherwise - public void MachineDescriptionToName(bool throwOnError = false) + internal void MachineDescriptionToName(bool throwOnError = false) { try { @@ -1251,6 +1252,39 @@ namespace SabreTools.DatFiles } } + /// + /// Ensure that all roms are in their own game (or at least try to ensure) + /// + internal void SetOneRomPerGame() + { + // For each rom, we want to update the game to be "/" +#if NET452_OR_GREATER || NETCOREAPP + Parallel.ForEach(SortedKeys, Core.Globals.ParallelOptions, key => +#elif NET40_OR_GREATER + Parallel.ForEach(SortedKeys, key => +#else + foreach (var key in SortedKeys) +#endif + { + var items = GetItemsForBucket(key); + if (items == null) +#if NET40_OR_GREATER || NETCOREAPP + return; +#else + continue; +#endif + + foreach (var item in items) + { + SetOneRomPerGame(item); + } +#if NET40_OR_GREATER || NETCOREAPP + }); +#else + } +#endif + } + /// /// Filter a DAT using 1G1R logic given an ordered set of regions /// @@ -1265,7 +1299,7 @@ namespace SabreTools.DatFiles /// to clone sets based on name, nor does it have the ability to match on the /// Release DatItem type. /// - public void SetOneGamePerRegion(List regionList) + internal void SetOneGamePerRegion(List regionList) { // If we have null region list, make it empty regionList ??= []; @@ -1351,43 +1385,10 @@ namespace SabreTools.DatFiles RemoveTagsFromChild(); } - /// - /// Ensure that all roms are in their own game (or at least try to ensure) - /// - public void SetOneRomPerGame() - { - // For each rom, we want to update the game to be "/" -#if NET452_OR_GREATER || NETCOREAPP - Parallel.ForEach(SortedKeys, Core.Globals.ParallelOptions, key => -#elif NET40_OR_GREATER - Parallel.ForEach(SortedKeys, key => -#else - foreach (var key in SortedKeys) -#endif - { - var items = GetItemsForBucket(key); - if (items == null) -#if NET40_OR_GREATER || NETCOREAPP - return; -#else - continue; -#endif - - foreach (var item in items) - { - SetOneRomPerGame(item); - } -#if NET40_OR_GREATER || NETCOREAPP - }); -#else - } -#endif - } - /// /// Strip the dates from the beginning of scene-style set names /// - public void StripSceneDatesFromItems() + internal void StripSceneDatesFromItems() { // Set the regex pattern to use string pattern = @"([0-9]{2}\.[0-9]{2}\.[0-9]{2}-)(.*?-.*?)"; @@ -1599,12 +1600,13 @@ namespace SabreTools.DatFiles #endregion + // TODO: All internal, can this be put into a better location? #region Splitting /// /// Use romof tags to add roms to the children /// - public void AddRomsFromBios() + internal void AddRomsFromBios() { List games = [.. SortedKeys]; foreach (string game in games) @@ -1650,7 +1652,7 @@ namespace SabreTools.DatFiles /// /// True if only child device sets are touched, false for non-device sets /// True if slotoptions tags are used as well, false otherwise - public bool AddRomsFromDevices(bool dev, bool useSlotOptions) + internal bool AddRomsFromDevices(bool dev, bool useSlotOptions) { bool foundnew = false; List games = [.. SortedKeys]; @@ -1812,7 +1814,7 @@ namespace SabreTools.DatFiles /// /// Use cloneof tags to add roms to the children, setting the new romof tag in the process /// - public void AddRomsFromParent() + internal void AddRomsFromParent() { List games = [.. SortedKeys]; foreach (string game in games) @@ -1875,7 +1877,7 @@ namespace SabreTools.DatFiles /// /// True to add DatItems to subfolder of parent (not including Disk), false otherwise /// True to skip checking for duplicate ROMs in parent, false otherwise - public void AddRomsFromChildren(bool subfolder, bool skipDedup) + internal void AddRomsFromChildren(bool subfolder, bool skipDedup) { List games = [.. SortedKeys]; foreach (string game in games) @@ -2002,7 +2004,7 @@ namespace SabreTools.DatFiles /// /// Remove all BIOS and device sets /// - public void RemoveBiosAndDeviceSets() + internal void RemoveBiosAndDeviceSets() { List games = [.. SortedKeys]; foreach (string game in games) @@ -2033,7 +2035,7 @@ namespace SabreTools.DatFiles /// Use romof tags to remove bios roms from children /// /// True if only child Bios sets are touched, false for non-bios sets - public void RemoveBiosRomsFromChild(bool bios) + internal void RemoveBiosRomsFromChild(bool bios) { // Loop through the romof tags List games = [.. SortedKeys]; @@ -2078,7 +2080,7 @@ namespace SabreTools.DatFiles /// /// Use cloneof tags to remove roms from the children /// - public void RemoveRomsFromChild() + internal void RemoveRomsFromChild() { List games = [.. SortedKeys]; foreach (string game in games) @@ -2134,7 +2136,7 @@ namespace SabreTools.DatFiles /// /// Remove all romof and cloneof tags from all games /// - public void RemoveTagsFromChild() + internal void RemoveTagsFromChild() { List games = [.. SortedKeys]; foreach (string game in games) diff --git a/SabreTools.DatFiles/SabreTools.DatFiles.csproj b/SabreTools.DatFiles/SabreTools.DatFiles.csproj index 5cd96433..f75b8af9 100644 --- a/SabreTools.DatFiles/SabreTools.DatFiles.csproj +++ b/SabreTools.DatFiles/SabreTools.DatFiles.csproj @@ -24,6 +24,7 @@ + diff --git a/SabreTools.DatTools/Cleaner.cs b/SabreTools.DatTools/Cleaner.cs index abbd0cf7..29f2a11e 100644 --- a/SabreTools.DatTools/Cleaner.cs +++ b/SabreTools.DatTools/Cleaner.cs @@ -106,43 +106,25 @@ namespace SabreTools.DatTools // Bucket and dedupe according to the flag if (DedupeRoms == DedupeType.Full) - { - datFile.Items.BucketBy(ItemKey.CRC, DedupeRoms); - datFile.ItemsDB.BucketBy(ItemKey.CRC, DedupeRoms); - } + datFile.BucketBy(ItemKey.CRC, DedupeRoms); else if (DedupeRoms == DedupeType.Game) - { - datFile.Items.BucketBy(ItemKey.Machine, DedupeRoms); - datFile.ItemsDB.BucketBy(ItemKey.Machine, DedupeRoms); - } + datFile.BucketBy(ItemKey.Machine, DedupeRoms); // Process description to machine name if (DescriptionAsName == true) - { - datFile.Items.MachineDescriptionToName(throwOnError); - datFile.ItemsDB.MachineDescriptionToName(throwOnError); - } + datFile.MachineDescriptionToName(throwOnError); // If we are removing scene dates, do that now if (SceneDateStrip == true) - { - datFile.Items.StripSceneDatesFromItems(); - datFile.ItemsDB.StripSceneDatesFromItems(); - } + datFile.StripSceneDatesFromItems(); // Run the one rom per game logic, if required if (OneGamePerRegion == true && RegionList != null) - { - datFile.Items.SetOneGamePerRegion(RegionList); - datFile.ItemsDB.SetOneGamePerRegion(RegionList); - } + datFile.SetOneGamePerRegion(RegionList); // Run the one rom per game logic, if required if (OneRomPerGame == true) - { - datFile.Items.SetOneRomPerGame(); - datFile.ItemsDB.SetOneRomPerGame(); - } + datFile.SetOneRomPerGame(); // Remove all marked items datFile.ClearMarked(); @@ -174,7 +156,7 @@ namespace SabreTools.DatTools foreach (string key in keys) { // For every item in the current key - var items = datFile.Items[key]; + var items = datFile.GetItemsForBucket(key); if (items == null) continue; @@ -203,7 +185,7 @@ namespace SabreTools.DatTools foreach (string key in keys) { // For every item in the current key - var items = datFile.ItemsDB.GetItemsForBucket(key); + var items = datFile.GetItemsForBucketDB(key); if (items == null) continue; diff --git a/SabreTools.DatTools/ExtraIni.cs b/SabreTools.DatTools/ExtraIni.cs index fd822768..9c7a4c2e 100644 --- a/SabreTools.DatTools/ExtraIni.cs +++ b/SabreTools.DatTools/ExtraIni.cs @@ -95,7 +95,7 @@ namespace SabreTools.DatTools try { // Bucket by game first - datFile.Items.BucketBy(ItemKey.Machine, DedupeType.None); + datFile.BucketBy(ItemKey.Machine, DedupeType.None); // Create mappings based on the extra items var combinedMaps = CombineExtras(); @@ -109,7 +109,7 @@ namespace SabreTools.DatTools continue; // Get the list of DatItems for the machine - var datItems = datFile.Items[machine]; + var datItems = datFile.GetItemsForBucket(machine); if (datItems == null) continue; @@ -158,7 +158,7 @@ namespace SabreTools.DatTools try { // Bucket by game first - datFile.ItemsDB.BucketBy(ItemKey.Machine, DedupeType.None); + datFile.BucketBy(ItemKey.Machine, DedupeType.None); // Create mappings based on the extra items var combinedMaps = CombineExtras(); @@ -168,7 +168,7 @@ namespace SabreTools.DatTools foreach (string game in games) { // Get the list of DatItems for the machine - var datItems = datFile.ItemsDB.GetItemsForBucket(game); + var datItems = datFile.GetItemsForBucketDB(game); if (datItems == null) continue; diff --git a/SabreTools.DatTools/MergeSplit.cs b/SabreTools.DatTools/MergeSplit.cs index 5b0f840a..836f97cf 100644 --- a/SabreTools.DatTools/MergeSplit.cs +++ b/SabreTools.DatTools/MergeSplit.cs @@ -102,18 +102,14 @@ namespace SabreTools.DatTools _staticLogger.User("Creating device non-merged sets from the DAT"); // For sake of ease, the first thing we want to do is bucket by game - datFile.Items.BucketBy(ItemKey.Machine, DedupeType.None, norename: true); - datFile.ItemsDB.BucketBy(ItemKey.Machine, DedupeType.None, norename: true); + datFile.BucketBy(ItemKey.Machine, DedupeType.None, norename: true); // Now we want to loop through all of the games and set the correct information - while (datFile.Items.AddRomsFromDevices(false, false)) ; - while (datFile.ItemsDB.AddRomsFromDevices(false, false)) ; - while (datFile.Items.AddRomsFromDevices(true, false)) ; - while (datFile.ItemsDB.AddRomsFromDevices(true, false)) ; + while (datFile.AddRomsFromDevices(false, false)) ; + while (datFile.AddRomsFromDevices(true, false)) ; // Then, remove the romof and cloneof tags so it's not picked up by the manager - datFile.Items.RemoveTagsFromChild(); - datFile.ItemsDB.RemoveTagsFromChild(); + datFile.RemoveTagsFromChild(); } /// @@ -125,22 +121,17 @@ namespace SabreTools.DatTools _staticLogger.User("Creating fully merged sets from the DAT"); // For sake of ease, the first thing we want to do is bucket by game - datFile.Items.BucketBy(ItemKey.Machine, DedupeType.None, norename: true); - datFile.ItemsDB.BucketBy(ItemKey.Machine, DedupeType.None, norename: true); + datFile.BucketBy(ItemKey.Machine, DedupeType.None, norename: true); // Now we want to loop through all of the games and set the correct information - datFile.Items.AddRomsFromChildren(true, false); - datFile.ItemsDB.AddRomsFromChildren(true, false); + datFile.AddRomsFromChildren(true, false); // Now that we have looped through the cloneof tags, we loop through the romof tags - datFile.Items.RemoveBiosRomsFromChild(false); - datFile.ItemsDB.RemoveBiosRomsFromChild(false); - datFile.Items.RemoveBiosRomsFromChild(true); - datFile.ItemsDB.RemoveBiosRomsFromChild(true); + datFile.RemoveBiosRomsFromChild(false); + datFile.RemoveBiosRomsFromChild(true); // Finally, remove the romof and cloneof tags so it's not picked up by the manager - datFile.Items.RemoveTagsFromChild(); - datFile.ItemsDB.RemoveTagsFromChild(); + datFile.RemoveTagsFromChild(); } /// @@ -152,24 +143,18 @@ namespace SabreTools.DatTools _staticLogger.User("Creating fully non-merged sets from the DAT"); // For sake of ease, the first thing we want to do is bucket by game - datFile.Items.BucketBy(ItemKey.Machine, DedupeType.None, norename: true); - datFile.ItemsDB.BucketBy(ItemKey.Machine, DedupeType.None, norename: true); + datFile.BucketBy(ItemKey.Machine, DedupeType.None, norename: true); // Now we want to loop through all of the games and set the correct information - while (datFile.Items.AddRomsFromDevices(true, true)) ; - while (datFile.ItemsDB.AddRomsFromDevices(true, true)) ; - datFile.Items.AddRomsFromDevices(false, true); - datFile.ItemsDB.AddRomsFromDevices(false, true); - datFile.Items.AddRomsFromParent(); - datFile.ItemsDB.AddRomsFromParent(); + while (datFile.AddRomsFromDevices(true, true)) ; + datFile.AddRomsFromDevices(false, true); + datFile.AddRomsFromParent(); // Now that we have looped through the cloneof tags, we loop through the romof tags - datFile.Items.AddRomsFromBios(); - datFile.ItemsDB.AddRomsFromBios(); + datFile.AddRomsFromBios(); // Then, remove the romof and cloneof tags so it's not picked up by the manager - datFile.Items.RemoveTagsFromChild(); - datFile.ItemsDB.RemoveTagsFromChild(); + datFile.RemoveTagsFromChild(); } /// @@ -181,22 +166,17 @@ namespace SabreTools.DatTools _staticLogger.User("Creating merged sets from the DAT"); // For sake of ease, the first thing we want to do is bucket by game - datFile.Items.BucketBy(ItemKey.Machine, DedupeType.None, norename: true); - datFile.ItemsDB.BucketBy(ItemKey.Machine, DedupeType.None, norename: true); + datFile.BucketBy(ItemKey.Machine, DedupeType.None, norename: true); // Now we want to loop through all of the games and set the correct information - datFile.Items.AddRomsFromChildren(true, true); - datFile.ItemsDB.AddRomsFromChildren(true, true); + datFile.AddRomsFromChildren(true, true); // Now that we have looped through the cloneof tags, we loop through the romof tags - datFile.Items.RemoveBiosRomsFromChild(false); - datFile.ItemsDB.RemoveBiosRomsFromChild(false); - datFile.Items.RemoveBiosRomsFromChild(true); - datFile.ItemsDB.RemoveBiosRomsFromChild(true); + datFile.RemoveBiosRomsFromChild(false); + datFile.RemoveBiosRomsFromChild(true); // Finally, remove the romof and cloneof tags so it's not picked up by the manager - datFile.Items.RemoveTagsFromChild(); - datFile.ItemsDB.RemoveTagsFromChild(); + datFile.RemoveTagsFromChild(); } /// @@ -208,22 +188,17 @@ namespace SabreTools.DatTools _staticLogger.User("Creating non-merged sets from the DAT"); // For sake of ease, the first thing we want to do is bucket by game - datFile.Items.BucketBy(ItemKey.Machine, DedupeType.None, norename: true); - datFile.ItemsDB.BucketBy(ItemKey.Machine, DedupeType.None, norename: true); + datFile.BucketBy(ItemKey.Machine, DedupeType.None, norename: true); // Now we want to loop through all of the games and set the correct information - datFile.Items.AddRomsFromParent(); - datFile.ItemsDB.AddRomsFromParent(); + datFile.AddRomsFromParent(); // Now that we have looped through the cloneof tags, we loop through the romof tags - datFile.Items.RemoveBiosRomsFromChild(false); - datFile.ItemsDB.RemoveBiosRomsFromChild(false); - datFile.Items.RemoveBiosRomsFromChild(true); - datFile.ItemsDB.RemoveBiosRomsFromChild(true); + datFile.RemoveBiosRomsFromChild(false); + datFile.RemoveBiosRomsFromChild(true); // Finally, remove the romof and cloneof tags so it's not picked up by the manager - datFile.Items.RemoveTagsFromChild(); - datFile.ItemsDB.RemoveTagsFromChild(); + datFile.RemoveTagsFromChild(); } /// @@ -235,22 +210,17 @@ namespace SabreTools.DatTools _staticLogger.User("Creating split sets from the DAT"); // For sake of ease, the first thing we want to do is bucket by game - datFile.Items.BucketBy(ItemKey.Machine, DedupeType.None, norename: true); - datFile.ItemsDB.BucketBy(ItemKey.Machine, DedupeType.None, norename: true); + datFile.BucketBy(ItemKey.Machine, DedupeType.None, norename: true); // Now we want to loop through all of the games and set the correct information - datFile.Items.RemoveRomsFromChild(); - datFile.ItemsDB.RemoveRomsFromChild(); + datFile.RemoveRomsFromChild(); // Now that we have looped through the cloneof tags, we loop through the romof tags - datFile.Items.RemoveBiosRomsFromChild(false); - datFile.ItemsDB.RemoveBiosRomsFromChild(false); - datFile.Items.RemoveBiosRomsFromChild(true); - datFile.ItemsDB.RemoveBiosRomsFromChild(true); + datFile.RemoveBiosRomsFromChild(false); + datFile.RemoveBiosRomsFromChild(true); // Finally, remove the romof and cloneof tags so it's not picked up by the manager - datFile.Items.RemoveTagsFromChild(); - datFile.ItemsDB.RemoveTagsFromChild(); + datFile.RemoveTagsFromChild(); } #endregion diff --git a/SabreTools.DatTools/Rebuilder.cs b/SabreTools.DatTools/Rebuilder.cs index 5466e9f3..43894b1b 100644 --- a/SabreTools.DatTools/Rebuilder.cs +++ b/SabreTools.DatTools/Rebuilder.cs @@ -53,7 +53,7 @@ namespace SabreTools.DatTools #region Perform setup // If the DAT is not populated and inverse is not set, inform the user and quit - if (datFile.Items.DatStatistics.TotalCount == 0 && !inverse) + if (datFile.DatStatistics.TotalCount == 0 && !inverse) { _staticLogger.User("No entries were found to rebuild, exiting..."); return false; @@ -106,7 +106,7 @@ namespace SabreTools.DatTools return success; // Now that we have a list of depots, we want to bucket the input DAT by SHA-1 - datFile.Items.BucketBy(ItemKey.SHA1, DedupeType.None); + datFile.BucketBy(ItemKey.SHA1, DedupeType.None); // Then we want to loop through each of the hashes and see if we can rebuild List keys = [.. datFile.Items.SortedKeys]; @@ -147,10 +147,10 @@ namespace SabreTools.DatTools continue; // Ensure we are sorted correctly (some other calls can change this) - //datFile.Items.BucketBy(ItemKey.SHA1, DedupeType.None); + //datFile.BucketBy(ItemKey.SHA1, DedupeType.None); // If there are no items in the hash, we continue - var items = datFile.Items[hash]; + var items = datFile.GetItemsForBucket(hash); if (items == null || items.Count == 0) continue; @@ -204,7 +204,7 @@ namespace SabreTools.DatTools #region Perform setup // If the DAT is not populated and inverse is not set, inform the user and quit - if (datFile.Items.DatStatistics.TotalCount == 0 && !inverse) + if (datFile.DatStatistics.TotalCount == 0 && !inverse) { _staticLogger.User("No entries were found to rebuild, exiting..."); return false; @@ -451,7 +451,7 @@ namespace SabreTools.DatTools if (outputFormat == OutputFormat.Folder && datFile.Header.GetStringFieldValue(Models.Metadata.Header.ForcePackingKey).AsEnumValue() == PackingFlag.Partial) { shouldCheck = true; - datFile.Items.BucketBy(ItemKey.Machine, DedupeType.None, lower: false); + datFile.BucketBy(ItemKey.Machine, DedupeType.None, lower: false); } // Now loop through the list and rebuild accordingly @@ -463,7 +463,7 @@ namespace SabreTools.DatTools continue; // If we should check for the items in the machine - var items = datFile.Items[machine.GetStringFieldValue(Models.Metadata.Machine.NameKey)!]; + var items = datFile.GetItemsForBucket(machine.GetStringFieldValue(Models.Metadata.Machine.NameKey)!); if (shouldCheck && items!.Count > 1) outputFormat = OutputFormat.Folder; else if (shouldCheck && items!.Count == 1) @@ -553,7 +553,7 @@ namespace SabreTools.DatTools private static bool ShouldRebuild(DatFile datFile, DatItem datItem, Stream? stream, bool inverse, out List dupes) { // Find if the file has duplicates in the DAT - dupes = datFile.Items.GetDuplicates(datItem); + dupes = datFile.GetDuplicates(datItem); bool hasDuplicates = dupes.Count > 0; // If we have duplicates but we're filtering @@ -609,7 +609,7 @@ namespace SabreTools.DatTools private static bool ShouldRebuildDB(DatFile datFile, KeyValuePair datItem, Stream? stream, bool inverse, out Dictionary dupes) { // Find if the file has duplicates in the DAT - dupes = datFile.ItemsDB.GetDuplicates(datItem); + dupes = datFile.GetDuplicatesDB(datItem); bool hasDuplicates = dupes.Count > 0; // If we have duplicates but we're filtering diff --git a/SabreTools.DatTools/Splitter.cs b/SabreTools.DatTools/Splitter.cs index fbc0ecb7..0ca95100 100644 --- a/SabreTools.DatTools/Splitter.cs +++ b/SabreTools.DatTools/Splitter.cs @@ -41,7 +41,7 @@ namespace SabreTools.DatTools public static (DatFile? extADat, DatFile? extBDat) SplitByExtension(DatFile datFile, List extA, List extB) { // If roms is empty, return false - if (datFile.Items.DatStatistics.TotalCount == 0) + if (datFile.DatStatistics.TotalCount == 0) return (null, null); InternalStopwatch watch = new($"Splitting DAT by extension"); @@ -73,7 +73,7 @@ namespace SabreTools.DatTools foreach (var key in datFile.Items.Keys) #endif { - var items = datFile.Items[key]; + var items = datFile.GetItemsForBucket(key); if (items == null) #if NET40_OR_GREATER || NETCOREAPP return; @@ -249,7 +249,7 @@ namespace SabreTools.DatTools foreach (var key in datFile.Items.Keys) #endif { - var items = datFile.Items[key]; + var items = datFile.GetItemsForBucket(key); if (items == null) #if NET40_OR_GREATER || NETCOREAPP return; @@ -493,7 +493,7 @@ namespace SabreTools.DatTools InternalStopwatch watch = new($"Splitting DAT by level"); // First, bucket by games so that we can do the right thing - datFile.Items.BucketBy(ItemKey.Machine, DedupeType.None, lower: false, norename: true); + datFile.BucketBy(ItemKey.Machine, DedupeType.None, lower: false, norename: true); // Create a temporary DAT to add things to DatFile tempDat = DatFileTool.CreateDatFile(datFile.Header); @@ -521,7 +521,7 @@ namespace SabreTools.DatTools } // Clean the input list and set all games to be pathless - List? items = datFile.Items[key]; + List? items = datFile.GetItemsForBucket(key); if (items == null) #if NET40_OR_GREATER || NETCOREAPP return; @@ -638,7 +638,7 @@ namespace SabreTools.DatTools foreach (var key in datFile.Items.Keys) #endif { - List? items = datFile.Items[key]; + List? items = datFile.GetItemsForBucket(key); if (items == null) #if NET40_OR_GREATER || NETCOREAPP return; @@ -777,7 +777,7 @@ namespace SabreTools.DatTools InternalStopwatch watch = new($"Splitting DAT by total size"); // Sort the DatFile by machine name - datFile.Items.BucketBy(ItemKey.Machine, DedupeType.None); + datFile.BucketBy(ItemKey.Machine, DedupeType.None); // Get the keys in a known order for easier sorting var keys = datFile.Items.SortedKeys; @@ -920,7 +920,7 @@ namespace SabreTools.DatTools foreach (var key in datFile.Items.Keys) #endif { - List items = DatFileTool.Merge(datFile.Items[key]); + List items = DatFileTool.Merge(datFile.GetItemsForBucket(key)); // If the rom list is empty or null, just skip it if (items == null || items.Count == 0) diff --git a/SabreTools.DatTools/Statistics.cs b/SabreTools.DatTools/Statistics.cs index 544fff2d..1f6a1ba0 100644 --- a/SabreTools.DatTools/Statistics.cs +++ b/SabreTools.DatTools/Statistics.cs @@ -81,21 +81,18 @@ namespace SabreTools.DatTools // Add single DAT stats (if asked) if (single) { - DatStatistics individualStats = datdata.Items.DatStatistics; - //DatStatistics individualStats = datdata.ItemsDB.DatStatistics; + DatStatistics individualStats = datdata.DatStatistics; individualStats.DisplayName = datdata.Header.GetStringFieldValue(DatHeader.FileNameKey); individualStats.MachineCount = datdata.Items.Keys.Count; stats.Add(individualStats); } // Add single DAT stats to dir - dirStats.AddStatistics(datdata.Items.DatStatistics); - //dirStats.AddStatistics(datdata.ItemsDB.DatStatistics); + dirStats.AddStatistics(datdata.DatStatistics); dirStats.GameCount += datdata.Items.Keys.Count; // Add single DAT stats to totals - totalStats.AddStatistics(datdata.Items.DatStatistics); - //totalStats.AddStatistics(datdata.ItemsDB.DatStatistics); + totalStats.AddStatistics(datdata.DatStatistics); totalStats.GameCount += datdata.Items.Keys.Count; // Make sure to assign the new directory diff --git a/SabreTools.DatTools/Verification.cs b/SabreTools.DatTools/Verification.cs index 6e6ddff5..9ffb1f8b 100644 --- a/SabreTools.DatTools/Verification.cs +++ b/SabreTools.DatTools/Verification.cs @@ -55,7 +55,7 @@ namespace SabreTools.DatTools return success; // Now that we have a list of depots, we want to bucket the input DAT by SHA-1 - datFile.Items.BucketBy(ItemKey.SHA1, DedupeType.None); + datFile.BucketBy(ItemKey.SHA1, DedupeType.None); // Then we want to loop through each of the hashes and see if we can rebuild List keys = [.. datFile.Items.SortedKeys]; @@ -96,8 +96,8 @@ namespace SabreTools.DatTools continue; // Now we want to remove all duplicates from the DAT - datFile.Items.GetDuplicates(fileinfo.ConvertToRom()) - .AddRange(datFile.Items.GetDuplicates(fileinfo.ConvertToDisk())); + datFile.GetDuplicates(fileinfo.ConvertToRom()) + .AddRange(datFile.GetDuplicates(fileinfo.ConvertToDisk())); } watch.Stop(); @@ -140,7 +140,7 @@ namespace SabreTools.DatTools return success; // Now that we have a list of depots, we want to bucket the input DAT by SHA-1 - datFile.ItemsDB.BucketBy(ItemKey.SHA1, DedupeType.None); + datFile.BucketBy(ItemKey.SHA1, DedupeType.None); // Then we want to loop through each of the hashes and see if we can rebuild List keys = [.. datFile.ItemsDB.SortedKeys]; @@ -181,8 +181,8 @@ namespace SabreTools.DatTools continue; // Now we want to remove all duplicates from the DAT - datFile.ItemsDB.GetDuplicates(new KeyValuePair(-1, fileinfo.ConvertToRom())) - .Concat(datFile.ItemsDB.GetDuplicates(new KeyValuePair(-1, fileinfo.ConvertToDisk()))); + datFile.GetDuplicatesDB(new KeyValuePair(-1, fileinfo.ConvertToRom())) + .Concat(datFile.GetDuplicatesDB(new KeyValuePair(-1, fileinfo.ConvertToDisk()))); } watch.Stop(); @@ -211,15 +211,15 @@ namespace SabreTools.DatTools // Force bucketing according to the flags datFile.Items.SetBucketedBy(ItemKey.NULL); if (hashOnly) - datFile.Items.BucketBy(ItemKey.CRC, DedupeType.Full); + datFile.BucketBy(ItemKey.CRC, DedupeType.Full); else - datFile.Items.BucketBy(ItemKey.Machine, DedupeType.Full); + datFile.BucketBy(ItemKey.Machine, DedupeType.Full); // Then mark items for removal List keys = [.. datFile.Items.SortedKeys]; foreach (string key in keys) { - List? items = datFile.Items[key]; + List? items = datFile.GetItemsForBucket(key); if (items == null) continue; @@ -259,9 +259,9 @@ namespace SabreTools.DatTools // Force bucketing according to the flags if (hashOnly) - datFile.ItemsDB.BucketBy(ItemKey.CRC, DedupeType.Full); + datFile.BucketBy(ItemKey.CRC, DedupeType.Full); else - datFile.ItemsDB.BucketBy(ItemKey.Machine, DedupeType.Full); + datFile.BucketBy(ItemKey.Machine, DedupeType.Full); // Then mark items for removal List keys = [.. datFile.ItemsDB.SortedKeys]; diff --git a/SabreTools.DatTools/Writer.cs b/SabreTools.DatTools/Writer.cs index 0a73b63d..6f24e56d 100644 --- a/SabreTools.DatTools/Writer.cs +++ b/SabreTools.DatTools/Writer.cs @@ -77,12 +77,10 @@ namespace SabreTools.DatTools EnsureHeaderFields(datFile); // Bucket roms by game name, if not already - datFile.Items.BucketBy(ItemKey.Machine, DedupeType.None); - datFile.ItemsDB.BucketBy(ItemKey.Machine, DedupeType.None); + datFile.BucketBy(ItemKey.Machine, DedupeType.None); // Output the number of items we're going to be writing - _staticLogger.User($"A total of {datFile.Items.DatStatistics.TotalCount - datFile.Items.DatStatistics.RemovedCount} items will be written out to '{datFile.Header.GetStringFieldValue(DatHeader.FileNameKey)}'"); - //logger.User($"A total of {datFile.ItemsDB.DatStatistics.TotalCount - datFile.ItemsDB.DatStatistics.RemovedCount} items will be written out to '{datFile.Header.GetStringFieldValue(DatHeader.FileNameKey)}'"); + _staticLogger.User($"A total of {datFile.DatStatistics.TotalCount - datFile.DatStatistics.RemovedCount} items will be written out to '{datFile.Header.GetStringFieldValue(DatHeader.FileNameKey)}'"); // Get the outfile names Dictionary outfiles = datFile.Header.CreateOutFileNames(outDir!, overwrite); @@ -133,33 +131,21 @@ namespace SabreTools.DatTools /// Current DatFile object to write from public static void WriteStatsToConsole(DatFile datFile) { - long diskCount = datFile.Items.DatStatistics.GetItemCount(ItemType.Disk); - long mediaCount = datFile.Items.DatStatistics.GetItemCount(ItemType.Media); - long romCount = datFile.Items.DatStatistics.GetItemCount(ItemType.Rom); + long diskCount = datFile.DatStatistics.GetItemCount(ItemType.Disk); + long mediaCount = datFile.DatStatistics.GetItemCount(ItemType.Media); + long romCount = datFile.DatStatistics.GetItemCount(ItemType.Rom); if (diskCount + mediaCount + romCount == 0) datFile.Items.RecalculateStats(); - diskCount = datFile.ItemsDB.DatStatistics.GetItemCount(ItemType.Disk); - mediaCount = datFile.ItemsDB.DatStatistics.GetItemCount(ItemType.Media); - romCount = datFile.ItemsDB.DatStatistics.GetItemCount(ItemType.Rom); + datFile.BucketBy(ItemKey.Machine, DedupeType.None, norename: true); - if (diskCount + mediaCount + romCount == 0) - datFile.ItemsDB.RecalculateStats(); - - datFile.Items.BucketBy(ItemKey.Machine, DedupeType.None, norename: true); - datFile.ItemsDB.BucketBy(ItemKey.Machine, DedupeType.None, norename: true); - - datFile.Items.DatStatistics.DisplayName = datFile.Header.GetStringFieldValue(DatHeader.FileNameKey); - datFile.Items.DatStatistics.MachineCount = datFile.Items.Keys.Count; - - datFile.ItemsDB.DatStatistics.DisplayName = datFile.Header.GetStringFieldValue(DatHeader.FileNameKey); - datFile.ItemsDB.DatStatistics.MachineCount = datFile.Items.Keys.Count; + datFile.DatStatistics.DisplayName = datFile.Header.GetStringFieldValue(DatHeader.FileNameKey); + datFile.DatStatistics.MachineCount = datFile.Items.Keys.Count; List statsList = [ - datFile.Items.DatStatistics, - //datFile.ItemsDB.DatStatistics, + datFile.DatStatistics, ]; var consoleOutput = BaseReport.Create(StatReportFormat.None, statsList); consoleOutput!.WriteToFile(null, true, true); @@ -232,13 +218,13 @@ namespace SabreTools.DatTools datFile.ItemsDB.RecalculateStats(); // If there's nothing there, abort - if (datFile.Items.DatStatistics.TotalCount == 0) + if (datFile.DatStatistics.TotalCount == 0) return false; // if (datFile.ItemsDB.DatStatistics.TotalCount == 0) // return false; // If every item is removed, abort - if (datFile.Items.DatStatistics.TotalCount == datFile.Items.DatStatistics.RemovedCount) + if (datFile.DatStatistics.TotalCount == datFile.DatStatistics.RemovedCount) return false; // if (datFile.ItemsDB.DatStatistics.TotalCount == datFile.ItemsDB.DatStatistics.RemovedCount) // return false; diff --git a/SabreTools/Features/Batch.cs b/SabreTools/Features/Batch.cs index 2c748fdc..367fdd2b 100644 --- a/SabreTools/Features/Batch.cs +++ b/SabreTools/Features/Batch.cs @@ -236,8 +236,7 @@ Reset the internal state: reset();"; /// public override void Process(BatchState batchState) { - batchState.DatFile.Items.MachineDescriptionToName(); - batchState.DatFile.ItemsDB.MachineDescriptionToName(); + batchState.DatFile.MachineDescriptionToName(); } } @@ -608,8 +607,7 @@ Reset the internal state: reset();"; /// public override void Process(BatchState batchState) { - batchState.DatFile.Items.SetOneGamePerRegion([.. Arguments]); - batchState.DatFile.ItemsDB.SetOneGamePerRegion([.. Arguments]); + batchState.DatFile.SetOneGamePerRegion([.. Arguments]); } } @@ -642,8 +640,7 @@ Reset the internal state: reset();"; /// public override void Process(BatchState batchState) { - batchState.DatFile.Items.SetOneRomPerGame(); - batchState.DatFile.ItemsDB.SetOneRomPerGame(); + batchState.DatFile.SetOneRomPerGame(); } } @@ -777,8 +774,7 @@ Reset the internal state: reset();"; /// public override void Process(BatchState batchState) { - batchState.DatFile.Items.StripSceneDatesFromItems(); - batchState.DatFile.ItemsDB.StripSceneDatesFromItems(); + batchState.DatFile.StripSceneDatesFromItems(); } }