[TGZTest, Build] Add archive and temp folder options

This commit is contained in:
Matt Nadareski
2016-08-25 10:59:24 -07:00
parent 1d6548538a
commit fc4a676f52
2 changed files with 76 additions and 7 deletions

View File

@@ -256,8 +256,13 @@ Usage: TGZTest [options] [filename|dirname] ...
Options:
-?, -h, --help Show this help
-out= Output directory
-t=, --temp= Set the temporary directory to use
-d, --delete Delete input files
-r, --romba Enable Romba depot dir output");
-r, --romba Enable Romba depot dir output
-7z={0} Set scanning level for 7z archives
-gz={2} Set scanning level for GZip archives
-rar={2} Set scanning level for RAR archives
-zip={0} Set scanning level for ZIP archives");
break;
default:
Console.Write("This is the default help output");

View File

@@ -10,8 +10,13 @@ namespace SabreTools
// User-defined variables
private List<string> _inputs;
private string _outdir;
private string _tempdir;
private bool _delete;
private bool _romba;
private ArchiveScanLevel _7z;
private ArchiveScanLevel _gz;
private ArchiveScanLevel _rar;
private ArchiveScanLevel _zip;
private Logger _logger;
// We still need access permissions for each of the archive files as well, kind of like DATFromDir
@@ -21,15 +26,25 @@ namespace SabreTools
/// </summary>
/// <param name="inputs">List of all inputted files and folders</param>
/// <param name="outdir">Output directory (empty for default directory)</param>
/// <param name="tempdir">Temporary directory for archive extraction</param>
/// <param name="delete">True if input files should be deleted, false otherwise</param>
/// <param name="romba">True if files should be output in Romba depot folders, false otherwise</param>
/// <param name="sevenzip">Integer representing the archive handling level for 7z</param>
/// <param name="gz">Integer representing the archive handling level for GZip</param>
/// <param name="rar">Integer representing the archive handling level for RAR</param>
/// <param name="zip">Integer representing the archive handling level for Zip</param>
/// <param name="logger">Logger object for file and console output</param>
public TGZTest(List<string> inputs, string outdir, bool delete, bool romba, Logger logger)
public TGZTest(List<string> inputs, string outdir, string tempdir, bool delete,
bool romba, int sevenzip, int gz, int rar, int zip, Logger logger)
{
_inputs = inputs;
_outdir = (String.IsNullOrEmpty(outdir) ? "tgz" : outdir);
_delete = delete;
_romba = romba;
_7z = (ArchiveScanLevel)(sevenzip < 0 || sevenzip > 2 ? 0 : sevenzip);
_gz = (ArchiveScanLevel)(gz < 0 || gz > 2 ? 0 : gz);
_rar = (ArchiveScanLevel)(rar < 0 || rar > 2 ? 0 : rar);
_zip = (ArchiveScanLevel)(zip < 0 || zip > 2 ? 0 : zip);
_logger = logger;
}
@@ -72,7 +87,12 @@ namespace SabreTools
delete = false,
romba = false,
tgz = true;
string outdir = "";
int sevenzip = 0,
gz = 2,
rar = 2,
zip = 0;
string outdir = "",
tempdir = "";
List<string> inputs = new List<string>();
// Determine which switches are enabled (with values if necessary)
@@ -96,10 +116,42 @@ namespace SabreTools
romba = true;
break;
default:
if (temparg.StartsWith("-out=") || temparg.StartsWith("--out="))
if (temparg.StartsWith("-7z=") || temparg.StartsWith("--7z="))
{
if (!Int32.TryParse(temparg.Split('=')[1], out sevenzip))
{
sevenzip = 0;
}
}
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);
@@ -136,7 +188,7 @@ namespace SabreTools
// If we are doing a simple sort
if (tgz)
{
InitTGZTest(inputs, outdir, delete, romba, logger);
InitTGZTest(inputs, outdir, tempdir, delete, romba, sevenzip, gz, rar, zip, logger);
}
// If nothing is set, show the help
@@ -154,10 +206,16 @@ namespace SabreTools
/// </summary>
/// <param name="inputs">List of all inputted files and folders</param>
/// <param name="outdir">Output directory (empty for default directory)</param>
/// <param name="tempdir">Temporary directory for archive extraction</param>
/// <param name="delete">True if input files should be deleted, false otherwise</param>
/// <param name="romba">True if files should be output in Romba depot folders, false otherwise</param>
/// <param name="sevenzip">Integer representing the archive handling level for 7z</param>
/// <param name="gz">Integer representing the archive handling level for GZip</param>
/// <param name="rar">Integer representing the archive handling level for RAR</param>
/// <param name="zip">Integer representing the archive handling level for Zip</param>
/// <param name="logger">Logger object for file and console output</param>
public static bool InitTGZTest(List<string> inputs, string outdir, bool delete, bool romba, Logger logger)
public static bool InitTGZTest(List<string> inputs, string outdir, string tempdir, bool delete,
bool romba, int sevenzip, int gz, int rar, int zip, Logger logger)
{
// Get all individual files from the inputs
List<string> newinputs = new List<string>();
@@ -176,7 +234,7 @@ namespace SabreTools
}
}
TGZTest tgztest = new TGZTest(newinputs, outdir, delete, romba, logger);
TGZTest tgztest = new TGZTest(newinputs, outdir, tempdir, delete, romba, sevenzip, gz, rar, zip, logger);
return tgztest.Process();
}
@@ -189,7 +247,13 @@ namespace SabreTools
foreach (string input in _inputs)
{
_logger.User("Processing file " + input);
// Do an external scan of the file, if necessary
ArchiveTools.WriteTorrentGZ(input, _outdir, _romba, _logger);
// Process the file as an archive, if necessary
// Delete the soruce file if we're supposed to
if (_delete)
{
try