[ALL] Allow expanded output format set, convert methods over to new system, add skeletons for remaining output formats, remove simplesort standalone

This commit is contained in:
Matt Nadareski
2016-10-25 16:04:45 -07:00
parent 39eb40bb36
commit 87744405f0
9 changed files with 485 additions and 178 deletions

View File

@@ -148,13 +148,19 @@ namespace SabreTools.Helper.Data
helptext.Add(" -?, -h, --help Show this help");
// Convert
helptext.Add(" -cv, --convert Enable conversion of input files to TZip");
helptext.Add(" -cv, --convert Enable conversion of input files to folder");
helptext.Add(" -dat= DAT to be used as a filter for conversion");
helptext.Add(" -out= Output directory");
helptext.Add(" -t=, --temp= Set the temporary directory to use");
helptext.Add(" -del, --delete Delete input files [DO NOT USE]");
//helptext.Add(" -t7z Enable Torrent7z output");
//helptext.Add(" -tar Enable TAR output");
helptext.Add(" -tgz Enable TorrentGZ output");
helptext.Add(" -r, --romba Enable Romba depot dir output");
//helptext.Add(" -tlrz Enable TorrentLRZ output");
//helptext.Add(" -trar Enable TorrentRAR output");
//helptext.Add(" -txz Enable TorrentXZ output");
helptext.Add(" -tzip Enable TorrentZip output");
helptext.Add(" -7z={0} 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");
@@ -221,9 +227,14 @@ namespace SabreTools.Helper.Data
helptext.Add(" -del, --delete Delete input files [DO NOT USE]");
helptext.Add(" -qs, --quick Enable quick scanning of archives");
helptext.Add(" -ad, --add-date Add original dates from DAT, if possible");
//helptext.Add(" -t7z Enable Torrent7z output");
//helptext.Add(" -tar Enable TAR output");
helptext.Add(" -tgz Enable TorrentGZ output");
helptext.Add(" -r, --romba Enable Romba depot dir output");
helptext.Add(" -do, --directory Output files as uncompressed");
//helptext.Add(" -tlrz Enable TorrentLRZ output");
//helptext.Add(" -trar Enable TorrentRAR output");
//helptext.Add(" -txz Enable TorrentXZ output");
helptext.Add(" -tzip Enable TorrentZip output");
helptext.Add(" -h=, --header= Set a header skipper to use, blank means all");
helptext.Add(" -7z={0} Set scanning level for 7z archives");
helptext.Add(" -gz={2} Set scanning level for GZip archives");

View File

