Beispiel #1
0
 private void Init(Stream stream)
 {
     SevenZipExtractor.ValidateStream(stream);
     this._Format = FileChecker.CheckSignature(stream);
     SevenZipLibraryManager.LoadLibrary((object)this, (Enum)this._Format);
     try
     {
         this._InStream   = stream;
         this._Archive    = SevenZipLibraryManager.InArchive(this._Format, (object)this);
         this._PackedSize = new long?(stream.Length);
     }
     catch (SevenZipLibraryException ex)
     {
         SevenZipLibraryManager.FreeLibrary((object)this, (Enum)this._Format);
         throw;
     }
 }
Beispiel #2
0
        public void ExtractFiles(string directory, params int[] indexes)
        {
            this.DisposedCheck();
            this.ClearExceptions();
            if (!SevenZipExtractor.CheckIndexes(indexes))
            {
                if (!this.ThrowException((SevenZipBase)null, (Exception) new ArgumentException("The indexes must be more or equal to zero.", nameof(indexes))))
                {
                    return;
                }
            }
            this.InitArchiveFileData(false);
            uint[] numArray = new uint[indexes.Length];
            for (int index = 0; index < indexes.Length; ++index)
            {
                numArray[index] = (uint)indexes[index];
            }
            foreach (uint num in numArray)
            {
                uint?filesCount = this._FilesCount;
                if ((num < filesCount.GetValueOrDefault() ? 0 : (filesCount.HasValue ? 1 : 0)) != 0)
                {
                    if (!this.ThrowException((SevenZipBase)null, (Exception) new ArgumentOutOfRangeException(nameof(indexes), "Index must be less than " + this._FilesCount.Value.ToString((IFormatProvider)CultureInfo.InvariantCulture) + "!")))
                    {
                        return;
                    }
                }
            }
            List <uint> actualIndexes = new List <uint>((IEnumerable <uint>)numArray);

            actualIndexes.Sort();
            uint[] indexes1 = actualIndexes.ToArray();
            if (this._IsSolid.Value)
            {
                indexes1 = SevenZipExtractor.SolidIndexes(indexes1);
            }
            try
            {
                IInStream archiveStream;
                using ((archiveStream = this.GetArchiveStream(actualIndexes.Count != 1)) as IDisposable)
                {
                    ArchiveOpenCallback archiveOpenCallback = this.GetArchiveOpenCallback();
                    ulong maxCheckStartPosition             = 32768;
                    if (!this._Opened)
                    {
                        if (this._Archive.Open(archiveStream, ref maxCheckStartPosition, (IArchiveOpenCallback)archiveOpenCallback) != 0)
                        {
                            if (!this.ThrowException((SevenZipBase)null, (Exception) new SevenZipArchiveException()))
                            {
                                return;
                            }
                        }
                        this._Opened = true;
                    }
                    using (ArchiveExtractCallback archiveExtractCallback = this.GetArchiveExtractCallback(directory, (int)this._FilesCount.Value, actualIndexes))
                    {
                        try
                        {
                            this.CheckedExecute(this._Archive.Extract(indexes1, (uint)indexes1.Length, 0, (IArchiveExtractCallback)archiveExtractCallback), "The extraction has failed for an unknown reason with code ", (SevenZipBase)archiveExtractCallback);
                        }
                        finally
                        {
                            this.FreeArchiveExtractCallback(archiveExtractCallback);
                        }
                    }
                }
                this.OnExtractionFinished(EventArgs.Empty);
            }
            finally
            {
                if (actualIndexes.Count > 1)
                {
                    this._Archive.Close();
                    this._ArchiveStream = (IInStream)null;
                    this._Opened        = false;
                }
            }
            this.ThrowUserException();
        }
