本文整理汇总了C#中ICSharpCode.SharpZipLib.Zip.ZipHelperStream.WriteEndOfCentralDirectory方法的典型用法代码示例。如果您正苦于以下问题:C# ZipHelperStream.WriteEndOfCentralDirectory方法的具体用法?C# ZipHelperStream.WriteEndOfCentralDirectory怎么用?C# ZipHelperStream.WriteEndOfCentralDirectory使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ICSharpCode.SharpZipLib.Zip.ZipHelperStream
的用法示例。
在下文中一共展示了ZipHelperStream.WriteEndOfCentralDirectory方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RunUpdates
void RunUpdates()
{
long sizeEntries = 0;
long endOfStream = 0;
bool directUpdate = false;
long destinationPosition = 0; // NOT SFX friendly
ZipFile workFile;
if ( IsNewArchive ) {
workFile = this;
workFile.baseStream_.Position = 0;
directUpdate = true;
}
else if ( archiveStorage_.UpdateMode == FileUpdateMode.Direct ) {
workFile = this;
workFile.baseStream_.Position = 0;
directUpdate = true;
// Sort the updates by offset within copies/modifies, then adds.
// This ensures that data required by copies will not be overwritten.
updates_.Sort(new UpdateComparer());
}
else {
workFile = ZipFile.Create(archiveStorage_.GetTemporaryOutput());
workFile.UseZip64 = UseZip64;
if (key != null) {
workFile.key = (byte[])key.Clone();
}
}
try {
foreach ( ZipUpdate update in updates_ ) {
if (update != null) {
switch (update.Command) {
case UpdateCommand.Copy:
if (directUpdate) {
CopyEntryDirect(workFile, update, ref destinationPosition);
}
else {
CopyEntry(workFile, update);
}
break;
case UpdateCommand.Modify:
// TODO: Direct modifying of an entry will take some legwork.
ModifyEntry(workFile, update);
break;
case UpdateCommand.Add:
if (!IsNewArchive && directUpdate) {
workFile.baseStream_.Position = destinationPosition;
}
AddEntry(workFile, update);
if (directUpdate) {
destinationPosition = workFile.baseStream_.Position;
}
break;
}
}
}
if ( !IsNewArchive && directUpdate ) {
workFile.baseStream_.Position = destinationPosition;
}
long centralDirOffset = workFile.baseStream_.Position;
foreach ( ZipUpdate update in updates_ ) {
if (update != null) {
sizeEntries += workFile.WriteCentralDirectoryHeader(update.OutEntry);
}
}
byte[] theComment = (newComment_ != null) ? newComment_.RawComment : ZipConstants.ConvertToArray(comment_);
using ( ZipHelperStream zhs = new ZipHelperStream(workFile.baseStream_) ) {
zhs.WriteEndOfCentralDirectory(updateCount_, sizeEntries, centralDirOffset, theComment);
}
endOfStream = workFile.baseStream_.Position;
// And now patch entries...
foreach ( ZipUpdate update in updates_ ) {
if (update != null)
{
// If the size of the entry is zero leave the crc as 0 as well.
// The calculated crc will be all bits on...
if ((update.CrcPatchOffset > 0) && (update.OutEntry.CompressedSize > 0)) {
workFile.baseStream_.Position = update.CrcPatchOffset;
workFile.WriteLEInt((int)update.OutEntry.Crc);
}
if (update.SizePatchOffset > 0) {
workFile.baseStream_.Position = update.SizePatchOffset;
if (update.OutEntry.LocalHeaderRequiresZip64) {
workFile.WriteLeLong(update.OutEntry.Size);
workFile.WriteLeLong(update.OutEntry.CompressedSize);
//.........这里部分代码省略.........
示例2: Finish
//.........这里部分代码省略.........
if (entry.IsZip64Forced() ||
(entry.Size >= 0xffffffff))
{
ed.AddLeLong(entry.Size);
}
if (entry.IsZip64Forced() ||
(entry.CompressedSize >= 0xffffffff))
{
ed.AddLeLong(entry.CompressedSize);
}
if (entry.Offset >= 0xffffffff)
{
ed.AddLeLong(entry.Offset);
}
ed.AddNewEntry(1);
}
else
{
ed.Delete(1);
}
#if !NET_1_1 && !NETCF_2_0
if (entry.AESKeySize > 0)
{
AddExtraDataAES(entry, ed);
}
#endif
byte[] extra = ed.GetEntryData();
byte[] entryComment =
(entry.Comment != null)
? ZipConstants.ConvertToArray(entry.Flags, entry.Comment)
: new byte[0];
if (entryComment.Length > 0xffff)
{
throw new ZipException("Comment too long.");
}
WriteLeShort(name.Length);
WriteLeShort(extra.Length);
WriteLeShort(entryComment.Length);
WriteLeShort(0); // disk number
WriteLeShort(0); // internal file attributes
// external file attributes
if (entry.ExternalFileAttributes != -1)
{
WriteLeInt(entry.ExternalFileAttributes);
}
else
{
if (entry.IsDirectory)
{
// mark entry as directory (from nikolam.AT.perfectinfo.com)
WriteLeInt(16);
}
else
{
WriteLeInt(0);
}
}
if (entry.Offset >= uint.MaxValue)
{
WriteLeInt(-1);
}
else
{
WriteLeInt((int) entry.Offset);
}
if (name.Length > 0)
{
baseOutputStream_.Write(name, 0, name.Length);
}
if (extra.Length > 0)
{
baseOutputStream_.Write(extra, 0, extra.Length);
}
if (entryComment.Length > 0)
{
baseOutputStream_.Write(entryComment, 0, entryComment.Length);
}
sizeEntries += ZipConstants.CentralHeaderBaseSize + name.Length + extra.Length + entryComment.Length;
}
using (var zhs = new ZipHelperStream(baseOutputStream_))
{
zhs.WriteEndOfCentralDirectory(numEntries, sizeEntries, offset, zipComment);
}
entries = null;
}
示例3: CommitUpdate
/// <summary>
/// Commit current updates, updating this archive.
/// </summary>
/// <seealso cref="BeginUpdate()"></seealso>
/// <seealso cref="AbortUpdate"></seealso>
/// <exception cref="ObjectDisposedException">ZipFile has been closed.</exception>
public void CommitUpdate()
{
if ( isDisposed_ ) {
throw new ObjectDisposedException("ZipFile");
}
CheckUpdating();
try {
updateIndex_.Clear();
updateIndex_=null;
if( contentsEdited_ ) {
RunUpdates();
}
else if( commentEdited_ ) {
UpdateCommentOnly();
}
else {
// Create an empty archive if none existed originally.
if( entries_.Length==0 ) {
byte[] theComment=(newComment_!=null)?newComment_.RawComment:ZipConstants.ConvertToArray(comment_);
using( ZipHelperStream zhs=new ZipHelperStream(baseStream_) ) {
zhs.WriteEndOfCentralDirectory(0, 0, 0, theComment);
}
}
}
}
finally {
PostUpdateCleanup();
}
}
示例4: CommitUpdate
/// <summary>
/// Commit current updates, updating this archive.
/// </summary>
/// <seealso cref="BeginUpdate()"></seealso>
/// <seealso cref="AbortUpdate"></seealso>
public void CommitUpdate()
{
CheckUpdating();
if ( contentsEdited_ ) {
RunUpdates();
}
else if ( commentEdited_ ) {
UpdateCommentOnly();
}
else {
// Create an empty archive if none existed originally.
if ( (entries_ != null) && (entries_.Length == 0) ) {
byte[] theComment = (newComment_ != null) ? newComment_.RawComment : ZipConstants.ConvertToArray(comment_);
using ( ZipHelperStream zhs = new ZipHelperStream(baseStream_) ) {
zhs.WriteEndOfCentralDirectory(0, 0, 0, theComment);
}
}
}
PostUpdateCleanup();
}
示例5: RunUpdates
void RunUpdates()
{
long sizeEntries = 0;
long endOfStream = 0;
bool allOk = true;
bool directUpdate = false;
long destinationPosition = 0;
ZipFile workFile;
if ( IsNewArchive ) {
workFile = this;
workFile.baseStream_.Position = 0;
directUpdate = true;
}
else if ( archiveStorage_.UpdateMode == FileUpdateMode.Direct ) {
workFile = this;
workFile.baseStream_.Position = 0;
directUpdate = true;
updates_.Sort(new UpdateComparer());
}
else {
workFile = ZipFile.Create(archiveStorage_.GetTemporaryOutput());
workFile.UseZip64 = UseZip64;
if (key != null) {
workFile.key = (byte[])key.Clone();
}
}
try {
foreach ( ZipUpdate update in updates_ ) {
if (update != null) {
switch (update.Command) {
case UpdateCommand.Copy:
if (directUpdate) {
CopyEntryDirect(workFile, update, ref destinationPosition);
}
else {
CopyEntry(workFile, update);
}
break;
case UpdateCommand.Modify:
ModifyEntry(workFile, update);
break;
case UpdateCommand.Add:
if (!IsNewArchive && directUpdate) {
workFile.baseStream_.Position = destinationPosition;
}
AddEntry(workFile, update);
if (directUpdate) {
destinationPosition = workFile.baseStream_.Position;
}
break;
}
}
}
if ( !IsNewArchive && directUpdate ) {
workFile.baseStream_.Position = destinationPosition;
}
long centralDirOffset = workFile.baseStream_.Position;
foreach ( ZipUpdate update in updates_ ) {
if (update != null) {
sizeEntries += workFile.WriteCentralDirectoryHeader(update.OutEntry);
}
}
byte[] theComment = (newComment_ != null) ? newComment_.RawComment : ZipConstants.ConvertToArray(comment_);
using ( ZipHelperStream zhs = new ZipHelperStream(workFile.baseStream_) ) {
zhs.WriteEndOfCentralDirectory(updateCount_, sizeEntries, centralDirOffset, theComment);
}
endOfStream = workFile.baseStream_.Position;
foreach ( ZipUpdate update in updates_ ) {
if (update != null)
{
if ((update.CrcPatchOffset > 0) && (update.OutEntry.CompressedSize > 0)) {
workFile.baseStream_.Position = update.CrcPatchOffset;
workFile.WriteLEInt((int)update.OutEntry.Crc);
}
if (update.SizePatchOffset > 0) {
workFile.baseStream_.Position = update.SizePatchOffset;
if (update.OutEntry.LocalHeaderRequiresZip64) {
workFile.WriteLeLong(update.OutEntry.Size);
workFile.WriteLeLong(update.OutEntry.CompressedSize);
}
else {
workFile.WriteLEInt((int)update.OutEntry.CompressedSize);
workFile.WriteLEInt((int)update.OutEntry.Size);
}
//.........这里部分代码省略.........
示例6: CommitUpdate
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();
}
}
示例7: RunUpdates
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_00EC;
}
this.CopyEntryDirect(file, update, ref destinationPosition);
continue;
}
case UpdateCommand.Modify:
{
this.ModifyEntry(file, update);
continue;
}
case UpdateCommand.Add:
goto Label_0104;
}
}
continue;
Label_00EC:
this.CopyEntry(file, update);
continue;
Label_0104:
if (!this.IsNewArchive && flag)
{
file.baseStream_.Position = destinationPosition;
}
this.AddEntry(file, update);
if (flag)
{
destinationPosition = file.baseStream_.Position;
}
}
if (!this.IsNewArchive && flag)
{
file.baseStream_.Position = destinationPosition;
}
long position = file.baseStream_.Position;
foreach (ZipUpdate update2 in this.updates_)
{
if (update2 != null)
{
sizeEntries += file.WriteCentralDirectoryHeader(update2.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 update3 in this.updates_)
{
if (update3 != null)
{
if ((update3.CrcPatchOffset > 0L) && (update3.OutEntry.CompressedSize > 0L))
{
file.baseStream_.Position = update3.CrcPatchOffset;
file.WriteLEInt((int) update3.OutEntry.Crc);
}
if (update3.SizePatchOffset > 0L)
{
file.baseStream_.Position = update3.SizePatchOffset;
//.........这里部分代码省略.........
示例8: Finish
//.........这里部分代码省略.........
this.WriteLeInt((int) entry.Crc);
if (entry.IsZip64Forced() || (entry.CompressedSize >= 0xffffffffL))
{
this.WriteLeInt(-1);
}
else
{
this.WriteLeInt((int) entry.CompressedSize);
}
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("Name too long.");
}
ZipExtraData extraData = new ZipExtraData(entry.ExtraData);
if (entry.CentralHeaderRequiresZip64)
{
extraData.StartNewEntry();
if (entry.IsZip64Forced() || (entry.Size >= 0xffffffffL))
{
extraData.AddLeLong(entry.Size);
}
if (entry.IsZip64Forced() || (entry.CompressedSize >= 0xffffffffL))
{
extraData.AddLeLong(entry.CompressedSize);
}
if (entry.Offset >= 0xffffffffL)
{
extraData.AddLeLong(entry.Offset);
}
extraData.AddNewEntry(1);
}
else
{
extraData.Delete(1);
}
if (entry.AESKeySize > 0)
{
AddExtraDataAES(entry, extraData);
}
byte[] entryData = extraData.GetEntryData();
byte[] buffer3 = (entry.Comment != null) ? ZipConstants.ConvertToArray(entry.Flags, entry.Comment) : new byte[0];
if (buffer3.Length > 0xffff)
{
throw new ZipException("Comment too long.");
}
this.WriteLeShort(buffer.Length);
this.WriteLeShort(entryData.Length);
this.WriteLeShort(buffer3.Length);
this.WriteLeShort(0);
this.WriteLeShort(0);
if (entry.ExternalFileAttributes != -1)
{
this.WriteLeInt(entry.ExternalFileAttributes);
}
else if (entry.IsDirectory)
{
this.WriteLeInt(0x10);
}
else
{
this.WriteLeInt(0);
}
if (entry.Offset >= 0xffffffffL)
{
this.WriteLeInt(-1);
}
else
{
this.WriteLeInt((int) entry.Offset);
}
if (buffer.Length > 0)
{
base.baseOutputStream_.Write(buffer, 0, buffer.Length);
}
if (entryData.Length > 0)
{
base.baseOutputStream_.Write(entryData, 0, entryData.Length);
}
if (buffer3.Length > 0)
{
base.baseOutputStream_.Write(buffer3, 0, buffer3.Length);
}
sizeEntries += ((0x2e + buffer.Length) + entryData.Length) + buffer3.Length;
}
using (ZipHelperStream stream = new ZipHelperStream(base.baseOutputStream_))
{
stream.WriteEndOfCentralDirectory(count, sizeEntries, this.offset, this.zipComment);
}
this.entries = null;
}
}