diff --git a/SabreTools.Helper/Tools/DatTools.cs b/SabreTools.Helper/Tools/DatTools.cs index f2d6767c..1852a1ff 100644 --- a/SabreTools.Helper/Tools/DatTools.cs +++ b/SabreTools.Helper/Tools/DatTools.cs @@ -7,8 +7,13 @@ using System.Xml; namespace SabreTools.Helper { + /// + /// DAT manipulation tools that rely on Rom and related structs + /// public class DatTools { + #region DAT Parsing + /// /// Get what type of DAT the input file is /// @@ -1422,6 +1427,10 @@ namespace SabreTools.Helper return datdata; } + #endregion + + #region Bucketing methods + /// /// Take an arbitrarily ordered List and return a Dictionary sorted by Game /// @@ -1570,6 +1579,10 @@ namespace SabreTools.Helper return sortable; } + #endregion + + #region Converting and updating + /// /// Convert, update, and filter a DAT file /// @@ -2280,5 +2293,7 @@ namespace SabreTools.Helper Output.WriteDatfile(userData, outdir, logger); } } + + #endregion } } diff --git a/SabreTools.Helper/Tools/DatToolsHash.cs b/SabreTools.Helper/Tools/DatToolsHash.cs index e1097e86..821accf3 100644 --- a/SabreTools.Helper/Tools/DatToolsHash.cs +++ b/SabreTools.Helper/Tools/DatToolsHash.cs @@ -12,6 +12,8 @@ namespace SabreTools.Helper /// public class DatToolsHash { + #region DAT Parsing + /// /// Parse a DAT and return all found games and roms within /// @@ -1380,6 +1382,10 @@ namespace SabreTools.Helper return datdata; } + #endregion + + #region Bucketing methods + /// /// Take an arbitrarily ordered List and return a Dictionary sorted by Game /// @@ -1456,5 +1462,82 @@ namespace SabreTools.Helper return sortable; } + + /// + /// Take an arbitrarily ordered List and return a Dictionary sorted by size and hash + /// + /// Input unsorted list + /// True if roms should be deduped, false otherwise + /// True if games should only be compared on game and file name, false if system and source are counted + /// Logger object for file and console output + /// True if the number of hashes counted is to be output (default), false otherwise + /// SortedDictionary bucketed by size and hash + public static SortedDictionary> BucketByHashSize(List list, bool mergeroms, bool norename, Logger logger, bool output = true) + { + Dictionary> dict = new Dictionary>(); + dict.Add("key", list); + return BucketByHashSize(dict, mergeroms, norename, logger, output); + } + + /// + /// Take an arbitrarily bucketed Dictionary and return one sorted by size and hash + /// + /// Input unsorted dictionary + /// True if roms should be deduped, false otherwise + /// True if games should only be compared on game and file name, false if system and source are counted + /// Logger object for file and console output + /// True if the number of hashes counted is to be output (default), false otherwise + /// SortedDictionary bucketed by size and hash + public static SortedDictionary> BucketByHashSize(IDictionary> dict, bool mergeroms, bool norename, Logger logger, bool output = true) + { + SortedDictionary> sortable = new SortedDictionary>(); + long count = 0; + + // If we have a null dict or an empty one, output a new dictionary + if (dict == null || dict.Count == 0) + { + return sortable; + } + + // Process each all of the roms + foreach (List hashes in dict.Values) + { + List newhashes = hashes; + if (mergeroms) + { + newhashes = RomTools.Merge(newhashes, logger); + } + + foreach (HashData hash in newhashes) + { + count++; + string key = hash.Size + "-" + BitConverter.ToString(hash.CRC).Replace("-", string.Empty); + if (sortable.ContainsKey(key)) + { + sortable[key].Add(hash); + } + else + { + List temp = new List(); + temp.Add(hash); + sortable.Add(key, temp); + } + } + } + + // Output the count if told to + if (output) + { + logger.User("A total of " + count + " file hashes will be written out to file"); + } + + return sortable; + } + + #endregion + + #region Converting and updating + + #endregion } }