private void StreamFilesButton_Click(object sender, EventArgs e) { OutputLine("Uncompressing..."); int totalUncompressedDataSize = 0; int totalCompressedDataSize = 0; int numFilesUncompressed = 0; double totalElapsedTime = 0.0f; CompressionInterop.Suite decompressor = new CompressionInterop.Suite(); CompressionInterop.Stats stats = new CompressionInterop.Stats(); foreach (ListViewItem lvi in mFileList.Items) { String ext = Path.GetExtension(lvi.Text); String inputFileName = getOutputFileName(lvi.Text, "Compressed", ext + "-ctd"); String outputFileName = getOutputFileName(lvi.Text, "Uncompressed", ext); if (!File.Exists(inputFileName)) { continue; } Byte[] uncompressedData; bool result = decompressor.Decompress(inputFileName, out uncompressedData, ref stats); if (result) { totalUncompressedDataSize += stats.UncompressedDataSize; totalCompressedDataSize += stats.CompressedDataSize; totalElapsedTime += stats.ElapsedTime; numFilesUncompressed++; using (FileStream stream = new FileStream(outputFileName, FileMode.Create)) { using (BinaryWriter writer = new BinaryWriter(stream)) { writer.Write(uncompressedData); writer.Close(); } } StringBuilder sb = new StringBuilder(256); sb.AppendFormat("Uncompressed {0} from {1}b -> {2}b in {3:0.00000}s", inputFileName, stats.CompressedDataSize, stats.UncompressedDataSize, stats.ElapsedTime); OutputLine(sb.ToString()); } else { StringBuilder sb = new StringBuilder(256); sb.AppendFormat("Error uncompressing {0}!", inputFileName); OutputLine(sb.ToString()); } } if (numFilesUncompressed > 0) { StringBuilder sb = new StringBuilder(256); sb.AppendFormat("Total: Uncompressed {0} files ({1}b -> {2}b). Time: {3:0.00000}s", numFilesUncompressed, totalCompressedDataSize, totalUncompressedDataSize, totalElapsedTime); OutputLine(sb.ToString()); } }
private void CompressFilesButton_Click(object sender, EventArgs e) { String selectedAlgorithm = AlgorithmCombo.SelectedItem as String; CompressionInterop.Algorithm algorithm = (CompressionInterop.Algorithm)Enum.Parse(typeof(CompressionInterop.Algorithm), selectedAlgorithm); OutputLine("Compressing with " + selectedAlgorithm + "..."); int totalUncompressedDataSize = 0; int totalCompressedDataSize = 0; int numFilesCompressed = 0; double totalElapsedTime = 0.0f; CompressionInterop.Suite compressor = new CompressionInterop.Suite(); CompressionInterop.Stats stats = new CompressionInterop.Stats(); foreach (ListViewItem lvi in mFileList.Items) { String inputFileName = lvi.Text; String ext = Path.GetExtension(inputFileName); String outputFileName = getOutputFileName(inputFileName, "Compressed", ext + "-ctd"); bool result = compressor.Compress(inputFileName, algorithm, outputFileName, ref stats); if (result) { totalUncompressedDataSize += stats.UncompressedDataSize; totalCompressedDataSize += stats.CompressedDataSize; totalElapsedTime += stats.ElapsedTime; numFilesCompressed++; float ratio = ((float)stats.CompressedDataSize / (float)stats.UncompressedDataSize) * 100.0f; StringBuilder sb = new StringBuilder(256); sb.AppendFormat("Compressed {0}. Compression ratio: {1:0.000}% ({2}b -> {3}b). Time: {4:0.00000}s", inputFileName, ratio, stats.UncompressedDataSize, stats.CompressedDataSize, stats.ElapsedTime); OutputLine(sb.ToString()); } else { StringBuilder sb = new StringBuilder(256); sb.AppendFormat("Error compressing {0}!", inputFileName); OutputLine(sb.ToString()); } } if (numFilesCompressed > 0) { float ratio = ((float)totalCompressedDataSize / (float)totalUncompressedDataSize) * 100.0f; StringBuilder sb = new StringBuilder(256); sb.AppendFormat("Total: Compressed {0} files. Compression ratio: {1:0.000}% ({2}b -> {3}b). Time: {4:0.00000}s", numFilesCompressed, ratio, totalUncompressedDataSize, totalCompressedDataSize, totalElapsedTime); OutputLine(sb.ToString()); } }
private void StreamFilesButton_Click(object sender, EventArgs e) { OutputLine("Uncompressing..."); int totalUncompressedDataSize = 0; int totalCompressedDataSize = 0; int numFilesUncompressed = 0; double totalElapsedTime = 0.0f; CompressionInterop.Suite decompressor = new CompressionInterop.Suite(); CompressionInterop.Stats stats = new CompressionInterop.Stats(); foreach (ListViewItem lvi in mFileList.Items) { String ext = Path.GetExtension(lvi.Text); String inputFileName = getOutputFileName(lvi.Text, "Compressed", ext + "-ctd"); String outputFileName = getOutputFileName(lvi.Text, "Uncompressed", ext); if (!File.Exists(inputFileName)) continue; Byte[] uncompressedData; bool result = decompressor.Decompress(inputFileName, out uncompressedData, ref stats); if (result) { totalUncompressedDataSize += stats.UncompressedDataSize; totalCompressedDataSize += stats.CompressedDataSize; totalElapsedTime += stats.ElapsedTime; numFilesUncompressed++; using (FileStream stream = new FileStream(outputFileName, FileMode.Create)) { using (BinaryWriter writer = new BinaryWriter(stream)) { writer.Write(uncompressedData); writer.Close(); } } StringBuilder sb = new StringBuilder(256); sb.AppendFormat("Uncompressed {0} from {1}b -> {2}b in {3:0.00000}s", inputFileName, stats.CompressedDataSize, stats.UncompressedDataSize, stats.ElapsedTime); OutputLine(sb.ToString()); } else { StringBuilder sb = new StringBuilder(256); sb.AppendFormat("Error uncompressing {0}!", inputFileName); OutputLine(sb.ToString()); } } if (numFilesUncompressed > 0) { StringBuilder sb = new StringBuilder(256); sb.AppendFormat("Total: Uncompressed {0} files ({1}b -> {2}b). Time: {3:0.00000}s", numFilesUncompressed, totalCompressedDataSize, totalUncompressedDataSize, totalElapsedTime); OutputLine(sb.ToString()); } }