diff --git a/SabreTools.Helper/Data/Build.cs b/SabreTools.Helper/Data/Build.cs index 833f33a1..760cbd4d 100644 --- a/SabreTools.Helper/Data/Build.cs +++ b/SabreTools.Helper/Data/Build.cs @@ -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"); diff --git a/SabreTools.Helper/External/OptimizedCRC.cs b/SabreTools.Helper/External/OptimizedCRC.cs index bbc5d97b..6139bd9b 100644 --- a/SabreTools.Helper/External/OptimizedCRC.cs +++ b/SabreTools.Helper/External/OptimizedCRC.cs @@ -56,7 +56,7 @@ namespace OCRC } } - private uint value; + public uint UnsignedValue; public OptimizedCRC() { @@ -68,12 +68,12 @@ namespace OCRC /// 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; } } } \ No newline at end of file diff --git a/SabreTools.Helper/Objects/SimpleSort.cs b/SabreTools.Helper/Objects/SimpleSort.cs index d1040e04..ef3a6431 100644 --- a/SabreTools.Helper/Objects/SimpleSort.cs +++ b/SabreTools.Helper/Objects/SimpleSort.cs @@ -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 /// 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 is for TorrentZip, False is for TorrentGZ, Null is for standard zip /// 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 @@ -49,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 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 diff --git a/SabreTools.Helper/README.1ST b/SabreTools.Helper/README.1ST index 295d4c02..43a7362d 100644 --- a/SabreTools.Helper/README.1ST +++ b/SabreTools.Helper/README.1ST @@ -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 diff --git a/SabreTools/Partials/SabreTools_Inits.cs b/SabreTools/Partials/SabreTools_Inits.cs index 41a56756..fac03801 100644 --- a/SabreTools/Partials/SabreTools_Inits.cs +++ b/SabreTools/Partials/SabreTools_Inits.cs @@ -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 /// 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 is for TorrentZip, False is for TorrentGZ, Null is for standard zip /// True if files should be output in Romba depot folders, false otherwise /// Integer representing the archive handling level for GZip /// Integer representing the archive handling level for RAR @@ -381,7 +381,7 @@ namespace SabreTools /// True if the updated DAT should be output, false otherwise /// Logger object for file and console output private static void InitSortVerify(List datfiles, List 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(); } diff --git a/SimpleSort/SimpleSortApp.cs b/SimpleSort/SimpleSortApp.cs index cc6edaae..abcc08b6 100644 --- a/SimpleSort/SimpleSortApp.cs +++ b/SimpleSort/SimpleSortApp.cs @@ -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 /// 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 is for TorrentZip, False is for TorrentGZ, Null is for standard zip /// True if files should be output in Romba depot folders, false otherwise /// Integer representing the archive handling level for GZip /// Integer representing the archive handling level for RAR @@ -248,7 +248,7 @@ namespace SabreTools /// True if the updated DAT should be output, false otherwise /// Logger object for file and console output private static void InitSortVerify(List datfiles, List 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(); } }