예제 #1
0
 /// <summary>
 /// update archive file to use file or directory as item
 /// </summary>
 /// <param name="existingArchive"></param>
 /// <param name="addFileOrDirectory"></param>
 /// <param name="directoryPathInArchive"></param>
 public static void UpdateArchiveItem(ZipFileInfo existingArchive, string addFileOrDirectory, string directoryPathInArchive)
 {
     using (var zip = ZipFile.Read(existingArchive.Filename))
     {
         zip.UseZip64WhenSaving = Zip64Option.AsNecessary;
         zip.UpdateItem(addFileOrDirectory, directoryPathInArchive);
         zip.Save();
     }
 }
예제 #2
0
 /// <summary>
 /// compress a directory
 /// </summary>
 /// <param name="archive"></param>
 /// <param name="directoryName"></param>
 public static void CompressDirectory(ZipFileInfo archive, string directoryName)
 {
     using (var zip = new ZipFile(Encoding.UTF8))
     {
         SetZipFile(zip, archive);
         zip.AddDirectory(directoryName);
         zip.Save(archive.Filename);
     }
 }
예제 #3
0
 private static void SetZipFile(ZipEntry zipEntry, ZipFileInfo file)
 {
     if (!string.IsNullOrEmpty(file.Password))
     {
         zipEntry.Password = file.Password;
     }
     zipEntry.Comment           = file.Comment;
     zipEntry.CompressionMethod = (Ionic.Zip.CompressionMethod)((int)file.CompressionMethod);
     zipEntry.CompressionLevel  = (Ionic.Zlib.CompressionLevel)((int)file.CompressionLevel);
 }
예제 #4
0
 /// <summary>
 /// compress a file to archive file
 /// </summary>
 /// <param name="archive"></param>
 /// <param name="directoryName"></param>
 /// <param name="directoryPathInArchive"></param>
 public static void CompressAndSpecifyPathArchive(ZipFileInfo archive, string directoryName, string directoryPathInArchive)
 {
     using (var zip = new ZipFile(Encoding.UTF8))
     {
         SetZipFile(zip, archive);
         var entry = zip.AddDirectory(directoryName, directoryPathInArchive);
         SetZipFile(entry, archive);
         zip.Save(archive.Filename);
     }
 }
예제 #5
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="archive"></param>
 /// <param name="stream"></param>
 /// <param name="streamFile"></param>
 public static void AddStreamToArchive(ZipFileInfo archive, ZipFileInfo streamFile, Stream stream)
 {
     using (var zip = new ZipFile(Encoding.UTF8))
     {
         SetZipFile(zip, archive);
         var entry = zip.AddEntry(streamFile.Filename, stream);
         SetZipFile(entry, streamFile);
         zip.Save(archive.Filename);
     }
 }
예제 #6
0
 /// <summary>
 /// compress any files
 /// </summary>
 /// <param name="archive"></param>
 /// <param name="fileInfos"></param>
 public static void CompressFile(ZipFileInfo archive, List <ZipFileInfo> fileInfos, string directoryPathInArchive)
 {
     using (var zip = new ZipFile(Encoding.UTF8))
     {
         SetZipFile(zip, archive);
         foreach (var file in fileInfos)
         {
             SetZipFile(zip, file);
             zip.AddFile(file.Filename, directoryPathInArchive);
         }
         zip.Save(archive.Filename);
     }
 }
예제 #7
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="existingArchive"></param>
 /// <param name="filePathInArchive"></param>
 /// <returns></returns>
 public static bool ExistItemInArchive(ZipFileInfo existingArchive, string filePathInArchive)
 {
     using (var zip = ZipFile.Read(existingArchive.Filename))
     {
         zip.UseZip64WhenSaving = Zip64Option.AsNecessary;
         var entryQuery = zip.Entries.Where(o => o.FileName.Equals(filePathInArchive));
         if (!entryQuery.Any())
         {
             return(false);
         }
         return(true);
     }
 }