mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
[Filter] Strip out individual EXE methods
This commit is contained in:
@@ -24,196 +24,6 @@ namespace SabreTools
|
||||
private bool? _nodump;
|
||||
private Logger _logger;
|
||||
|
||||
/// <summary>
|
||||
/// Start help or use supplied parameters
|
||||
/// </summary>
|
||||
/// <param name="args">String array representing command line parameters</param>
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
// If output is being redirected, don't allow clear screens
|
||||
if (!Console.IsOutputRedirected)
|
||||
{
|
||||
Console.Clear();
|
||||
}
|
||||
|
||||
// Credits take precidence over all
|
||||
if ((new List<string>(args)).Contains("--credits"))
|
||||
{
|
||||
Build.Credits();
|
||||
return;
|
||||
}
|
||||
|
||||
Logger logger = new Logger(true, "filter.log");
|
||||
logger.Start();
|
||||
|
||||
// First things first, take care of all of the arguments that this could have
|
||||
bool? nodump = null;
|
||||
string outdir = "", gamename = "", romname = "", romtype = "", crc = "", md5 = "", sha1= "";
|
||||
long sgt = -1, slt = -1, seq = -1;
|
||||
List<string> inputs = new List<string>();
|
||||
foreach (string arg in args)
|
||||
{
|
||||
switch (arg)
|
||||
{
|
||||
case "-h":
|
||||
case "-?":
|
||||
case "--help":
|
||||
Build.Help();
|
||||
logger.Close();
|
||||
return;
|
||||
case "-nd":
|
||||
case "--nodump":
|
||||
nodump = true;
|
||||
break;
|
||||
case "-nnd":
|
||||
case "--not-nodump":
|
||||
nodump = false;
|
||||
break;
|
||||
default:
|
||||
// Numerical inputs
|
||||
if (arg.StartsWith("-seq=") || arg.StartsWith("--equal="))
|
||||
{
|
||||
if (!Int64.TryParse(arg.Split('=')[1], out seq))
|
||||
{
|
||||
seq = -1;
|
||||
}
|
||||
}
|
||||
else if (arg.StartsWith("-sgt=") || arg.StartsWith("--greater="))
|
||||
{
|
||||
if (!Int64.TryParse(arg.Split('=')[1], out sgt))
|
||||
{
|
||||
sgt = -1;
|
||||
}
|
||||
}
|
||||
else if (arg.StartsWith("-slt=") || arg.StartsWith("--less="))
|
||||
{
|
||||
if (!Int64.TryParse(arg.Split('=')[1], out slt))
|
||||
{
|
||||
slt = -1;
|
||||
}
|
||||
}
|
||||
|
||||
// String inputs
|
||||
else if (arg.StartsWith("-out=") || arg.StartsWith("--out="))
|
||||
{
|
||||
outdir = arg.Split('=')[1];
|
||||
}
|
||||
else if (arg.StartsWith("-crc=") || arg.StartsWith("--crc="))
|
||||
{
|
||||
crc = arg.Split('=')[1];
|
||||
}
|
||||
else if (arg.StartsWith("-gn=") || arg.StartsWith("--game-name="))
|
||||
{
|
||||
gamename = arg.Split('=')[1];
|
||||
}
|
||||
else if (arg.StartsWith("-md5=") || arg.StartsWith("--md5="))
|
||||
{
|
||||
md5 = arg.Split('=')[1];
|
||||
}
|
||||
else if (arg.StartsWith("-rn=") || arg.StartsWith("--rom-name="))
|
||||
{
|
||||
romname = arg.Split('=')[1];
|
||||
}
|
||||
else if (arg.StartsWith("-rt=") || arg.StartsWith("--rom-type="))
|
||||
{
|
||||
romtype = arg.Split('=')[1];
|
||||
}
|
||||
else if (arg.StartsWith("-sha1=") || arg.StartsWith("--sha1="))
|
||||
{
|
||||
sha1 = arg.Split('=')[1];
|
||||
}
|
||||
else
|
||||
{
|
||||
inputs.Add(arg);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// If there's no inputs, show the help
|
||||
if (inputs.Count == 0)
|
||||
{
|
||||
Build.Help();
|
||||
logger.Close();
|
||||
return;
|
||||
}
|
||||
|
||||
// Output the title
|
||||
Build.Start("Filter");
|
||||
|
||||
// If any of the inputs are not valid, show the help
|
||||
foreach (string input in inputs)
|
||||
{
|
||||
if (!File.Exists(input) && !Directory.Exists(input))
|
||||
{
|
||||
logger.Error(input + " is not a valid input!");
|
||||
Console.WriteLine();
|
||||
Build.Help();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Run the filter
|
||||
InitFilter(inputs, outdir, gamename, romname, romtype, sgt, slt, seq, crc, md5, sha1, nodump, logger);
|
||||
|
||||
logger.Close();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Wrap filtering a DAT or set of DATs
|
||||
/// </summary>
|
||||
/// <param name="inputs">List of inputs to be procesed</param>
|
||||
/// <param name="outdir">Output directory for new files (optional)</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="logger">Logging object for file and console output</param>
|
||||
private static void InitFilter(List<string> inputs, string outdir, string gamename, string romname, string romtype, long sgt,
|
||||
long slt, long seq, string crc, string md5, string sha1, bool? nodump, Logger logger)
|
||||
{
|
||||
// Create new Filter objects for each input
|
||||
Filter filter;
|
||||
bool success = true;
|
||||
foreach (string input in inputs)
|
||||
{
|
||||
string newinput = Path.GetFullPath(input.Replace("\"", ""));
|
||||
|
||||
if (File.Exists(newinput))
|
||||
{
|
||||
filter = new Filter(newinput, outdir, gamename, romname, romtype, sgt, slt, seq, crc, md5, sha1, nodump, logger);
|
||||
success &= filter.Process();
|
||||
}
|
||||
|
||||
if (Directory.Exists(newinput))
|
||||
{
|
||||
foreach (string file in Directory.EnumerateFiles(newinput, "*", SearchOption.AllDirectories))
|
||||
{
|
||||
string nestedoutdir = "";
|
||||
if (outdir != "")
|
||||
{
|
||||
nestedoutdir = outdir + Path.GetDirectoryName(file).Remove(0, newinput.Length);
|
||||
}
|
||||
filter = new Filter(file, nestedoutdir, gamename, romname, romtype, sgt, slt, seq, crc, md5, sha1, nodump, logger);
|
||||
success &= filter.Process();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// If we failed, show the help
|
||||
if (!success)
|
||||
{
|
||||
Console.WriteLine();
|
||||
Build.Help();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create a Filter object
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user