[ArchiveTools] Make absolutely sure that TGZ files don't overwrite

This commit is contained in:
Matt Nadareski
2016-10-05 20:52:30 -07:00
parent 422efd3951
commit 19d23d5ebb

View File

@@ -1043,9 +1043,15 @@ namespace SabreTools.Helper
// Now get the Rom info for the file so we have hashes and size // Now get the Rom info for the file so we have hashes and size
Rom rom = FileTools.GetFileInfo(input, logger); Rom rom = FileTools.GetFileInfo(input, logger);
// If it doesn't exist, create the output file and then write // Get the output file name
string outfile = Path.Combine(outDir, rom.SHA1 + ".gz"); string outfile = Path.Combine(outDir, rom.SHA1 + ".gz");
// If the output file exists, don't try to write again
if (File.Exists(outfile))
{
return true;
}
// 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); GZipStream outputStream = new GZipStream(File.Open(outfile, FileMode.Create, FileAccess.Write), CompressionMode.Compress);