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); }
public IOutFileStream CreateOutFileStream(BaseProtocol protocol, IInStream instream, bool append) { var pOutFileStream = CreateOutFileStream(protocol, instream.Name, null, append); pOutFileStream?.Link(instream); return(pOutFileStream); }
/// <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); }
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; }
public override void PublishStream(uint appId, IInStream inStream, string type = "live") { if (OutboundCluster != null) { OutboundCluster.PublishStream(appId, inStream, type); } }
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; }
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); } }
IIOStream <T> CloneStream <T>(IInStream <T> stream) { var mem = new MemoryIOStream <T>(); mem.AssignFrom(stream); return(mem); }
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); }
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); }
public bool Sync() { var changed = FInStream.Sync(); FCurrentInStream = FInStream; return(changed); }
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); }
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); }
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); } }
/// <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); }
/* ----------------------------------------------------------------- */ /// /// 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);
public static int GetLengthSum<T>(this IInStream<IInStream<T>> streams) { int result = 0; foreach (var stream in streams) { result += stream.Length; } return result; }
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); } }
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; }
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); }
public QuotedPrintableEncoder(IInStream stream, uint internalBufSize) { Debug.Assert(internalBufSize != 0); _stream = stream; _line = new byte[EncodedBytesPerLine]; _buf = new byte[internalBufSize]; _lines = readLines().GetEnumerator(); }
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); } }
public void Close() { if (inArchive != null) { inArchive.Close(); inArchive = null; } if (stream != null && stream is IDisposable) { ((IDisposable)stream).Dispose(); } stream = null; }
private void CopyOnWrite() { if (FCurrentInStream == FInStream) { // Copy data FIOStream.AssignFrom(FInStream); // Set current inStream to ioStream FCurrentInStream = FIOStream; } }
/// <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(); }
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(); }
public bool UnLink() { if (InStream == null) { Logger.WARN("BaseOutStream::UnLink: This stream is not linked"); return(true); } InStream = null; SignalDetachedFromInStream(); return(true); }
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); } } }
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; } }
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); } }
private static void ReadAsEnumerable <T>(IInStream <T> stream, int length) { int slicesRead = 0; while (slicesRead < length) { foreach (var value in stream) { slicesRead++; } } }
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; }
public void Close() { if (inArchive != null) { inArchive.Close(); inArchive = null; } if (stream != null && stream is IDisposable) { ((IDisposable)stream).Dispose(); } stream = null; }
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); }); }
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; }
/// <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; }
/// <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); } }
/// <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; }
/// <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(); }
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; }
public IOutFileStream CreateOutFileStream(BaseProtocol protocol, IInStream instream, bool append) { var pOutFileStream = CreateOutFileStream(protocol, instream.Name,null, append); pOutFileStream?.Link(instream); return pOutFileStream; }
internal Archive(FileInfo aFile, IArchiveOpenCallback callback, Guid format) { stream = new SevenZipFileStream(aFile, FileMode.Open, FileAccess.Read); InternalOpen(callback, format); }
public void Open(IInStream s, ref UInt64 maxCheckStartPosition, IArchiveOpenCallback openArchiveCallback) { throw new NotImplementedException(); }
public QuotedPrintableDecoder(IInStream source) { _source = source; _encodedLine = new byte[MaxEncodedLength]; _decodedLine = new byte[MaxEncodedLength + 2]; }
public Base64Encoder(IInStream stream) { _stream = stream; }
public abstract void PublishStream(uint appId, IInStream inStream,string type = "live");
public QuotedPrintableEncoder(IInStream stream) : this(stream, RecommendedBufferSize) { }
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; }
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; }
int IArchiveOpenVolumeCallback.GetStream(string name, ref IInStream inStream) { return (owner as IArchiveOpenVolumeCallback).GetStream(name, ref inStream); }
/// <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(); }
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; }
/// <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; }
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; }
/// <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; }
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; }
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); }
public int GetStream(string name, out IInStream inStream) { throw new System.NotImplementedException(); }
public override void PublishStream(uint appId, IInStream inStream,string type="live") { if (OutboundCluster != null) OutboundCluster.PublishStream(appId, inStream,type); }
public Base64Decoder(IInStream source) { _source = source; }