Beispiel #3
0
        public void ExtractFile(int index, Stream stream)
        {
            this.DisposedCheck();
            this.ClearExceptions();
            if (!SevenZipExtractor.CheckIndexes(index))
            {
                if (!this.ThrowException((SevenZipBase)null, (Exception) new ArgumentException("The index must be more or equal to zero.", nameof(index))))
                {
                    return;
                }
            }
            if (!stream.CanWrite)
            {
                if (!this.ThrowException((SevenZipBase)null, (Exception) new ArgumentException("The specified stream can not be written.", nameof(stream))))
                {
                    return;
                }
            }
            this.InitArchiveFileData(false);
            long num        = (long)index;
            uint?filesCount = this._FilesCount;
            uint?nullable   = filesCount.HasValue ? new uint?(filesCount.GetValueOrDefault() - 1U) : new uint?();

            if ((num <= (long)nullable.GetValueOrDefault() ? 0 : (nullable.HasValue ? 1 : 0)) != 0)
            {
                if (!this.ThrowException((SevenZipBase)null, (Exception) new ArgumentOutOfRangeException(nameof(index), "The specified index is greater than the archive files count.")))
                {
                    return;
                }
            }
            uint[] indexes = new uint[1] {
                (uint)index
            };
            if (this._IsSolid.Value)
            {
                indexes = SevenZipExtractor.SolidIndexes(indexes);
            }
            IInStream           archiveStream       = this.GetArchiveStream(false);
            ArchiveOpenCallback archiveOpenCallback = this.GetArchiveOpenCallback();
            ulong maxCheckStartPosition             = 32768;

            if (!this._Opened)
            {
                if (this._Archive.Open(archiveStream, ref maxCheckStartPosition, (IArchiveOpenCallback)archiveOpenCallback) != 0)
                {
                    this.ThrowException((SevenZipBase)null, (Exception) new SevenZipArchiveException());
                }
                this._Opened = true;
            }
            using (ArchiveExtractCallback archiveExtractCallback = this.GetArchiveExtractCallback(stream, (uint)index, indexes.Length))
            {
                try
                {
                    this.CheckedExecute(this._Archive.Extract(indexes, (uint)indexes.Length, 0, (IArchiveExtractCallback)archiveExtractCallback), "The extraction has failed for an unknown reason with code ", (SevenZipBase)archiveExtractCallback);
                }
                finally
                {
                    this.FreeArchiveExtractCallback(archiveExtractCallback);
                }
            }
            this.OnExtractionFinished(EventArgs.Empty);
            this.ThrowUserException();
        }
Beispiel #4
0
 private void Init(IInArchive archive, Stream stream, int filesCount, uint fileIndex, SevenZipExtractor extractor)
 {
     this._Archive    = archive;
     this._FileStream = new OutStreamWrapper(stream, false);
     this._FileStream.BytesWritten += new EventHandler <IntEventArgs>(this.IntEventArgsHandler);
     this._FilesCount = filesCount;
     this._FileIndex  = new uint?(fileIndex);
     this._FakeStream = new FakeOutStreamWrapper();
     this._FakeStream.BytesWritten += new EventHandler <IntEventArgs>(this.IntEventArgsHandler);
     this._Extractor = extractor;
 }
Beispiel #5
0
 private void Init(IInArchive archive, string directory, int filesCount, List <uint> actualIndexes, SevenZipExtractor extractor)
 {
     this._Archive       = archive;
     this._Directory     = directory;
     this._FilesCount    = filesCount;
     this._ActualIndexes = actualIndexes;
     if (!directory.EndsWith(new string(Path.DirectorySeparatorChar, 1), StringComparison.CurrentCulture))
     {
         this._Directory += (string)(object)Path.DirectorySeparatorChar;
     }
     this._FakeStream = new FakeOutStreamWrapper();
     this._FakeStream.BytesWritten += new EventHandler <IntEventArgs>(this.IntEventArgsHandler);
     this._Extractor = extractor;
 }
Beispiel #6
0
 public ArchiveExtractCallback(IInArchive archive, Stream stream, int filesCount, uint fileIndex, string password, SevenZipExtractor extractor)
     : base(password)
 {
     this.Init(archive, stream, filesCount, fileIndex, extractor);
 }
Beispiel #7
0
 public ArchiveExtractCallback(IInArchive archive, string directory, int filesCount, List <uint> actualIndexes, string password, SevenZipExtractor extractor)
     : base(password)
 {
     this.Init(archive, directory, filesCount, actualIndexes, extractor);
 }