Beispiel #1
0
        ////////////////////////////////////////////////////////////////////
        // Save new archive file
        ////////////////////////////////////////////////////////////////////

        private void OnSave()
        {
            // clear local directory
            ZipDir = null;

            // Write zip directory and close deflate zip file
            if (Deflate.SaveArchive())
            {
                MessageBox.Show("Save ZIP file Error\n" + Deflate.ExceptionStack[0] + "\n" + Deflate.ExceptionStack[1]);
            }

            // display zip file directory in data grid view
            LoadDataGrid();
            return;
        }
Beispiel #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);
        }