public int GetStream(uint index, out ISequentialInStream inStream)
 {
     index -= this._IndexOffset;
     if (this._Files != null)
     {
         if ((this._Files[index].Attributes & FileAttributes.Directory) == (FileAttributes)0)
         {
             try
             {
                 this._FileStream = new InStreamWrapper((Stream) new FileStream(this._Files[index].FullName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite), true);
             }
             catch (Exception ex)
             {
                 this.AddException(ex);
                 inStream = (ISequentialInStream)null;
                 return(-1);
             }
             EventHandler <IntEventArgs> eventHandler = new EventHandler <IntEventArgs>(this.IntEventArgsHandler);
             this._FileStream.BytesRead  += eventHandler;
             this._FileStream.StreamSeek += eventHandler;
             inStream = (ISequentialInStream)this._FileStream;
         }
         else
         {
             inStream = (ISequentialInStream)null;
         }
         this._DoneRate += 1f / (float)this._ActualFilesCount;
         FileNameEventArgs e = new FileNameEventArgs(this._Files[index].Name, PercentDoneEventArgs.ProducePercentDone(this._DoneRate));
         this.OnFileCompression(e);
         if (e.Cancel)
         {
             this.Canceled = true;
             return(-1);
         }
     }
     else if (this._Streams == null)
     {
         inStream = (ISequentialInStream)this._FileStream;
     }
     else
     {
         this._FileStream            = new InStreamWrapper(this._Streams[index], true);
         this._FileStream.BytesRead += new EventHandler <IntEventArgs>(this.IntEventArgsHandler);
         inStream        = (ISequentialInStream)this._FileStream;
         this._DoneRate += 1f / (float)this._ActualFilesCount;
         FileNameEventArgs e = new FileNameEventArgs(this._Entries[index], PercentDoneEventArgs.ProducePercentDone(this._DoneRate));
         this.OnFileCompression(e);
         if (e.Cancel)
         {
             this.Canceled = true;
             return(-1);
         }
     }
     return(0);
 }
        public void SetOperationResult(OperationResult operationResult)
        {
            if (operationResult != OperationResult.Ok && this.ReportErrors)
            {
                switch (operationResult)
                {
                case OperationResult.UnsupportedMethod:
                    this.AddException((Exception) new ExtractionFailedException("Unsupported method error has occured."));
                    break;

                case OperationResult.DataError:
                    this.AddException((Exception) new ExtractionFailedException("File is corrupted. Data error has occured."));
                    break;

                case OperationResult.CrcError:
                    this.AddException((Exception) new ExtractionFailedException("File is corrupted. Crc check has failed."));
                    break;
                }
            }
            if (this._FileStream != null)
            {
                try
                {
                    if (this._Compressor.ArchiveFormat != OutArchiveFormat.Zip)
                    {
                        this._FileStream.Dispose();
                        this._FileStream = (InStreamWrapper)null;
                    }
                    else
                    {
                        this._WrappersToDispose.Add(this._FileStream);
                    }
                }
                catch (ObjectDisposedException ex)
                {
                }
            }
            this.OnFileCompressionFinished(EventArgs.Empty);
        }
 private void Init(Stream stream, SevenZipCompressor compressor, UpdateData updateData, bool directoryStructure)
 {
     this._FileStream            = new InStreamWrapper(stream, false);
     this._FileStream.BytesRead += new EventHandler <IntEventArgs>(this.IntEventArgsHandler);
     this._ActualFilesCount      = 1;
     try
     {
         this._BytesCount = stream.Length;
     }
     catch (NotSupportedException ex)
     {
         this._BytesCount = -1L;
     }
     try
     {
         stream.Seek(0L, SeekOrigin.Begin);
     }
     catch (NotSupportedException ex)
     {
         this._BytesCount = -1L;
     }
     this.CommonInit(compressor, updateData, directoryStructure);
 }
 public int GetStream(string name, out IInStream inStream)
 {
     if (!File.Exists(name))
     {
         name = Path.Combine(Path.GetDirectoryName(this._FileInfo.FullName), name);
         if (!File.Exists(name))
         {
             inStream = (IInStream)null;
             return(1);
         }
     }
     if (this._Wrappers.ContainsKey(name))
     {
         inStream = (IInStream)this._Wrappers[name];
     }
     else
     {
         InStreamWrapper inStreamWrapper = new InStreamWrapper((Stream) new FileStream(name, FileMode.Open, FileAccess.Read, FileShare.ReadWrite), true);
         this._Wrappers.Add(name, inStreamWrapper);
         inStream = (IInStream)inStreamWrapper;
     }
     return(0);
 }