///////////////////////////////////////////////////////////////// // Update file ///////////////////////////////////////////////////////////////// private Boolean UpdateFile() { // translate to file header FileHeader FH = ZipDir[DirIndex]; String FullFileName = RootDir.EndsWith("\\") ? RootDir + FH.FileName : RootDir + "\\" + FH.FileName; // save directory name in zip file if ((FH.FileAttr & FileAttributes.Directory) != 0) { if (Deflate.SaveDirectoryPath(FullFileName, FH.FileName)) { Trace.Write("Save directory path error\n" + Deflate.ExceptionStack[0] + "\n" + Deflate.ExceptionStack[1]); AppendStatus("Save directory failed [" + Deflate.ExceptionStack[0] + "]"); return(true); } } // compress file else { Deflate.CompressionLevel = CompLevel; if (Deflate.Compress(FullFileName, FH.FileName)) { Trace.Write("Compression Error\n" + Deflate.ExceptionStack[0] + "\n" + Deflate.ExceptionStack[1]); AppendStatus("Compression failed [" + Deflate.ExceptionStack[0] + "]"); return(true); } } // successful return AppendStatus("OK"); return(false); }
//////////////////////////////////////////////////////////////////// // 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); }