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);
 }
Esempio n. 2
0
        public void SetProgress(long inSize, long outSize)
        {
            if (this.Working == null)
            {
                return;
            }
            float doneRate1 = ((float)inSize + 0.0f) / (float)this._InSize;
            float doneRate2 = doneRate1 - this._OldPercentDone;

            if ((double)doneRate2 * 100.0 < 1.0)
            {
                doneRate2 = 0.0f;
            }
            else
            {
                this._OldPercentDone = doneRate1;
            }
            this.Working((object)this, new ProgressEventArgs(PercentDoneEventArgs.ProducePercentDone(doneRate1), (double)doneRate2 > 0.0 ? PercentDoneEventArgs.ProducePercentDone(doneRate2) : (byte)0));
        }
Esempio n. 3
0
 public int GetStream(uint index, out ISequentialOutStream outStream, AskMode askExtractMode)
 {
     outStream = (ISequentialOutStream)null;
     if (askExtractMode == AskMode.Extract)
     {
         string str1 = this._Directory;
         for (int index1 = 0; index1 < 1; ++index1)
         {
             if (!this._FileIndex.HasValue)
             {
                 if (this._ActualIndexes == null || this._ActualIndexes.Contains(index))
                 {
                     PropVariant var = new PropVariant();
                     this._Archive.GetProperty(index, ItemPropId.Path, ref var);
                     string str2 = NativeMethods.SafeCast <string>(var, "");
                     if (string.IsNullOrEmpty(str2))
                     {
                         if (this._FilesCount == 1)
                         {
                             string fileName = Path.GetFileName(this._Extractor.FileName);
                             string str3     = fileName.Substring(0, fileName.LastIndexOf('.'));
                             if (!str3.EndsWith(".tar", StringComparison.OrdinalIgnoreCase))
                             {
                                 str3 += ".tar";
                             }
                             str2 = str3;
                         }
                         else
                         {
                             str2 = "[no name] " + index.ToString((IFormatProvider)CultureInfo.InvariantCulture);
                         }
                     }
                     str1 += str2;
                     this._Archive.GetProperty(index, ItemPropId.IsDirectory, ref var);
                     try
                     {
                         str1 = ArchiveExtractCallback.ValidateFileName(str1);
                     }
                     catch (Exception ex)
                     {
                         this.AddException(ex);
                         break;
                     }
                     if (!NativeMethods.SafeCast <bool>(var, false))
                     {
                         this._Archive.GetProperty(index, ItemPropId.LastWriteTime, ref var);
                         DateTime time = NativeMethods.SafeCast <DateTime>(var, DateTime.MinValue);
                         if (File.Exists(str1))
                         {
                             FileOverwriteEventArgs e = new FileOverwriteEventArgs(str1);
                             this.OnFileExists(e);
                             if (e.Cancel)
                             {
                                 this.Canceled = true;
                                 return(-1);
                             }
                             if (string.IsNullOrEmpty(e.FileName))
                             {
                                 outStream = (ISequentialOutStream)this._FakeStream;
                                 break;
                             }
                             str1 = e.FileName;
                         }
                         try
                         {
                             this._FileStream = new OutStreamWrapper((Stream)File.Create(str1), str1, time, true);
                         }
                         catch (Exception ex)
                         {
                             if (ex is FileNotFoundException)
                             {
                                 this.AddException((Exception) new IOException("The file \"" + str1 + "\" was not extracted due to the File.Create fail."));
                             }
                             else
                             {
                                 this.AddException(ex);
                             }
                             outStream = (ISequentialOutStream)this._FakeStream;
                             break;
                         }
                         this._FileStream.BytesWritten += new EventHandler <IntEventArgs>(this.IntEventArgsHandler);
                         outStream = (ISequentialOutStream)this._FileStream;
                     }
                     else if (!Directory.Exists(str1))
                     {
                         try
                         {
                             Directory.CreateDirectory(str1);
                         }
                         catch (Exception ex)
                         {
                             this.AddException(ex);
                         }
                         outStream = (ISequentialOutStream)this._FakeStream;
                     }
                 }
                 else
                 {
                     outStream = (ISequentialOutStream)this._FakeStream;
                 }
             }
             else
             {
                 uint num       = index;
                 uint?fileIndex = this._FileIndex;
                 if (((int)num != (int)fileIndex.GetValueOrDefault() ? 0 : (fileIndex.HasValue ? 1 : 0)) != 0)
                 {
                     outStream       = (ISequentialOutStream)this._FileStream;
                     this._FileIndex = new uint?();
                 }
                 else
                 {
                     outStream = (ISequentialOutStream)this._FakeStream;
                 }
             }
         }
         this._DoneRate += 1f / (float)this._FilesCount;
         FileInfoEventArgs e1 = new FileInfoEventArgs(this._Extractor.ArchiveFileData[(int)index], PercentDoneEventArgs.ProducePercentDone(this._DoneRate));
         this.OnFileExtractionStarted(e1);
         if (e1.Cancel)
         {
             if (!string.IsNullOrEmpty(str1))
             {
                 this._FileStream.Dispose();
                 if (File.Exists(str1))
                 {
                     try
                     {
                         File.Delete(str1);
                     }
                     catch (Exception ex)
                     {
                         this.AddException(ex);
                     }
                 }
             }
             this.Canceled = true;
             return(-1);
         }
     }
     return(0);
 }