コード例 #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 (Exception)
         {
             AddException(new FileNotFoundException("Failed to open the volume \"" + name + "\". Extraction is impossible."));
             inStream = null;
             return(1);
         }
     }
     return(0);
 }
コード例 #2
0
        public IOutFileStream CreateOutFileStream(BaseProtocol protocol, IInStream instream, bool append)
        {
            var pOutFileStream = CreateOutFileStream(protocol, instream.Name, null, append);

            pOutFileStream?.Link(instream);
            return(pOutFileStream);
        }
コード例 #3
0
        /// <summary>
        /// Gets the archive input stream.
        /// </summary>
        /// <returns>The archive input wrapper stream.</returns>
        private IInStream GetArchiveStream(bool dispose)
        {
            if (_archiveStream != null)
            {
                if (_archiveStream is DisposeVariableWrapper)
                {
                    (_archiveStream as DisposeVariableWrapper).DisposeStream = dispose;
                }
                return(_archiveStream);
            }

            if (_inStream != null)
            {
                _inStream.Seek(0, SeekOrigin.Begin);
                _archiveStream = new InStreamWrapper(_inStream, false);
            }
            else
            {
                if (!_fileName.EndsWith(".001", StringComparison.OrdinalIgnoreCase))
                {
                    _archiveStream = new InStreamWrapper(
                        new ArchiveEmulationStreamProxy(new FileStream(
                                                            _fileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite),
                                                        _offset),
                        dispose);
                }
                else
                {
                    _archiveStream = new InMultiStreamWrapper(_fileName, dispose);
                    _packedSize    = (_archiveStream as InMultiStreamWrapper).Length;
                }
            }
            return(_archiveStream);
        }
コード例 #4
0
 public MultiDimInStream(IIOFactory factory, InputAttribute attribute)
 {
     FDataContainer    = factory.CreateIOContainer <IInStream <T> >(attribute.DecreaseBinSizeWrapCount(), false);
     FBinSizeContainer = factory.CreateIOContainer <IInStream <int> >(attribute.GetBinSizeInputAttribute(FDataContainer), false);
     FDataStream       = FDataContainer.IOObject;
     FBinSizeStream    = FBinSizeContainer.IOObject;
 }
コード例 #5
0
 public override void PublishStream(uint appId, IInStream inStream, string type = "live")
 {
     if (OutboundCluster != null)
     {
         OutboundCluster.PublishStream(appId, inStream, type);
     }
 }
コード例 #6
0
 public MultiDimInStream(IIOFactory factory, InputAttribute attribute)
 {
     FDataContainer    = factory.CreateIOContainer <IInStream <T> >(attribute, false);
     FBinSizeContainer = factory.CreateIOContainer <IInStream <int> >(attribute.GetBinSizeInputAttribute(), false);
     FDataStream       = FDataContainer.IOObject;
     FBinSizeStream    = (IntInStream)FBinSizeContainer.IOObject;
 }
コード例 #7
0
 public override void PublishStream(uint appId, IInStream inStream,string type="live")
 {
     foreach (var inboundClusterProtocol in InboundClusters.Where(x=>inStream.GetProtocol()!=x))
     {
         inboundClusterProtocol.PublishStream(appId, inStream,type);
     }
 }
コード例 #8
0
        IIOStream <T> CloneStream <T>(IInStream <T> stream)
        {
            var mem = new MemoryIOStream <T>();

            mem.AssignFrom(stream);
            return(mem);
        }
コード例 #9
0
 private IInStream GetArchiveStream(bool dispose)
 {
     if (this._ArchiveStream != null)
     {
         if (this._ArchiveStream is DisposeVariableWrapper)
         {
             (this._ArchiveStream as DisposeVariableWrapper).DisposeStream = dispose;
         }
         return(this._ArchiveStream);
     }
     if (this._InStream != null)
     {
         this._InStream.Seek(0L, SeekOrigin.Begin);
         this._ArchiveStream = (IInStream) new InStreamWrapper(this._InStream, false);
     }
     else if (!this._FileName.EndsWith(".001", StringComparison.OrdinalIgnoreCase))
     {
         this._ArchiveStream = (IInStream) new InStreamWrapper((Stream) new FileStream(this._FileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite), dispose);
     }
     else
     {
         this._ArchiveStream = (IInStream) new InMultiStreamWrapper(this._FileName, dispose);
         this._PackedSize    = new long?((this._ArchiveStream as InMultiStreamWrapper).Length);
     }
     return(this._ArchiveStream);
 }
コード例 #10
0
ファイル: StreamUtils.cs プロジェクト: m4d-vvvv/vvvv-sdk
        public static int Sum(this IInStream <int> stream)
        {
            var result = 0;

            using (var buffer = MemoryPool <int> .GetBuffer())
                using (var reader = stream.GetReader())
                {
                    var array = buffer.Array;
                    while (!reader.Eos)
                    {
                        var itemsRead = reader.Read(array, 0, array.Length);
                        if (itemsRead != array.Length)
                        {
                            for (int i = 0; i < itemsRead; i++)
                            {
                                result += array[i];
                            }
                        }
                        else
                        {
                            // No index out of bounds check
                            for (int i = 0; i < array.Length; i++)
                            {
                                result += array[i];
                            }
                        }
                    }
                }
            return(result);
        }
