diff --git a/SabreTools.DatFiles/DatFile.cs b/SabreTools.DatFiles/DatFile.cs index ee50e921..dd72c101 100644 --- a/SabreTools.DatFiles/DatFile.cs +++ b/SabreTools.DatFiles/DatFile.cs @@ -233,9 +233,7 @@ namespace SabreTools.DatFiles // If only adding statistics, we add an empty key for games and then just item stats if (statsOnly) { - if (Items.ContainsKey(key)) - Items.Add(key, new List()); - + Items.EnsureKey(key); Items.AddItemStatistics(item); } else diff --git a/SabreTools.DatFiles/ItemDictionary.cs b/SabreTools.DatFiles/ItemDictionary.cs index 3905b61d..dabbd720 100644 --- a/SabreTools.DatFiles/ItemDictionary.cs +++ b/SabreTools.DatFiles/ItemDictionary.cs @@ -669,6 +669,17 @@ namespace SabreTools.DatFiles return false; } + /// + /// Ensure the key exists in the items dictionary + /// + /// Key to ensure + public void EnsureKey(string key) + { + // If the key is missing from the dictionary, add it + if (!items.ContainsKey(key)) + items.TryAdd(key, new List()); + } + /// /// Get a list of filtered items for a given key /// @@ -768,17 +779,6 @@ namespace SabreTools.DatFiles bucketedBy = newBucket; } - /// - /// Ensure the key exists in the items dictionary - /// - /// Key to ensure - private void EnsureKey(string key) - { - // If the key is missing from the dictionary, add it - if (!items.ContainsKey(key)) - items.TryAdd(key, new List()); - } - /// /// Remove from the statistics given a DatItem /// diff --git a/SabreTools.DatTools/Statistics.cs b/SabreTools.DatTools/Statistics.cs index 036dad93..37b8e1e4 100644 --- a/SabreTools.DatTools/Statistics.cs +++ b/SabreTools.DatTools/Statistics.cs @@ -110,7 +110,7 @@ namespace SabreTools.DatTools logger.Verbose($"Beginning stat collection for '{file.CurrentPath}'"); List games = new List(); - DatFile datdata = Parser.CreateAndParse(file.CurrentPath); + DatFile datdata = Parser.CreateAndParse(file.CurrentPath, statsOnly: true); datdata.Items.BucketBy(ItemKey.Machine, DedupeType.None, norename: true); // Output single DAT stats (if asked)