private void WriteLocalEntryHeader(ZipUpdate update) { ZipEntry outEntry = update.OutEntry; outEntry.Offset = this.baseStream_.Position; if (update.Command != UpdateCommand.Copy) { if (outEntry.CompressionMethod == CompressionMethod.Deflated) { if (outEntry.Size == 0L) { outEntry.CompressedSize = outEntry.Size; outEntry.Crc = 0L; outEntry.CompressionMethod = CompressionMethod.Stored; } } else if (outEntry.CompressionMethod == CompressionMethod.Stored) { outEntry.Flags &= -9; } if (this.HaveKeys) { outEntry.IsCrypted = true; if (outEntry.Crc < 0L) { outEntry.Flags |= 8; } } else { outEntry.IsCrypted = false; } switch (this.useZip64_) { case Maticsoft.ZipLib.Zip.UseZip64.On: outEntry.ForceZip64(); break; case Maticsoft.ZipLib.Zip.UseZip64.Dynamic: if (outEntry.Size < 0L) { outEntry.ForceZip64(); } break; } } this.WriteLEInt(0x4034b50); this.WriteLEShort(outEntry.Version); this.WriteLEShort(outEntry.Flags); this.WriteLEShort((byte) outEntry.CompressionMethod); this.WriteLEInt((int) outEntry.DosTime); if (!outEntry.HasCrc) { update.CrcPatchOffset = this.baseStream_.Position; this.WriteLEInt(0); } else { this.WriteLEInt((int) outEntry.Crc); } if (outEntry.LocalHeaderRequiresZip64) { this.WriteLEInt(-1); this.WriteLEInt(-1); } else { if ((outEntry.CompressedSize < 0L) || (outEntry.Size < 0L)) { update.SizePatchOffset = this.baseStream_.Position; } this.WriteLEInt((int) outEntry.CompressedSize); this.WriteLEInt((int) outEntry.Size); } byte[] buffer = ZipConstants.ConvertToArray(outEntry.Flags, outEntry.Name); if (buffer.Length > 0xffff) { throw new ZipException("Entry name too long."); } ZipExtraData data = new ZipExtraData(outEntry.ExtraData); if (outEntry.LocalHeaderRequiresZip64) { data.StartNewEntry(); data.AddLeLong(outEntry.Size); data.AddLeLong(outEntry.CompressedSize); data.AddNewEntry(1); } else { data.Delete(1); } outEntry.ExtraData = data.GetEntryData(); this.WriteLEShort(buffer.Length); this.WriteLEShort(outEntry.ExtraData.Length); if (buffer.Length > 0) { this.baseStream_.Write(buffer, 0, buffer.Length); } if (outEntry.LocalHeaderRequiresZip64) { if (!data.Find(1)) { throw new ZipException("Internal error cannot find extra data"); } update.SizePatchOffset = this.baseStream_.Position + data.CurrentReadIndex; } if (outEntry.ExtraData.Length > 0) { this.baseStream_.Write(outEntry.ExtraData, 0, outEntry.ExtraData.Length); } }
private void WriteLocalHeader(ZipEntry entry, EntryPatchData patchData) { CompressionMethod compressionMethod = entry.CompressionMethod; bool flag = true; bool flag2 = false; this.WriteLEInt(0x4034b50); this.WriteLEShort(entry.Version); this.WriteLEShort(entry.Flags); this.WriteLEShort((byte) compressionMethod); this.WriteLEInt((int) entry.DosTime); if (flag) { this.WriteLEInt((int) entry.Crc); if (entry.LocalHeaderRequiresZip64) { this.WriteLEInt(-1); this.WriteLEInt(-1); } else { this.WriteLEInt(entry.IsCrypted ? (((int) entry.CompressedSize) + 12) : ((int) entry.CompressedSize)); this.WriteLEInt((int) entry.Size); } } else { if (patchData != null) { patchData.CrcPatchOffset = this.stream_.Position; } this.WriteLEInt(0); if (patchData != null) { patchData.SizePatchOffset = this.stream_.Position; } if (entry.LocalHeaderRequiresZip64 && flag2) { this.WriteLEInt(-1); this.WriteLEInt(-1); } else { this.WriteLEInt(0); this.WriteLEInt(0); } } byte[] buffer = ZipConstants.ConvertToArray(entry.Flags, entry.Name); if (buffer.Length > 0xffff) { throw new ZipException("Entry name too long."); } ZipExtraData data = new ZipExtraData(entry.ExtraData); if (entry.LocalHeaderRequiresZip64 && (flag || flag2)) { data.StartNewEntry(); if (flag) { data.AddLeLong(entry.Size); data.AddLeLong(entry.CompressedSize); } else { data.AddLeLong(-1L); data.AddLeLong(-1L); } data.AddNewEntry(1); if (!data.Find(1)) { throw new ZipException("Internal error cant find extra data"); } if (patchData != null) { patchData.SizePatchOffset = data.CurrentReadIndex; } } else { data.Delete(1); } byte[] entryData = data.GetEntryData(); this.WriteLEShort(buffer.Length); this.WriteLEShort(entryData.Length); if (buffer.Length > 0) { this.stream_.Write(buffer, 0, buffer.Length); } if (entry.LocalHeaderRequiresZip64 && flag2) { patchData.SizePatchOffset += this.stream_.Position; } if (entryData.Length > 0) { this.stream_.Write(entryData, 0, entryData.Length); } }
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"); } this.WriteLEInt(0x2014b50); this.WriteLEShort(0x33); this.WriteLEShort(entry.Version); this.WriteLEShort(entry.Flags); this.WriteLEShort((byte) entry.CompressionMethod); this.WriteLEInt((int) entry.DosTime); this.WriteLEInt((int) entry.Crc); if (entry.IsZip64Forced() || (entry.CompressedSize >= 0xffffffffL)) { this.WriteLEInt(-1); } else { this.WriteLEInt((int) (((ulong) entry.CompressedSize) & 0xffffffffL)); } if (entry.IsZip64Forced() || (entry.Size >= 0xffffffffL)) { this.WriteLEInt(-1); } else { this.WriteLEInt((int) entry.Size); } byte[] buffer = ZipConstants.ConvertToArray(entry.Flags, entry.Name); if (buffer.Length > 0xffff) { throw new ZipException("Entry name is too long."); } this.WriteLEShort(buffer.Length); ZipExtraData data = new ZipExtraData(entry.ExtraData); if (entry.CentralHeaderRequiresZip64) { data.StartNewEntry(); if ((entry.Size >= 0xffffffffL) || (this.useZip64_ == Maticsoft.ZipLib.Zip.UseZip64.On)) { data.AddLeLong(entry.Size); } if ((entry.CompressedSize >= 0xffffffffL) || (this.useZip64_ == Maticsoft.ZipLib.Zip.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(); this.WriteLEShort(entryData.Length); this.WriteLEShort((entry.Comment != null) ? entry.Comment.Length : 0); this.WriteLEShort(0); this.WriteLEShort(0); if (entry.ExternalFileAttributes != -1) { this.WriteLEInt(entry.ExternalFileAttributes); } else if (entry.IsDirectory) { this.WriteLEUint(0x10); } else { this.WriteLEUint(0); } if (entry.Offset >= 0xffffffffL) { this.WriteLEUint(uint.MaxValue); } else { this.WriteLEUint((uint) ((int) entry.Offset)); } if (buffer.Length > 0) { this.baseStream_.Write(buffer, 0, buffer.Length); } if (entryData.Length > 0) { this.baseStream_.Write(entryData, 0, entryData.Length); } byte[] buffer3 = (entry.Comment != null) ? Encoding.ASCII.GetBytes(entry.Comment) : new byte[0]; if (buffer3.Length > 0) { this.baseStream_.Write(buffer3, 0, buffer3.Length); } return (((0x2e + buffer.Length) + entryData.Length) + buffer3.Length); }