Esempio n. 1
0
 public int GetStream(string name, out IInStream inStream)
 {
     if (!File.Exists(name))
     {
         name = Path.Combine(Path.GetDirectoryName(_fileInfo.FullName), name);
         if (!File.Exists(name))
         {
             inStream = null;
             AddException(new FileNotFoundException("The volume \"" + name + "\" was not found. Extraction can be impossible."));
             return(1);
         }
     }
     _volumeFileNames.Add(name);
     if (_wrappers.ContainsKey(name))
     {
         inStream = _wrappers[name];
     }
     else
     {
         try
         {
             var wrapper = new InStreamWrapper(
                 new FileStream(name, FileMode.Open, FileAccess.Read, FileShare.ReadWrite), true);
             _wrappers.Add(name, wrapper);
             inStream = wrapper;
         }
         catch
         {
             AddException(new FileNotFoundException("Failed to open the volume \"" + name + "\". Extraction is impossible."));
             inStream = null;
             return(1);
         }
     }
     return(0);
 }
Esempio n. 2
0
        /// <summary>
        /// Gets the stream for 7-zip library.
        /// </summary>
        /// <param name="index">File index</param>
        /// <param name="inStream">Input file stream</param>
        /// <returns>Zero if Ok</returns>
        public int GetStream(uint index, out
#if !MONO
                             ISequentialInStream
#else
                             HandleRef
#endif
                             inStream)
        {
            index -= _indexOffset;
            if (_files != null)
            {
                _fileStream = null;
                try
                {
                    if (File.Exists(_files[index].FullName))
                    {
                        _fileStream = new InStreamWrapper(
                            new FileStream(_files[index].FullName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite),
                            true);
                    }
                }
                catch (Exception e)
                {
                    AddException(e);
                    inStream = null;
                    return(-1);
                }
                inStream = _fileStream;
                if (!EventsForGetStream(index))
                {
                    return(-1);
                }
            }
            else
            {
                if (_streams == null)
                {
                    inStream = _fileStream;
                }
                else
                {
                    _fileStream = new InStreamWrapper(_streams[index], true);
                    inStream    = _fileStream;
                    if (!EventsForGetStream(index))
                    {
                        return(-1);
                    }
                }
            }
            return(0);
        }
Esempio n. 3
0
        public void SetOperationResult(OperationResult operationResult)
        {
            if (operationResult != OperationResult.Ok && ReportErrors)
            {
                switch (operationResult)
                {
                case OperationResult.CrcError:
                    AddException(new ExtractionFailedException("File is corrupted. Crc check has failed."));
                    break;

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

                case OperationResult.UnsupportedMethod:
                    AddException(new ExtractionFailedException("Unsupported method error has occured."));
                    break;
                }
            }
            if (_fileStream != null)
            {
                _fileStream.BytesRead -= IntEventArgsHandler;
                //Specific Zip implementation - can not Dispose files for Zip.
                if (_compressor.ArchiveFormat != OutArchiveFormat.Zip)
                {
                    try
                    {
                        _fileStream.Dispose();
                    }
                    catch (ObjectDisposedException) {}
                }
                else
                {
                    _wrappersToDispose.Add(_fileStream);
                }
                _fileStream = null;
                GC.Collect();
                // Issue #6987
                //GC.WaitForPendingFinalizers();
            }
            OnFileCompressionFinished(EventArgs.Empty);
        }
Esempio n. 4
0
 private void Init(
     Stream stream, KCompressCompressor compressor, UpdateData updateData, bool directoryStructure)
 {
     _fileStream            = new InStreamWrapper(stream, false);
     _fileStream.BytesRead += IntEventArgsHandler;
     _actualFilesCount      = 1;
     try
     {
         _bytesCount = stream.Length;
     }
     catch (NotSupportedException)
     {
         _bytesCount = -1;
     }
     try
     {
         stream.Seek(0, SeekOrigin.Begin);
     }
     catch (NotSupportedException)
     {
         _bytesCount = -1;
     }
     CommonInit(compressor, updateData, directoryStructure);
 }