Make stats use the reduced parsing model

This commit is contained in:
Matt Nadareski
2020-12-23 14:06:48 -08:00
parent 616d4fec5e
commit 8a60d824e3
3 changed files with 13 additions and 15 deletions

View File

@@ -233,9 +233,7 @@ namespace SabreTools.DatFiles
// If only adding statistics, we add an empty key for games and then just item stats // If only adding statistics, we add an empty key for games and then just item stats
if (statsOnly) if (statsOnly)
{ {
if (Items.ContainsKey(key)) Items.EnsureKey(key);
Items.Add(key, new List<DatItem>());
Items.AddItemStatistics(item); Items.AddItemStatistics(item);
} }
else else

View File

@@ -669,6 +669,17 @@ namespace SabreTools.DatFiles
return false; return false;
} }
/// <summary>
/// Ensure the key exists in the items dictionary
/// </summary>
/// <param name="key">Key to ensure</param>
public void EnsureKey(string key)
{
// If the key is missing from the dictionary, add it
if (!items.ContainsKey(key))
items.TryAdd(key, new List<DatItem>());
}
/// <summary> /// <summary>
/// Get a list of filtered items for a given key /// Get a list of filtered items for a given key
/// </summary> /// </summary>
@@ -768,17 +779,6 @@ namespace SabreTools.DatFiles
bucketedBy = newBucket; bucketedBy = newBucket;
} }
/// <summary>
/// Ensure the key exists in the items dictionary
/// </summary>
/// <param name="key">Key to ensure</param>
private void EnsureKey(string key)
{
// If the key is missing from the dictionary, add it
if (!items.ContainsKey(key))
items.TryAdd(key, new List<DatItem>());
}
/// <summary> /// <summary>
/// Remove from the statistics given a DatItem /// Remove from the statistics given a DatItem
/// </summary> /// </summary>

View File

@@ -110,7 +110,7 @@ namespace SabreTools.DatTools
logger.Verbose($"Beginning stat collection for '{file.CurrentPath}'"); logger.Verbose($"Beginning stat collection for '{file.CurrentPath}'");
List<string> games = new List<string>(); List<string> games = new List<string>();
DatFile datdata = Parser.CreateAndParse(file.CurrentPath); DatFile datdata = Parser.CreateAndParse(file.CurrentPath, statsOnly: true);
datdata.Items.BucketBy(ItemKey.Machine, DedupeType.None, norename: true); datdata.Items.BucketBy(ItemKey.Machine, DedupeType.None, norename: true);
// Output single DAT stats (if asked) // Output single DAT stats (if asked)