コード例 #11
0
ファイル: InputPin.cs プロジェクト: mechaz/vvvv-sdk
        public bool Sync()
        {
            var changed = FInStream.Sync();

            FCurrentInStream = FInStream;
            return(changed);
        }
コード例 #12
0
ファイル: StreamUtils.cs プロジェクト: mechaz/vvvv-sdk
        public static int Sum(this IInStream <int> stream)
        {
            var result = 0;
            var buffer = MemoryPool <int> .GetArray();

            var reader = stream.GetReader();

            try
            {
                while (!reader.Eos)
                {
                    var itemsRead = reader.Read(buffer, 0, buffer.Length);
                    for (int i = 0; i < itemsRead; i++)
                    {
                        result += buffer[i];
                    }
                }
            }
            finally
            {
                MemoryPool <int> .PutArray(buffer);

                reader.Dispose();
            }
            return(result);
        }
コード例 #13
0
 public virtual bool Link(IInStream pInStream, bool reverseLink = true)
 {
     if (!pInStream.IsCompatibleWithType(Type) || !IsCompatibleWithType(pInStream.Type))
     {
         Logger.FATAL("stream type {0} not compatible with stream type {1}", Type.TagToString(), pInStream.Type.TagToString());
         return(false);
     }
     if (InStream != null)
     {
         if (InStream.UniqueId == pInStream.UniqueId)
         {
             Logger.WARN("BaseOutStream::Link: This stream is already linked");
             return(true);
         }
         Logger.FATAL("BaseOutStream::Link: This stream is already linked to stream with unique id {0}", InStream.UniqueId);
         return(false);
     }
     InStream = pInStream;
     if (reverseLink)
     {
         if (!InStream.Link(this, false))
         {
             Logger.FATAL("BaseOutStream::Link: Unable to reverse link");
             InStream = null;
             return(false);
         }
     }
     SignalAttachedToInStream();
     return(true);
 }
コード例 #14
0
 public override void PublishStream(uint appId, IInStream inStream, string type = "live")
 {
     foreach (var inboundClusterProtocol in InboundClusters.Where(x => inStream.GetProtocol() != x))
     {
         inboundClusterProtocol.PublishStream(appId, inStream, type);
     }
 }
コード例 #15
0
        /// <summary>
        /// Opens the archive and throws exceptions or returns OperationResult.DataError if any error occurs.
        /// </summary>
        /// <param name="archiveStream">The IInStream compliant class instance, that is, the input stream.</param>
        /// <param name="openCallback">The ArchiveOpenCallback instance.</param>
        /// <returns>OperationResult.Ok if Open() succeeds.</returns>
        private OperationResult OpenArchiveInner(IInStream archiveStream,
                                                 IArchiveOpenCallback openCallback)
        {
            ulong checkPos = 1 << 15;
            int   res      = _archive.Open(archiveStream, ref checkPos, openCallback);

            return((OperationResult)res);
        }
