diff --git a/README.MD b/README.MD
index fcbd9207..a5190352 100644
--- a/README.MD
+++ b/README.MD
@@ -59,6 +59,7 @@ A simple rebuild-from-DAT tool that allows users to sort from the commandline.
Verify a folder against a DAT (create a fixDat)
Rebuild to TGZ archives
Rebuild to Romba depot
+ Convert to Romba depot (no DAT required)
Power User Tools
@@ -71,14 +72,6 @@ This section is for tools that have been requested for a highly specific purpose
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.
-TGZConvert
-
-A simple tool to convert a folder to TGZ, optionally to a specific folder.
-
- - Optionally delete source files (if possible)
- - Create a Romba depot from an input folder
-
-
Licensing
The preceeding programs use, in part or in whole, code, libraries, and/or applications from the 7-zip project. 7-zip is licenced under the GNU LGPL.
diff --git a/SabreTools.Helper/Data/Build.cs b/SabreTools.Helper/Data/Build.cs
index 485b04f5..3e1220c1 100644
--- a/SabreTools.Helper/Data/Build.cs
+++ b/SabreTools.Helper/Data/Build.cs
@@ -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;
diff --git a/SabreTools.Helper/Objects/SimpleSort.cs b/SabreTools.Helper/Objects/SimpleSort.cs
index 3bf7011f..3f6b9f43 100644
--- a/SabreTools.Helper/Objects/SimpleSort.cs
+++ b/SabreTools.Helper/Objects/SimpleSort.cs
@@ -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
/// True to enable external scanning of archives, false otherwise
/// 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 input files should be deleted, 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 7z
@@ -47,7 +49,7 @@ namespace SabreTools.Helper
/// True if the updated DAT should be output, false otherwise
/// Logger object for file and console output
public SimpleSort(Dat datdata, List 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;
}
+
+ ///
+ /// Process inputs and convert to TGZ, optionally converting to Romba
+ ///
+ /// True if processing was a success, false otherwise
+ 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;
+ }
}
}
diff --git a/SabreTools.Helper/README.1ST b/SabreTools.Helper/README.1ST
index adaa6898..8ac2d6b6 100644
--- a/SabreTools.Helper/README.1ST
+++ b/SabreTools.Helper/README.1ST
@@ -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
diff --git a/SabreTools.sln b/SabreTools.sln
index 1b7a8c26..82cd20b1 100644
--- a/SabreTools.sln
+++ b/SabreTools.sln
@@ -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
diff --git a/SabreTools/Partials/SabreTools_Inits.cs b/SabreTools/Partials/SabreTools_Inits.cs
index 26723c66..647d82af 100644
--- a/SabreTools/Partials/SabreTools_Inits.cs
+++ b/SabreTools/Partials/SabreTools_Inits.cs
@@ -396,6 +396,7 @@ namespace SabreTools
/// 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 input files should be deleted, 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
@@ -404,7 +405,7 @@ namespace SabreTools
/// 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)
+ 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();
}
diff --git a/SimpleSort/SimpleSortApp.cs b/SimpleSort/SimpleSortApp.cs
index a4d79973..80def902 100644
--- a/SimpleSort/SimpleSortApp.cs
+++ b/SimpleSort/SimpleSortApp.cs
@@ -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
/// 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 input files should be deleted, 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
@@ -225,7 +243,7 @@ namespace SabreTools
/// 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)
+ 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();
}
+
+ ///
+ /// Wrap sorting files using an input DAT
+ ///
+ /// List of all inputted files and folders
+ /// Output directory (empty for default directory)
+ /// Temporary directory for archive extraction
+ /// True if input files should be deleted, false otherwise
+ /// True if files should be output in Romba depot folders, 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 static bool InitTGZConvert(List 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 newinputs = new List();
+ 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();
+ }
}
}
\ No newline at end of file
diff --git a/TGZConvert/App.config b/TGZConvert/App.config
deleted file mode 100644
index 88fa4027..00000000
--- a/TGZConvert/App.config
+++ /dev/null
@@ -1,6 +0,0 @@
-
-
-
-
-
-
\ No newline at end of file
diff --git a/TGZConvert/Properties/AssemblyInfo.cs b/TGZConvert/Properties/AssemblyInfo.cs
deleted file mode 100644
index 9eac89ab..00000000
--- a/TGZConvert/Properties/AssemblyInfo.cs
+++ /dev/null
@@ -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")]
diff --git a/TGZConvert/TGZConvert.cs b/TGZConvert/TGZConvert.cs
deleted file mode 100644
index 758dd745..00000000
--- a/TGZConvert/TGZConvert.cs
+++ /dev/null
@@ -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 _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;
-
- ///
- /// Create a new TGZTest object
- ///
- /// List of all inputted files and folders
- /// Output directory (empty for default directory)
- /// Temporary directory for archive extraction
- /// True if input files should be deleted, false otherwise
- /// True if files should be output in Romba depot folders, 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 TGZConvert(List 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;
- }
-
- ///
- /// 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, "tgztest.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("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 inputs = new List();
-
- // 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;
- }
-
- ///
- /// Wrap sorting files using an input DAT
- ///
- /// List of all inputted files and folders
- /// Output directory (empty for default directory)
- /// Temporary directory for archive extraction
- /// True if input files should be deleted, false otherwise
- /// True if files should be output in Romba depot folders, 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 static bool InitTGZTest(List 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 newinputs = new List();
- 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();
- }
-
- ///
- /// Process all input files
- ///
- /// True if processing was a success, false otherwise
- 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;
- }
- }
-}
diff --git a/TGZConvert/TGZConvert.csproj b/TGZConvert/TGZConvert.csproj
deleted file mode 100644
index bf3e4d32..00000000
--- a/TGZConvert/TGZConvert.csproj
+++ /dev/null
@@ -1,91 +0,0 @@
-
-
-
-
- Debug
- AnyCPU
- {73FBE2C1-39FB-4FFC-93F4-FB4998492429}
- Exe
- Properties
- TGZConvert
- TGZConvert
- v4.5.2
- 512
- true
-
-
- AnyCPU
- true
- full
- false
- ..\..\Debug\
- DEBUG;TRACE
- prompt
- 4
-
-
- AnyCPU
- pdbonly
- true
- ..\..\Release\
- TRACE
- prompt
- 4
-
-
- true
- ..\..\Debug-x64\
- DEBUG;TRACE
- full
- x64
- prompt
- MinimumRecommendedRules.ruleset
- true
-
-
- ..\..\Release-x64\
- TRACE
- true
- pdbonly
- x64
- prompt
- MinimumRecommendedRules.ruleset
- true
-
-
-
- ..\packages\SharpCompress.0.12.4\lib\net45\SharpCompress.dll
- True
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- {225a1afd-0890-44e8-b779-7502665c23a5}
- SabreTools.Helper
-
-
-
-
-
\ No newline at end of file
diff --git a/TGZConvert/packages.config b/TGZConvert/packages.config
deleted file mode 100644
index 6d513b53..00000000
--- a/TGZConvert/packages.config
+++ /dev/null
@@ -1,4 +0,0 @@
-
-
-
-
\ No newline at end of file