[SimpleSort] Add TorrentZip flag

This commit is contained in:
Matt Nadareski
2016-09-16 11:55:29 -07:00
parent c69dddbc26
commit 9267ecf674
6 changed files with 55 additions and 36 deletions

View File

@@ -272,7 +272,8 @@ namespace SabreTools.Helper
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(" -tgz Enable TorrentGZ output");
helptext.Add(" -tzip Enable TorrentZip output");
helptext.Add(" -r, --romba Enable Romba depot dir output");
helptext.Add(" -do, --directory Output files as uncompressed");
helptext.Add(" -7z={0} Set scanning level for 7z archives");

View File

@@ -56,7 +56,7 @@ namespace OCRC
}
}
private uint value;
public uint UnsignedValue;
public OptimizedCRC()
{
@@ -68,12 +68,12 @@ namespace OCRC
/// </summary>
public void Init()
{
value = kInitial;
UnsignedValue = kInitial;
}
public int Value
{
get { return (int)~value; }
get { return (int)~UnsignedValue; }
}
public void Update(byte[] data, int offset, int count)
@@ -83,7 +83,7 @@ namespace OCRC
var table = OptimizedCRC.Table;
uint crc = value;
uint crc = UnsignedValue;
for (; (offset & 7) != 0 && count != 0; count--)
crc = (crc >> 8) ^ table[(byte)crc ^ data[offset++]];
@@ -118,7 +118,7 @@ namespace OCRC
while (count-- != 0)
crc = (crc >> 8) ^ table[(byte)crc ^ data[offset++]];
value = crc;
UnsignedValue = crc;
}
static public int Compute(byte[] data, int offset, int count)
@@ -140,7 +140,7 @@ namespace OCRC
public void Dispose()
{
value = 0;
UnsignedValue = 0;
}
}
}

View File

@@ -15,7 +15,7 @@ namespace SabreTools.Helper
private bool _toFolder;
private bool _verify;
private bool _delete;
private bool _tgz;
private bool? _torrentX; // True is for TorrentZip, False is for TorrentGZ, Null is for standard zip
private bool _romba;
private bool _updateDat;
private ArchiveScanLevel _7z;
@@ -40,7 +40,7 @@ namespace SabreTools.Helper
/// <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="torrentX">True is for TorrentZip, False is for TorrentGZ, Null is 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>
/// <param name="gz">Integer representing the archive handling level for GZip</param>
@@ -49,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 delete, bool tgz, bool romba, int sevenzip,
bool quickScan, bool toFolder, bool verify, bool delete, bool? torrentX, bool romba, int sevenzip,
int gz, int rar, int zip, bool updateDat, Logger logger)
{
_datdata = datdata;
@@ -60,7 +60,7 @@ namespace SabreTools.Helper
_toFolder = toFolder;
_verify = verify;
_delete = delete;
_tgz = tgz;
_torrentX = torrentX;
_romba = romba;
_7z = (ArchiveScanLevel)(sevenzip < 0 || sevenzip > 2 ? 0 : sevenzip);
_gz = (ArchiveScanLevel)(gz < 0 || gz > 2 ? 0 : gz);
@@ -321,7 +321,7 @@ namespace SabreTools.Helper
Directory.CreateDirectory(gamedir);
}
_logger.Log("Rebuilding file '" + Path.GetFileName(rom.Name) + "' to '" + (_tgz ? found.HashData.SHA1 : found.Name) + "'");
_logger.Log("Rebuilding file '" + Path.GetFileName(rom.Name) + "' to '" + (_torrentX == false ? found.HashData.SHA1 : found.Name) + "'");
try
{
File.Copy(input, Path.Combine(gamedir, Path.GetFileName(found.Name)));
@@ -330,14 +330,17 @@ namespace SabreTools.Helper
}
else
{
if (_tgz)
if (_torrentX == true)
{
FileTools.WriteTorrentZip(input, _outdir, found, _logger);
}
else if (_torrentX == false)
{
FileTools.WriteTorrentGZ(input, _outdir, _romba, _logger);
}
else
{
FileTools.WriteToArchive(input, _outdir, found);
//FileTools.WriteTorrentZip(input, _outdir, found, _logger);
}
}
}
@@ -389,7 +392,7 @@ namespace SabreTools.Helper
Directory.CreateDirectory(gamedir);
}
_logger.Log("Rebuilding file '" + Path.GetFileName(rom.Name) + "' to '" + (_tgz ? found.HashData.SHA1 : found.Name) + "'");
_logger.Log("Rebuilding file '" + Path.GetFileName(rom.Name) + "' to '" + (_torrentX == false ? found.HashData.SHA1 : found.Name) + "'");
try
{
File.Copy(newinput, Path.Combine(gamedir, Path.GetFileName(found.Name)));
@@ -398,14 +401,17 @@ namespace SabreTools.Helper
}
else
{
if (_tgz)
if (_torrentX == true)
{
FileTools.WriteTorrentZip(newinput, _outdir, found, _logger);
}
else if (_torrentX == false)
{
FileTools.WriteTorrentGZ(newinput, _outdir, _romba, _logger);
}
else
{
FileTools.WriteToArchive(newinput, _outdir, found);
//FileTools.WriteTorrentZip(newinput, _outdir, found, _logger);
}
}
@@ -446,14 +452,17 @@ namespace SabreTools.Helper
else
{
_logger.Log("Matched name: " + newfound.Name);
if (_tgz)
if (_torrentX == true)
{
FileTools.WriteTorrentZip(input, _outdir, newfound, _logger);
}
else if (_torrentX == false)
{
FileTools.WriteTorrentGZ(input, _outdir, _romba, _logger);
}
else
{
FileTools.WriteToArchive(input, _outdir, newfound);
//FileTools.WriteTorrentZip(input, _outdir, newfound, _logger);
}
}
}
@@ -526,21 +535,24 @@ namespace SabreTools.Helper
else
{
// Copy file between archives
_logger.Log("Rebuilding file '" + Path.GetFileName(rom.Name) + "' to '" + (_tgz ? found.HashData.SHA1 : found.Name) + "'");
_logger.Log("Rebuilding file '" + Path.GetFileName(rom.Name) + "' to '" + (_torrentX == false ? found.HashData.SHA1 : found.Name) + "'");
if (Build.MonoEnvironment || _tgz)
if (Build.MonoEnvironment || _torrentX == false)
{
string outfile = FileTools.ExtractSingleItemFromArchive(input, rom.Name, _tempdir, _logger);
if (File.Exists(outfile))
{
if (_tgz)
if (_torrentX == true)
{
FileTools.WriteTorrentZip(outfile, _outdir, found, _logger);
}
else if (_torrentX == false)
{
FileTools.WriteTorrentGZ(outfile, _outdir, _romba, _logger);
}
else
{
FileTools.WriteToArchive(input, _outdir, found);
//FileTools.WriteTorrentZip(input, _outdir, found, _logger);
FileTools.WriteToArchive(outfile, _outdir, found);
}
try

View File

@@ -684,6 +684,12 @@ Options:
includes two auxilary files, .romba_size and .romba_size.backup, that have the
compressed size of the folder inside for use with Romba.
-tzip Enable TorrentZip output
Instead of outputting the files to standard ZIP archives, 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.
-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

View File

@@ -78,7 +78,7 @@ namespace SabreTools
}
}
SimpleSort ss = new SimpleSort(new Dat(), newinputs, outdir, tempdir, false, false, false, delete, true, romba, sevenzip, gz, rar, zip, false, logger);
SimpleSort ss = new SimpleSort(new Dat(), newinputs, outdir, tempdir, false, false, false, delete, false, romba, sevenzip, gz, rar, zip, false, logger);
return ss.Convert();
}
@@ -373,7 +373,7 @@ namespace SabreTools
/// <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="torrentX">True is for TorrentZip, False is for TorrentGZ, Null is 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>
/// <param name="rar">Integer representing the archive handling level for RAR</param>
@@ -381,7 +381,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 InitSortVerify(List<string> datfiles, List<string> inputs, string outdir, string tempdir, bool quickScan,
bool toFolder, bool verify, bool delete, bool tgz, bool romba, int sevenzip, int gz, int rar, int zip, bool updateDat, Logger logger)
bool toFolder, bool verify, bool delete, bool? torrentX, 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();
@@ -391,7 +391,7 @@ namespace SabreTools
}
SimpleSort ss = new SimpleSort(datdata, inputs, outdir, tempdir, quickScan, toFolder, verify,
delete, tgz, romba, sevenzip, gz, rar, zip, updateDat, logger);
delete, torrentX, romba, sevenzip, gz, rar, zip, updateDat, logger);
ss.StartProcessing();
}

