Fix files not compressing even if the dialog is okayed.

This commit is contained in:
KillzXGaming 2019-05-03 21:08:29 -04:00
parent ed33ef65f9
commit 4bc037e681
6 changed files with 14 additions and 18 deletions

Binary file not shown.

View file

@ -24,16 +24,16 @@ namespace Switch_Toolbox.Library.IO
byte[] data = FileFormat.Save(); byte[] data = FileFormat.Save();
FileFormat.IFileInfo.DecompressedSize = (uint)data.Length; FileFormat.IFileInfo.DecompressedSize = (uint)data.Length;
CompressFileFormat(data, byte[] FinalData = CompressFileFormat(data,
FileFormat.IFileInfo.FileIsCompressed, FileFormat.IFileInfo.FileIsCompressed,
FileFormat.IFileInfo.Alignment, FileFormat.IFileInfo.Alignment,
FileFormat.IFileInfo.CompressionType, FileFormat.IFileInfo.CompressionType,
FileName, FileName,
EnableDialog); EnableDialog);
FileFormat.IFileInfo.CompressedSize = (uint)data.Length; FileFormat.IFileInfo.CompressedSize = (uint)FinalData.Length;
File.WriteAllBytes(FileName, data); File.WriteAllBytes(FileName, FinalData);
MessageBox.Show($"File has been saved to {FileName}"); MessageBox.Show($"File has been saved to {FileName}");
Cursor.Current = Cursors.Default; Cursor.Current = Cursors.Default;
} }
@ -42,13 +42,13 @@ namespace Switch_Toolbox.Library.IO
CompressionType CompressionType, string FileName, bool EnableDialog = true) CompressionType CompressionType, string FileName, bool EnableDialog = true)
{ {
Cursor.Current = Cursors.WaitCursor; Cursor.Current = Cursors.WaitCursor;
CompressFileFormat(data, FileIsCompressed, Alignment, CompressionType, FileName, EnableDialog); byte[] FinalData = CompressFileFormat(data, FileIsCompressed, Alignment, CompressionType, FileName, EnableDialog);
File.WriteAllBytes(FileName, data); File.WriteAllBytes(FileName, FinalData);
MessageBox.Show($"File has been saved to {FileName}"); MessageBox.Show($"File has been saved to {FileName}");
Cursor.Current = Cursors.Default; Cursor.Current = Cursors.Default;
} }
private static void CompressFileFormat(byte[] data, bool FileIsCompressed, int Alignment, private static byte[] CompressFileFormat(byte[] data, bool FileIsCompressed, int Alignment,
CompressionType CompressionType, string FileName, bool EnableDialog = true) CompressionType CompressionType, string FileName, bool EnableDialog = true)
{ {
string extension = Path.GetExtension(FileName); string extension = Path.GetExtension(FileName);
@ -73,29 +73,25 @@ namespace Switch_Toolbox.Library.IO
switch (CompressionType) switch (CompressionType)
{ {
case CompressionType.Yaz0: case CompressionType.Yaz0:
data = EveryFileExplorer.YAZ0.Compress(data, Runtime.Yaz0CompressionLevel, (uint)Alignment); return EveryFileExplorer.YAZ0.Compress(data, Runtime.Yaz0CompressionLevel, (uint)Alignment);
break;
case CompressionType.Zstb: case CompressionType.Zstb:
data = STLibraryCompression.ZSTD.Compress(data); return STLibraryCompression.ZSTD.Compress(data);
break;
case CompressionType.Lz4: case CompressionType.Lz4:
data = STLibraryCompression.Type_LZ4.Compress(data); return STLibraryCompression.Type_LZ4.Compress(data);
break;
case CompressionType.Lz4f: case CompressionType.Lz4f:
data = STLibraryCompression.Type_LZ4F.Compress(data); return STLibraryCompression.Type_LZ4F.Compress(data);
break;
case CompressionType.Gzip: case CompressionType.Gzip:
data = STLibraryCompression.GZIP.Compress(data); return STLibraryCompression.GZIP.Compress(data);
break;
case CompressionType.Zlib: case CompressionType.Zlib:
data = STLibraryCompression.ZLIB.Compress(data, 2); return STLibraryCompression.ZLIB.Compress(data, 2);
break;
default: default:
MessageBox.Show($"Compression Type {CompressionType} not supported!!"); MessageBox.Show($"Compression Type {CompressionType} not supported!!");
break; break;
} }
} }
} }
return data;
} }
} }