Esempio 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;
        }
Esempio n. 2
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);
        }