From db6e51997733fc7b2ccb00a2df7f83d018f03213 Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Tue, 21 Jun 2016 13:41:18 -0700 Subject: [PATCH] [SimpleSort] Add directory output as string --- SabreTools.Helper/Data/Build.cs | 1 + SimpleSort/SimpleSort.cs | 32 ++++++++++++++++++++------------ 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/SabreTools.Helper/Data/Build.cs b/SabreTools.Helper/Data/Build.cs index 76d9ad0e..89d7e9b3 100644 --- a/SabreTools.Helper/Data/Build.cs +++ b/SabreTools.Helper/Data/Build.cs @@ -225,6 +225,7 @@ Options: -out= Output directory -t=, --temp= Set the temporary directory to use -qs, --quick Enable quick scanning of archives + -do, --directory Output files as uncompressed -7z={0} Set scanning level for 7z archives -gz={2} Set scanning level for GZip archives -rar={2} Set scanning level for RAR archives diff --git a/SimpleSort/SimpleSort.cs b/SimpleSort/SimpleSort.cs index 8d494603..2257b250 100644 --- a/SimpleSort/SimpleSort.cs +++ b/SimpleSort/SimpleSort.cs @@ -14,7 +14,7 @@ namespace SabreTools private string _outdir; private string _tempdir; private bool _quickScan; - private bool _toFolder = false; + private bool _toFolder; private ArchiveScanLevel _7z; private ArchiveScanLevel _gz; private ArchiveScanLevel _rar; @@ -29,19 +29,21 @@ namespace SabreTools /// Output directory to use to build to /// Temporary directory for archive extraction /// True to enable external scanning of archives, false otherwise + /// True if files should be output to folder, false otherwise /// Integer representing the archive handling level for 7z /// Integer representing the archive handling level for GZip /// Integer representing the archive handling level for RAR /// Integer representing the archive handling level for Zip /// Logger object for file and console output public SimpleSort(Dat datdata, List inputs, string outdir, string tempdir, - bool quickScan, int sevenzip, int gz, int rar, int zip, Logger logger) + bool quickScan, bool toFolder, int sevenzip, int gz, int rar, int zip, Logger logger) { _datdata = datdata; _inputs = inputs; _outdir = (outdir == "" ? "Rebuild" : outdir); _tempdir = (tempdir == "" ? "__TEMP__" : tempdir); _quickScan = quickScan; + _toFolder = toFolder; _7z = (ArchiveScanLevel)(sevenzip < 0 || sevenzip > 2 ? 0 : sevenzip); _gz = (ArchiveScanLevel)(gz < 0 || gz > 2 ? 0 : gz); _rar = (ArchiveScanLevel)(rar < 0 || rar > 2 ? 0 : rar); @@ -86,7 +88,8 @@ namespace SabreTools // Set all default values bool help = false, quickScan = false, - simpleSort = true; + simpleSort = true, + toFolder = false; int sevenzip = 0, gz = 2, rar = 2, @@ -106,6 +109,10 @@ namespace SabreTools case "--help": help = true; break; + case "-do": + case "--directory": + toFolder = true; + break; case "-qs": case "--quick": quickScan = true; @@ -200,7 +207,7 @@ namespace SabreTools { if (datfiles.Count > 0) { - InitSimpleSort(datfiles, inputs, outdir, tempdir, quickScan, sevenzip, gz, rar, zip, logger); + InitSimpleSort(datfiles, inputs, outdir, tempdir, quickScan, toFolder, sevenzip, gz, rar, zip, logger); } else { @@ -230,12 +237,13 @@ namespace SabreTools /// 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 /// Integer representing the archive handling level for GZip /// Integer representing the archive handling level for RAR /// Integer representing the archive handling level for Zip /// Logger object for file and console output private static void InitSimpleSort(List datfiles, List inputs, string outdir, string tempdir, - bool quickScan, int sevenzip, int gz, int rar, int zip, Logger logger) + bool quickScan, bool toFolder, int sevenzip, int gz, int rar, int zip, Logger logger) { // Add all of the input DATs into one huge internal DAT Dat datdata = new Dat(); @@ -244,15 +252,15 @@ namespace SabreTools datdata = DatTools.Parse(datfile, 0, 0, datdata, logger); } - SimpleSort ss = new SimpleSort(datdata, inputs, outdir, tempdir, quickScan, sevenzip, gz, rar, zip, logger); - ss.RebuildToFolder(); + SimpleSort ss = new SimpleSort(datdata, inputs, outdir, tempdir, quickScan, toFolder, sevenzip, gz, rar, zip, logger); + ss.RebuildToOutput(); } /// /// Process the DAT and find all matches in input files and folders /// /// True if rebuilding was a success, false otherwise - public bool RebuildToFolder() + public bool RebuildToOutput() { bool success = true; @@ -280,7 +288,7 @@ namespace SabreTools if (File.Exists(input)) { _logger.Log("File found: '" + input + "'"); - success &= RebuildToFolderHelper(input); + success &= RebuildToOutputHelper(input); Output.CleanDirectory(_tempdir); } else if (Directory.Exists(input)) @@ -289,7 +297,7 @@ namespace SabreTools foreach (string file in Directory.EnumerateFiles(input, "*", SearchOption.AllDirectories)) { _logger.Log("File found: '" + file + "'"); - success &= RebuildToFolderHelper(file); + success &= RebuildToOutputHelper(file); Output.CleanDirectory(_tempdir); } } @@ -321,7 +329,7 @@ namespace SabreTools /// The name of the input file /// True if this is in a recurse step and the file should be deleted, false otherwise (default) /// True if it was processed properly, false otherwise - private bool RebuildToFolderHelper(string input, bool recurse = false) + private bool RebuildToOutputHelper(string input, bool recurse = false) { bool success = true; @@ -558,7 +566,7 @@ namespace SabreTools _logger.User("Archive found! Successfully extracted"); foreach (string file in Directory.EnumerateFiles(_tempdir, "*", SearchOption.AllDirectories)) { - success &= RebuildToFolderHelper(file, true); + success &= RebuildToOutputHelper(file, true); } } }