[DatItem] Add HasDuplicates method for when we don't care what the dupes actually are

This commit is contained in:
Matt Nadareski
2016-10-06 16:19:09 -07:00
parent 4bd4e3250f
commit b9388de8cb
2 changed files with 74 additions and 2 deletions

View File

@@ -606,6 +606,78 @@ namespace SabreTools.Helper
return true;
}
/// <summary>
/// Check if a DAT contains the given rom
/// </summary>
/// <param name="datdata">Dat to match against</param>
/// <param name="logger">Logger object for console and/or file output</param>
/// <returns>True if it contains the rom, false otherwise</returns>
public bool HasDuplicates(DatFile datdata, Logger logger)
{
// Check for an empty rom list first
if (datdata.Files == null || datdata.Files.Count == 0)
{
return false;
}
// Get the correct dictionary based on what is available
string key = "";
if (_itemType == ItemType.Rom && ((Rom)this).CRC != null)
{
key = ((Rom)this).CRC;
datdata.BucketByCRC(false, logger, false);
}
else if (_itemType == ItemType.Rom && ((Rom)this).MD5 != null)
{
key = ((Rom)this).MD5;
datdata.BucketByMD5(false, logger, false);
}
else if (_itemType == ItemType.Disk && ((Disk)this).MD5 != null)
{
key = ((Disk)this).MD5;
datdata.BucketByMD5(false, logger, false);
}
else if (_itemType == ItemType.Rom && ((Rom)this).SHA1 != null)
{
key = ((Rom)this).SHA1;
datdata.BucketBySHA1(false, logger, false);
}
else if (_itemType == ItemType.Disk && ((Disk)this).SHA1 != null)
{
key = ((Disk)this).SHA1;
datdata.BucketBySHA1(false, logger, false);
}
else if (_itemType == ItemType.Rom)
{
key = ((Rom)this).Size.ToString();
datdata.BucketBySize(false, logger, false);
}
else
{
key = "-1";
datdata.BucketBySize(false, logger, false);
}
// If the key doesn't exist, return the empty list
if (!datdata.Files.ContainsKey(key))
{
return false;
}
// Try to find duplicates
List<DatItem> roms = datdata.Files[key];
foreach (DatItem rom in roms)
{
if (IsDuplicate(rom, logger))
{
return true;
}
}
return false;
}
/// <summary>
/// List all duplicates found in a DAT based on a rom
/// </summary>