예제 #1
0
 public void ReadDataDescriptor(bool zip64, DescriptorData data)
 {
     if (this.ReadLEInt() != 0x8074b50)
     {
         throw new ZipException("Data descriptor signature not found");
     }
     data.Crc = this.ReadLEInt();
     if (zip64)
     {
         data.CompressedSize = this.ReadLELong();
         data.Size = this.ReadLELong();
     }
     else
     {
         data.CompressedSize = this.ReadLEInt();
         data.Size = this.ReadLEInt();
     }
 }
예제 #2
0
 public bool TestArchive(bool testData, TestStrategy strategy, ZipTestResultHandler resultHandler)
 {
     if (this.isDisposed_)
     {
         throw new ObjectDisposedException("ZipFile");
     }
     TestStatus status = new TestStatus(this);
     if (resultHandler != null)
     {
         resultHandler(status, null);
     }
     HeaderTest tests = testData ? (HeaderTest.Header | HeaderTest.Extract) : HeaderTest.Header;
     bool flag = true;
     try
     {
         for (int i = 0; flag && (i < this.Count); i++)
         {
             if (resultHandler != null)
             {
                 status.SetEntry(this[i]);
                 status.SetOperation(TestOperation.EntryHeader);
                 resultHandler(status, null);
             }
             try
             {
                 this.TestLocalHeader(this[i], tests);
             }
             catch (ZipException exception)
             {
                 status.AddError();
                 if (resultHandler != null)
                 {
                     resultHandler(status, string.Format("Exception during test - '{0}'", exception.Message));
                 }
                 if (strategy == TestStrategy.FindFirstError)
                 {
                     flag = false;
                 }
             }
             if ((flag && testData) && this[i].IsFile)
             {
                 if (resultHandler != null)
                 {
                     status.SetOperation(TestOperation.EntryData);
                     resultHandler(status, null);
                 }
                 Crc32 crc = new Crc32();
                 using (Stream stream = this.GetInputStream(this[i]))
                 {
                     int num3;
                     byte[] buffer = new byte[0x1000];
                     long num2 = 0L;
                     while ((num3 = stream.Read(buffer, 0, buffer.Length)) > 0)
                     {
                         crc.Update(buffer, 0, num3);
                         if (resultHandler != null)
                         {
                             num2 += num3;
                             status.SetBytesTested(num2);
                             resultHandler(status, null);
                         }
                     }
                 }
                 if (this[i].Crc != crc.Value)
                 {
                     status.AddError();
                     if (resultHandler != null)
                     {
                         resultHandler(status, "CRC mismatch");
                     }
                     if (strategy == TestStrategy.FindFirstError)
                     {
                         flag = false;
                     }
                 }
                 if ((this[i].Flags & 8) != 0)
                 {
                     ZipHelperStream stream2 = new ZipHelperStream(this.baseStream_);
                     DescriptorData data = new DescriptorData();
                     stream2.ReadDataDescriptor(this[i].LocalHeaderRequiresZip64, data);
                     if (this[i].Crc != data.Crc)
                     {
                         status.AddError();
                     }
                     if (this[i].CompressedSize != data.CompressedSize)
                     {
                         status.AddError();
                     }
                     if (this[i].Size != data.Size)
                     {
                         status.AddError();
                     }
                 }
             }
             if (resultHandler != null)
             {
                 status.SetOperation(TestOperation.EntryComplete);
                 resultHandler(status, null);
             }
         }
         if (resultHandler != null)
         {
             status.SetOperation(TestOperation.MiscellaneousTests);
             resultHandler(status, null);
         }
     }
     catch (Exception exception2)
     {
         status.AddError();
         if (resultHandler != null)
         {
             resultHandler(status, string.Format("Exception during test - '{0}'", exception2.Message));
         }
     }
     if (resultHandler != null)
     {
         status.SetOperation(TestOperation.Complete);
         status.SetEntry(null);
         resultHandler(status, null);
     }
     return (status.ErrorCount == 0);
 }