Exemple #1
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);
        }
Exemple #2
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;
        }
Exemple #3
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;
        }
Exemple #4
0
 public static Boolean  IsOpen(DeflateZipFile Deflate)
 {
     return(Deflate != null && Deflate.WriteFile != null);
 }
Exemple #5
0
        ////////////////////////////////////////////////////////////////////
        // Test Single File
        ////////////////////////////////////////////////////////////////////

        private Int32 TestZip()
        {
            // add extension to compressed file name
            CompFileName += ".zip";

            // create compressiom object
            DeflateZipFile Def = new DeflateZipFile(CompLevel);

            // create empty zip file
            if (Def.CreateArchive(CompFileName))
            {
                // save exception stack on error
                ExceptionStack = Def.ExceptionStack;
                return(1);
            }

            // split the input file name to path and name
            String FileName;
            Int32  Ptr = InputFileName.LastIndexOf('\\');

            FileName = Ptr < 0 ? InputFileName : InputFileName.Substring(Ptr + 1);

            // save start time
            Int32 StartTime = Environment.TickCount;

            // compress file
            if (Def.Compress(InputFileName, FileName))
            {
                // save exception stack on error
                ExceptionStack = Def.ExceptionStack;
                return(1);
            }

            // save compression elapse time
            CompTime = Environment.TickCount - StartTime;

            // save input and compressed file length
            InputFileLen = Def.ReadTotal;
            CompFileLen  = Def.WriteTotal;

            // save archive
            if (Def.SaveArchive())
            {
                // save exception stack on error
                ExceptionStack = Def.ExceptionStack;
                return(1);
            }

            // save start time
            StartTime = Environment.TickCount;

            // create decompression object
            InflateZipFile Inf = new InflateZipFile();

            // open the zip file
            if (Inf.OpenZipFile(CompFileName))
            {
                // save exception stack on error
                ExceptionStack = Inf.ExceptionStack;
                return(2);
            }

            // decompress the file
            if (Inf.DecompressZipFile(Inf.ZipDir[0], null, DecompFileName, false, true))
            {
                // save exception stack on error
                ExceptionStack = Inf.ExceptionStack;
                return(2);
            }

            // save decompression elapse time
            DecompTime = Environment.TickCount - StartTime;

            // save restored file length
            DecompFileLen = Inf.WriteTotal;

            // close the zip file
            Inf.CloseZipFile();

            // successful exit
            return(0);
        }
Exemple #6
0
 public static bool IsOpen(DeflateZipFile deflate)
 {
     return(deflate != null && deflate._writeFile != null);
 }
 public static bool IsOpen(DeflateZipFile deflate)
 {
     return deflate != null && deflate._writeFile != null;
 }