View File

@@ -48,11 +48,11 @@ namespace SabreTools
quickScan = false,
romba = false,
simpleSort = true,
tgz = false,
toFolder = false,
tzip = false,
updateDat = false,
verify = false;
bool? torrentX = null;
int sevenzip = 0,
gz = 2,
rar = 2,
@@ -94,11 +94,11 @@ namespace SabreTools
break;
case "-tgz":
case "--tgz":
tgz = true;
torrentX = false;
break;
case "-tzip":
case "--tzip":
tzip = true;
torrentX = true;
break;
case "-ud":
case "--updated-dat":
@@ -207,7 +207,7 @@ namespace SabreTools
if (datfiles.Count > 0)
{
InitSortVerify(datfiles, inputs, outdir, tempdir, quickScan, toFolder,
verify, delete, tgz, romba, sevenzip, gz, rar, zip, updateDat, logger);
verify, delete, torrentX, romba, sevenzip, gz, rar, zip, updateDat, logger);
}
else
{
@@ -240,7 +240,7 @@ namespace SabreTools
/// <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="torrentX">True is for TorrentZip, False is for TorrentGZ, Null is 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>
/// <param name="rar">Integer representing the archive handling level for RAR</param>
@@ -248,7 +248,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 InitSortVerify(List<string> datfiles, List<string> inputs, string outdir, string tempdir, bool quickScan,
bool toFolder, bool verify, bool delete, bool tgz, bool romba, int sevenzip, int gz, int rar, int zip, bool updateDat, Logger logger)
bool toFolder, bool verify, bool delete, bool? torrentX, 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();
@@ -258,7 +258,7 @@ namespace SabreTools
}
SimpleSort ss = new SimpleSort(datdata, inputs, outdir, tempdir, quickScan, toFolder, verify,
delete, tgz, romba, sevenzip, gz, rar, zip, updateDat, logger);
delete, torrentX, romba, sevenzip, gz, rar, zip, updateDat, logger);
ss.StartProcessing();
}
@@ -296,7 +296,7 @@ namespace SabreTools
}
SimpleSort ss = new SimpleSort(new Dat(), newinputs, outdir, tempdir, false, false, false,
delete, true, romba, sevenzip, gz, rar, zip, false, logger);
delete, false, romba, sevenzip, gz, rar, zip, false, logger);
return ss.Convert();
}
}