mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
[SimpleSort, TGZConvert] Merge TGZConvert functionality into SimpleSort
This commit is contained in:
@@ -59,6 +59,7 @@ A simple rebuild-from-DAT tool that allows users to sort from the commandline.
|
||||
<li>Verify a folder against a DAT (create a fixDat)</li>
|
||||
<li>Rebuild to TGZ archives</li>
|
||||
<li>Rebuild to Romba depot</li>
|
||||
<li>Convert to Romba depot (no DAT required)</li>
|
||||
</ul>
|
||||
|
||||
<h3>Power User Tools</h3>
|
||||
@@ -71,14 +72,6 @@ This section is for tools that have been requested for a highly specific purpose
|
||||
<p/>
|
||||
An in-progress tool that will try to act as a C# port of the Go-based Romba program. All features that are not already a part of SabreTools will be attempted to be added to this program. It is NOT ready for use yet.
|
||||
|
||||
<b>TGZConvert</b>
|
||||
<p/>
|
||||
A simple tool to convert a folder to TGZ, optionally to a specific folder.
|
||||
<ul>
|
||||
<li>Optionally delete source files (if possible)</li>
|
||||
<li>Create a Romba depot from an input folder</li>
|
||||
</ul>
|
||||
|
||||
<h3>Licensing</h3>
|
||||
<p/>
|
||||
The preceeding programs use, in part or in whole, code, libraries, and/or applications from the <a href="www.7-zip.org">7-zip project</a>. 7-zip is licenced under the GNU LGPL.<br/>
|
||||
|
||||
@@ -290,8 +290,10 @@ namespace SabreTools.Helper
|
||||
helptext.Add(" -dat= Input DAT to rebuild against (REQUIRED)");
|
||||
helptext.Add(" -out= Output directory");
|
||||
helptext.Add(" -t=, --temp= Set the temporary directory to use");
|
||||
helptext.Add(" -d, --delete Delete input files");
|
||||
helptext.Add(" -qs, --quick Enable quick scanning of archives");
|
||||
helptext.Add(" -v, --verify Enable verification of output directory");
|
||||
helptext.Add(" -c, --convert Enable conversion of input files to TGZ");
|
||||
helptext.Add(" -tgz, --tgz Enable TorrentGZ output");
|
||||
helptext.Add(" -r, --romba Enable Romba depot dir output");
|
||||
helptext.Add(" -do, --directory Output files as uncompressed");
|
||||
@@ -306,27 +308,6 @@ namespace SabreTools.Helper
|
||||
helptext.Add(" 1 Only hash contents");
|
||||
helptext.Add(" 2 Only hash archive");
|
||||
break;
|
||||
case "TGZConvert":
|
||||
helptext.Add(Resources.Resources.TGZTest_Name + " - " + Resources.Resources.TGZTest_Desc);
|
||||
helptext.Add(barrier);
|
||||
helptext.Add(Resources.Resources.Usage + ": " + Resources.Resources.TGZTest_Name + " [options] [filename|dirname] ...");
|
||||
helptext.Add("");
|
||||
helptext.Add("Options:");
|
||||
helptext.Add(" -?, -h, --help Show this help");
|
||||
helptext.Add(" -out= Output directory");
|
||||
helptext.Add(" -t=, --temp= Set the temporary directory to use");
|
||||
helptext.Add(" -d, --delete Delete input files");
|
||||
helptext.Add(" -r, --romba Enable Romba depot dir output");
|
||||
helptext.Add(" -7z={1} Set scanning level for 7z archives");
|
||||
helptext.Add(" -gz={2} Set scanning level for GZip archives");
|
||||
helptext.Add(" -rar={2} Set scanning level for RAR archives");
|
||||
helptext.Add(" -zip={1} Set scanning level for ZIP archives");
|
||||
helptext.Add("");
|
||||
helptext.Add("Archive scanning levels:");
|
||||
helptext.Add(" 0 Hash archive and contents");
|
||||
helptext.Add(" 1 Only hash contents");
|
||||
helptext.Add(" 2 Only hash archive");
|
||||
break;
|
||||
default:
|
||||
helptext.Add(Resources.Resources.Default_Desc);
|
||||
break;
|
||||
|
||||
@@ -14,6 +14,7 @@ namespace SabreTools.Helper
|
||||
private bool _quickScan;
|
||||
private bool _toFolder;
|
||||
private bool _verify;
|
||||
private bool _delete;
|
||||
private bool _tgz;
|
||||
private bool _romba;
|
||||
private bool _updateDat;
|
||||
@@ -38,6 +39,7 @@ namespace SabreTools.Helper
|
||||
/// <param name="quickScan">True to enable external scanning of archives, false otherwise</param>
|
||||
/// <param name="toFolder">True if files should be output to folder, false otherwise</param>
|
||||
/// <param name="verify">True if output directory should be checked instead of rebuilt to, false otherwise</param>
|
||||
/// <param name="delete">True if input files should be deleted, false otherwise</param>
|
||||
/// <param name="tgz">True if files should be output in TorrentGZ format, false for standard zip</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>
|
||||
@@ -47,7 +49,7 @@ namespace SabreTools.Helper
|
||||
/// <param name="updateDat">True if the updated DAT should be output, false otherwise</param>
|
||||
/// <param name="logger">Logger object for file and console output</param>
|
||||
public SimpleSort(Dat datdata, List<string> inputs, string outdir, string tempdir,
|
||||
bool quickScan, bool toFolder, bool verify, bool tgz, bool romba, int sevenzip,
|
||||
bool quickScan, bool toFolder, bool verify, bool delete, bool tgz, bool romba, int sevenzip,
|
||||
int gz, int rar, int zip, bool updateDat, Logger logger)
|
||||
{
|
||||
_datdata = datdata;
|
||||
@@ -57,6 +59,7 @@ namespace SabreTools.Helper
|
||||
_quickScan = quickScan;
|
||||
_toFolder = toFolder;
|
||||
_verify = verify;
|
||||
_delete = delete;
|
||||
_tgz = tgz;
|
||||
_romba = romba;
|
||||
_7z = (ArchiveScanLevel)(sevenzip < 0 || sevenzip > 2 ? 0 : sevenzip);
|
||||
@@ -711,5 +714,118 @@ namespace SabreTools.Helper
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Process inputs and convert to TGZ, optionally converting to Romba
|
||||
/// </summary>
|
||||
/// <returns>True if processing was a success, false otherwise</returns>
|
||||
public bool Convert()
|
||||
{
|
||||
bool success = true;
|
||||
|
||||
// First, check that the output directory exists
|
||||
if (!Directory.Exists(_outdir))
|
||||
{
|
||||
Directory.CreateDirectory(_outdir);
|
||||
_outdir = Path.GetFullPath(_outdir);
|
||||
}
|
||||
|
||||
// Then create or clean the temp directory
|
||||
if (!Directory.Exists(_tempdir))
|
||||
{
|
||||
Directory.CreateDirectory(_tempdir);
|
||||
}
|
||||
else
|
||||
{
|
||||
FileTools.CleanDirectory(_tempdir);
|
||||
}
|
||||
|
||||
// Now process all of the inputs
|
||||
foreach (string input in _inputs)
|
||||
{
|
||||
_logger.User("Examining file " + input);
|
||||
|
||||
// Get if the file should be scanned internally and externally
|
||||
bool shouldExternalProcess, shouldInternalProcess;
|
||||
FileTools.GetInternalExternalProcess(input, _7z, _gz, _rar, _zip, _logger, out shouldExternalProcess, out shouldInternalProcess);
|
||||
|
||||
// Do an external scan of the file, if necessary
|
||||
if (shouldExternalProcess)
|
||||
{
|
||||
_logger.User("Processing file " + input);
|
||||
success &= FileTools.WriteTorrentGZ(input, _outdir, _romba, _logger);
|
||||
}
|
||||
|
||||
// Process the file as an archive, if necessary
|
||||
if (shouldInternalProcess)
|
||||
{
|
||||
// Now, if the file is a supported archive type, also run on all files within
|
||||
bool encounteredErrors = FileTools.ExtractArchive(input, _tempdir, _7z, _gz, _rar, _zip, _logger);
|
||||
|
||||
// If no errors were encountered, we loop through the temp directory
|
||||
if (!encounteredErrors)
|
||||
{
|
||||
_logger.Log("Archive found! Successfully extracted");
|
||||
foreach (string file in Directory.EnumerateFiles(_tempdir, "*", SearchOption.AllDirectories))
|
||||
{
|
||||
_logger.User("Processing extracted file " + file);
|
||||
success &= FileTools.WriteTorrentGZ(file, _outdir, _romba, _logger);
|
||||
}
|
||||
|
||||
FileTools.CleanDirectory(_tempdir);
|
||||
}
|
||||
}
|
||||
|
||||
// Delete the source file if we're supposed to
|
||||
if (_delete)
|
||||
{
|
||||
try
|
||||
{
|
||||
_logger.User("Attempting to delete " + input);
|
||||
File.Delete(input);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.Error(ex.ToString());
|
||||
success &= false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Now one final delete of the temp directory
|
||||
while (Directory.Exists(_tempdir))
|
||||
{
|
||||
try
|
||||
{
|
||||
Directory.Delete(_tempdir, true);
|
||||
}
|
||||
catch
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// If we're in romba mode and the size file doesn't exist, create it
|
||||
if (_romba && !File.Exists(Path.Combine(_outdir, ".romba_size")))
|
||||
{
|
||||
// Get the size of all of the files in the output folder
|
||||
long size = 0;
|
||||
foreach (string file in Directory.EnumerateFiles(_outdir, "*", SearchOption.AllDirectories))
|
||||
{
|
||||
FileInfo tempinfo = new FileInfo(file);
|
||||
size += tempinfo.Length;
|
||||
}
|
||||
|
||||
// Write out the value to each of the romba depot files
|
||||
using (StreamWriter tw = new StreamWriter(File.Open(Path.Combine(_outdir, ".romba_size"), FileMode.Create, FileAccess.Write)))
|
||||
using (StreamWriter twb = new StreamWriter(File.Open(Path.Combine(_outdir, ".romba_size.backup"), FileMode.Create, FileAccess.Write)))
|
||||
{
|
||||
tw.Write(size);
|
||||
twb.Write(size);
|
||||
}
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,6 @@ Table of Contents
|
||||
2.1 RombaSharp
|
||||
2.2 SabreTools
|
||||
2.3 SimpleSort
|
||||
2.4 TGZConvert
|
||||
3.0 Examples
|
||||
4.0 Contributors
|
||||
5.0 Licensing
|
||||
@@ -725,6 +724,11 @@ Options:
|
||||
(inside the running folder) is not preferred. This is used for any operations that
|
||||
require an archive to be extracted.
|
||||
|
||||
-d, --delete Enable deletion of the input files
|
||||
Optionally, the input files, once processed, can be deleted. This can be useful
|
||||
when the original file structure is no longer needed or if there is limited space
|
||||
on the source drive.
|
||||
|
||||
-qs, --quick Enable quick scanning of archives
|
||||
For all archives, if this flag is enabled, it will only use the header information
|
||||
to get the archive entries' file information. The upside to this is that it is much
|
||||
@@ -737,6 +741,11 @@ Options:
|
||||
simple FixDAT. This can be misleading, currently, because it only checks for exact
|
||||
matches.
|
||||
|
||||
-c, --convert Enable conversion of input files to TGZ
|
||||
This allows conversion of a folder or set of folders to TorrentGZ format without
|
||||
requiring a DAT to rebuild from. It is only useful in a small amount of situations at
|
||||
the present, but it is mostly meant for Romba compatibility at the present.
|
||||
|
||||
-tgz Enable Torrent GZ output
|
||||
Instead of outputting the files to ZIP archives, files will be rebuilt to TorrentGZ
|
||||
(TGZ) files. This format is based on the GZip archive format, but with custom header
|
||||
@@ -770,50 +779,6 @@ Options:
|
||||
Once the files that were able to rebuilt are taken care of, a DAT of the files
|
||||
that could not be matched will be output to the program directory.
|
||||
|
||||
** Section 2.4 - TGZConvert
|
||||
|
||||
TGZConvert is a small program that allows conversion of a folder or set of folders to
|
||||
TorrentGZ format. It is only useful in a small amount of situations at the present,
|
||||
but it is mostly meant for Romba compatibility at the present.
|
||||
|
||||
Usage:
|
||||
TGZTest.exe [options] [filename|dirname] ...
|
||||
|
||||
Options:
|
||||
-?, -h, --help Show the built-in help text
|
||||
Built-in to most of the programs is a basic help text
|
||||
|
||||
-out= Set the name of the output directory
|
||||
This sets an output folder to be used by when files are rebuilt. It also serves
|
||||
as the base folder if Romba mode is enabled. See -r, --romba for more details
|
||||
|
||||
-t=, --temp= Set the name of the temporary directory
|
||||
Optionally, a temp folder can be supplied in the case the default temp directory
|
||||
(inside the running folder) is not preferred. This is used for any operations that
|
||||
require an archive to be extracted.
|
||||
|
||||
-d, --delete Enable deletion of the input files
|
||||
Optionally, the input files, once processed, can be deleted. This can be useful
|
||||
when the original file structure is no longer needed or if there is limited space
|
||||
on the source drive.
|
||||
|
||||
-r, --romba Enable Romba depot directory output
|
||||
Optionally, this outputs the TGZ files into directories based on the structure
|
||||
used by Romba. This uses nested folders using the first 4 bytes of the SHA-1,
|
||||
1 byte for each layer of the directory name. It also includes two auxilary
|
||||
files, .romba_size and .romba_size.backup, that have the compressed size of the
|
||||
folder inside for use with Romba.
|
||||
|
||||
-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
|
||||
For each of the major archive types recognized by the libraries used by this
|
||||
program, scan the archive in one of the following ways:
|
||||
0 Hash both archive and its contents
|
||||
1 Only hash contents of the archive
|
||||
2 Only hash archive itself (treat like a regular file)
|
||||
|
||||
** Section 3.0 - Examples
|
||||
|
||||
Here, any user-requested examples will go
|
||||
|
||||
@@ -9,8 +9,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SabreTools.Helper", "SabreT
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SimpleSort", "SimpleSort\SimpleSort.csproj", "{7668FFA4-19AF-4F5D-8463-C7EF5B080FA4}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TGZConvert", "TGZConvert\TGZConvert.csproj", "{73FBE2C1-39FB-4FFC-93F4-FB4998492429}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RombaSharp", "RombaSharp\RombaSharp.csproj", "{4728D479-8CFB-43E9-8C63-4774C6D73200}"
|
||||
EndProject
|
||||
Global
|
||||
@@ -46,14 +44,6 @@ Global
|
||||
{7668FFA4-19AF-4F5D-8463-C7EF5B080FA4}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{7668FFA4-19AF-4F5D-8463-C7EF5B080FA4}.Release|x64.ActiveCfg = Release|x64
|
||||
{7668FFA4-19AF-4F5D-8463-C7EF5B080FA4}.Release|x64.Build.0 = Release|x64
|
||||
{73FBE2C1-39FB-4FFC-93F4-FB4998492429}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{73FBE2C1-39FB-4FFC-93F4-FB4998492429}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{73FBE2C1-39FB-4FFC-93F4-FB4998492429}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{73FBE2C1-39FB-4FFC-93F4-FB4998492429}.Debug|x64.Build.0 = Debug|x64
|
||||
{73FBE2C1-39FB-4FFC-93F4-FB4998492429}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{73FBE2C1-39FB-4FFC-93F4-FB4998492429}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{73FBE2C1-39FB-4FFC-93F4-FB4998492429}.Release|x64.ActiveCfg = Release|x64
|
||||
{73FBE2C1-39FB-4FFC-93F4-FB4998492429}.Release|x64.Build.0 = Release|x64
|
||||
{4728D479-8CFB-43E9-8C63-4774C6D73200}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{4728D479-8CFB-43E9-8C63-4774C6D73200}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{4728D479-8CFB-43E9-8C63-4774C6D73200}.Debug|x64.ActiveCfg = Debug|x64
|
||||
|
||||
@@ -396,6 +396,7 @@ namespace SabreTools
|
||||
/// <param name="sevenzip">Integer representing the archive handling level for 7z</param>
|
||||
/// <param name="toFolder">True if files should be output to folder, false otherwise</param>
|
||||
/// <param name="verify">True if output directory should be checked instead of rebuilt to, false otherwise</param>
|
||||
/// <param name="delete">True if input files should be deleted, false otherwise</param>
|
||||
/// <param name="tgz">True if files should be output in TorrentGZ format, false for standard zip</param>
|
||||
/// <param name="romba">True if files should be output in Romba depot folders, false otherwise</param>
|
||||
/// <param name="gz">Integer representing the archive handling level for GZip</param>
|
||||
@@ -404,7 +405,7 @@ namespace SabreTools
|
||||
/// <param name="updateDat">True if the updated DAT should be output, false otherwise</param>
|
||||
/// <param name="logger">Logger object for file and console output</param>
|
||||
private static void InitSimpleSort(List<string> datfiles, List<string> 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)
|
||||
bool toFolder, bool verify, bool delete, 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();
|
||||
@@ -413,7 +414,8 @@ namespace SabreTools
|
||||
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);
|
||||
SimpleSort ss = new SimpleSort(datdata, inputs, outdir, tempdir, quickScan, toFolder, verify,
|
||||
delete, tgz, romba, sevenzip, gz, rar, zip, updateDat, logger);
|
||||
ss.StartProcessing();
|
||||
}
|
||||
|
||||
|
||||
@@ -43,6 +43,8 @@ namespace SabreTools
|
||||
|
||||
// Set all default values
|
||||
bool help = false,
|
||||
convert = false,
|
||||
delete = false,
|
||||
quickScan = false,
|
||||
romba = false,
|
||||
simpleSort = true,
|
||||
@@ -69,6 +71,14 @@ namespace SabreTools
|
||||
case "--help":
|
||||
help = true;
|
||||
break;
|
||||
case "-c":
|
||||
case "--convert":
|
||||
convert = true;
|
||||
break;
|
||||
case "-d":
|
||||
case "--delete":
|
||||
delete = true;
|
||||
break;
|
||||
case "-do":
|
||||
case "--directory":
|
||||
toFolder = true;
|
||||
@@ -172,7 +182,7 @@ namespace SabreTools
|
||||
}
|
||||
|
||||
// If a switch that requires a filename is set and no file is, show the help screen
|
||||
if (inputs.Count == 0 && (simpleSort && !verify))
|
||||
if (inputs.Count == 0 && ((simpleSort && !verify) || convert))
|
||||
{
|
||||
logger.Error("This feature requires at least one input");
|
||||
Build.Help();
|
||||
@@ -180,12 +190,19 @@ namespace SabreTools
|
||||
return;
|
||||
}
|
||||
|
||||
// If we are converting the folder to TGZ
|
||||
if (convert)
|
||||
{
|
||||
InitTGZConvert(inputs, outdir, tempdir, delete, romba, sevenzip, gz, rar, zip, logger);
|
||||
}
|
||||
|
||||
// If we are doing a simple sort
|
||||
if (simpleSort)
|
||||
else if (simpleSort)
|
||||
{
|
||||
if (datfiles.Count > 0)
|
||||
{
|
||||
InitSimpleSort(datfiles, inputs, outdir, tempdir, quickScan, toFolder, verify, tgz, romba, sevenzip, gz, rar, zip, updateDat, logger);
|
||||
InitSimpleSort(datfiles, inputs, outdir, tempdir, quickScan, toFolder,
|
||||
verify, delete, tgz, romba, sevenzip, gz, rar, zip, updateDat, logger);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -217,6 +234,7 @@ namespace SabreTools
|
||||
/// <param name="sevenzip">Integer representing the archive handling level for 7z</param>
|
||||
/// <param name="toFolder">True if files should be output to folder, false otherwise</param>
|
||||
/// <param name="verify">True if output directory should be checked instead of rebuilt to, false otherwise</param>
|
||||
/// <param name="delete">True if input files should be deleted, false otherwise</param>
|
||||
/// <param name="tgz">True if files should be output in TorrentGZ format, false for standard zip</param>
|
||||
/// <param name="romba">True if files should be output in Romba depot folders, false otherwise</param>
|
||||
/// <param name="gz">Integer representing the archive handling level for GZip</param>
|
||||
@@ -225,7 +243,7 @@ namespace SabreTools
|
||||
/// <param name="updateDat">True if the updated DAT should be output, false otherwise</param>
|
||||
/// <param name="logger">Logger object for file and console output</param>
|
||||
private static void InitSimpleSort(List<string> datfiles, List<string> 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)
|
||||
bool toFolder, bool verify, bool delete, 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();
|
||||
@@ -234,8 +252,46 @@ namespace SabreTools
|
||||
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);
|
||||
SimpleSort ss = new SimpleSort(datdata, inputs, outdir, tempdir, quickScan, toFolder, verify,
|
||||
delete, tgz, romba, sevenzip, gz, rar, zip, updateDat, logger);
|
||||
ss.StartProcessing();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Wrap sorting files using an input DAT
|
||||
/// </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 InitTGZConvert(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>();
|
||||
foreach (string input in inputs)
|
||||
{
|
||||
if (File.Exists(input))
|
||||
{
|
||||
newinputs.Add(Path.GetFullPath(input));
|
||||
}
|
||||
else if (Directory.Exists(input))
|
||||
{
|
||||
foreach (string file in Directory.EnumerateFiles(input, "*", SearchOption.AllDirectories))
|
||||
{
|
||||
newinputs.Add(Path.GetFullPath(file));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SimpleSort ss = new SimpleSort(new Dat(), newinputs, outdir, tempdir, false, false, false, delete, true, romba, sevenzip, gz, rar, zip, false, logger);
|
||||
return ss.Convert();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<configuration>
|
||||
<startup>
|
||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
|
||||
</startup>
|
||||
</configuration>
|
||||
@@ -1,36 +0,0 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("TGZTest")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("TGZTest")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2016")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("73fbe2c1-39fb-4ffc-93f4-fb4998492429")]
|
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||
@@ -1,352 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using SabreTools.Helper;
|
||||
namespace SabreTools
|
||||
{
|
||||
public class TGZConvert
|
||||
{
|
||||
// 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;
|
||||
|
||||
/// <summary>
|
||||
/// Create a new TGZTest object
|
||||
/// </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 TGZConvert(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);
|
||||
_tempdir = (String.IsNullOrEmpty(tempdir) ? "__temp__" : tempdir);
|
||||
_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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Main entry point for the program
|
||||
/// </summary>
|
||||
/// <param name="args">List of arguments to be parsed</param>
|
||||
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, "tgztest.log");
|
||||
logger.Start();
|
||||
|
||||
// Credits take precidence over all
|
||||
if ((new List<string>(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("TGZTest");
|
||||
|
||||
// Set all default values
|
||||
bool help = false,
|
||||
delete = false,
|
||||
romba = false,
|
||||
tgz = true;
|
||||
int sevenzip = 1,
|
||||
gz = 2,
|
||||
rar = 2,
|
||||
zip = 1;
|
||||
string outdir = "",
|
||||
tempdir = "";
|
||||
List<string> inputs = new List<string>();
|
||||
|
||||
// Determine which switches are enabled (with values if necessary)
|
||||
foreach (string arg in args)
|
||||
{
|
||||
string temparg = arg.Replace("\"", "").Replace("file://", "");
|
||||
|
||||
switch (temparg)
|
||||
{
|
||||
case "-?":
|
||||
case "-h":
|
||||
case "--help":
|
||||
help = true;
|
||||
break;
|
||||
case "-d":
|
||||
case "--delete":
|
||||
delete = true;
|
||||
break;
|
||||
case "-r":
|
||||
case "--romba":
|
||||
romba = true;
|
||||
break;
|
||||
default:
|
||||
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);
|
||||
}
|
||||
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 && tgz)
|
||||
{
|
||||
logger.Error("This feature requires at least one input");
|
||||
Build.Help();
|
||||
logger.Close();
|
||||
return;
|
||||
}
|
||||
|
||||
// If we are doing a simple sort
|
||||
if (tgz)
|
||||
{
|
||||
InitTGZTest(inputs, outdir, tempdir, delete, romba, sevenzip, gz, rar, zip, logger);
|
||||
}
|
||||
|
||||
// If nothing is set, show the help
|
||||
else
|
||||
{
|
||||
Build.Help();
|
||||
}
|
||||
|
||||
logger.Close();
|
||||
return;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Wrap sorting files using an input DAT
|
||||
/// </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, 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>();
|
||||
foreach (string input in inputs)
|
||||
{
|
||||
if (File.Exists(input))
|
||||
{
|
||||
newinputs.Add(Path.GetFullPath(input));
|
||||
}
|
||||
else if (Directory.Exists(input))
|
||||
{
|
||||
foreach (string file in Directory.EnumerateFiles(input, "*", SearchOption.AllDirectories))
|
||||
{
|
||||
newinputs.Add(Path.GetFullPath(file));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TGZConvert tgztest = new TGZConvert(newinputs, outdir, tempdir, delete, romba, sevenzip, gz, rar, zip, logger);
|
||||
return tgztest.Process();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Process all input files
|
||||
/// </summary>
|
||||
/// <returns>True if processing was a success, false otherwise</returns>
|
||||
public bool Process()
|
||||
{
|
||||
bool success = true;
|
||||
|
||||
// First, check that the output directory exists
|
||||
if (!Directory.Exists(_outdir))
|
||||
{
|
||||
Directory.CreateDirectory(_outdir);
|
||||
_outdir = Path.GetFullPath(_outdir);
|
||||
}
|
||||
|
||||
// Then create or clean the temp directory
|
||||
if (!Directory.Exists(_tempdir))
|
||||
{
|
||||
Directory.CreateDirectory(_tempdir);
|
||||
}
|
||||
else
|
||||
{
|
||||
FileTools.CleanDirectory(_tempdir);
|
||||
}
|
||||
|
||||
// Now process all of the inputs
|
||||
foreach (string input in _inputs)
|
||||
{
|
||||
_logger.User("Examining file " + input);
|
||||
|
||||
// Get if the file should be scanned internally and externally
|
||||
bool shouldExternalProcess, shouldInternalProcess;
|
||||
FileTools.GetInternalExternalProcess(input, _7z, _gz, _rar, _zip, _logger, out shouldExternalProcess, out shouldInternalProcess);
|
||||
|
||||
// Do an external scan of the file, if necessary
|
||||
if (shouldExternalProcess)
|
||||
{
|
||||
_logger.User("Processing file " + input);
|
||||
success &= FileTools.WriteTorrentGZ(input, _outdir, _romba, _logger);
|
||||
}
|
||||
|
||||
// Process the file as an archive, if necessary
|
||||
if (shouldInternalProcess)
|
||||
{
|
||||
// Now, if the file is a supported archive type, also run on all files within
|
||||
bool encounteredErrors = FileTools.ExtractArchive(input, _tempdir, _7z, _gz, _rar, _zip, _logger);
|
||||
|
||||
// If no errors were encountered, we loop through the temp directory
|
||||
if (!encounteredErrors)
|
||||
{
|
||||
_logger.Log("Archive found! Successfully extracted");
|
||||
foreach (string file in Directory.EnumerateFiles(_tempdir, "*", SearchOption.AllDirectories))
|
||||
{
|
||||
_logger.User("Processing extracted file " + file);
|
||||
success &= FileTools.WriteTorrentGZ(file, _outdir, _romba, _logger);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Delete the source file if we're supposed to
|
||||
if (_delete)
|
||||
{
|
||||
try
|
||||
{
|
||||
_logger.User("Attempting to delete " + input);
|
||||
File.Delete(input);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.Error(ex.ToString());
|
||||
success &= false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Now one final delete of the temp directory
|
||||
while (Directory.Exists(_tempdir))
|
||||
{
|
||||
try
|
||||
{
|
||||
Directory.Delete(_tempdir, true);
|
||||
}
|
||||
catch
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// If we're in romba mode and the size file doesn't exist, create it
|
||||
if (_romba && !File.Exists(Path.Combine(_outdir, ".romba_size")))
|
||||
{
|
||||
// Get the size of all of the files in the output folder
|
||||
long size = 0;
|
||||
foreach (string file in Directory.EnumerateFiles(_outdir, "*", SearchOption.AllDirectories))
|
||||
{
|
||||
FileInfo tempinfo = new FileInfo(file);
|
||||
size += tempinfo.Length;
|
||||
}
|
||||
|
||||
// Write out the value to each of the romba depot files
|
||||
using (StreamWriter tw = new StreamWriter(File.Open(Path.Combine(_outdir, ".romba_size"), FileMode.Create, FileAccess.Write)))
|
||||
using (StreamWriter twb = new StreamWriter(File.Open(Path.Combine(_outdir, ".romba_size.backup"), FileMode.Create, FileAccess.Write)))
|
||||
{
|
||||
tw.Write(size);
|
||||
twb.Write(size);
|
||||
}
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,91 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{73FBE2C1-39FB-4FFC-93F4-FB4998492429}</ProjectGuid>
|
||||
<OutputType>Exe</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>TGZConvert</RootNamespace>
|
||||
<AssemblyName>TGZConvert</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>..\..\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>..\..\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<OutputPath>..\..\Debug-x64\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<DebugType>full</DebugType>
|
||||
<PlatformTarget>x64</PlatformTarget>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
|
||||
<Prefer32Bit>true</Prefer32Bit>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
|
||||
<OutputPath>..\..\Release-x64\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<Optimize>true</Optimize>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<PlatformTarget>x64</PlatformTarget>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
|
||||
<Prefer32Bit>true</Prefer32Bit>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="SharpCompress, Version=0.12.4.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\SharpCompress.0.12.4\lib\net45\SharpCompress.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Net.Http" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="TGZConvert.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="App.config" />
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\SabreTools.Helper\SabreTools.Helper.csproj">
|
||||
<Project>{225a1afd-0890-44e8-b779-7502665c23a5}</Project>
|
||||
<Name>SabreTools.Helper</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
||||
@@ -1,4 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="SharpCompress" version="0.12.4" targetFramework="net452" />
|
||||
</packages>
|
||||
Reference in New Issue
Block a user