[DatTools] Remove old Filter

This commit is contained in:
Matt Nadareski
2016-09-06 12:47:39 -07:00
parent 60e05089d5
commit c5d7345193

View File

@@ -1867,198 +1867,6 @@ namespace SabreTools.Helper
return datHeaders; return datHeaders;
} }
/// <summary>
/// Filter an input DAT file
/// </summary>
/// <param name="datdata">User specified inputs contained in a DatData object</param>
/// <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="nodump">Select roms with nodump status as follows: null (match all), true (match Nodump only), false (exclude Nodump)</param>
/// <param name="trim">True if we are supposed to trim names to NTFS length, false otherwise</param>
/// <param name="single">True if all games should be replaced by '!', false otherwise</param>
/// <param name="root">String representing root directory to compare against for length calculation</param>
/// <param name="logger">Logging object for console and file output</param>
/// <returns>Returns filtered DatData object</returns>
public static Dat Filter(Dat datdata, string gamename, string romname, string romtype, long sgt,
long slt, long seq, string crc, string md5, string sha1, bool? nodump, bool trim, bool single, string root, Logger logger)
{
// Now loop through and create a new Rom dictionary using filtered values
Dictionary<string, List<Rom>> dict = new Dictionary<string, List<Rom>>();
List<string> keys = datdata.Files.Keys.ToList();
foreach (string key in keys)
{
List<Rom> roms = datdata.Files[key];
for (int i = 0; i < roms.Count; i++)
{
Rom rom = roms[i];
// Filter on nodump status
if (nodump == true && !rom.Nodump)
{
continue;
}
if (nodump == false && rom.Nodump)
{
continue;
}
// Filter on game name
if (gamename != "")
{
if (gamename.StartsWith("*") && gamename.EndsWith("*") && !rom.Machine.Name.ToLowerInvariant().Contains(gamename.ToLowerInvariant().Replace("*", "")))
{
continue;
}
else if (gamename.StartsWith("*") && !rom.Machine.Name.EndsWith(gamename.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase))
{
continue;
}
else if (gamename.EndsWith("*") && !rom.Machine.Name.StartsWith(gamename.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase))
{
continue;
}
}
// Filter on rom name
if (romname != "")
{
if (romname.StartsWith("*") && romname.EndsWith("*") && !rom.Name.ToLowerInvariant().Contains(romname.ToLowerInvariant().Replace("*", "")))
{
continue;
}
else if (romname.StartsWith("*") && !rom.Name.EndsWith(romname.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase))
{
continue;
}
else if (romname.EndsWith("*") && !rom.Name.StartsWith(romname.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase))
{
continue;
}
}
// Filter on rom type
if (romtype != "" && rom.Type.ToString().ToLowerInvariant() != romtype.ToLowerInvariant())
{
continue;
}
// Filter on rom size
if (seq != -1 && rom.HashData.Size != seq)
{
continue;
}
else
{
if (sgt != -1 && rom.HashData.Size < sgt)
{
continue;
}
if (slt != -1 && rom.HashData.Size > slt)
{
continue;
}
}
// Filter on crc
if (crc != "")
{
if (crc.StartsWith("*") && crc.EndsWith("*") && !rom.HashData.CRC.ToLowerInvariant().Contains(crc.ToLowerInvariant().Replace("*", "")))
{
continue;
}
else if (crc.StartsWith("*") && !rom.HashData.CRC.EndsWith(crc.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase))
{
continue;
}
else if (crc.EndsWith("*") && !rom.HashData.CRC.StartsWith(crc.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase))
{
continue;
}
}
// Filter on md5
if (md5 != "")
{
if (md5.StartsWith("*") && md5.EndsWith("*") && !rom.HashData.MD5.ToLowerInvariant().Contains(md5.ToLowerInvariant().Replace("*", "")))
{
continue;
}
else if (md5.StartsWith("*") && !rom.HashData.MD5.EndsWith(md5.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase))
{
continue;
}
else if (md5.EndsWith("*") && !rom.HashData.MD5.StartsWith(md5.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase))
{
continue;
}
}
// Filter on sha1
if (sha1 != "")
{
if (sha1.StartsWith("*") && sha1.EndsWith("*") && !rom.HashData.SHA1.ToLowerInvariant().Contains(sha1.ToLowerInvariant().Replace("*", "")))
{
continue;
}
else if (sha1.StartsWith("*") && !rom.HashData.SHA1.EndsWith(sha1.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase))
{
continue;
}
else if (sha1.EndsWith("*") && !rom.HashData.SHA1.StartsWith(sha1.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase))
{
continue;
}
}
// If we are in single game mode, rename all games
if (single)
{
rom.Machine.Name = "!";
}
// If we are in NTFS trim mode, trim the game name
if (trim)
{
// Windows max name length is 260
int usableLength = 260 - rom.Machine.Name.Length - root.Length;
if (rom.Name.Length > usableLength)
{
string ext = Path.GetExtension(rom.Name);
rom.Name = rom.Name.Substring(0, usableLength - ext.Length);
rom.Name += ext;
}
}
// If it made it this far, add the rom to the output dictionary
if (dict.ContainsKey(key))
{
dict[key].Add(rom);
}
else
{
List<Rom> temp = new List<Rom>();
temp.Add(rom);
dict.Add(key, temp);
}
}
// Now clean up by removing the old list
datdata.Files[key] = null;
}
// Resassign the new dictionary to the DatData object
datdata.Files = dict;
return datdata;
}
/// <summary> /// <summary>
/// Determine if a rom should be included based on filters /// Determine if a rom should be included based on filters
/// </summary> /// </summary>