本文整理汇总了C#中ICSharpCode.SharpZipLib.Zip.ZipExtraData.ReadInt方法的典型用法代码示例。如果您正苦于以下问题:C# ZipExtraData.ReadInt方法的具体用法?C# ZipExtraData.ReadInt怎么用?C# ZipExtraData.ReadInt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ICSharpCode.SharpZipLib.Zip.ZipExtraData
的用法示例。
在下文中一共展示了ZipExtraData.ReadInt方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ProcessExtraData
/// <summary>
/// Process extra data fields updating the entry based on the contents.
/// </summary>
/// <param name="localHeader">True if the extra data fields should be handled
/// for a local header, rather than for a central header.
/// </param>
internal void ProcessExtraData(bool localHeader)
{
var extraData = new ZipExtraData(extra);
if (extraData.Find(0x0001))
{
// Version required to extract is ignored here as some archivers dont set it correctly
// in theory it should be version 45 or higher
// The recorded size will change but remember that this is zip64.
forceZip64_ = true;
if (extraData.ValueLength < 4)
{
throw new ZipException("Extra data extended Zip64 information length is invalid");
}
if (localHeader || (size == uint.MaxValue))
{
size = (ulong) extraData.ReadLong();
}
if (localHeader || (compressedSize == uint.MaxValue))
{
compressedSize = (ulong) extraData.ReadLong();
}
if (!localHeader && (offset == uint.MaxValue))
{
offset = extraData.ReadLong();
}
// Disk number on which file starts is ignored
}
else
{
if (
((versionToExtract & 0xff) >= ZipConstants.VersionZip64) &&
((size == uint.MaxValue) || (compressedSize == uint.MaxValue))
)
{
throw new ZipException("Zip64 Extended information required but is missing.");
}
}
if (extraData.Find(10))
{
// No room for any tags.
if (extraData.ValueLength < 4)
{
throw new ZipException("NTFS Extra data invalid");
}
extraData.ReadInt(); // Reserved
while (extraData.UnreadCount >= 4)
{
int ntfsTag = extraData.ReadShort();
int ntfsLength = extraData.ReadShort();
if (ntfsTag == 1)
{
if (ntfsLength >= 24)
{
long lastModification = extraData.ReadLong();
long lastAccess = extraData.ReadLong();
long createTime = extraData.ReadLong();
DateTime = DateTime.FromFileTime(lastModification);
}
break;
}
else
{
// An unknown NTFS tag so simply skip it.
extraData.Skip(ntfsLength);
}
}
}
else if (extraData.Find(0x5455))
{
int length = extraData.ValueLength;
int flags = extraData.ReadByte();
// Can include other times but these are ignored. Length of data should
// actually be 1 + 4 * no of bits in flags.
if (((flags & 1) != 0) && (length >= 5))
{
int iTime = extraData.ReadInt();
DateTime = (new DateTime(1970, 1, 1, 0, 0, 0).ToUniversalTime() +
new TimeSpan(0, 0, 0, iTime, 0)).ToLocalTime();
}
}
if (method == CompressionMethod.WinZipAES)
//.........这里部分代码省略.........
示例2: ReadOverrunInt
public void ReadOverrunInt()
{
ZipExtraData zed = new ZipExtraData(new byte[] { 1, 0, 0, 0 });
Assert.AreEqual(4, zed.Length, "Length should be 4");
Assert.IsTrue(zed.Find(1), "Should find tag 1");
// Empty Tag
bool exceptionCaught = false;
try {
zed.ReadInt();
}
catch (ZipException) {
exceptionCaught = true;
}
Assert.IsTrue(exceptionCaught, "Expected EOS exception");
// three bytes
zed = new ZipExtraData(new byte[] { 1, 0, 3, 0, 1, 2, 3 });
Assert.IsTrue(zed.Find(1), "Should find tag 1");
exceptionCaught = false;
try {
zed.ReadInt();
}
catch (ZipException) {
exceptionCaught = true;
}
Assert.IsTrue(exceptionCaught, "Expected EOS exception");
zed = new ZipExtraData(new byte[] { 1, 0, 7, 0, 1, 2, 3, 4, 5, 6, 7 });
Assert.IsTrue(zed.Find(1), "Should find tag 1");
zed.ReadInt();
exceptionCaught = false;
try {
zed.ReadInt();
}
catch (ZipException) {
exceptionCaught = true;
}
Assert.IsTrue(exceptionCaught, "Expected EOS exception");
}
示例3: ProcessExtraData
internal void ProcessExtraData(bool localHeader)
{
ZipExtraData extraData = new ZipExtraData(this.extra);
if (extraData.Find(1))
{
this.forceZip64_ = true;
if (extraData.ValueLength < 4)
{
throw new ZipException("Extra data extended Zip64 information length is invalid");
}
if (localHeader || (this.size == 0xffffffffL))
{
this.size = (ulong) extraData.ReadLong();
}
if (localHeader || (this.compressedSize == 0xffffffffL))
{
this.compressedSize = (ulong) extraData.ReadLong();
}
if (!localHeader && (this.offset == 0xffffffffL))
{
this.offset = extraData.ReadLong();
}
}
else if (((this.versionToExtract & 0xff) >= 0x2d) && ((this.size == 0xffffffffL) || (this.compressedSize == 0xffffffffL)))
{
throw new ZipException("Zip64 Extended information required but is missing.");
}
if (extraData.Find(10))
{
if (extraData.ValueLength < 4)
{
throw new ZipException("NTFS Extra data invalid");
}
extraData.ReadInt();
while (extraData.UnreadCount >= 4)
{
int num = extraData.ReadShort();
int amount = extraData.ReadShort();
if (num == 1)
{
if (amount >= 0x18)
{
long fileTime = extraData.ReadLong();
extraData.ReadLong();
extraData.ReadLong();
this.DateTime = System.DateTime.FromFileTime(fileTime);
}
break;
}
extraData.Skip(amount);
}
}
else if (extraData.Find(0x5455))
{
int valueLength = extraData.ValueLength;
if (((extraData.ReadByte() & 1) != 0) && (valueLength >= 5))
{
int seconds = extraData.ReadInt();
System.DateTime time = new System.DateTime(0x7b2, 1, 1, 0, 0, 0);
this.DateTime = (time.ToUniversalTime() + new TimeSpan(0, 0, 0, seconds, 0)).ToLocalTime();
}
}
if (this.method == ICSharpCode.SharpZipLib.Zip.CompressionMethod.WinZipAES)
{
this.ProcessAESExtraData(extraData);
}
}
示例4: ProcessExtraData
/// <summary>
/// Process extra data fields updating the entry based on the contents.
/// </summary>
/// <param name="localHeader">True if the extra data fields should be handled
/// for a local header, rather than for a central header.
/// </param>
internal void ProcessExtraData(bool localHeader)
{
ZipExtraData extraData = new ZipExtraData(this.extra);
if ( extraData.Find(0x0001) ) {
if ( (versionToExtract & 0xff) < ZipConstants.VersionZip64 ) {
throw new ZipException("Zip64 Extended information found but version is not valid");
}
// The recorded size will change but remember that this is zip64.
forceZip64_ = true;
if ( extraData.ValueLength < 4 ) {
throw new ZipException("Extra data extended Zip64 information length is invalid");
}
if ( localHeader || (size == uint.MaxValue) ) {
size = (ulong)extraData.ReadLong();
}
if ( localHeader || (compressedSize == uint.MaxValue) ) {
compressedSize = (ulong)extraData.ReadLong();
}
}
else {
if (
((versionToExtract & 0xff) >= ZipConstants.VersionZip64) &&
( (size == uint.MaxValue) ||
(compressedSize == uint.MaxValue) )) {
throw new ZipException("Zip64 Extended information required but is missing.");
}
}
/* TODO: Testing for handling of windows extra data
if ( extraData.Find(10) ) {
// No room for any tags.
if ( extraData.ValueLength < 8 ) {
throw new ZipException("NTFS Extra data invalid");
}
extraData.ReadInt(); // Reserved
while ( extraData.UnreadCount >= 4 ) {
int ntfsTag = extraData.ReadShort();
int ntfsLength = extraData.ReadShort();
if ( ntfsTag == 1 ) {
if ( ntfsLength >= 24 ) {
long lastModification = extraData.ReadLong();
long lastAccess = extraData.ReadLong();
long createTime = extraData.ReadLong();
DateTime = System.DateTime.FromFileTime(lastModification);
}
break;
}
else {
// An unknown NTFS tag so simply skip it.
extraData.Skip(ntfsLength);
}
}
}
else
*/
if ( extraData.Find(0x5455) ) {
int length = extraData.ValueLength;
int flags = extraData.ReadByte();
// Can include other times but these are ignored. Length of data should
// actually be 1 + 4 * no of bits in flags.
if ( ((flags & 1) != 0) && (length >= 5) ) {
int iTime = extraData.ReadInt();
DateTime = (new System.DateTime ( 1970, 1, 1, 0, 0, 0 ).ToUniversalTime() +
new TimeSpan ( 0, 0, 0, iTime, 0 )).ToLocalTime();
}
}
}
示例5: ProcessExtraData
internal void ProcessExtraData(bool localHeader)
{
ZipExtraData extraData = new ZipExtraData(this.extra);
if ( extraData.Find(0x0001) ) {
if ( (versionToExtract & 0xff) < ZipConstants.VersionZip64 ) {
throw new ZipException("Zip64 Extended information found but version is not valid");
}
forceZip64_ = true;
if ( extraData.ValueLength < 4 ) {
throw new ZipException("Extra data extended Zip64 information length is invalid");
}
if ( localHeader || (size == uint.MaxValue) ) {
size = (ulong)extraData.ReadLong();
}
if ( localHeader || (compressedSize == uint.MaxValue) ) {
compressedSize = (ulong)extraData.ReadLong();
}
if ( !localHeader && (offset == uint.MaxValue) ) {
offset = extraData.ReadLong();
}
}
else {
if (
((versionToExtract & 0xff) >= ZipConstants.VersionZip64) &&
((size == uint.MaxValue) || (compressedSize == uint.MaxValue))
) {
throw new ZipException("Zip64 Extended information required but is missing.");
}
}
if ( extraData.Find(10) ) {
if ( extraData.ValueLength < 8 ) {
throw new ZipException("NTFS Extra data invalid");
}
extraData.ReadInt();
while ( extraData.UnreadCount >= 4 ) {
int ntfsTag = extraData.ReadShort();
int ntfsLength = extraData.ReadShort();
if ( ntfsTag == 1 ) {
if ( ntfsLength >= 24 ) {
long lastModification = extraData.ReadLong();
long lastAccess = extraData.ReadLong();
long createTime = extraData.ReadLong();
DateTime = System.DateTime.FromFileTime(lastModification);
}
break;
}
else {
extraData.Skip(ntfsLength);
}
}
}
else if ( extraData.Find(0x5455) ) {
int length = extraData.ValueLength;
int flags = extraData.ReadByte();
if ( ((flags & 1) != 0) && (length >= 5) ) {
int iTime = extraData.ReadInt();
DateTime = (new System.DateTime ( 1970, 1, 1, 0, 0, 0 ).ToUniversalTime() +
new TimeSpan ( 0, 0, 0, iTime, 0 )).ToLocalTime();
}
}
}