Пример #1
0
        ////////////////////////////////////////////////////////////////////
        // Add file to archive
        ////////////////////////////////////////////////////////////////////

        private void OnAdd
        (
            object sender,
            EventArgs e
        )
        {
            // if inflate is open, switch to deflate mode
            if (SwitchMode())
            {
                return;
            }

            // display files and folders selection screen
            AddFilesAndFoldersForm AddFilesDialog = new AddFilesAndFoldersForm();

            if (AddFilesDialog.ShowDialog(this) == DialogResult.Cancel)
            {
                return;
            }

            // create update dialog
            ProcessFilesForm UpdateDialog = new ProcessFilesForm();

            // display extract dialog
            UpdateDialog.UpdateMode = true;
            UpdateDialog.ZipDir     = AddFilesDialog.AddDir;
            UpdateDialog.RootDir    = AddFilesDialog.RootDir;
            UpdateDialog.CompLevel  = AddFilesDialog.CompLevel;
            UpdateDialog.Deflate    = Deflate;
            UpdateDialog.ShowDialog(this);

            // display zip file directory in data grid view
            LoadDataGrid();
            return;
        }
Пример #2
0
        ////////////////////////////////////////////////////////////////////
        // Decompress file one or more files
        ////////////////////////////////////////////////////////////////////

        private void OnExtract
        (
            object sender,
            EventArgs e
        )
        {
            // display extract control dialog box
            ExtractSelectionForm SelectDialog = new ExtractSelectionForm();

            // get selected rows
            DataGridViewSelectedRowCollection RowCollection = DataGrid.SelectedRows;

            // count archive files (not directories) with deflate compression or no compression
            SelectDialog.ArchiveFiles = 0;
            SelectDialog.ArchiveSize  = 0;
            foreach (DataGridViewRow VR in DataGrid.Rows)
            {
                FileHeader FH = ZipDir[(Int32)VR.Tag];
                if ((FH.CompMethod == 0 || FH.CompMethod == 8) && (FH.FileAttr & FileAttributes.Directory) == 0)
                {
                    SelectDialog.ArchiveFiles++;
                    SelectDialog.ArchiveSize += FH.FileSize;
                }
            }

            // count selection files (not directories) with deflate compression or no compression
            SelectDialog.SelectionFiles = 0;
            SelectDialog.SelectionSize  = 0;
            foreach (DataGridViewRow VR in RowCollection)
            {
                FileHeader FH = ZipDir[(Int32)VR.Tag];
                if ((FH.CompMethod == 0 || FH.CompMethod == 8) && (FH.FileAttr & FileAttributes.Directory) == 0)
                {
                    SelectDialog.SelectionFiles++;
                    SelectDialog.SelectionSize += FH.FileSize;
                }
            }

            // show dialog
            if (SelectDialog.ShowDialog(this) == DialogResult.Cancel)
            {
                return;
            }

            // create extract dialog
            ProcessFilesForm ExtractDialog = new ProcessFilesForm();

            // user selected extract all
            if (ProgramState.State.ExtractAll)
            {
                ExtractDialog.ZipDir = ZipDir;
            }

            // create extract list if the user extract by selection
            else
            {
                ExtractDialog.ZipDir = new List <FileHeader>();
                foreach (DataGridViewRow VR in RowCollection)
                {
                    ExtractDialog.ZipDir.Add(ZipDir[(Int32)VR.Tag]);
                }
                ExtractDialog.ZipDir.Sort();
            }

            // display extract dialog
            ExtractDialog.UpdateMode = false;
            ExtractDialog.Inflate    = Inflate;
            ExtractDialog.Show(this);
            return;
        }