コード例 #16
0
 /* ----------------------------------------------------------------- */
 ///
 /// GetStream
 ///
 /// <summary>
 /// 読み込むボリュームに対応するストリームを取得します。
 /// </summary>
 ///
 /// <param name="name">ボリューム名</param>
 /// <param name="stream">読み込みストリーム</param>
 ///
 /// <returns>OperationResult</returns>
 ///
 /* ----------------------------------------------------------------- */
 public int GetStream(string name, out IInStream stream)
 {
     stream = Invoke(() =>
     {
         var src = IO.Exists(name) ? name : IO.Combine(IO.Get(Source).DirectoryName, name);
         if (!IO.Exists(src))
         {
             return(default);
コード例 #17
0
ファイル: StreamUtils.cs プロジェクト: vnmone/vvvv-sdk
 public static int GetLengthSum<T>(this IInStream<IInStream<T>> streams)
 {
     int result = 0;
     foreach (var stream in streams)
     {
         result += stream.Length;
     }
     return result;
 }
コード例 #18
0
        private static void ReadCyclic <T>(IInStream <T> stream, int length, int stepSize)
        {
            T[] buffer = new T[length];

            using (var reader = stream.GetCyclicReader())
            {
                reader.Read(buffer, 0, buffer.Length, stepSize);
            }
        }
コード例 #19
0
ファイル: RangeStream.cs プロジェクト: vnmone/vvvv-sdk
 public RangeStream(IInStream <T> source, int offset, int count)
 {
     Debug.Assert(offset >= 0);
     Debug.Assert(count >= 0);
     Debug.Assert(offset + count <= source.Length || source is CyclicStream <T>);
     FSource = source;
     FOffset = offset;
     FCount  = count;
 }
コード例 #20
0
 public void Dispose()
 {
     if (!this._Disposed)
     {
         if (this._Opened)
         {
             try
             {
                 this._Archive.Close();
                 this._Archive                   = (IInArchive)null;
                 this._ArchiveFileData           = (List <ArchiveFileInfo>)null;
                 this._ArchiveProperties         = (ReadOnlyCollection <ArchiveProperty>)null;
                 this._ArchiveFileInfoCollection = (ReadOnlyCollection <ArchiveFileInfo>)null;
                 this._InStream                  = (Stream)null;
             }
             catch (InvalidComObjectException ex)
             {
             }
         }
         if (this._OpenCallback != null)
         {
             try
             {
                 this._OpenCallback.Dispose();
             }
             catch (ObjectDisposedException ex)
             {
             }
             this._OpenCallback = (ArchiveOpenCallback)null;
         }
         if (this._ArchiveStream != null)
         {
             if (this._ArchiveStream is IDisposable)
             {
                 try
                 {
                     if (this._ArchiveStream is DisposeVariableWrapper)
                     {
                         (this._ArchiveStream as DisposeVariableWrapper).DisposeStream = true;
                     }
                     (this._ArchiveStream as IDisposable).Dispose();
                 }
                 catch (ObjectDisposedException ex)
                 {
                 }
                 this._ArchiveStream = (IInStream)null;
             }
         }
         if (!string.IsNullOrEmpty(this._FileName))
         {
             SevenZipLibraryManager.FreeLibrary((object)this, (Enum)this._Format);
         }
     }
     this._Disposed = true;
     GC.SuppressFinalize((object)this);
 }
コード例 #21
0
		public QuotedPrintableEncoder(IInStream stream, uint internalBufSize)
		{
			Debug.Assert(internalBufSize != 0);

			_stream = stream;
			_line = new byte[EncodedBytesPerLine];
			_buf = new byte[internalBufSize];

			_lines = readLines().GetEnumerator();
		}
コード例 #22
0
ファイル: StreamUtils.cs プロジェクト: vnmone/vvvv-sdk
 public static void Append<T>(this IOutStream<T> outStream, IInStream<T> inStream, T[] buffer)
 {
     var initialOutLength = outStream.Length;
     outStream.Length += inStream.Length;
     using (var writer = outStream.GetWriter())
     {
         writer.Position = initialOutLength;
         writer.Write(inStream, buffer);
     }
 }
コード例 #23
0
ファイル: Archive.cs プロジェクト: vaginessa/unrarit
 public void Close()
 {
     if (inArchive != null) {
     inArchive.Close();
     inArchive = null;
       }
       if (stream != null && stream is IDisposable) {
     ((IDisposable)stream).Dispose();
       }
       stream = null;
 }
コード例 #24
0
ファイル: InputPin.cs プロジェクト: mechaz/vvvv-sdk
        private void CopyOnWrite()
        {
            if (FCurrentInStream == FInStream)
            {
                // Copy data
                FIOStream.AssignFrom(FInStream);

                // Set current inStream to ioStream
                FCurrentInStream = FIOStream;
            }
        }
コード例 #25
0
        /// <summary>
        /// Unpacks the whole archive to the specified directory.
        /// </summary>
        /// <param name="directory">The directory where the files are to be unpacked.</param>
        public void ExtractArchive(string directory)
        {
            DisposedCheck();
            ClearExceptions();
            InitArchiveFileData(false);

            try
            {
                IInStream archiveStream;

                using ((archiveStream = GetArchiveStream(true)) as IDisposable)
                {
                    var openCallback = GetArchiveOpenCallback();

                    if (!OpenArchive(archiveStream, openCallback))
                    {
                        return;
                    }

                    try
                    {
                        using (var aec = GetArchiveExtractCallback(directory, (int)_filesCount, null))
                        {
                            try
                            {
                                CheckedExecute(
                                    _archive.Extract(null, uint.MaxValue, 0, aec),
                                    SevenZipExtractionFailedException.DEFAULT_MESSAGE, aec);
                                OnEvent(ExtractionFinished, EventArgs.Empty, false);
                            }
                            finally
                            {
                                FreeArchiveExtractCallback(aec);
                            }
                        }
                    }
                    catch (Exception)
                    {
                        if (openCallback.ThrowException())
                        {
                            throw;
                        }
                    }
                }
            }
            finally
            {
                _archive?.Close();
                _archiveStream = null;
                _opened        = false;
            }

            ThrowUserException();
        }
コード例 #26
0
 public InputBinSpreadStream(IIOFactory ioFactory, InputAttribute attribute, bool checkIfChanged, Func <IIOContainer <IInStream <int> > > binSizeIOContainerFactory)
 {
     // Don't do this, as spread max won't get computed for this pin
     //                attribute.AutoValidate = false;
     attribute.CheckIfChanged = checkIfChanged;
     FDataContainer           = ioFactory.CreateIOContainer <IInStream <T> >(attribute, false);
     FBinSizeContainer        = binSizeIOContainerFactory();
     FDataStream    = FDataContainer.IOObject;
     FBinSizeStream = FBinSizeContainer.IOObject;
     FDataIO        = FDataContainer.GetPluginIO();
 }
コード例 #27
0
 public bool UnLink()
 {
     if (InStream == null)
     {
         Logger.WARN("BaseOutStream::UnLink: This stream is not linked");
         return(true);
     }
     InStream = null;
     SignalDetachedFromInStream();
     return(true);
 }
コード例 #28
0
ファイル: StreamUtils.cs プロジェクト: ehenze/vvvv-sdk
 public static void Write <T>(this IStreamWriter <T> writer, IInStream <T> inStream, T[] buffer)
 {
     using (var reader = inStream.GetReader())
     {
         while (!reader.Eos)
         {
             int numSlicesRead = reader.Read(buffer, 0, buffer.Length);
             writer.Write(buffer, 0, numSlicesRead);
         }
     }
 }
コード例 #29
0
ファイル: StreamUtils.cs プロジェクト: vnmone/vvvv-sdk
 public static void SetLengthBy<T>(this IInStream<IOutStream<T>> outputStreams, IInStream<T> inputStream)
 {
     int outputLength = outputStreams.Length;
     int remainder = 0;
     int lengthPerStream = outputLength > 0 ? Math.DivRem(inputStream.Length, outputLength, out remainder) : 0;
     if (remainder > 0) lengthPerStream++;
     
     foreach (var outputStream in outputStreams)
     {
         outputStream.Length = lengthPerStream;
     }
 }
コード例 #30
0
ファイル: StreamUtils.cs プロジェクト: vnmone/vvvv-sdk
 public static void Append<T>(this IOutStream<T> outStream, IInStream<T> inStream)
 {
     var buffer = MemoryPool<T>.GetArray();
     try
     {
         outStream.Append(inStream, buffer);
     }
     finally
     {
         MemoryPool<T>.PutArray(buffer);
     }
 }
コード例 #31
0
        private static void ReadAsEnumerable <T>(IInStream <T> stream, int length)
        {
            int slicesRead = 0;

            while (slicesRead < length)
            {
                foreach (var value in stream)
                {
                    slicesRead++;
                }
            }
        }
コード例 #32
0
 internal CyclicStreamReader(IInStream <T> stream)
 {
     if (stream.Length == 0)
     {
         FReader = StreamUtils.GetEmptyStream <T>().GetReader();
     }
     else
     {
         FReader = stream.GetReader();
     }
     Eos    = stream.Length == 0;
     Length = stream.Length;
 }
コード例 #33
0
ファイル: Archive.cs プロジェクト: bra1nb3am3r/unrarit
 public void Close()
 {
     if (inArchive != null)
     {
         inArchive.Close();
         inArchive = null;
     }
     if (stream != null && stream is IDisposable)
     {
         ((IDisposable)stream).Dispose();
     }
     stream = null;
 }
コード例 #34
0
 public void PublishStream(uint appId, IInStream inNetStream,string type = "live")
 {
     _outStreamIdGenerator++;
     var outStream = new OutClusterStream(this, GetRoom(appId).StreamsManager, inNetStream.Name, _outStreamIdGenerator);
     outStream.Link(inNetStream);
     //Send(ClusterMessageType.Publish, new { AppId = appId, inNetStream.Name, inNetStream.Type, outStream.StreamId, inNetStream.ChunkSize ,PublishType=type});
     Send(ClusterMessageType.Publish, o =>
     {
         o.Write7BitValue(appId);
         o.Write(inNetStream.Name);
         o.Write(inNetStream.Type);
         o.Write7BitValue(outStream.StreamId);
         o.Write7BitValue(inNetStream.ChunkSize);
         o.Write(type);
     });
 }
コード例 #35
0
 private IOutArchive MakeOutArchive(IInStream inArchiveStream)
 {
     IInArchive inArchive = SevenZipLibraryManager.InArchive(
         Formats.InForOutFormats[_archiveFormat], this);
     using (ArchiveOpenCallback openCallback = GetArchiveOpenCallback())
     {
         ulong checkPos = 1 << 15;
         if (inArchive.Open(inArchiveStream, ref checkPos, openCallback) != (int)OperationResult.Ok)
         {
             if (
                 !ThrowException(null, new SevenZipArchiveException("Can not update the archive: Open() failed.")))
             {
                 return null;
             }
         }
         _oldFilesCount = inArchive.GetNumberOfItems();
     }
     return (IOutArchive)inArchive;
 }
コード例 #36
0
 /// <summary>
 /// Performs the archive integrity test.
 /// </summary>
 /// <returns>True is the archive is ok; otherwise, false.</returns>
 public bool Check()
 {
     DisposedCheck();
     try
     {
         InitArchiveFileData(false);
         var archiveStream = GetArchiveStream(true);
         var openCallback = GetArchiveOpenCallback();
         if (!OpenArchive(archiveStream, openCallback))
         {
             return false;
         }
         using (var aec = GetArchiveExtractCallback("", (int)_filesCount, null))
         {
             try
             {
                 CheckedExecute(
                     _archive.Extract(null, UInt32.MaxValue, 1, aec),
                     SevenZipExtractionFailedException.DEFAULT_MESSAGE, aec);
             }
             finally
             {
                 FreeArchiveExtractCallback(aec);
             }
         }
     }
     catch (Exception)
     {
         return false;
     }
     finally
     {
         if (_archive != null)
         {
             _archive.Close();
         }
         ((InStreamWrapper)_archiveStream).Dispose();
         _archiveStream = null;
         _opened = false;
     }
     return true;
 }
コード例 #37
0
        /// <summary>
        /// Retrieves all information about the archive.
        /// </summary>
        /// <exception cref="SevenZip.SevenZipArchiveException"/>
        private void GetArchiveInfo(bool disposeStream)
        {
            if (_archive == null)
            {
                if (!ThrowException(null, new SevenZipArchiveException()))
                {
                    return;
                }
            }
            else
            {
                IInStream archiveStream;
                using ((archiveStream = GetArchiveStream(disposeStream)) as IDisposable)
                {
                    var openCallback = GetArchiveOpenCallback();
                    if (!_opened)
                    {
                        if (!OpenArchive(archiveStream, openCallback))
                        {
                            return;
                        }
                        _opened = !disposeStream;
                    }
                    _filesCount = _archive.GetNumberOfItems();
                    _archiveFileData = new List<ArchiveFileInfo>((int)_filesCount);
                    if (_filesCount != 0)
                    {
                        var data = new PropVariant();
                        try
                        {
                            #region Getting archive items data

                            for (uint i = 0; i < _filesCount; i++)
                            {
                                try
                                {
                                    var fileInfo = new ArchiveFileInfo { Index = (int)i };
                                    _archive.GetProperty(i, ItemPropId.Path, ref data);
                                    fileInfo.FileName = NativeMethods.SafeCast(data, "[no name]");
                                    _archive.GetProperty(i, ItemPropId.LastWriteTime, ref data);
                                    fileInfo.LastWriteTime = NativeMethods.SafeCast(data, DateTime.Now);
                                    _archive.GetProperty(i, ItemPropId.CreationTime, ref data);
                                    fileInfo.CreationTime = NativeMethods.SafeCast(data, DateTime.Now);
                                    _archive.GetProperty(i, ItemPropId.LastAccessTime, ref data);
                                    fileInfo.LastAccessTime = NativeMethods.SafeCast(data, DateTime.Now);
                                    _archive.GetProperty(i, ItemPropId.Size, ref data);
                                    fileInfo.Size = NativeMethods.SafeCast<ulong>(data, 0);
                                    if (fileInfo.Size == 0)
                                    {
                                        fileInfo.Size = NativeMethods.SafeCast<uint>(data, 0);
                                    }
                                    _archive.GetProperty(i, ItemPropId.Attributes, ref data);
                                    fileInfo.Attributes = NativeMethods.SafeCast<uint>(data, 0);
                                    _archive.GetProperty(i, ItemPropId.IsDirectory, ref data);
                                    fileInfo.IsDirectory = NativeMethods.SafeCast(data, false);
                                    _archive.GetProperty(i, ItemPropId.Encrypted, ref data);
                                    fileInfo.Encrypted = NativeMethods.SafeCast(data, false);
                                    _archive.GetProperty(i, ItemPropId.Crc, ref data);
                                    fileInfo.Crc = NativeMethods.SafeCast<uint>(data, 0);
                                    _archive.GetProperty(i, ItemPropId.Comment, ref data);
                                    fileInfo.Comment = NativeMethods.SafeCast(data, "");
                                    _archiveFileData.Add(fileInfo);
                                }
                                catch (InvalidCastException)
                                {
                                    ThrowException(null, new SevenZipArchiveException("probably archive is corrupted."));
                                }
                            }

                            #endregion

                            #region Getting archive properties

                            uint numProps = _archive.GetNumberOfArchiveProperties();
                            var archProps = new List<ArchiveProperty>((int)numProps);
                            for (uint i = 0; i < numProps; i++)
                            {
                                string propName;
                                ItemPropId propId;
                                ushort varType;
                                _archive.GetArchivePropertyInfo(i, out propName, out propId, out varType);
                                _archive.GetArchiveProperty(propId, ref data);
                                if (propId == ItemPropId.Solid)
                                {
                                    _isSolid = NativeMethods.SafeCast(data, true);
                                }
                                // TODO Add more archive properties
                                if (PropIdToName.PropIdNames.ContainsKey(propId))
                                {
                                    archProps.Add(new ArchiveProperty
                                    {
                                        Name = PropIdToName.PropIdNames[propId],
                                        Value = data.Object
                                    });
                                }
                                else
                                {
                                    Debug.WriteLine(
                                        "An unknown archive property encountered (code " +
                                        ((int)propId).ToString(CultureInfo.InvariantCulture) + ')');
                                }
                            }
                            _archiveProperties = new ReadOnlyCollection<ArchiveProperty>(archProps);
                            if (!_isSolid.HasValue && _format == InArchiveFormat.Zip)
                            {
                                _isSolid = false;
                            }
                            if (!_isSolid.HasValue)
                            {
                                _isSolid = true;
                            }

                            #endregion
                        }
                        catch (Exception)
                        {
                            if (openCallback.ThrowException())
                            {
                                throw;
                            }
                        }
                    }
                }
                if (disposeStream)
                {
                    _archive.Close();
                    _archiveStream = null;
                }
                _archiveFileInfoCollection = new ReadOnlyCollection<ArchiveFileInfo>(_archiveFileData);
            }
        }
コード例 #38
0
 /// <summary>
 /// Opens the archive and throws exceptions or returns OperationResult.DataError if any error occurs.
 /// </summary>       
 /// <param name="archiveStream">The IInStream compliant class instance, that is, the input stream.</param>
 /// <param name="openCallback">The ArchiveOpenCallback instance.</param>
 /// <returns>OperationResult.Ok if Open() succeeds.</returns>
 private OperationResult OpenArchiveInner(IInStream archiveStream,
     IArchiveOpenCallback openCallback)
 {
     ulong checkPos = 1 << 15;
     int res = _archive.Open(archiveStream, ref checkPos, openCallback);
     return (OperationResult)res;
 }
コード例 #39
0
 /// <summary>
 /// Unpacks the whole archive to the specified directory.
 /// </summary>
 /// <param name="directory">The directory where the files are to be unpacked.</param>
 public void ExtractArchive(string directory)
 {
     DisposedCheck();          
     ClearExceptions();
     InitArchiveFileData(false);
     try
     {
         IInStream archiveStream;
         using ((archiveStream = GetArchiveStream(true)) as IDisposable)
         {
             var openCallback = GetArchiveOpenCallback();
             if (!OpenArchive(archiveStream, openCallback))
             {
                 return;
             }
             try
             {
                 using (var aec = GetArchiveExtractCallback(directory, (int) _filesCount, null))
                 {
                     try
                     {
                         CheckedExecute(
                             _archive.Extract(null, UInt32.MaxValue, 0, aec),
                             SevenZipExtractionFailedException.DEFAULT_MESSAGE, aec);
                         OnEvent(ExtractionFinished, EventArgs.Empty, false);
                     }
                     finally
                     {
                         FreeArchiveExtractCallback(aec);
                     }
                 }
             }
             catch (Exception)
             {
                 if (openCallback.ThrowException())
                 {
                     throw;
                 }
             }
         }
     }
     finally
     {
         if (_archive != null)
         {
             _archive.Close();
         }
         _archiveStream = null;
         _opened = false;
     }
     ThrowUserException();
 }        
コード例 #40
0
 public int GetStream(string name, out IInStream inStream)
 {
     if (!(((name == null) || !name.Equals(".rar", StringComparison.OrdinalIgnoreCase)) || string.IsNullOrEmpty(this.NameFormat)))
     {
         name = string.Format(this.NameFormat, ++this.NameCounter);
     }
     if (File.Exists(name))
     {
         inStream = new InStreamTimedWrapper(this.Context.Proxy.Open(name, FileMode.Open, FileAccess.Read, FileShare.Read));
         return 0;
     }
     inStream = null;
     return 1;
 }
コード例 #41
0
 public IOutFileStream CreateOutFileStream(BaseProtocol protocol, IInStream instream, bool append)
 {
     var pOutFileStream = CreateOutFileStream(protocol, instream.Name,null, append);
     pOutFileStream?.Link(instream);
     return pOutFileStream;
 }
コード例 #42
0
ファイル: Archive.cs プロジェクト: vaginessa/unrarit
 internal Archive(FileInfo aFile, IArchiveOpenCallback callback, Guid format)
 {
     stream = new SevenZipFileStream(aFile, FileMode.Open, FileAccess.Read);
       InternalOpen(callback, format);
 }
コード例 #43
0
ファイル: Archive.cs プロジェクト: vaginessa/unrarit
 public void Open(IInStream s, ref UInt64 maxCheckStartPosition, IArchiveOpenCallback openArchiveCallback)
 {
     throw new NotImplementedException();
 }
コード例 #44
0
		public QuotedPrintableDecoder(IInStream source)
		{
			_source = source;
			_encodedLine = new byte[MaxEncodedLength];
			_decodedLine = new byte[MaxEncodedLength + 2];
		}
コード例 #45
0
		public Base64Encoder(IInStream stream)
		{
			_stream = stream;
		}
コード例 #46
0
 public abstract void PublishStream(uint appId, IInStream inStream,string type = "live");
コード例 #47
0
		public QuotedPrintableEncoder(IInStream stream)
			: this(stream, RecommendedBufferSize)
		{
		}
コード例 #48
0
ファイル: ArchiveOpenCallback.cs プロジェクト: GEPWNAGE/Steel
        public int GetStream(string name, out IInStream inStream)
        {
            if (_subArchiveMode)
            {
                inStream = null;
                return HRESULT.S_FALSE;
            }

            if (_streams.ContainsKey(name))
            {
                inStream = _streams[name];
            }
            else
            {
                string path = Path.Combine(Path.GetDirectoryName(_fileName), name);
                try
                {
                    InStreamWrapper stream = new InStreamWrapper(File.OpenRead(path));
                    _volumes.Add(path);
                    _streams.Add(path, stream);
                    _currentVolumeSize = stream.BaseStream.Length;
                    _packedSize += _currentVolumeSize;
                    inStream = stream;
                }
                catch (FileNotFoundException)
                {
                    inStream = null;
                    return HRESULT.S_FALSE;
                }
                catch (Exception e)
                {
                    if (_exception == null)
                    {
                        _exception = new SevenZipException("Unable to open the volume: " + path, e);
                    }
                    inStream = null;
                    return HRESULT.E_INVALIDARG;
                }
            }
            return HRESULT.S_OK;
        }
コード例 #49
0
        void ConvertOneByOne(Stream srcStream, MemoryIOStream<double> dstStream, IInStream<ValueTypeFormat> formatStream, ByteOrder byteOrder)
        {
            var binaryReader = new BinaryReader(srcStream);
            int dstStreamLength = 0;
        	int counter = 0;
        	int maxCount = 0;

            using (var writer = dstStream.GetWriter())
            using (var formatStreamReader = formatStream.GetCyclicReader())
            {
                while (srcStream.Position < srcStream.Length && counter <= maxCount)
                {
                    var format = formatStreamReader.Read();
                    double result;
                    switch (format)
                    {
                        case ValueTypeFormat.Boolean:
                            result = (Double)Convert.ChangeType(binaryReader.ReadBoolean(byteOrder), typeof(Double));
                            break;
                        case ValueTypeFormat.SByte:
                            result = (Double)binaryReader.ReadSByte();
                            break;
                        case ValueTypeFormat.Byte:
                            result = (Double)binaryReader.ReadByte();
                            break;
                        case ValueTypeFormat.Int16:
                            result = (Double)binaryReader.ReadInt16(byteOrder);
                            break;
                        case ValueTypeFormat.UInt16:
                            result = (Double)binaryReader.ReadUInt16(byteOrder);
                            break;
                        case ValueTypeFormat.Int32:
                            result = (Double)binaryReader.ReadInt32(byteOrder);
                            break;
                        case ValueTypeFormat.UInt32:
                            result = (Double)binaryReader.ReadUInt32(byteOrder);
                            break;
                        case ValueTypeFormat.Int64:
                            result = (Double)binaryReader.ReadInt64(byteOrder);
                            break;
                        case ValueTypeFormat.UInt64:
                            result = (Double)binaryReader.ReadUInt64(byteOrder);
                            break;
                        case ValueTypeFormat.Single:
                            result = (Double)binaryReader.ReadSingle(byteOrder);
                            break;
                        case ValueTypeFormat.Double:
                            result = binaryReader.ReadDouble(byteOrder);
                            break;
                        default:
                            throw new NotImplementedException();
                    }
                    //if (result == -1) stop = true;
                	if ( counter == 0 ) maxCount = (int)result;
                	else{
	                	writer.Write(result);
	                    dstStreamLength++;
                	}
                	counter++;
                }
            	if(srcStream.Position == srcStream.Length) FEof[0] = true;
            }
            dstStream.Length = dstStreamLength;
        }
コード例 #50
0
ファイル: ArchiveFile.cs プロジェクト: vaginessa/unrarit
 int IArchiveOpenVolumeCallback.GetStream(string name, ref IInStream inStream)
 {
     return (owner as IArchiveOpenVolumeCallback).GetStream(name, ref inStream);
 }
コード例 #51
0
        /// <summary>
        /// Unpacks files by their indices to the specified directory.
        /// </summary>
        /// <param name="indexes">indexes of the files in the archive file table.</param>
        /// <param name="directory">Directory where the files are to be unpacked.</param>
        public void ExtractFiles(string directory, params int[] indexes)
        {
            DisposedCheck();
            ClearExceptions();
            if (!CheckIndexes(indexes))
            {
                if (
                    !ThrowException(null, new ArgumentException("The indexes must be more or equal to zero.", "indexes")))
                {
                    return;
                }
            }
            InitArchiveFileData(false);

            #region Indexes stuff

            var uindexes = new uint[indexes.Length];
            for (int i = 0; i < indexes.Length; i++)
            {
                uindexes[i] = (uint) indexes[i];
            }
#if CS4
            if (uindexes.Where(i => i >= _filesCount).Any(
                i => !ThrowException(null, 
                                     new ArgumentOutOfRangeException("indexes", 
                                                                    "Index must be less than " + 
                                                                        _filesCount.Value.ToString(
                                                                            CultureInfo.InvariantCulture) + "!"))))
            {
                return;
            }
#else
            foreach (uint i in uindexes)
            {
                if (i >= _filesCount)
                {
                    if (!ThrowException(null,
                                        new ArgumentOutOfRangeException("indexes",
                                                                        "Index must be less than " +
                                                                            _filesCount.Value.ToString(
                                                                                CultureInfo.InvariantCulture) + "!")))
                    {
                        return;
                    }
                }
            }
#endif
            var origIndexes = new List<uint>(uindexes);
            origIndexes.Sort();
            uindexes = origIndexes.ToArray();
            if (_isSolid.Value)
            {
                uindexes = SolidIndexes(uindexes);
            }

            #endregion

            try
            {
                IInStream archiveStream;
                using ((archiveStream = GetArchiveStream(origIndexes.Count != 1)) as IDisposable)
                {
                    var openCallback = GetArchiveOpenCallback();
                    if (!OpenArchive(archiveStream, openCallback))
                    {
                        return;
                    }
                    try
                    {
                        using (var aec = GetArchiveExtractCallback(directory, (int) _filesCount, origIndexes))
                        {
                            try
                            {
                                CheckedExecute(
                                    _archive.Extract(uindexes, (uint) uindexes.Length, 0, aec),
                                    SevenZipExtractionFailedException.DEFAULT_MESSAGE, aec);
                            }
                            finally
                            {
                                FreeArchiveExtractCallback(aec);
                            }
                        }
                    }
                    catch (Exception)
                    {
                        if (openCallback.ThrowException())
                        {
                            throw;
                        }
                    }
                }
                OnEvent(ExtractionFinished, EventArgs.Empty, false);
            }
            finally
            {
                if (origIndexes.Count > 1)
                {
                    if (_archive != null)
                    {
                        _archive.Close();
                    }
                    _archiveStream = null;
                    _opened = false;
                }
            }
            ThrowUserException();
        }
コード例 #52
0
ファイル: ArchiveFile.cs プロジェクト: vaginessa/unrarit
 int IArchiveOpenVolumeCallback.GetStream(string name, ref IInStream stream)
 {
     var c = new FileInfo(name);
       if (!c.Exists) {
     stream = null;
     return 1;
       }
       current = c;
       if (fileStreams.ContainsKey(name)) {
     stream = fileStreams[name];
     stream.Seek(0, 0);
     return 0;
       }
       var fileStream = new SevenZipFileStream(current, FileMode.Open, FileAccess.Read);
       fileStreams[name] = fileStream;
       stream = fileStream;
       return 0;
 }
コード例 #53
0
        /// <summary>
        /// Gets the archive input stream.
        /// </summary>
        /// <returns>The archive input wrapper stream.</returns>
        private IInStream GetArchiveStream(bool dispose)
        {
            if (_archiveStream != null)
            {
                if (_archiveStream is DisposeVariableWrapper)
                {
                    (_archiveStream as DisposeVariableWrapper).DisposeStream = dispose;
                }
                return _archiveStream;
            }

            if (_inStream != null)
            {
                _inStream.Seek(0, SeekOrigin.Begin);
                _archiveStream = new InStreamWrapper(_inStream, false);
            }
            else
            {
                if (!_fileName.EndsWith(".001", StringComparison.OrdinalIgnoreCase))
                {
                    _archiveStream = new InStreamWrapper(
                        new ArchiveEmulationStreamProxy(new FileStream(
                            _fileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite),
                            _offset),
                        dispose);
                }
                else
                {
                    _archiveStream = new InMultiStreamWrapper(_fileName, dispose);
                    _packedSize = (_archiveStream as InMultiStreamWrapper).Length;
                }
            }
            return _archiveStream;
        }
コード例 #54
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 (Exception)
         {
             AddException(new FileNotFoundException("Failed to open the volume \"" + name + "\". Extraction is impossible."));
             inStream = null;
             return 1;
         }
     }
     return 0;
 }
コード例 #55
0
 /// <summary>
 /// Opens the archive and throws exceptions or returns OperationResult.DataError if any error occurs.
 /// </summary>
 /// <param name="archiveStream">The IInStream compliant class instance, that is, the input stream.</param>
 /// <param name="openCallback">The ArchiveOpenCallback instance.</param>
 /// <returns>True if Open() succeeds; otherwise, false.</returns>
 private bool OpenArchive(IInStream archiveStream,
     ArchiveOpenCallback openCallback)
 {
     if (!_opened)
     {
         if (OpenArchiveInner(archiveStream, openCallback) != OperationResult.Ok)
         {
             if (!ThrowException(null, new SevenZipArchiveException()))
             {
                 return false;
             }
         }
         _volumeFileNames = new ReadOnlyCollection<string>(openCallback.VolumeFileNames);
         _opened = true;
     }
     return true;
 }
コード例 #56
0
            public int GetStream(string name, out IInStream inStream)
            {
                IFileObject volumeFileObject = parent.resolveFile(Path.GetFileName(name));
                if (volumeFileObject != null && volumeFileObject.exists())
                {
                    fileSystem.fireVolumeOpened(volumeFileObject);

                    FileInfo file = parent.FileSystem.replicateFile(volumeFileObject, Selectors.SELECT_SELF);
                    Stream fs = file.Open(FileMode.Open, FileAccess.Read, FileShare.Read);
                    streams.Add(fs);

                    inStream = new InStreamWrapper(fs);
                    return 0;
                }

                inStream = null;
                return 1;
            }
コード例 #57
0
 private void CommonDispose()
 {
     if (_opened)
     {
         try
         {
             if (_archive != null)
             {
                 _archive.Close();
             }
         }
         catch (Exception) { }
     }
     _archive = null;
     _archiveFileData = null;
     _archiveProperties = null;
     _archiveFileInfoCollection = null;
     _inStream = null;
     if (_openCallback != null)
     {
         try
         {
             _openCallback.Dispose();
         }
         catch (ObjectDisposedException) { }
         _openCallback = null;
     }
     if (_archiveStream != null)
     {
         if (_archiveStream is IDisposable)
         {
             try
             {
                 if (_archiveStream is DisposeVariableWrapper)
                 {
                     (_archiveStream as DisposeVariableWrapper).DisposeStream = true;
                 }
                 (_archiveStream as IDisposable).Dispose();
             }
             catch (ObjectDisposedException) { }
             _archiveStream = null;
         }
     }
     SevenZipLibraryManager.FreeLibrary(this, _format);
 }
コード例 #58
0
 public int GetStream(string name, out IInStream inStream)
 {
     throw new System.NotImplementedException();
 }
コード例 #59
0
 public override void PublishStream(uint appId, IInStream inStream,string type="live")
 {
     if (OutboundCluster != null) OutboundCluster.PublishStream(appId, inStream,type);
 }
コード例 #60
0
		public Base64Decoder(IInStream source)
		{
			_source = source;
		}