Exemplo n.º 1
0
        private async void compressCheckedFilesToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (dialogSaveHpi.ShowDialog() == DialogResult.OK)
            {
                toolStrip.Enabled     = false;
                listViewFiles.Enabled = false;

                firstStatusLabel.Text = "Compressing... Last processed:";

                //Calculate total size and number of chunks
                int chunkTotal = 0;
                foreach (ListViewItem item in listViewFiles.CheckedItems)
                {
                    chunkTotal += FileEntry.CalculateChunkQuantity((int)item.SubItems[3].Tag);
                }

                CompressionFlavor flavor;
                Enum.TryParse(flavorLevelComboBox.Text, out flavor);

                var    fileList = GetCheckedFileNames();
                string target   = fileList.First().Key;

                progressBar.Maximum = chunkTotal + 1;
                progressBar.Value   = 0;
                progressBar.Visible = true;
                progressBar.Style   = ProgressBarStyle.Continuous;

                var progress = new Progress <string>(last =>
                {
                    secondStatusLabel.Text = last;
                    progressBar.Value++;
                });

                var timer = new Stopwatch();
                timer.Start();

                await Task.Run(() => HpiFile.CreateFromFileList(fileList[target].ToArray(), target, dialogSaveHpi.FileName, progress, flavor));

                timer.Stop();
                progressBar.Value = progressBar.Maximum;

                firstStatusLabel.Text = String.Format("Done! Elapsed time: {0}h {1}m {2}s {3}ms", timer.Elapsed.Hours, timer.Elapsed.Minutes,
                                                      timer.Elapsed.Seconds, timer.Elapsed.Milliseconds);
                secondStatusLabel.Text = dialogSaveHpi.FileName;
                toolStrip.Enabled      = true;
                ChangeArchiverMode(true, true);
            }
        }