diff --git a/SimpleSort/SimpleSort.cs b/SabreTools.Helper/Objects/SimpleSort.cs similarity index 77% rename from SimpleSort/SimpleSort.cs rename to SabreTools.Helper/Objects/SimpleSort.cs index 9b424d6f..3bf7011f 100644 --- a/SimpleSort/SimpleSort.cs +++ b/SabreTools.Helper/Objects/SimpleSort.cs @@ -1,9 +1,8 @@ -using SabreTools.Helper; -using System; +using System; using System.Collections.Generic; using System.IO; -namespace SabreTools +namespace SabreTools.Helper { public class SimpleSort { @@ -75,237 +74,6 @@ namespace SabreTools }; } - /// - /// Main entry point for the program - /// - /// List of arguments to be parsed - public static void Main(string[] args) - { - // If output is being redirected, don't allow clear screens - if (!Console.IsOutputRedirected) - { - Console.Clear(); - } - - // Perform initial setup and verification - Logger logger = new Logger(true, "simplesort.log"); - logger.Start(); - - // Credits take precidence over all - if ((new List(args)).Contains("--credits")) - { - Build.Credits(); - return; - } - - // If there's no arguments, show help - if (args.Length == 0) - { - Build.Help(); - logger.Close(); - return; - } - - // Output the title - Build.Start("SimpleSort"); - - // Set all default values - bool help = false, - quickScan = false, - romba = false, - simpleSort = true, - tgz = false, - toFolder = false, - updateDat = false, - verify = false; - int sevenzip = 0, - gz = 2, - rar = 2, - zip = 0; - string outdir = "", - tempdir = ""; - List inputs = new List(); - List datfiles = new List(); - - // Determine which switches are enabled (with values if necessary) - foreach (string arg in args) - { - switch (arg) - { - case "-?": - case "-h": - case "--help": - help = true; - break; - case "-do": - case "--directory": - toFolder = true; - break; - case "-qs": - case "--quick": - quickScan = true; - break; - case "-r": - case "--romba": - romba = true; - break; - case "-tgz": - case "--tgz": - tgz = true; - break; - case "-ud": - case "--updated-dat": - updateDat = true; - break; - case "-v": - case "--verify": - verify = true; - break; - default: - string temparg = arg.Replace("\"", "").Replace("file://", ""); - - if (temparg.StartsWith("-7z=") || temparg.StartsWith("--7z=")) - { - if (!Int32.TryParse(temparg.Split('=')[1], out sevenzip)) - { - sevenzip = 0; - } - } - else if (temparg.StartsWith("-dat=") || temparg.StartsWith("--dat=")) - { - string datfile = temparg.Split('=')[1]; - if (!File.Exists(datfile)) - { - logger.Error("DAT must be a valid file: " + datfile); - Console.WriteLine(); - Build.Help(); - logger.Close(); - return; - } - datfiles.Add(datfile); - } - else if (temparg.StartsWith("-gz=") || temparg.StartsWith("--gz=")) - { - if (!Int32.TryParse(temparg.Split('=')[1], out gz)) - { - gz = 2; - } - } - else if (temparg.StartsWith("-out=") || temparg.StartsWith("--out=")) - { - outdir = temparg.Split('=')[1]; - } - else if (temparg.StartsWith("-rar=") || temparg.StartsWith("--rar=")) - { - if (!Int32.TryParse(temparg.Split('=')[1], out rar)) - { - rar = 2; - } - } - else if (temparg.StartsWith("-t=") || temparg.StartsWith("--temp=")) - { - tempdir = temparg.Split('=')[1]; - } - else if (temparg.StartsWith("-zip=") || temparg.StartsWith("--zip=")) - { - if (!Int32.TryParse(temparg.Split('=')[1], out zip)) - { - zip = 0; - } - } - else if (File.Exists(temparg) || Directory.Exists(temparg)) - { - inputs.Add(temparg); - } - else - { - logger.Error("Invalid input detected: " + arg); - Console.WriteLine(); - Build.Help(); - Console.WriteLine(); - logger.Error("Invalid input detected: " + arg); - logger.Close(); - return; - } - break; - } - } - - // If help is set, show the help screen - if (help) - { - Build.Help(); - logger.Close(); - return; - } - - // If a switch that requires a filename is set and no file is, show the help screen - if (inputs.Count == 0 && (simpleSort && !verify)) - { - logger.Error("This feature requires at least one input"); - Build.Help(); - logger.Close(); - return; - } - - // If we are doing a simple sort - if (simpleSort) - { - if (datfiles.Count > 0) - { - InitSimpleSort(datfiles, inputs, outdir, tempdir, quickScan, toFolder, verify, tgz, romba, sevenzip, gz, rar, zip, updateDat, logger); - } - else - { - logger.Error("A datfile is required to use this feature"); - Build.Help(); - logger.Close(); - return; - } - } - - // If nothing is set, show the help - else - { - Build.Help(); - } - - logger.Close(); - return; - } - - /// - /// Wrap sorting files using an input DAT - /// - /// Names of the DATs to compare against - /// List of input files/folders to check - /// Output directory to use to build to - /// Temporary directory for archive extraction - /// True to enable external scanning of archives, false otherwise - /// Integer representing the archive handling level for 7z - /// True if files should be output to folder, false otherwise - /// True if output directory should be checked instead of rebuilt to, false otherwise - /// True if files should be output in TorrentGZ format, false for standard zip - /// True if files should be output in Romba depot folders, false otherwise - /// Integer representing the archive handling level for GZip - /// Integer representing the archive handling level for RAR - /// Integer representing the archive handling level for Zip - /// True if the updated DAT should be output, false otherwise - /// Logger object for file and console output - private static void InitSimpleSort(List datfiles, List inputs, string outdir, string tempdir, bool quickScan, - bool toFolder, bool verify, bool tgz, bool romba, int sevenzip, int gz, int rar, int zip, bool updateDat, Logger logger) - { - // Add all of the input DATs into one huge internal DAT - Dat datdata = new Dat(); - foreach (string datfile in datfiles) - { - datdata = DatTools.Parse(datfile, 99, 99, datdata, logger); - } - - SimpleSort ss = new SimpleSort(datdata, inputs, outdir, tempdir, quickScan, toFolder, verify, tgz, romba, sevenzip, gz, rar, zip, updateDat, logger); - ss.StartProcessing(); - } - /// /// Pick the appropriate action based on the inputs /// @@ -525,7 +293,7 @@ namespace SabreTools // Add rom to the matched list string key = found.HashData.Size + "-" + found.HashData.CRC; - if(_matched.Files.ContainsKey(key)) + if (_matched.Files.ContainsKey(key)) { _matched.Files[key].Add(found); } @@ -944,4 +712,4 @@ namespace SabreTools return success; } } -} \ No newline at end of file +} diff --git a/SabreTools.Helper/SabreTools.Helper.csproj b/SabreTools.Helper/SabreTools.Helper.csproj index 9d0eea7a..4d51feeb 100644 --- a/SabreTools.Helper/SabreTools.Helper.csproj +++ b/SabreTools.Helper/SabreTools.Helper.csproj @@ -94,6 +94,7 @@ + True True diff --git a/SimpleSort/SimpleSort.csproj b/SimpleSort/SimpleSort.csproj index ba55fdda..f1a960ab 100644 --- a/SimpleSort/SimpleSort.csproj +++ b/SimpleSort/SimpleSort.csproj @@ -67,7 +67,7 @@ - +