本文整理汇总了C#中ZipUpdate类的典型用法代码示例。如果您正苦于以下问题:C# ZipUpdate类的具体用法?C# ZipUpdate怎么用?C# ZipUpdate使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ZipUpdate类属于命名空间,在下文中一共展示了ZipUpdate类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: CopyEntryDataDirect
private void CopyEntryDataDirect(ZipUpdate update, Stream stream, bool updateCrc, ref long destinationPosition, ref long sourcePosition)
{
int num4;
long compressedSize = update.Entry.CompressedSize;
Crc32 crc = new Crc32();
byte[] buffer = GetBuffer();
long num2 = compressedSize;
long num3 = 0L;
do
{
int length = buffer.Length;
if (compressedSize < length)
{
length = (int)compressedSize;
}
stream.Position = sourcePosition;
num4 = stream.Read(buffer, 0, length);
if (num4 > 0)
{
if (updateCrc)
{
crc.Update(buffer, 0, num4);
}
stream.Position = destinationPosition;
stream.Write(buffer, 0, num4);
destinationPosition += num4;
sourcePosition += num4;
compressedSize -= num4;
num3 += num4;
}
}
while ((num4 > 0) && (compressedSize > 0L));
if (num3 != num2)
{
throw new ZipException(string.Format("Failed to copy bytes expected {0} read {1}", num2, num3));
}
if (updateCrc)
{
update.OutEntry.Crc = crc.Value;
}
}
开发者ID:ouyh18,项目名称:LteTools,代码行数:41,代码来源:ZipFile.cs
示例2: AddEntry
void AddEntry(ZipFile workFile, ZipUpdate update)
{
Stream source = null;
if ( update.Entry.IsFile ) {
source = update.GetSource();
if ( source == null ) {
source = updateDataSource_.GetSource(update.Entry, update.Filename);
}
}
if ( source != null ) {
using ( source ) {
long sourceStreamLength = source.Length;
if ( update.OutEntry.Size < 0 ) {
update.OutEntry.Size = sourceStreamLength;
}
else {
// Check for errant entries.
if ( update.OutEntry.Size != sourceStreamLength ) {
throw new ZipException("Entry size/stream size mismatch");
}
}
workFile.WriteLocalEntryHeader(update);
long dataStart = workFile.baseStream_.Position;
using ( Stream output = workFile.GetOutputStream(update.OutEntry) ) {
CopyBytes(update, output, source, sourceStreamLength, true);
}
long dataEnd = workFile.baseStream_.Position;
update.OutEntry.CompressedSize = dataEnd - dataStart;
if ((update.OutEntry.Flags & (int)GeneralBitFlags.Descriptor) == (int)GeneralBitFlags.Descriptor)
{
ZipHelperStream helper = new ZipHelperStream(workFile.baseStream_);
helper.WriteDataDescriptor(update.OutEntry);
}
}
}
else {
workFile.WriteLocalEntryHeader(update);
update.OutEntry.CompressedSize = 0;
}
}
开发者ID:jamesbascle,项目名称:SharpZipLib,代码行数:49,代码来源:ZipFile.cs
示例3: CopyEntryDirect
void CopyEntryDirect(ZipFile workFile, ZipUpdate update, ref long destinationPosition)
{
bool skipOver = false;
if ( update.Entry.Offset == destinationPosition ) {
skipOver = true;
}
if ( !skipOver ) {
baseStream_.Position = destinationPosition;
workFile.WriteLocalEntryHeader(update);
destinationPosition = baseStream_.Position;
}
long sourcePosition = 0;
const int NameLengthOffset = 26;
// TODO: Add base for SFX friendly handling
long entryDataOffset = update.Entry.Offset + NameLengthOffset;
baseStream_.Seek(entryDataOffset, SeekOrigin.Begin);
// Clumsy way of handling retrieving the original name and extra data length for now.
// TODO: Stop re-reading name and data length in CopyEntryDirect.
uint nameLength = ReadLEUshort();
uint extraLength = ReadLEUshort();
sourcePosition = baseStream_.Position + nameLength + extraLength;
if (skipOver) {
if (update.OffsetBasedSize != -1)
destinationPosition += update.OffsetBasedSize;
else
// TODO: Find out why this calculation comes up 4 bytes short on some entries in ODT (Office Document Text) archives.
// WinZip produces a warning on these entries:
// "caution: value of lrec.csize (compressed size) changed from ..."
destinationPosition +=
(sourcePosition - entryDataOffset) + NameLengthOffset + // Header size
update.Entry.CompressedSize + GetDescriptorSize(update);
}
else {
if ( update.Entry.CompressedSize > 0 ) {
CopyEntryDataDirect(update, baseStream_, false, ref destinationPosition, ref sourcePosition );
}
CopyDescriptorBytesDirect(update, baseStream_, ref destinationPosition, sourcePosition);
}
}
开发者ID:jamesbascle,项目名称:SharpZipLib,代码行数:47,代码来源:ZipFile.cs
示例4: CopyBytes
void CopyBytes(ZipUpdate update, Stream destination, Stream source,
long bytesToCopy, bool updateCrc)
{
if ( destination == source ) {
throw new InvalidOperationException("Destination and source are the same");
}
// NOTE: Compressed size is updated elsewhere.
Crc32 crc = new Crc32();
byte[] buffer = GetBuffer();
long targetBytes = bytesToCopy;
long totalBytesRead = 0;
int bytesRead;
do {
int readSize = buffer.Length;
if ( bytesToCopy < readSize ) {
readSize = (int)bytesToCopy;
}
bytesRead = source.Read(buffer, 0, readSize);
if ( bytesRead > 0 ) {
if ( updateCrc ) {
crc.Update(buffer, 0, bytesRead);
}
destination.Write(buffer, 0, bytesRead);
bytesToCopy -= bytesRead;
totalBytesRead += bytesRead;
}
}
while ( (bytesRead > 0) && (bytesToCopy > 0) );
if ( totalBytesRead != targetBytes ) {
throw new ZipException(string.Format("Failed to copy bytes expected {0} read {1}", targetBytes, totalBytesRead));
}
if ( updateCrc ) {
update.OutEntry.Crc = crc.Value;
}
}
开发者ID:jamesbascle,项目名称:SharpZipLib,代码行数:42,代码来源:ZipFile.cs
示例5: CopyDescriptorBytesDirect
void CopyDescriptorBytesDirect(ZipUpdate update, Stream stream, ref long destinationPosition, long sourcePosition)
{
int bytesToCopy = GetDescriptorSize(update);
while ( bytesToCopy > 0 ) {
int readSize = (int)bytesToCopy;
byte[] buffer = GetBuffer();
stream.Position = sourcePosition;
int bytesRead = stream.Read(buffer, 0, readSize);
if ( bytesRead > 0 ) {
stream.Position = destinationPosition;
stream.Write(buffer, 0, bytesRead);
bytesToCopy -= bytesRead;
destinationPosition += bytesRead;
sourcePosition += bytesRead;
}
else {
throw new ZipException("Unxpected end of stream");
}
}
}
开发者ID:jamesbascle,项目名称:SharpZipLib,代码行数:22,代码来源:ZipFile.cs
示例6: CopyEntryDirect
void CopyEntryDirect(ZipFile workFile, ZipUpdate update, ref long destinationPosition)
{
bool skipOver = false;
if ( update.Entry.Offset == destinationPosition ) {
skipOver = true;
}
if ( !skipOver ) {
baseStream_.Position = destinationPosition;
workFile.WriteLocalEntryHeader(update);
destinationPosition = baseStream_.Position;
}
long sourcePosition = 0;
const int NameLengthOffset = 26;
// TODO: Add base for SFX friendly handling
long entryDataOffset = update.Entry.Offset + NameLengthOffset;
baseStream_.Seek(entryDataOffset, SeekOrigin.Begin);
// Clumsy way of handling retrieving the original name and extra data length for now.
// TODO: Stop re-reading name and data length in CopyEntryDirect.
uint nameLength = ReadLEUshort();
uint extraLength = ReadLEUshort();
sourcePosition = baseStream_.Position + nameLength + extraLength;
if ( skipOver ) {
destinationPosition +=
(sourcePosition - entryDataOffset) + NameLengthOffset + // Header size
update.Entry.CompressedSize + GetDescriptorSize(update);
}
else {
if ( update.Entry.CompressedSize > 0 ) {
CopyEntryDataDirect(update, baseStream_, false, ref destinationPosition, ref sourcePosition );
}
CopyDescriptorBytesDirect(update, baseStream_, ref destinationPosition, sourcePosition);
}
}
开发者ID:VISTALL,项目名称:game-updater,代码行数:41,代码来源:ZipFile.cs
示例7: WriteLocalEntryHeader
void WriteLocalEntryHeader(ZipUpdate update)
{
ZipEntry entry = update.OutEntry;
// TODO: Local offset will require adjusting for multi-disk zip files.
entry.Offset = baseStream_.Position;
// TODO: Need to clear any entry flags that dont make sense or throw an exception here.
if (update.Command != UpdateCommand.Copy) {
if (entry.CompressionMethod == CompressionMethod.Deflated) {
if (entry.Size == 0) {
// No need to compress - no data.
entry.CompressedSize = entry.Size;
entry.Crc = 0;
entry.CompressionMethod = CompressionMethod.Stored;
}
}
else if (entry.CompressionMethod == CompressionMethod.Stored) {
entry.Flags &= ~(int)GeneralBitFlags.Descriptor;
}
if (HaveKeys) {
entry.IsCrypted = true;
if (entry.Crc < 0) {
entry.Flags |= (int)GeneralBitFlags.Descriptor;
}
}
else {
entry.IsCrypted = false;
}
switch (useZip64_) {
case UseZip64.Dynamic:
if (entry.Size < 0) {
entry.ForceZip64();
}
break;
case UseZip64.On:
entry.ForceZip64();
break;
case UseZip64.Off:
// Do nothing. The entry itself may be using Zip64 independantly.
break;
}
}
// Write the local file header
WriteLEInt(ZipConstants.LocalHeaderSignature);
WriteLEShort(entry.Version);
WriteLEShort(entry.Flags);
WriteLEShort((byte)entry.CompressionMethod);
WriteLEInt(( int )entry.DosTime);
if ( !entry.HasCrc ) {
// Note patch address for updating CRC later.
update.CrcPatchOffset = baseStream_.Position;
WriteLEInt(( int )0);
}
else {
WriteLEInt(unchecked(( int )entry.Crc));
}
if (entry.LocalHeaderRequiresZip64) {
WriteLEInt(-1);
WriteLEInt(-1);
}
else {
if ( (entry.CompressedSize < 0) || (entry.Size < 0) ) {
update.SizePatchOffset = baseStream_.Position;
}
WriteLEInt(( int )entry.CompressedSize);
WriteLEInt(( int )entry.Size);
}
byte[] name = ZipConstants.ConvertToArray(entry.Flags, entry.Name);
if ( name.Length > 0xFFFF ) {
throw new ZipException("Entry name too long.");
}
ZipExtraData ed = new ZipExtraData(entry.ExtraData);
if ( entry.LocalHeaderRequiresZip64 ) {
ed.StartNewEntry();
// Local entry header always includes size and compressed size.
// NOTE the order of these fields is reversed when compared to the normal headers!
ed.AddLeLong(entry.Size);
ed.AddLeLong(entry.CompressedSize);
ed.AddNewEntry(1);
}
else {
ed.Delete(1);
}
//.........这里部分代码省略.........
开发者ID:jamesbascle,项目名称:SharpZipLib,代码行数:101,代码来源:ZipFile.cs
示例8: AddUpdate
private void AddUpdate(ZipUpdate update)
{
contentsEdited_ = true;
int num = FindExistingUpdate(update.Entry.Name);
if (num >= 0)
{
if (updates_[num] == null)
{
updateCount_ += 1L;
}
updates_[num] = update;
}
else
{
num = updates_.Add(update);
updateCount_ += 1L;
updateIndex_.Add(update.Entry.Name, num);
}
}
开发者ID:ouyh18,项目名称:LteTools,代码行数:19,代码来源:ZipFile.cs
示例9: CopyBytes
private void CopyBytes(ZipUpdate update, Stream destination, Stream source, long bytesToCopy, bool updateCrc)
{
int num3;
if (destination == source)
{
throw new InvalidOperationException("Destination and source are the same");
}
Crc32 crc = new Crc32();
byte[] buffer = GetBuffer();
long num = bytesToCopy;
long num2 = 0L;
do
{
int length = buffer.Length;
if (bytesToCopy < length)
{
length = (int)bytesToCopy;
}
num3 = source.Read(buffer, 0, length);
if (num3 > 0)
{
if (updateCrc)
{
crc.Update(buffer, 0, num3);
}
destination.Write(buffer, 0, num3);
bytesToCopy -= num3;
num2 += num3;
}
}
while ((num3 > 0) && (bytesToCopy > 0L));
if (num2 != num)
{
throw new ZipException(string.Format("Failed to copy bytes expected {0} read {1}", num, num2));
}
if (updateCrc)
{
update.OutEntry.Crc = crc.Value;
}
}
开发者ID:ouyh18,项目名称:LteTools,代码行数:40,代码来源:ZipFile.cs
示例10: WriteLocalEntryHeader
private void WriteLocalEntryHeader(ZipUpdate update)
{
ZipEntry outEntry = update.OutEntry;
outEntry.Offset = 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 (HaveKeys)
{
outEntry.IsCrypted = true;
if (outEntry.Crc < 0L)
{
outEntry.Flags |= 8;
}
}
else
{
outEntry.IsCrypted = false;
}
switch (useZip64_)
{
case UseZip64.On:
outEntry.ForceZip64();
break;
case UseZip64.Dynamic:
if (outEntry.Size < 0L)
{
outEntry.ForceZip64();
}
break;
}
}
WriteLEInt(0x4034b50);
WriteLEShort(outEntry.Version);
WriteLEShort(outEntry.Flags);
WriteLEShort((byte)outEntry.CompressionMethod);
WriteLEInt((int)outEntry.DosTime);
if (!outEntry.HasCrc)
{
update.CrcPatchOffset = baseStream_.Position;
WriteLEInt(0);
}
else
{
WriteLEInt((int)outEntry.Crc);
}
if (outEntry.LocalHeaderRequiresZip64)
{
WriteLEInt(-1);
WriteLEInt(-1);
}
else
{
if ((outEntry.CompressedSize < 0L) || (outEntry.Size < 0L))
{
update.SizePatchOffset = baseStream_.Position;
}
WriteLEInt((int)outEntry.CompressedSize);
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();
WriteLEShort(buffer.Length);
WriteLEShort(outEntry.ExtraData.Length);
if (buffer.Length > 0)
{
baseStream_.Write(buffer, 0, buffer.Length);
}
if (outEntry.LocalHeaderRequiresZip64)
{
if (!data.Find(1))
//.........这里部分代码省略.........
开发者ID:ouyh18,项目名称:LteTools,代码行数:101,代码来源:ZipFile.cs
示例11: AddEntry
private void AddEntry(ZipFile workFile, ZipUpdate update)
{
Stream source = null;
if (update.Entry.IsFile)
{
source = update.GetSource();
if (source == null)
{
source = updateDataSource_.GetSource(update.Entry, update.Filename);
}
}
if (source != null)
{
using (source)
{
long length = source.Length;
if (update.OutEntry.Size < 0L)
{
update.OutEntry.Size = length;
}
else if (update.OutEntry.Size != length)
{
throw new ZipException("Entry size/stream size mismatch");
}
workFile.WriteLocalEntryHeader(update);
long position = workFile.baseStream_.Position;
using (Stream stream2 = workFile.GetOutputStream(update.OutEntry))
{
CopyBytes(update, stream2, source, length, true);
}
long num3 = workFile.baseStream_.Position;
update.OutEntry.CompressedSize = num3 - position;
if ((update.OutEntry.Flags & 8) == 8)
{
new ZipHelperStream(workFile.baseStream_).WriteDataDescriptor(update.OutEntry);
}
return;
}
}
workFile.WriteLocalEntryHeader(update);
update.OutEntry.CompressedSize = 0L;
}
开发者ID:ouyh18,项目名称:LteTools,代码行数:42,代码来源:ZipFile.cs
示例12: ModifyEntry
private void ModifyEntry(ZipFile workFile, ZipUpdate update)
{
workFile.WriteLocalEntryHeader(update);
long position = workFile.baseStream_.Position;
if (update.Entry.IsFile && (update.Filename != null))
{
using (Stream stream = workFile.GetOutputStream(update.OutEntry))
{
using (Stream stream2 = GetInputStream(update.Entry))
{
CopyBytes(update, stream, stream2, stream2.Length, true);
}
}
}
long num2 = workFile.baseStream_.Position;
update.Entry.CompressedSize = num2 - position;
}
开发者ID:ouyh18,项目名称:LteTools,代码行数:17,代码来源:ZipFile.cs
示例13: GetDescriptorSize
private int GetDescriptorSize(ZipUpdate update)
{
int num = 0;
if ((update.Entry.Flags & 8) != 0)
{
num = 12;
if (update.Entry.LocalHeaderRequiresZip64)
{
num = 20;
}
}
return num;
}
开发者ID:ouyh18,项目名称:LteTools,代码行数:13,代码来源:ZipFile.cs
示例14: CopyEntryDirect
private void CopyEntryDirect(ZipFile workFile, ZipUpdate update, ref long destinationPosition)
{
bool flag = false;
if (update.Entry.Offset == destinationPosition)
{
flag = true;
}
if (!flag)
{
baseStream_.Position = destinationPosition;
workFile.WriteLocalEntryHeader(update);
destinationPosition = baseStream_.Position;
}
long offset = update.Entry.Offset + 0x1aL;
baseStream_.Seek(offset, SeekOrigin.Begin);
uint num3 = ReadLEUshort();
uint num4 = ReadLEUshort();
long sourcePosition = (baseStream_.Position + num3) + num4;
if (flag)
{
if (update.OffsetBasedSize != -1L)
{
destinationPosition += update.OffsetBasedSize;
}
else
{
destinationPosition += (((sourcePosition - offset) + 0x1aL) + update.Entry.CompressedSize) + GetDescriptorSize(update);
}
}
else
{
if (update.Entry.CompressedSize > 0L)
{
CopyEntryDataDirect(update, baseStream_, false, ref destinationPosition, ref sourcePosition);
}
CopyDescriptorBytesDirect(update, baseStream_, ref destinationPosition, sourcePosition);
}
}
开发者ID:ouyh18,项目名称:LteTools,代码行数:38,代码来源:ZipFile.cs
示例15: CopyDescriptorBytes
void CopyDescriptorBytes(ZipUpdate update, Stream dest, Stream source)
{
int bytesToCopy = 0;
if ( (update.Entry.Flags & (int)GeneralBitFlags.Descriptor) != 0) {
bytesToCopy = 12;
if ( update.Entry.LocalHeaderRequiresZip64 ) {
bytesToCopy = 20;
}
}
if ( bytesToCopy > 0 ) {
byte[] buffer = GetBuffer();
while ( bytesToCopy > 0 ) {
int readSize = Math.Min(buffer.Length, bytesToCopy);
int bytesRead = source.Read(buffer, 0, readSize);
if ( bytesRead > 0 ) {
dest.Write(buffer, 0, bytesRead);
bytesToCopy -= bytesRead;
}
else {
throw new ZipException("Unxpected end of stream");
}
}
}
}
开发者ID:jiangguang5201314,项目名称:VMukti,代码行数:28,代码来源:ZipFile.cs
示例16: AddUpdate
void AddUpdate(ZipUpdate update)
{
_contentsEdited = true;
int index = FindExistingUpdate(update.Entry.Name);
if (index >= 0) {
if ( _updates[index] == null ) {
_updateCount += 1;
}
// Direct replacement is faster than delete and add.
_updates[index] = update;
}
else {
index = _updates.Add(update);
_updateCount += 1;
_updateIndex.Add(update.Entry.Name, index);
}
}
开发者ID:marinehero,项目名称:ThinkAway.net,代码行数:20,代码来源:ZipFile.cs
示例17: GetDescriptorSize
int GetDescriptorSize(ZipUpdate update)
{
int result = 0;
if ( (update.Entry.Flags & (int)GeneralBitFlags.Descriptor) != 0) {
result = 12;
if ( update.Entry.LocalHeaderRequiresZip64 ) {
result = 20;
}
}
return result;
}
开发者ID:jiangguang5201314,项目名称:VMukti,代码行数:11,代码来源:ZipFile.cs
示例18: UpdateComparer
/// <summary>
/// Compares two objects and returns a value indicating whether one is
/// less than, equal to or greater than the other.
/// </summary>
/// <param name="zx">First object to compare</param>
/// <param name="zy">Second object to compare.</param>
/// <returns>Compare result.</returns>
private static int UpdateComparer(
ZipUpdate zx,
ZipUpdate zy) {
int result;
if (zx==null) {
if (zy==null) {
result=0;
} else {
result=-1;
}
} else if (zy==null) {
result=1;
} else {
int xCmdValue=((zx.Command==UpdateCommand.Copy)||(zx.Command==UpdateCommand.Modify))?0:1;
int yCmdValue=((zy.Command==UpdateCommand.Copy)||(zy.Command==UpdateCommand.Modify))?0:1;
result=xCmdValue-yCmdValue;
if (result==0) {
long offsetDiff=zx.Entry.Offset-zy.Entry.Offset;
if (offsetDiff<0) {
result=-1;
} else if (offsetDiff==0) {
result=0;
} else {
result=1;
}
}
}
return result;
}
开发者ID:fanfeilong,项目名称:exceltk,代码行数:39,代码来源:ZipFile.cs
示例19: AddUpdate
void AddUpdate(ZipUpdate update)
{
contentsEdited_ = true;
int index = FindExistingUpdate(update.Entry.Name);
if (index >= 0) {
if ( updates_[index] == null ) {
updateCount_ += 1;
}
// Direct replacement is faster than delete and add.
updates_[index] = update;
}
else {
index = updates_.Add(update);
updateCount_ += 1;
updateIndex_.Add(update.Entry.Name, index);
}
}
开发者ID:jamesbascle,项目名称:SharpZipLib,代码行数:20,代码来源:ZipFile.cs
示例20: Add
/// <summary>
/// Add a new entry to the archive.
/// </summary>
/// <param name="fileName">The name of the file to add.</param>
/// <param name="compressionMethod">The compression method to use.</param>
/// <param name="useUnicodeText">Ensure Unicode text is used for name and comment for this entry.</param>
public void Add(string fileName, CompressionMethod compressionMethod, bool useUnicodeText )
{
if (fileName == null)
{
throw new ArgumentNullException("fileName");
}
if (!ZipEntry.IsCompressionMethodSupported(compressionMethod))
{
throw new ZipException("Compression method not supported");
}
CheckUpdating();
contentsEdited_ = true;
string zipEntryName = GetTransformedFileName(fileName);
int index = FindExistingUpdate(zipEntryName);
if (index >= 0)
{
updates_.RemoveAt(index);
}
ZipUpdate update = new ZipUpdate(fileName, zipEntryName, compressionMethod);
update.Entry.IsUnicodeText = useUnicodeText;
updates_.Add(update);
}
开发者ID:bobsummerwill,项目名称:ZXMAK2,代码行数:33,代码来源:ZipFile.cs
注:本文中的ZipUpdate类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论