Exemplo n.º 1
0
        ////////////////////////////////////////////////////////////////////
        // Open zip file
        ////////////////////////////////////////////////////////////////////

        private void OnOpen
        (
            object sender,
            EventArgs e
        )
        {
            // get zip file name from operator
            OpenFileDialog OFD = new OpenFileDialog();

            OFD.Filter           = "Zip files (*.ZIP)|*.ZIP";
            OFD.CheckFileExists  = true;
            OFD.CheckPathExists  = true;
            OFD.RestoreDirectory = true;
            if (OFD.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            // display empty datagrid
            AddDataGrid();

            // trace
            Trace.Write("Open exising ZIP archive: " + OFD.FileName);

            // create inflate object
            if (Inflate == null)
            {
                Inflate = new InflateZipFile();
            }

            // inflate is already open
            else if (InflateZipFile.IsOpen(Inflate))
            {
                // delete zip directory
                ZipDir = null;

                // close previous zip archive (if open)
                Inflate.CloseZipFile();

                // display empty directory in data grid view
                LoadDataGrid();
            }

            // open zip file and load zip file directory
            if (Inflate.OpenZipFile(OFD.FileName))
            {
                MessageBox.Show("Open ZIP file Error\n" + Inflate.ExceptionStack[0] + "\n" + Inflate.ExceptionStack[1]);
                return;
            }

            // get zip directory
            ZipDir = Inflate.ZipDir;

            // display zip file directory in data grid view
            LoadDataGrid();
            return;
        }
Exemplo n.º 2
0
        ////////////////////////////////////////////////////////////////////
        // Form is closing
        ////////////////////////////////////////////////////////////////////

        private void OnClosing
        (
            object sender,
            FormClosingEventArgs e
        )
        {
            // Inflate is active. Close the zip archive file
            if (InflateZipFile.IsOpen(Inflate))
            {
                Inflate.CloseZipFile();
            }

            // deflate is active
            if (Deflate != null)
            {
                // new archive is not empty
                if (!Deflate.IsEmpty)
                {
                    switch (MessageBox.Show(this, "Do you want to save your ZIP archive?\n" +
                                            "If you select NO, the archive will be deleted", "Save ZIP Archive",
                                            MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question))
                    {
                    case DialogResult.Cancel:
                        e.Cancel = true;
                        return;

                    case DialogResult.Yes:
                        OnSave();
                        break;

                    case DialogResult.No:
                        // clearing the zip directory will make SaveArchive delete the file
                        Deflate.ClearArchive();
                        break;
                    }
                }

                // deflate is empty
                else
                {
                    // save archive will delete the archive because it is empty
                    Deflate.ClearArchive();
                }
            }

            // trace exit
            Trace.Write("UZipDotNet exit");
            return;
        }
Exemplo n.º 3
0
        ////////////////////////////////////////////////////////////////////
        // Switch from extract zip to update zip
        ////////////////////////////////////////////////////////////////////

        private Boolean SwitchMode()
        {
            // inflate archive is not open
            if (!InflateZipFile.IsOpen(Inflate))
            {
                return(false);
            }

            // ask operator
            ArchiveUpdateForm Dialog = new ArchiveUpdateForm();

            Dialog.Inflate = Inflate;
            if (Dialog.ShowDialog(this) == DialogResult.Cancel)
            {
                return(true);
            }

            // create deflate object
            if (Deflate == null)
            {
                Deflate = new DeflateZipFile();
            }

            // reopen exiting zip file for read and write
            if (Deflate.OpenArchive(Inflate.ArchiveName))
            {
                MessageBox.Show("Reopen ZIP file Error\n" + Deflate.ExceptionStack[0] + "\n" + Deflate.ExceptionStack[1]);

                // get link to the empty zip directory
                ZipDir = null;

                // display zip file directory in data grid view
                LoadDataGrid();
                return(true);
            }

            // get zip directory
            ZipDir = Deflate.ZipDir;

            // display zip file directory in data grid view
            LoadDataGrid();

            // successful switch
            return(false);
        }
Exemplo n.º 4
0
        ////////////////////////////////////////////////////////////////////
        // Display archive name
        ////////////////////////////////////////////////////////////////////

        private void DisplayArchiveName()
        {
            // archive is open for reading
            if (InflateZipFile.IsOpen(Inflate))
            {
                ArchiveNameLabel.BackColor = Color.FromArgb(192, 255, 255);
                ArchiveNameLabel.Text      = Inflate.ArchiveName;
            }

            // archive is open for writing
            else if (DeflateZipFile.IsOpen(Deflate))
            {
                ArchiveNameLabel.BackColor = Color.FromArgb(255, 192, 255);
                ArchiveNameLabel.Text      = Deflate.ArchiveName;
            }

            // archive is not open
            else
            {
                ArchiveNameLabel.BackColor = SystemColors.Control;
                ArchiveNameLabel.Text      = "UZipDotNet";
            }

            // calculate required width
            Int32 Width = (Int32)Math.Ceiling(CreateGraphics().MeasureString(ArchiveNameLabel.Text, ArchiveNameLabel.Font).Width) + 50;

            // archive name position
            ArchiveNameLabel.Width = Math.Min(Math.Max(Width, 200), ClientSize.Width - 50);
            ArchiveNameLabel.Left  = (ClientSize.Width - ArchiveNameLabel.Width) / 2;
            ArchiveNameLabel.Top   = 8;

            // enable/disable some buttons
            OpenButton.Enabled    = !DeflateZipFile.IsOpen(Deflate);
            ExtractButton.Enabled = InflateZipFile.IsOpen(Inflate);
            AddButton.Enabled     = InflateZipFile.IsOpen(Inflate) || DeflateZipFile.IsOpen(Deflate);
            DeleteButton.Enabled  = AddButton.Enabled;

            // change button name
            NewButton.Text = DeflateZipFile.IsOpen(Deflate) ? "Save" : "New";

            // update control
            Refresh();
            return;
        }
Exemplo n.º 5
0
        ////////////////////////////////////////////////////////////////////
        // New/Save archive file
        ////////////////////////////////////////////////////////////////////

        private void OnNew
        (
            object sender,
            EventArgs e
        )
        {
            // test for save mode
            if (DeflateZipFile.IsOpen(Deflate))
            {
                OnSave();
                return;
            }

            // get zip file name from operator
            SaveFileDialog SFD = new SaveFileDialog();

            SFD.Filter           = "Zip files (*.zip)|*.zip";
            SFD.CheckFileExists  = false;
            SFD.CheckPathExists  = true;
            SFD.RestoreDirectory = true;
            SFD.OverwritePrompt  = true;
            SFD.DefaultExt       = "zip";
            SFD.AddExtension     = true;
            if (SFD.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            // display empty datagrid
            AddDataGrid();

            // trace
            Trace.Write("Create ZIP archive: " + SFD.FileName);

            // Inflate file is open
            if (InflateZipFile.IsOpen(Inflate))
            {
                // release zip directory object
                ZipDir = null;

                // close inflate zip file if open
                Inflate.CloseZipFile();

                // display zip file directory in data grid view
                LoadDataGrid();
            }

            // create deflate object
            if (Deflate == null)
            {
                Deflate = new DeflateZipFile();
            }

            // create empty zip file
            if (Deflate.CreateArchive(SFD.FileName))
            {
                MessageBox.Show("Create ZIP file Error\n" + Deflate.ExceptionStack[0] + "\n" + Deflate.ExceptionStack[1]);
                return;
            }

            // get link to the empty zip directory
            ZipDir = Deflate.ZipDir;

            // display zip file directory in data grid view
            LoadDataGrid();
            return;
        }