示例#1
0
 private int WriteCentralDirectoryHeader(ZipEntry entry)
 {
     if (entry.CompressedSize < 0L)
     {
         throw new ZipException("Attempt to write central directory entry with unknown csize");
     }
     if (entry.Size < 0L)
     {
         throw new ZipException("Attempt to write central directory entry with unknown size");
     }
     if (entry.Crc < 0L)
     {
         throw new ZipException("Attempt to write central directory entry with unknown crc");
     }
     WriteLEInt(0x2014b50);
     WriteLEShort(0x33);
     WriteLEShort(entry.Version);
     WriteLEShort(entry.Flags);
     WriteLEShort((byte)entry.CompressionMethod);
     WriteLEInt((int)entry.DosTime);
     WriteLEInt((int)entry.Crc);
     if (entry.IsZip64Forced() || (entry.CompressedSize >= 0xffffffffL))
     {
         WriteLEInt(-1);
     }
     else
     {
         WriteLEInt((int)(((ulong)entry.CompressedSize) & 0xffffffffL));
     }
     if (entry.IsZip64Forced() || (entry.Size >= 0xffffffffL))
     {
         WriteLEInt(-1);
     }
     else
     {
         WriteLEInt((int)entry.Size);
     }
     byte[] buffer = ZipConstants.ConvertToArray(entry.Flags, entry.Name);
     if (buffer.Length > 0xffff)
     {
         throw new ZipException("Entry name is too long.");
     }
     WriteLEShort(buffer.Length);
     ZipExtraData data = new ZipExtraData(entry.ExtraData);
     if (entry.CentralHeaderRequiresZip64)
     {
         data.StartNewEntry();
         if ((entry.Size >= 0xffffffffL) || (useZip64_ == UseZip64.On))
         {
             data.AddLeLong(entry.Size);
         }
         if ((entry.CompressedSize >= 0xffffffffL) || (useZip64_ == UseZip64.On))
         {
             data.AddLeLong(entry.CompressedSize);
         }
         if (entry.Offset >= 0xffffffffL)
         {
             data.AddLeLong(entry.Offset);
         }
         data.AddNewEntry(1);
     }
     else
     {
         data.Delete(1);
     }
     byte[] entryData = data.GetEntryData();
     WriteLEShort(entryData.Length);
     WriteLEShort((entry.Comment != null) ? entry.Comment.Length : 0);
     WriteLEShort(0);
     WriteLEShort(0);
     if (entry.ExternalFileAttributes != -1)
     {
         WriteLEInt(entry.ExternalFileAttributes);
     }
     else if (entry.IsDirectory)
     {
         WriteLEUint(0x10);
     }
     else
     {
         WriteLEUint(0);
     }
     if (entry.Offset >= 0xffffffffL)
     {
         WriteLEUint(uint.MaxValue);
     }
     else
     {
         WriteLEUint((uint)((int)entry.Offset));
     }
     if (buffer.Length > 0)
     {
         baseStream_.Write(buffer, 0, buffer.Length);
     }
     if (entryData.Length > 0)
     {
         baseStream_.Write(entryData, 0, entryData.Length);
     }
     byte[] buffer3 = (entry.Comment != null) ? Encoding.ASCII.GetBytes(entry.Comment) : new byte[0];
     if (buffer3.Length > 0)
     {
         baseStream_.Write(buffer3, 0, buffer3.Length);
     }
     return (((0x2e + buffer.Length) + entryData.Length) + buffer3.Length);
 }