mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
[DatItem, Filter] Abstract out Filter again
This commit is contained in:
@@ -228,321 +228,6 @@ namespace SabreTools.Helper.Dats
|
||||
|
||||
#region Sorting and Merging
|
||||
|
||||
/// <summary>
|
||||
/// Determine if a rom should be included based on filters
|
||||
/// </summary>
|
||||
/// <param name="gamename">Name of the game to match (can use asterisk-partials)</param>
|
||||
/// <param name="romname">Name of the rom to match (can use asterisk-partials)</param>
|
||||
/// <param name="romtype">Type of the rom to match</param>
|
||||
/// <param name="sgt">Find roms greater than or equal to this size</param>
|
||||
/// <param name="slt">Find roms less than or equal to this size</param>
|
||||
/// <param name="seq">Find roms equal to this size</param>
|
||||
/// <param name="crc">CRC of the rom to match (can use asterisk-partials)</param>
|
||||
/// <param name="md5">MD5 of the rom to match (can use asterisk-partials)</param>
|
||||
/// <param name="sha1">SHA-1 of the rom to match (can use asterisk-partials)</param>
|
||||
/// <param name="itemStatus">Select roms with the given status</param>
|
||||
/// <param name="logger">Logging object for console and file output</param>
|
||||
/// <returns>Returns true if it should be included, false otherwise</returns>
|
||||
public bool Filter(string gamename, string romname, string romtype, long sgt,
|
||||
long slt, long seq, string crc, string md5, string sha1, ItemStatus itemStatus, Logger logger)
|
||||
{
|
||||
// Take care of Rom and Disk specific differences
|
||||
if (Type == ItemType.Rom)
|
||||
{
|
||||
Rom rom = (Rom)this;
|
||||
|
||||
// Filter on status
|
||||
if (itemStatus != ItemStatus.NULL)
|
||||
{
|
||||
if (itemStatus == ItemStatus.NotNodump && rom.ItemStatus == ItemStatus.Nodump)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else if (itemStatus != ItemStatus.NotNodump && rom.ItemStatus != itemStatus)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Filter on rom size
|
||||
if (seq != -1 && rom.Size != seq)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (sgt != -1 && rom.Size < sgt)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (slt != -1 && rom.Size > slt)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Filter on crc
|
||||
if (!String.IsNullOrEmpty(crc))
|
||||
{
|
||||
if (crc.StartsWith("*") && crc.EndsWith("*"))
|
||||
{
|
||||
if (!rom.CRC.ToLowerInvariant().Contains(crc.ToLowerInvariant().Replace("*", "")))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (crc.StartsWith("*"))
|
||||
{
|
||||
if (!rom.CRC.EndsWith(crc.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (crc.EndsWith("*"))
|
||||
{
|
||||
if (!rom.CRC.StartsWith(crc.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!String.Equals(rom.CRC, crc, StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Filter on md5
|
||||
if (!String.IsNullOrEmpty(md5))
|
||||
{
|
||||
if (md5.StartsWith("*") && md5.EndsWith("*"))
|
||||
{
|
||||
if (!rom.MD5.ToLowerInvariant().Contains(md5.ToLowerInvariant().Replace("*", "")))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (md5.StartsWith("*"))
|
||||
{
|
||||
if (!rom.MD5.EndsWith(md5.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (md5.EndsWith("*"))
|
||||
{
|
||||
if (!rom.MD5.StartsWith(md5.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!String.Equals(rom.MD5, md5, StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Filter on sha1
|
||||
if (!String.IsNullOrEmpty(sha1))
|
||||
{
|
||||
if (sha1.StartsWith("*") && sha1.EndsWith("*"))
|
||||
{
|
||||
if (!rom.SHA1.ToLowerInvariant().Contains(sha1.ToLowerInvariant().Replace("*", "")))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (sha1.StartsWith("*"))
|
||||
{
|
||||
if (!rom.SHA1.EndsWith(sha1.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (sha1.EndsWith("*"))
|
||||
{
|
||||
if (!rom.SHA1.StartsWith(sha1.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!String.Equals(rom.SHA1, sha1, StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (Type == ItemType.Disk)
|
||||
{
|
||||
Disk rom = (Disk)this;
|
||||
|
||||
// Filter on status
|
||||
if (itemStatus != ItemStatus.NULL && rom.ItemStatus != itemStatus)
|
||||
{
|
||||
if (itemStatus == ItemStatus.NotNodump && rom.ItemStatus == ItemStatus.Nodump)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else if (itemStatus != ItemStatus.NotNodump && rom.ItemStatus != itemStatus)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Filter on md5
|
||||
if (!String.IsNullOrEmpty(md5))
|
||||
{
|
||||
if (md5.StartsWith("*") && md5.EndsWith("*"))
|
||||
{
|
||||
if (!rom.MD5.ToLowerInvariant().Contains(md5.ToLowerInvariant().Replace("*", "")))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (md5.StartsWith("*"))
|
||||
{
|
||||
if (!rom.MD5.EndsWith(md5.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (md5.EndsWith("*"))
|
||||
{
|
||||
if (!rom.MD5.StartsWith(md5.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!String.Equals(rom.MD5, md5, StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Filter on sha1
|
||||
if (!String.IsNullOrEmpty(sha1))
|
||||
{
|
||||
if (sha1.StartsWith("*") && sha1.EndsWith("*"))
|
||||
{
|
||||
if (!rom.SHA1.ToLowerInvariant().Contains(sha1.ToLowerInvariant().Replace("*", "")))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (sha1.StartsWith("*"))
|
||||
{
|
||||
if (!rom.SHA1.EndsWith(sha1.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (sha1.EndsWith("*"))
|
||||
{
|
||||
if (!rom.SHA1.StartsWith(sha1.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!String.Equals(rom.SHA1, sha1, StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Filter on game name
|
||||
if (!String.IsNullOrEmpty(gamename))
|
||||
{
|
||||
if (gamename.StartsWith("*") && gamename.EndsWith("*"))
|
||||
{
|
||||
if (!Machine.Name.ToLowerInvariant().Contains(gamename.ToLowerInvariant().Replace("*", "")))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (gamename.StartsWith("*"))
|
||||
{
|
||||
if (!Machine.Name.EndsWith(gamename.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (gamename.EndsWith("*"))
|
||||
{
|
||||
if (!Machine.Name.StartsWith(gamename.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!String.Equals(Machine.Name, gamename, StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Filter on rom name
|
||||
if (!String.IsNullOrEmpty(romname))
|
||||
{
|
||||
if (romname.StartsWith("*") && romname.EndsWith("*"))
|
||||
{
|
||||
if (!Name.ToLowerInvariant().Contains(romname.ToLowerInvariant().Replace("*", "")))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (romname.StartsWith("*"))
|
||||
{
|
||||
if (!Name.EndsWith(romname.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (romname.EndsWith("*"))
|
||||
{
|
||||
if (!Name.StartsWith(romname.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!String.Equals(Name, romname, StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Filter on rom type
|
||||
if (String.IsNullOrEmpty(romtype) && Type != ItemType.Rom && Type != ItemType.Disk)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (!String.IsNullOrEmpty(romtype) && !String.Equals(Type.ToString(), romtype, StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check if a DAT contains the given rom
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user