[ArchiveTools] Make TGZ output same as RVX

This commit is contained in:
Matt Nadareski
2016-10-19 10:25:25 -07:00
parent c9e8e28158
commit bb48d1bc6a

View File

@@ -1020,16 +1020,10 @@ namespace SabreTools.Helper
{ {
// Compress the input stream // Compress the input stream
FileStream inputStream = File.OpenRead(input); FileStream inputStream = File.OpenRead(input);
GZipStream outputStream = new GZipStream(File.Open(outfile, FileMode.Create, FileAccess.Write), CompressionMode.Compress); FileStream outputStream = File.Open(outfile, FileMode.Create, FileAccess.Write);
inputStream.CopyTo(outputStream);
// Dispose of the streams // Open the output file for writing
inputStream.Dispose(); BinaryWriter sw = new BinaryWriter(outputStream);
outputStream.Dispose();
// Now that it's ready, inject the header info
BinaryWriter sw = new BinaryWriter(new MemoryStream());
BinaryReader br = new BinaryReader(File.OpenRead(outfile));
// Write standard header and TGZ info // Write standard header and TGZ info
byte[] data = Constants.TorrentGZHeader byte[] data = Constants.TorrentGZHeader
@@ -1039,27 +1033,27 @@ namespace SabreTools.Helper
sw.Write(data); sw.Write(data);
sw.Write((ulong)rom.Size); // Long size (Unsigned, Mirrored) sw.Write((ulong)rom.Size); // Long size (Unsigned, Mirrored)
// Finally, copy the rest of the data from the original file // Now create a deflatestream from the input file
br.BaseStream.Seek(10, SeekOrigin.Begin); DeflateStream ds = new DeflateStream(outputStream, CompressionMode.Compress, CompressionLevel.BestCompression, true);
int i = 10;
while (br.BaseStream.Position < br.BaseStream.Length) // Copy the input stream to the output
byte[] ibuffer = new byte[_bufferSize];
int ilen;
while ((ilen = inputStream.Read(ibuffer, 0, _bufferSize)) > 0)
{ {
sw.Write(br.ReadByte()); ds.Write(ibuffer, 0, ilen);
i++; ds.Flush();
} }
ds.Dispose();
// Dispose of the stream // Now write the standard footer
br.Dispose(); sw.Write(Style.StringToByteArray(rom.CRC).Reverse().ToArray());
sw.Write((uint)rom.Size);
// Now write the new file over the original // Dispose of everything
BinaryWriter bw = new BinaryWriter(File.Open(outfile, FileMode.Create));
sw.BaseStream.Seek(0, SeekOrigin.Begin);
bw.BaseStream.Seek(0, SeekOrigin.Begin);
sw.BaseStream.CopyTo(bw.BaseStream);
// Dispose of the streams
bw.Dispose();
sw.Dispose(); sw.Dispose();
outputStream.Dispose();
inputStream.Dispose();
} }
// If we're in romba mode, create the subfolder and move the file // If we're in romba mode, create the subfolder and move the file