public void CommitUpdate() { if (this.isDisposed_) { throw new ObjectDisposedException("ZipFile"); } this.CheckUpdating(); try { this.updateIndex_.Clear(); this.updateIndex_ = null; if (this.contentsEdited_) { this.RunUpdates(); } else if (this.commentEdited_) { this.UpdateCommentOnly(); } else if (this.entries_.Length == 0) { byte[] comment = (this.newComment_ != null) ? this.newComment_.RawComment : ZipConstants.ConvertToArray(this.comment_); using (ZipHelperStream stream = new ZipHelperStream(this.baseStream_)) { stream.WriteEndOfCentralDirectory(0L, 0L, 0L, comment); } } } finally { this.PostUpdateCleanup(); } }
private void RunUpdates() { ZipFile file; long sizeEntries = 0L; long num2 = 0L; bool flag = false; long destinationPosition = 0L; if (this.IsNewArchive) { file = this; file.baseStream_.Position = 0L; flag = true; } else if (this.archiveStorage_.UpdateMode == FileUpdateMode.Direct) { file = this; file.baseStream_.Position = 0L; flag = true; this.updates_.Sort(new UpdateComparer()); } else { file = Create(this.archiveStorage_.GetTemporaryOutput()); file.UseZip64 = this.UseZip64; if (this.key != null) { file.key = (byte[]) this.key.Clone(); } } try { foreach (ZipUpdate update in this.updates_) { if (update != null) { switch (update.Command) { case UpdateCommand.Copy: if (!flag) { goto Label_012E; } this.CopyEntryDirect(file, update, ref destinationPosition); goto Label_0196; case UpdateCommand.Modify: this.ModifyEntry(file, update); goto Label_0196; case UpdateCommand.Add: if (!(this.IsNewArchive || !flag)) { file.baseStream_.Position = destinationPosition; } this.AddEntry(file, update); if (flag) { destinationPosition = file.baseStream_.Position; } goto Label_0196; } } goto Label_0196; Label_012E: this.CopyEntry(file, update); Label_0196:; } if (!(this.IsNewArchive || !flag)) { file.baseStream_.Position = destinationPosition; } long position = file.baseStream_.Position; foreach (ZipUpdate update in this.updates_) { if (update != null) { sizeEntries += file.WriteCentralDirectoryHeader(update.OutEntry); } } byte[] comment = (this.newComment_ != null) ? this.newComment_.RawComment : ZipConstants.ConvertToArray(this.comment_); using (ZipHelperStream stream = new ZipHelperStream(file.baseStream_)) { stream.WriteEndOfCentralDirectory(this.updateCount_, sizeEntries, position, comment); } num2 = file.baseStream_.Position; foreach (ZipUpdate update in this.updates_) { if (update != null) { if ((update.CrcPatchOffset > 0L) && (update.OutEntry.CompressedSize > 0L)) { file.baseStream_.Position = update.CrcPatchOffset; file.WriteLEInt((int) update.OutEntry.Crc); } if (update.SizePatchOffset > 0L) { file.baseStream_.Position = update.SizePatchOffset; if (update.OutEntry.LocalHeaderRequiresZip64) { file.WriteLeLong(update.OutEntry.Size); file.WriteLeLong(update.OutEntry.CompressedSize); } else { file.WriteLEInt((int) update.OutEntry.CompressedSize); file.WriteLEInt((int) update.OutEntry.Size); } } } } } catch { file.Close(); if (!(flag || (file.Name == null))) { File.Delete(file.Name); } throw; } if (flag) { file.baseStream_.SetLength(num2); file.baseStream_.Flush(); this.isNewArchive_ = false; this.ReadEntries(); } else { this.baseStream_.Close(); this.Reopen(this.archiveStorage_.ConvertTemporaryToFinal()); } }