@@ -4279,17 +4279,27 @@ namespace SabreTools.Helper.Dats
/// <param name="inputs">List of inputs to convert over to TorrentZip or TorrentGZ</param>
/// <param name="outDir">Output folder to rebuild to, blank is the current directory</param>
/// <param name="tempDir">Temporary directory to use in file extraction</param>
/// <param name="tgz">True if files should be output in TorrentGZ format, false for TorrentZip</param>
/// <param name="outputFormat">Output format that files should be written to</param>
/// <param name="romba">True if TorrentGZ files should be output in romba depot format, false otherwise</param>
/// <param name="delete">True if input files should be deleted, false otherwise</param>
/// <param name="archiveScanLevel">ArchiveScanLevel representing how files should be treated</param>
/// <param name="logger">Logger object for file and console output</param>
/// <returns>True if processing was a success, false otherwise</returns>
public bool ConvertFiles(List<string> inputs, string outDir, string tempDir, bool tgz,
public bool ConvertFiles(List<string> inputs, string outDir, string tempDir, OutputFormat outputFormat,
bool romba, bool delete, ArchiveScanLevel archiveScanLevel, Logger logger)
{
bool success = true;
// Check to see that there's an output directory and a temp directory defined
if (String.IsNullOrEmpty(outDir))
{
outDir = "output";
}
if (String.IsNullOrEmpty(tempDir))
{
tempDir = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
}
// First, check that the output directory exists
if (!Directory.Exists(outDir))
{
@@ -4332,13 +4342,17 @@ namespace SabreTools.Helper.Dats
logger.User("Processing file " + input);
if (tgz)
switch (outputFormat)
{
case OutputFormat.TorrentGzip:
success &= ArchiveTools.WriteTorrentGZ(input, outDir, romba, logger);
}
else
{
success &= ArchiveTools.WriteToArchive(input, outDir, rom, logger);
break;
case OutputFormat.TorrentZip:
success &= ArchiveTools.WriteTorrentZip(input, outDir, rom, logger);
break;
case OutputFormat.Folder:
default:
break;
}
}
@@ -4365,15 +4379,19 @@ namespace SabreTools.Helper.Dats
}
}
logger.User("Processing file " + input);
logger.User("Processing file " + file);
if (tgz)
switch (outputFormat)
{
case OutputFormat.TorrentGzip:
success &= ArchiveTools.WriteTorrentGZ(file, outDir, romba, logger);
}
else
{
success &= ArchiveTools.WriteToArchive(file, outDir, rom, logger);
break;
case OutputFormat.TorrentZip:
success &= ArchiveTools.WriteTorrentZip(file, outDir, rom, logger);
break;
case OutputFormat.Folder:
default:
break;
}
}
@@ -4443,9 +4461,8 @@ namespace SabreTools.Helper.Dats
/// <param name="tempDir">Temporary directory for archive extraction</param>
/// <param name="quickScan">True to enable external scanning of archives, false otherwise</param>
/// <param name="date">True if the date from the DAT should be used if available, false otherwise</param>
/// <param name="toFolder">True if files should be output to folder, false otherwise</param>
/// <param name="delete">True if input files should be deleted, false otherwise</param>
/// <param name="tgz">True if output files should be written to TorrentGZ instead of TorrentZip</param>
/// <param name="outputFormat">Output format that files should be written to</param>
/// <param name="romba">True if files should be output in Romba depot folders, false otherwise</param>
/// <param name="archiveScanLevel">ArchiveScanLevel representing the archive handling levels</param>
/// <param name="updateDat">True if the updated DAT should be output, false otherwise</param>
@@ -4453,7 +4470,7 @@ namespace SabreTools.Helper.Dats
/// <param name="logger">Logger object for file and console output</param>
/// <returns>True if rebuilding was a success, false otherwise</returns>
public bool RebuildToOutput(List<string> inputs, string outDir, string tempDir, bool quickScan, bool date,
bool toFolder, bool delete, bool tgz, bool romba, ArchiveScanLevel archiveScanLevel, bool updateDat, string headerToCheckAgainst,
bool delete, OutputFormat outputFormat, bool romba, ArchiveScanLevel archiveScanLevel, bool updateDat, string headerToCheckAgainst,
int maxDegreeOfParallelism, Logger logger)
{
#region Perform setup
@@ -4760,7 +4777,33 @@ namespace SabreTools.Helper.Dats
#region Rebuild games in order
logger.User("Rebuilding all files to " + (toFolder ? "directory" : (tgz ? "TorrentGZ" : "TorrentZip")));
switch (outputFormat)
{
case OutputFormat.Folder:
logger.User("Rebuilding all files to directory");
break;
case OutputFormat.TapeArchive:
logger.User("Rebuilding all files to TAR");
break;
case OutputFormat.Torrent7Zip:
logger.User("Rebuilding all files to Torrent7Z");
break;
case OutputFormat.TorrentGzip:
logger.User("Rebuilding all files to TorrentGZ");
break;
case OutputFormat.TorrentLrzip:
logger.User("Rebuilding all files to TorrentLRZ");
break;
case OutputFormat.TorrentRar:
logger.User("Rebuilding all files to TorrentRAR");
break;
case OutputFormat.TorrentXZ:
logger.User("Rebuilding all files to TorrentXZ");
break;
case OutputFormat.TorrentZip:
logger.User("Rebuilding all files to TorrentZip");
break;
}
start = DateTime.Now;
// Now loop through the keys and create the correct output items
@@ -4818,8 +4861,9 @@ namespace SabreTools.Helper.Dats
}
// And now rebuild accordingly
if (toFolder)
switch (outputFormat)
{
case OutputFormat.Folder:
for (int i = 0; i < romsInGame.Count; i++)
{
string infile = pathsToFiles[i];
@@ -4836,19 +4880,28 @@ namespace SabreTools.Helper.Dats
}
catch { }
}
}
else if (tgz)
{
break;
case OutputFormat.TapeArchive:
break;
case OutputFormat.Torrent7Zip:
break;
case OutputFormat.TorrentGzip:
for (int i = 0; i < itemsInGame.Count; i++)
{
string infile = pathsToFiles[i];
Rom outrom = romsInGame[i];
ArchiveTools.WriteTorrentGZ(infile, outDir, romba, logger);
}
}
else
{
ArchiveTools.WriteToArchive(pathsToFiles, outDir, romsInGame, logger);
break;
case OutputFormat.TorrentLrzip:
break;
case OutputFormat.TorrentRar:
break;
case OutputFormat.TorrentXZ:
break;
case OutputFormat.TorrentZip:
ArchiveTools.WriteTorrentZip(pathsToFiles, outDir, romsInGame, logger);
break;
}
// And now clear the temp folder to get rid of any transient files

View File

