mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
[SabreTools, Filter] Add inverse filters
This commit is contained in:
@@ -9,15 +9,22 @@ namespace SabreTools.Helper.Dats
|
||||
#region Private instance variables
|
||||
|
||||
private string _gameName;
|
||||
private string _notGameName;
|
||||
private string _romName;
|
||||
private string _notRomName;
|
||||
private string _romType;
|
||||
private string _notRomType;
|
||||
private long _sizeGreaterThanOrEqual;
|
||||
private long _sizeLessThanOrEqual;
|
||||
private long _sizeEqualTo;
|
||||
private string _crc;
|
||||
private string _notCrc;
|
||||
private string _md5;
|
||||
private string _notMd5;
|
||||
private string _sha1;
|
||||
private string _notSha1;
|
||||
private ItemStatus _itemStatus;
|
||||
private ItemStatus _itemNotStatus;
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -27,15 +34,22 @@ namespace SabreTools.Helper.Dats
|
||||
public Filter()
|
||||
{
|
||||
_gameName = null;
|
||||
_notGameName = null;
|
||||
_romName = null;
|
||||
_notRomName = null;
|
||||
_romType = null;
|
||||
_notRomType = null;
|
||||
_sizeGreaterThanOrEqual = -1;
|
||||
_sizeLessThanOrEqual = -1;
|
||||
_sizeEqualTo = -1;
|
||||
_crc = null;
|
||||
_notCrc = null;
|
||||
_md5 = null;
|
||||
_notMd5 = null;
|
||||
_sha1 = null;
|
||||
_notSha1 = null;
|
||||
_itemStatus = ItemStatus.NULL;
|
||||
_itemNotStatus = ItemStatus.NULL;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -51,19 +65,35 @@ namespace SabreTools.Helper.Dats
|
||||
/// <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="notgamename">Name of the game to match (can use asterisk-partials)</param>
|
||||
/// <param name="notromname">Name of the rom to match (can use asterisk-partials)</param>
|
||||
/// <param name="notromtype">Type of the rom to match</param>
|
||||
/// <param name="notcrc">CRC of the rom to match (can use asterisk-partials)</param>
|
||||
/// <param name="notmd5">MD5 of the rom to match (can use asterisk-partials)</param>
|
||||
/// <param name="notsha1">SHA-1 of the rom to match (can use asterisk-partials)</param>
|
||||
/// <param name="itemNotStatus">Select roms with the given status</param>
|
||||
public Filter(string gamename, string romname, string romtype, long sgt,
|
||||
long slt, long seq, string crc, string md5, string sha1, ItemStatus itemStatus)
|
||||
long slt, long seq, string crc, string md5, string sha1, ItemStatus itemStatus,
|
||||
string notgamename, string notromname, string notromtype, string notcrc, string notmd5,
|
||||
string notsha1, ItemStatus itemNotStatus)
|
||||
{
|
||||
_gameName = gamename;
|
||||
_notGameName = notgamename;
|
||||
_romName = romname;
|
||||
_notRomName = notromname;
|
||||
_romType = romtype;
|
||||
_notRomType = notromtype;
|
||||
_sizeGreaterThanOrEqual = sgt;
|
||||
_sizeLessThanOrEqual = slt;
|
||||
_sizeEqualTo = seq;
|
||||
_crc = crc;
|
||||
_notCrc = notcrc;
|
||||
_md5 = md5;
|
||||
_notMd5 = notmd5;
|
||||
_sha1 = sha1;
|
||||
_notSha1 = notsha1;
|
||||
_itemStatus = itemStatus;
|
||||
_itemNotStatus = itemNotStatus;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -80,16 +110,13 @@ namespace SabreTools.Helper.Dats
|
||||
Rom rom = (Rom)item;
|
||||
|
||||
// Filter on status
|
||||
if (_itemStatus != ItemStatus.NULL)
|
||||
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;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
if (_itemNotStatus != ItemStatus.NULL && rom.ItemStatus == _itemNotStatus)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Filter on rom size
|
||||
@@ -109,7 +136,7 @@ namespace SabreTools.Helper.Dats
|
||||
}
|
||||
}
|
||||
|
||||
// Filter on _crc
|
||||
// Filter on CRC
|
||||
if (!String.IsNullOrEmpty(_crc))
|
||||
{
|
||||
if (_crc.StartsWith("*") && _crc.EndsWith("*"))
|
||||
@@ -141,8 +168,39 @@ namespace SabreTools.Helper.Dats
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!String.IsNullOrEmpty(_notCrc))
|
||||
{
|
||||
if (_notCrc.StartsWith("*") && _notCrc.EndsWith("*"))
|
||||
{
|
||||
if (rom.CRC.ToLowerInvariant().Contains(_notCrc.ToLowerInvariant().Replace("*", "")))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (_notCrc.StartsWith("*"))
|
||||
{
|
||||
if (rom.CRC.EndsWith(_notCrc.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (_notCrc.EndsWith("*"))
|
||||
{
|
||||
if (rom.CRC.StartsWith(_notCrc.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (String.Equals(rom.CRC, _notCrc, StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Filter on _md5
|
||||
// Filter on MD5
|
||||
if (!String.IsNullOrEmpty(_md5))
|
||||
{
|
||||
if (_md5.StartsWith("*") && _md5.EndsWith("*"))
|
||||
@@ -174,8 +232,39 @@ namespace SabreTools.Helper.Dats
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!String.IsNullOrEmpty(_notMd5))
|
||||
{
|
||||
if (_notMd5.StartsWith("*") && _notMd5.EndsWith("*"))
|
||||
{
|
||||
if (rom.MD5.ToLowerInvariant().Contains(_notMd5.ToLowerInvariant().Replace("*", "")))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (_notMd5.StartsWith("*"))
|
||||
{
|
||||
if (rom.MD5.EndsWith(_notMd5.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (_notMd5.EndsWith("*"))
|
||||
{
|
||||
if (rom.MD5.StartsWith(_notMd5.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (String.Equals(rom.MD5, _notMd5, StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Filter on _sha1
|
||||
// Filter on SHA1
|
||||
if (!String.IsNullOrEmpty(_sha1))
|
||||
{
|
||||
if (_sha1.StartsWith("*") && _sha1.EndsWith("*"))
|
||||
@@ -207,6 +296,37 @@ namespace SabreTools.Helper.Dats
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!String.IsNullOrEmpty(_notSha1))
|
||||
{
|
||||
if (_notSha1.StartsWith("*") && _notSha1.EndsWith("*"))
|
||||
{
|
||||
if (rom.SHA1.ToLowerInvariant().Contains(_notSha1.ToLowerInvariant().Replace("*", "")))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (_notSha1.StartsWith("*"))
|
||||
{
|
||||
if (rom.SHA1.EndsWith(_notSha1.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (_notSha1.EndsWith("*"))
|
||||
{
|
||||
if (rom.SHA1.StartsWith(_notSha1.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (String.Equals(rom.SHA1, _notSha1, StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (item.Type == ItemType.Disk)
|
||||
{
|
||||
@@ -215,17 +335,14 @@ namespace SabreTools.Helper.Dats
|
||||
// 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;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
if (_itemNotStatus != ItemStatus.NULL && rom.ItemStatus == _itemNotStatus)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Filter on _md5
|
||||
// Filter on MD5
|
||||
if (!String.IsNullOrEmpty(_md5))
|
||||
{
|
||||
if (_md5.StartsWith("*") && _md5.EndsWith("*"))
|
||||
@@ -257,8 +374,39 @@ namespace SabreTools.Helper.Dats
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!String.IsNullOrEmpty(_notMd5))
|
||||
{
|
||||
if (_notMd5.StartsWith("*") && _notMd5.EndsWith("*"))
|
||||
{
|
||||
if (rom.MD5.ToLowerInvariant().Contains(_notMd5.ToLowerInvariant().Replace("*", "")))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (_notMd5.StartsWith("*"))
|
||||
{
|
||||
if (rom.MD5.EndsWith(_notMd5.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (_notMd5.EndsWith("*"))
|
||||
{
|
||||
if (rom.MD5.StartsWith(_notMd5.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (String.Equals(rom.MD5, _notMd5, StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Filter on _sha1
|
||||
// Filter on SHA1
|
||||
if (!String.IsNullOrEmpty(_sha1))
|
||||
{
|
||||
if (_sha1.StartsWith("*") && _sha1.EndsWith("*"))
|
||||
@@ -290,6 +438,37 @@ namespace SabreTools.Helper.Dats
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!String.IsNullOrEmpty(_notSha1))
|
||||
{
|
||||
if (_notSha1.StartsWith("*") && _notSha1.EndsWith("*"))
|
||||
{
|
||||
if (rom.SHA1.ToLowerInvariant().Contains(_notSha1.ToLowerInvariant().Replace("*", "")))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (_notSha1.StartsWith("*"))
|
||||
{
|
||||
if (rom.SHA1.EndsWith(_notSha1.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (_notSha1.EndsWith("*"))
|
||||
{
|
||||
if (rom.SHA1.StartsWith(_notSha1.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (String.Equals(rom.SHA1, _notSha1, StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Filter on game name
|
||||
@@ -324,6 +503,37 @@ namespace SabreTools.Helper.Dats
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!String.IsNullOrEmpty(_notGameName))
|
||||
{
|
||||
if (_notGameName.StartsWith("*") && _notGameName.EndsWith("*"))
|
||||
{
|
||||
if (item.Machine.Name.ToLowerInvariant().Contains(_notGameName.ToLowerInvariant().Replace("*", "")))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (_notGameName.StartsWith("*"))
|
||||
{
|
||||
if (item.Machine.Name.EndsWith(_notGameName.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (_notGameName.EndsWith("*"))
|
||||
{
|
||||
if (item.Machine.Name.StartsWith(_notGameName.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (String.Equals(item.Machine.Name, _notGameName, StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Filter on rom name
|
||||
if (!String.IsNullOrEmpty(_romName))
|
||||
@@ -357,9 +567,40 @@ namespace SabreTools.Helper.Dats
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!String.IsNullOrEmpty(_notRomName))
|
||||
{
|
||||
if (_notRomName.StartsWith("*") && _notRomName.EndsWith("*"))
|
||||
{
|
||||
if (item.Name.ToLowerInvariant().Contains(_notRomName.ToLowerInvariant().Replace("*", "")))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (_notRomName.StartsWith("*"))
|
||||
{
|
||||
if (item.Name.EndsWith(_notRomName.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (_notRomName.EndsWith("*"))
|
||||
{
|
||||
if (item.Name.StartsWith(_notRomName.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (String.Equals(item.Name, _notRomName, StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Filter on rom type
|
||||
if (String.IsNullOrEmpty(_romType) && item.Type != ItemType.Rom && item.Type != ItemType.Disk)
|
||||
if (String.IsNullOrEmpty(_romType) && String.IsNullOrEmpty(_notRomType) && item.Type != ItemType.Rom && item.Type != ItemType.Disk)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -367,6 +608,10 @@ namespace SabreTools.Helper.Dats
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (!String.IsNullOrEmpty(_notRomType) && String.Equals(item.Type.ToString(), _notRomType, StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user