Пример #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);
            }
        }
Пример #2
0
        private async void toolStripExtractButton_Click(object sender, EventArgs e)
        {
            if (listViewFiles.CheckedItems.Count > 0)
            {
                //dialogExtractToFolder.SelectedPath = Path.GetDirectoryName(toolStripPathTextBox.Text);
                if (dialogExtractToFolder.ShowDialog() == DialogResult.OK)
                {
                    toolStrip.Enabled              = false;
                    listViewFiles.Enabled          = false;
                    toolStripExtractButton.Enabled = false;

                    firstStatusLabel.Text = "Extracting " + listViewFiles.CheckedItems.Count.ToString() + " files...";

                    string target = (string)listViewFiles.CheckedItems[0].Tag;

                    var fileList = GetCheckedFileNames();
                    progressBar.Visible = true;
                    progressBar.Value   = 0;
                    progressBar.Maximum = fileList.Values.Sum(x => x.Count) + 1;
                    progressBar.Style   = ProgressBarStyle.Continuous;

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

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

                    await Task.Run(() => HpiFile.DoExtraction(fileList, dialogExtractToFolder.SelectedPath, progress));

                    timer.Stop();

                    firstStatusLabel.Text = String.Format("Done! Elapsed time: {0}m {1}s {2}ms", timer.Elapsed.Minutes,
                                                          timer.Elapsed.Seconds, timer.Elapsed.Milliseconds);
                    progressBar.Value      = progressBar.Maximum;
                    secondStatusLabel.Text = dialogExtractToFolder.SelectedPath;
                    toolStrip.Enabled      = true;
                    listViewFiles.Enabled  = true;
                    ChangeArchiverMode(true, true);
                }
            }
        }
Пример #3
0
        public List <ListViewItem> GetListViewGroupItens(string fullPath)
        {
            var listColection = new List <ListViewItem>();
            //Check if path is a directory or file
            FileAttributes fileAtt = File.GetAttributes(fullPath);

            if (fileAtt.HasFlag(FileAttributes.Directory)) //Directory
            {
                var fileList = Directory.GetFiles(fullPath, "*", SearchOption.AllDirectories);
                var group    = new ListViewGroup(fullPath, "Dir: " + fullPath);
                foreach (var file in fileList)
                {
                    var finfo = new FileInfo(file);
                    if (finfo.Length > Int32.MaxValue)
                    {
                        throw new Exception(finfo.Name + " is too large. File maximum size is 2GB (2 147 483 647 bytes).");
                    }

                    ListViewItem lvItem = new ListViewItem(group);
                    lvItem.Tag = fullPath;
                    var subItems = new ListViewItem.ListViewSubItem[3];
                    for (int i = 0; i < subItems.Length; i++)
                    {
                        subItems[i] = new ListViewItem.ListViewSubItem();
                    }
                    subItems[0].Text = file.Substring(fullPath.Length + 1);
                    subItems[0].Tag  = fullPath;
                    subItems[1].Text = Path.GetExtension(file).ToUpper();
                    subItems[2].Text = finfo.Length.ToString("N0");
                    subItems[2].Tag  = (int)finfo.Length;
                    lvItem.SubItems.AddRange(subItems);
                    listColection.Add(lvItem);
                }
            }
            else //HPI File or Files
            {
                var group = new ListViewGroup(fullPath, Path.GetExtension(fullPath).ToUpper() + " File: " + fullPath);
                using (HpiArchive hpia = HpiFile.Open(fullPath))
                    foreach (var entry in hpia.Entries)
                    {
                        ListViewItem lvItem = new ListViewItem(group);
                        lvItem.Tag = fullPath;
                        var subItems = new ListViewItem.ListViewSubItem[5];
                        for (int i = 0; i < subItems.Length; i++)
                        {
                            subItems[i] = new ListViewItem.ListViewSubItem();
                        }
                        subItems[0].Text = entry.Key;
                        subItems[0].Tag  = fullPath;
                        subItems[1].Text = Path.GetExtension(entry.Key).ToUpper();
                        subItems[2].Text = entry.Value.UncompressedSize.ToString("N0");
                        subItems[2].Tag  = entry.Value.UncompressedSize;
                        subItems[3].Text = entry.Value.CompressedSizeCount().ToString("N0");
                        subItems[3].Tag  = entry.Value.CompressedSizeCount();
                        subItems[4].Text = entry.Value.Ratio().ToString("P1");
                        subItems[4].Tag  = entry.Value.Ratio();
                        lvItem.SubItems.AddRange(subItems);
                        listColection.Add(lvItem);
                    }
            }

            return(listColection);
        }