@@ -140,10 +140,8 @@ Options:
-?, -h, --help Show the built-in help text
Built-in to most of the programs is a basic help text
-cv, --convert Enable conversion of input files to TorrentZip
Using a folder or set of folders, convert the input archives to TorrentZip, rebuilding
to another folder. This is useful for rebuilding non-TorrentZipped sets without having
to run them through a larger tool or helping to rebuild a romba depot
-cv, --convert Enable conversion of input files to unarchived folders
Using a folder or set of folders, rebuild to another folder.
-dat= Name of the DAT to be used as a filter
A supplied DAT file to be used as a filter in conversion. If a file is found in the
@@ -164,9 +162,20 @@ Options:
rebuilt. It is not recommended for normal use because it does not discriminate
whether or not the input files were rebuilt or not before deletion
-t7z Enable Torrent 7zip output [NOT IMPLEMENTED]
Instead of ouputting the files to folder, files will be rebuilt to Torrent7Zip (T7Z)
files. This format is based on the LZMA container format 7zip, but with custom header
information. This is currently unused by any major application.
-tar Enable Tape ARchive output [NOT IMPLEMENTED]
Instead of outputting the fiels to folder, files will be rebuilt to Tape ARchive (TAR)
files. This format is a standardized storage archive without any compression, usually
used with other compression formats around it. It is widely used in backup applications
and source code archives.
-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
Instead of outputting the files to folder, files will be rebuilt to TorrentGZ (TGZ)
files. This format is based on the GZip archive format, but with custom header
information and a file name replaced by the SHA-1 of the file inside. This is
primarily used by external tool Romba (https://github.com/uwedeportivo/romba), but
may be used more widely in the future.
@@ -178,6 +187,28 @@ Options:
includes two auxilary files, .romba_size and .romba_size.backup, that have the
compressed size of the folder inside for use with Romba.
-tlrz Enable Torrent Long-Range Zip output [NOT IMPLEMENTED]
Instead of ouputting the files to folder, files will be rebuilt to Torrent Long-Range
Zip (TLRZ) files. This format is based on the LRZip file format as defined at
https://github.com/ckolivas/lrzip but with custom header information. This is currently
unused by any major application.
-trar Enable Torrent RAR output [NOT IMPLEMENTED]
Instead of outputting files to folder, files will be rebuilt to Torrent RAR (TRAR)
files. This format is based on the RAR propietary format but with custom header
information. This is currently unused by any major application;
-txz Enable Torrent XZ output [NOT IMPLEMENTED]
Instead of outputting files to folder, files will be rebuilt to Torrent XZ (TXZ) files.
This format is based on the LZMA container format XZ, but with custom header
information. This is currently unused by any major application;
-tzip Enable Torrent Zip output
Instead of ouputting files to folder, files will be rebuilt to TorrentZip (TZ) files.
This format is based on the ZIP archive format, but with custom header information.
This is primarily used by external tool RomVault (http://www.romvault.com/) and is
already widely used.
-7z={0} Set scanning level for 7z archives
-gz={2} Set scanning level for GZip archives
-rar={2} Set scanning level for RAR archives
@@ -389,9 +420,7 @@ Options:
-ss, --sort Sort input files by a set of DATs
This feature allows the user to quickly rebuild based on a supplied DAT file(s). By
default all files will be rebuilt to TorrentZip (TZ) files. This format is based on
the ZIP archive format, but with custom header information. This is primarily used by
external tool RomVault (http://www.romvault.com/) and is already widely used.
default all files will be rebuilt to uncompressed folders in the output directory.
-dat= Name of the DAT to be used for the various options
The user-supplied DAT used to check which files need to be rebuilt. Multiple
@@ -423,9 +452,20 @@ Options:
invalidate the output files as proper TorrentZip files because the date will not
match the standard.
-t7z Enable Torrent 7zip output [NOT IMPLEMENTED]
Instead of ouputting the files to folder, files will be rebuilt to Torrent7Zip (T7Z)
files. This format is based on the LZMA container format 7zip, but with custom header
information. This is currently unused by any major application.
-tar Enable Tape ARchive output [NOT IMPLEMENTED]
Instead of outputting the fiels to folder, files will be rebuilt to Tape ARchive (TAR)
files. This format is a standardized storage archive without any compression, usually
used with other compression formats around it. It is widely used in backup applications
and source code archives.
-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
Instead of outputting the files to folder, files will be rebuilt to TorrentGZ (TGZ)
files. This format is based on the GZip archive format, but with custom header
information and a file name replaced by the SHA-1 of the file inside. This is
primarily used by external tool Romba (https://github.com/uwedeportivo/romba), but
may be used more widely in the future.
@@ -437,10 +477,27 @@ Options:
includes two auxilary files, .romba_size and .romba_size.backup, that have the
compressed size of the folder inside for use with Romba.
-do, --directory Enable outputting files uncompressed
Instead of outputting the files to ZIP archives, files will be rebuilt to named
subdirectories within the output folder. This is useful for when the DAT does not
already have the flag specified.
-tlrz Enable Torrent Long-Range Zip output [NOT IMPLEMENTED]
Instead of ouputting the files to folder, files will be rebuilt to Torrent Long-Range
Zip (TLRZ) files. This format is based on the LRZip file format as defined at
https://github.com/ckolivas/lrzip but with custom header information. This is currently
unused by any major application.
-trar Enable Torrent RAR output [NOT IMPLEMENTED]
Instead of outputting files to folder, files will be rebuilt to Torrent RAR (TRAR)
files. This format is based on the RAR propietary format but with custom header
information. This is currently unused by any major application;
-txz Enable Torrent XZ output [NOT IMPLEMENTED]
Instead of outputting files to folder, files will be rebuilt to Torrent XZ (TXZ) files.
This format is based on the LZMA container format XZ, but with custom header
information. This is currently unused by any major application;
-tzip Enable Torrent Zip output
Instead of ouputting files to folder, files will be rebuilt to TorrentZip (TZ) files.
This format is based on the ZIP archive format, but with custom header information.
This is primarily used by external tool RomVault (http://www.romvault.com/) and is
already widely used.
-h=, --header= Remove headers from hash calculations
If this is set, then all files that have copier headers that are detected will
@@ -468,6 +525,7 @@ Options:
-ud, --update-dat Output updated DAT (rebuild only)
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.
that could not be matched will be output to the program directory.
-st, --stats Get statistics on all input DATs
This will output by default the combined statistics for all input DAT files. The stats

View File

@@ -53,6 +53,7 @@
<RunPostBuildEvent>OnBuildSuccess</RunPostBuildEvent>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
<Reference Include="Mono.Data.Sqlite, Version=2.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756, processorArchitecture=MSIL">
<HintPath>..\packages\Mono.Data.Sqlite.Portable.1.0.3.5\lib\net4\Mono.Data.Sqlite.dll</HintPath>
<Private>True</Private>

View File

@@ -35,7 +35,7 @@ namespace SabreTools.Helper.Tools
{
string temp = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
string realName = ExtractItem(inputArchive, sourceEntryName, temp, logger);
bool success = WriteToArchive(realName, outDir, destEntry, logger);
bool success = WriteTorrentZip(realName, outDir, destEntry, logger);
Directory.Delete(temp, true);
return success;
}
@@ -738,7 +738,7 @@ namespace SabreTools.Helper.Tools
#region Writing
/// <summary>
/// Copy a file to an output torrentzip archive
/// Write an input file to a tape archive
/// </summary>
/// <param name="inputFile">Input filename to be moved</param>
/// <param name="outDir">Output directory to build to</param>
@@ -746,7 +746,7 @@ namespace SabreTools.Helper.Tools
/// <param name="logger">Logger object for file and console output</param>
/// <param name="date">True if the date from the DAT should be used if available, false otherwise (default)</param>
/// <returns>True if the archive was written properly, false otherwise</returns>
public static bool WriteToArchive(string inputFile, string outDir, Rom rom, Logger logger, bool date = false)
public static bool WriteTAR(string inputFile, string outDir, Rom rom, Logger logger, bool date = false)
{
// Wrap the individual inputs into lists
List<string> inputFiles = new List<string>();
@@ -754,11 +754,11 @@ namespace SabreTools.Helper.Tools
List<Rom> roms = new List<Rom>();
roms.Add(rom);
return WriteToArchive(inputFiles, outDir, roms, logger, date: date);
return WriteTAR(inputFiles, outDir, roms, logger, date: date);
}
/// <summary>
/// Copy a set of files to an output torrentzip archive (assuming the same output archive name)
/// Write a set of input files to a tape archive (assuming the same output archive name)
/// </summary>
/// <param name="inputFile">Input filenames to be moved</param>
/// <param name="outDir">Output directory to build to</param>
@@ -766,7 +766,259 @@ namespace SabreTools.Helper.Tools
/// <param name="logger">Logger object for file and console output</param>
/// <param name="date">True if the date from the DAT should be used if available, false otherwise (default)</param>
/// <returns>True if the archive was written properly, false otherwise</returns>
public static bool WriteToArchive(List<string> inputFiles, string outDir, List<Rom> roms, Logger logger, bool date = false)
public static bool WriteTAR(List<string> inputFiles, string outDir, List<Rom> roms, Logger logger, bool date = false)
{
return false;
}
/// <summary>
/// Write an input file to a torrent7z archive
/// </summary>
/// <param name="inputFile">Input filename to be moved</param>
/// <param name="outDir">Output directory to build to</param>
/// <param name="rom">RomData representing the new information</param>
/// <param name="logger">Logger object for file and console output</param>
/// <param name="date">True if the date from the DAT should be used if available, false otherwise (default)</param>
/// <returns>True if the archive was written properly, false otherwise</returns>
public static bool WriteTorrent7Zip(string inputFile, string outDir, Rom rom, Logger logger, bool date = false)
{
// Wrap the individual inputs into lists
List<string> inputFiles = new List<string>();
inputFiles.Add(inputFile);
List<Rom> roms = new List<Rom>();
roms.Add(rom);
return WriteTorrent7Zip(inputFiles, outDir, roms, logger, date: date);
}
/// <summary>
/// Write a set of input files to a torrent7z archive (assuming the same output archive name)
/// </summary>
/// <param name="inputFile">Input filenames to be moved</param>
/// <param name="outDir">Output directory to build to</param>
/// <param name="rom">List of Rom representing the new information</param>
/// <param name="logger">Logger object for file and console output</param>
/// <param name="date">True if the date from the DAT should be used if available, false otherwise (default)</param>
/// <returns>True if the archive was written properly, false otherwise</returns>
public static bool WriteTorrent7Zip(List<string> inputFiles, string outDir, List<Rom> roms, Logger logger, bool date = false)
{
return false;
}
/// <summary>
/// Write an input file to a torrent GZ file
/// </summary>
/// <param name="input">File to write from</param>
/// <param name="outDir">Directory to write archive to</param>
/// <param name="romba">True if files should be output in Romba depot folders, false otherwise</param>
/// <param name="logger">Logger object for file and console output</param>
/// <returns>True if the write was a success, false otherwise</returns>
/// <remarks>This works for now, but it can be sped up by using Ionic.Zip or another zlib wrapper that allows for header values built-in. See edc's code.</remarks>
public static bool WriteTorrentGZ(string input, string outDir, bool romba, Logger logger)
{
// Check that the input file exists
if (!File.Exists(input))
{
logger.Warning("File " + input + " does not exist!");
return false;
}
input = Path.GetFullPath(input);
// Make sure the output directory exists
if (!Directory.Exists(outDir))
{
Directory.CreateDirectory(outDir);
}
outDir = Path.GetFullPath(outDir);
// Now get the Rom info for the file so we have hashes and size
Rom rom = FileTools.GetFileInfo(input, logger);
// Get the output file name
string outfile = Path.Combine(outDir, rom.SHA1 + ".gz");
// If the output file exists, don't try to write again
if (!File.Exists(outfile))
{
// Compress the input stream
FileStream inputStream = File.OpenRead(input);
FileStream outputStream = File.Open(outfile, FileMode.Create, FileAccess.Write);
// Open the output file for writing
BinaryWriter sw = new BinaryWriter(outputStream);
// Write standard header and TGZ info
byte[] data = Constants.TorrentGZHeader
.Concat(Style.StringToByteArray(rom.MD5)) // MD5
.Concat(Style.StringToByteArray(rom.CRC)) // CRC
.ToArray();
sw.Write(data);
sw.Write((ulong)rom.Size); // Long size (Unsigned, Mirrored)
// Now create a deflatestream from the input file
DeflateStream ds = new DeflateStream(outputStream, CompressionMode.Compress, CompressionLevel.BestCompression, true);
// Copy the input stream to the output
byte[] ibuffer = new byte[_bufferSize];
int ilen;
while ((ilen = inputStream.Read(ibuffer, 0, _bufferSize)) > 0)
{
ds.Write(ibuffer, 0, ilen);
ds.Flush();
}
ds.Dispose();
// Now write the standard footer
sw.Write(Style.StringToByteArray(rom.CRC).Reverse().ToArray());
sw.Write((uint)rom.Size);
// Dispose of everything
sw.Dispose();
outputStream.Dispose();
inputStream.Dispose();
}
// If we're in romba mode, create the subfolder and move the file
if (romba)
{
MoveToRombaFolder(rom, outDir, outfile, logger);
}
return true;
}
/// <summary>
/// Write an input file to a torrentlrzip archive
/// </summary>
/// <param name="inputFile">Input filename to be moved</param>
/// <param name="outDir">Output directory to build to</param>
/// <param name="rom">RomData representing the new information</param>
/// <param name="logger">Logger object for file and console output</param>
/// <param name="date">True if the date from the DAT should be used if available, false otherwise (default)</param>
/// <returns>True if the archive was written properly, false otherwise</returns>
public static bool WriteTorrentLRZ(string inputFile, string outDir, Rom rom, Logger logger, bool date = false)
{
// Wrap the individual inputs into lists
List<string> inputFiles = new List<string>();
inputFiles.Add(inputFile);
List<Rom> roms = new List<Rom>();
roms.Add(rom);
return WriteTorrentLRZ(inputFiles, outDir, roms, logger, date: date);
}
/// <summary>
/// Write a set of input files to a torrentlrzip archive (assuming the same output archive name)
/// </summary>
/// <param name="inputFile">Input filenames to be moved</param>
/// <param name="outDir">Output directory to build to</param>
/// <param name="rom">List of Rom representing the new information</param>
/// <param name="logger">Logger object for file and console output</param>
/// <param name="date">True if the date from the DAT should be used if available, false otherwise (default)</param>
/// <returns>True if the archive was written properly, false otherwise</returns>
public static bool WriteTorrentLRZ(List<string> inputFiles, string outDir, List<Rom> roms, Logger logger, bool date = false)
{
return false;
}
/// <summary>
/// Write an input file to a torrentrar archive
/// </summary>
/// <param name="inputFile">Input filename to be moved</param>
/// <param name="outDir">Output directory to build to</param>
/// <param name="rom">RomData representing the new information</param>
/// <param name="logger">Logger object for file and console output</param>
/// <param name="date">True if the date from the DAT should be used if available, false otherwise (default)</param>
/// <returns>True if the archive was written properly, false otherwise</returns>
public static bool WriteTorrentRAR(string inputFile, string outDir, Rom rom, Logger logger, bool date = false)
{
// Wrap the individual inputs into lists
List<string> inputFiles = new List<string>();
inputFiles.Add(inputFile);
List<Rom> roms = new List<Rom>();
roms.Add(rom);
return WriteTorrentRAR(inputFiles, outDir, roms, logger, date: date);
}
/// <summary>
/// Write a set of input files to a torrentrar archive (assuming the same output archive name)
/// </summary>
/// <param name="inputFile">Input filenames to be moved</param>
/// <param name="outDir">Output directory to build to</param>
/// <param name="rom">List of Rom representing the new information</param>
/// <param name="logger">Logger object for file and console output</param>
/// <param name="date">True if the date from the DAT should be used if available, false otherwise (default)</param>
/// <returns>True if the archive was written properly, false otherwise</returns>
public static bool WriteTorrentRAR(List<string> inputFiles, string outDir, List<Rom> roms, Logger logger, bool date = false)
{
return false;
}
/// <summary>
/// Write an input file to a torrentxz archive
/// </summary>
/// <param name="inputFile">Input filename to be moved</param>
/// <param name="outDir">Output directory to build to</param>
/// <param name="rom">RomData representing the new information</param>
/// <param name="logger">Logger object for file and console output</param>
/// <param name="date">True if the date from the DAT should be used if available, false otherwise (default)</param>
/// <returns>True if the archive was written properly, false otherwise</returns>
public static bool WriteTorrentXZ(string inputFile, string outDir, Rom rom, Logger logger, bool date = false)
{
// Wrap the individual inputs into lists
List<string> inputFiles = new List<string>();
inputFiles.Add(inputFile);
List<Rom> roms = new List<Rom>();
roms.Add(rom);
return WriteTorrentXZ(inputFiles, outDir, roms, logger, date: date);
}
/// <summary>
/// Write a set of input files to a torrentxz archive (assuming the same output archive name)
/// </summary>
/// <param name="inputFile">Input filenames to be moved</param>
/// <param name="outDir">Output directory to build to</param>
/// <param name="rom">List of Rom representing the new information</param>
/// <param name="logger">Logger object for file and console output</param>
/// <param name="date">True if the date from the DAT should be used if available, false otherwise (default)</param>
/// <returns>True if the archive was written properly, false otherwise</returns>
public static bool WriteTorrentXZ(List<string> inputFiles, string outDir, List<Rom> roms, Logger logger, bool date = false)
{
return false;
}
/// <summary>
/// Write an input file to a torrentzip archive
/// </summary>
/// <param name="inputFile">Input filename to be moved</param>
/// <param name="outDir">Output directory to build to</param>
/// <param name="rom">RomData representing the new information</param>
/// <param name="logger">Logger object for file and console output</param>
/// <param name="date">True if the date from the DAT should be used if available, false otherwise (default)</param>
/// <returns>True if the archive was written properly, false otherwise</returns>
public static bool WriteTorrentZip(string inputFile, string outDir, Rom rom, Logger logger, bool date = false)
{
// Wrap the individual inputs into lists
List<string> inputFiles = new List<string>();
inputFiles.Add(inputFile);
List<Rom> roms = new List<Rom>();
roms.Add(rom);
return WriteTorrentZip(inputFiles, outDir, roms, logger, date: date);
}
/// <summary>
/// Write a set of input files to a torrentzip archive (assuming the same output archive name)
/// </summary>
/// <param name="inputFile">Input filenames to be moved</param>
/// <param name="outDir">Output directory to build to</param>
/// <param name="rom">List of Rom representing the new information</param>
/// <param name="logger">Logger object for file and console output</param>
/// <param name="date">True if the date from the DAT should be used if available, false otherwise (default)</param>
/// <returns>True if the archive was written properly, false otherwise</returns>
public static bool WriteTorrentZip(List<string> inputFiles, string outDir, List<Rom> roms, Logger logger, bool date = false)
{
bool success = false;
string tempFile = Path.GetTempFileName();
@@ -981,88 +1233,6 @@ namespace SabreTools.Helper.Tools
return true;
}
/// <summary>
/// Write an input file to a torrent GZ file
/// </summary>
/// <param name="input">File to write from</param>
/// <param name="outDir">Directory to write archive to</param>
/// <param name="romba">True if files should be output in Romba depot folders, false otherwise</param>
/// <param name="logger">Logger object for file and console output</param>
/// <returns>True if the write was a success, false otherwise</returns>
/// <remarks>This works for now, but it can be sped up by using Ionic.Zip or another zlib wrapper that allows for header values built-in. See edc's code.</remarks>
public static bool WriteTorrentGZ(string input, string outDir, bool romba, Logger logger)
{
// Check that the input file exists
if (!File.Exists(input))
{
logger.Warning("File " + input + " does not exist!");
return false;
}
input = Path.GetFullPath(input);
// Make sure the output directory exists
if (!Directory.Exists(outDir))
{
Directory.CreateDirectory(outDir);
}
outDir = Path.GetFullPath(outDir);
// Now get the Rom info for the file so we have hashes and size
Rom rom = FileTools.GetFileInfo(input, logger);
// Get the output file name
string outfile = Path.Combine(outDir, rom.SHA1 + ".gz");
// If the output file exists, don't try to write again
if (!File.Exists(outfile))
{
// Compress the input stream
FileStream inputStream = File.OpenRead(input);
FileStream outputStream = File.Open(outfile, FileMode.Create, FileAccess.Write);
// Open the output file for writing
BinaryWriter sw = new BinaryWriter(outputStream);
// Write standard header and TGZ info
byte[] data = Constants.TorrentGZHeader
.Concat(Style.StringToByteArray(rom.MD5)) // MD5
.Concat(Style.StringToByteArray(rom.CRC)) // CRC
.ToArray();
sw.Write(data);
sw.Write((ulong)rom.Size); // Long size (Unsigned, Mirrored)
// Now create a deflatestream from the input file
DeflateStream ds = new DeflateStream(outputStream, CompressionMode.Compress, CompressionLevel.BestCompression, true);
// Copy the input stream to the output
byte[] ibuffer = new byte[_bufferSize];
int ilen;
while ((ilen = inputStream.Read(ibuffer, 0, _bufferSize)) > 0)
{
ds.Write(ibuffer, 0, ilen);
ds.Flush();
}
ds.Dispose();
// Now write the standard footer
sw.Write(Style.StringToByteArray(rom.CRC).Reverse().ToArray());
sw.Write((uint)rom.Size);
// Dispose of everything
sw.Dispose();
outputStream.Dispose();
inputStream.Dispose();
}
// If we're in romba mode, create the subfolder and move the file
if (romba)
{
MoveToRombaFolder(rom, outDir, outfile, logger);
}
return true;
}
/// <summary>
/// Get the romba path for a file based on the rom's SHA-1
/// </summary>

View File

@@ -7,8 +7,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SabreTools", "SabreTools\Sa
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SabreTools.Helper", "SabreTools.Helper\SabreTools.Helper.csproj", "{225A1AFD-0890-44E8-B779-7502665C23A5}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SimpleSort", "SimpleSort\SimpleSort.csproj", "{7668FFA4-19AF-4F5D-8463-C7EF5B080FA4}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RombaSharp", "RombaSharp\RombaSharp.csproj", "{4728D479-8CFB-43E9-8C63-4774C6D73200}"
EndProject
Global
@@ -36,14 +34,6 @@ Global
{225A1AFD-0890-44E8-B779-7502665C23A5}.Release|Any CPU.Build.0 = Release|Any CPU
{225A1AFD-0890-44E8-B779-7502665C23A5}.Release|x64.ActiveCfg = Release|x64
{225A1AFD-0890-44E8-B779-7502665C23A5}.Release|x64.Build.0 = Release|x64
{7668FFA4-19AF-4F5D-8463-C7EF5B080FA4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7668FFA4-19AF-4F5D-8463-C7EF5B080FA4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7668FFA4-19AF-4F5D-8463-C7EF5B080FA4}.Debug|x64.ActiveCfg = Debug|x64
{7668FFA4-19AF-4F5D-8463-C7EF5B080FA4}.Debug|x64.Build.0 = Debug|x64
{7668FFA4-19AF-4F5D-8463-C7EF5B080FA4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{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
{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

View File

@@ -21,14 +21,14 @@ namespace SabreTools
/// <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="tgz">True to output files in TorrentGZ format, false for TorrentZip</param>
/// <param name="outputFormat">Output format that files should be written to</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>
public static bool InitConvertFolder(List<string> datfiles, List<string> inputs, string outDir, string tempDir, bool delete,
bool tgz, bool romba, int sevenzip, int gz, int rar, int zip)
OutputFormat outputFormat, bool romba, int sevenzip, int gz, int rar, int zip)
{
// Get the archive scanning level
ArchiveScanLevel asl = ArchiveTools.GetArchiveScanLevelFromNumbers(sevenzip, gz, rar, zip);
@@ -64,7 +64,7 @@ namespace SabreTools
}
_logger.User("Organizing complete in " + DateTime.Now.Subtract(start).ToString(@"hh\:mm\:ss\.fffff"));
return datdata.ConvertFiles(inputs, outDir, tempDir, tgz, romba, delete, asl, _logger);
return datdata.ConvertFiles(inputs, outDir, tempDir, outputFormat, romba, delete, asl, _logger);
}
/// <summary>
@@ -307,19 +307,18 @@ namespace SabreTools
/// <param name="tempDir">Temporary directory for archive extraction</param>
/// <param name="quickScan">True to enable external scanning of archives, false otherwise</param>
/// <param name="date">True if the date from the DAT should be used if available, false otherwise</param>
/// <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="delete">True if input files should be deleted, false otherwise</param>
/// <param name="tgz">True to output files in TorrentGZ format, false for TorrentZip</param>
/// <param name="outputFormat">Output format that files should be written to</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="updateDat">True if the updated DAT should be output, false otherwise</param>
/// <param name="headerToCheckAgainst">Populated string representing the name of the skipper to use, a blank string to use the first available checker, null otherwise</param>
/// <param name="maxDegreeOfParallelism">Integer representing the maximum amount of parallelization to be used</param>
private static void InitSort(List<string> datfiles, List<string> inputs, string outDir, string tempDir, bool quickScan, bool date,
bool toFolder, bool delete, bool tgz, bool romba, int sevenzip, int gz, int rar, int zip, bool updateDat, string headerToCheckAgainst,
private static void InitSort(List<string> datfiles, List<string> inputs, string outDir, string tempDir, bool quickScan, bool date, bool delete,
OutputFormat outputFormat, bool romba, int sevenzip, int gz, int rar, int zip, bool updateDat, string headerToCheckAgainst,
int maxDegreeOfParallelism)
{
// Get the archive scanning level
@@ -336,7 +335,7 @@ namespace SabreTools
}
_logger.User("Populating complete in " + DateTime.Now.Subtract(start).ToString(@"hh\:mm\:ss\.fffff"));
datdata.RebuildToOutput(inputs, outDir, tempDir, quickScan, date, toFolder, delete, tgz, romba, asl,
datdata.RebuildToOutput(inputs, outDir, tempDir, quickScan, date, delete, outputFormat, romba, asl,
updateDat, headerToCheckAgainst, maxDegreeOfParallelism, _logger);
}

View File

@@ -389,9 +389,26 @@ namespace SabreTools
case "--softlist":
softlist = true;
break;
case "-t7z":
case "--t7z":
outputFormat = OutputFormat.Torrent7Zip;
break;
case "-tar":
case "--tar":
outputFormat = OutputFormat.TapeArchive;
break;
case "-tgz":
case "--tgz":
tgz = true;
outputFormat = OutputFormat.TorrentGzip;
break;
case "-tlrz":
case "--tlrz":
outputFormat = OutputFormat.TorrentLrzip;
break;
case "-trar":
case "--trar":
outputFormat = OutputFormat.TorrentRar;
break;
case "-trim":
case "--trim":
@@ -401,6 +418,14 @@ namespace SabreTools
case "--tsv":
statDatFormat = StatDatFormat.TSV;
break;
case "-txz":
case "--txz":
outputFormat = OutputFormat.TorrentXZ;
break;
case "-tzip":
case "--tzip":
outputFormat = OutputFormat.TorrentZip;
break;
case "-ud":
case "--update":
update = true;
@@ -908,7 +933,7 @@ namespace SabreTools
// Convert a folder to TGZ or TorrentZip
if (convert)
{
InitConvertFolder(datfiles, inputs, outDir, tempDir, delete, tgz, romba, sevenzip, gz, rar, zip);
InitConvertFolder(datfiles, inputs, outDir, tempDir, delete, outputFormat, romba, sevenzip, gz, rar, zip);
}
// Create a DAT from a directory or set of directories

View File

@@ -390,7 +390,7 @@ namespace SabreTools
}
logger.User("Organizing complete in " + DateTime.Now.Subtract(start).ToString(@"hh\:mm\:ss\.fffff"));
return datdata.ConvertFiles(inputs, outDir, tempDir, tgz, romba, delete, asl, logger);
return datdata.ConvertFiles(inputs, outDir, tempDir, (tgz ? OutputFormat.TorrentGzip : OutputFormat.TorrentZip), romba, delete, asl, logger);
}
/// <summary>