/// <summary>
        ///     Gets data from the <see cref="cFStream" />
        /// </summary>
        /// <param name="cFStream"></param>
        /// <param name="offset"></param>
        /// <param name="count"></param>
        /// <returns></returns>
        /// <exception cref="CFDisposedException">Raised when the file is closed</exception>
        internal byte[] GetData(CFStream cFStream, long offset, ref int count)
        {
            var directoryEntry = cFStream.DirEntry;
            count = (int) Math.Min(directoryEntry.Size - offset, count);

            StreamView streamView;

            if (directoryEntry.Size < _header.MinSizeStandardStream)
            {
                streamView
                    = new StreamView(GetSectorChain(directoryEntry.StartSector, SectorType.Mini), Sector.MinisectorSize,
                        directoryEntry.Size,
                        SourceStream);
            }
            else
            {
                streamView = new StreamView(GetSectorChain(directoryEntry.StartSector, SectorType.Normal),
                    GetSectorSize(), directoryEntry.Size,
                    SourceStream);
            }

            var result = new byte[count];
            streamView.Seek(offset, SeekOrigin.Begin);
            streamView.Read(result, 0, result.Length);

            return result;
        }
        /// <summary>
        ///     Gets data from the <see cref="cFStream" />
        /// </summary>
        /// <param name="cFStream"></param>
        /// <returns></returns>
        /// <exception cref="CFDisposedException">Raised when the file is closed</exception>
        internal byte[] GetData(CFStream cFStream)
        {
            if (IsClosed)
                throw new CFDisposedException("Compound File closed: cannot access data");

            byte[] result;

            var directoryEntry = cFStream.DirEntry;

            if (directoryEntry.Size < _header.MinSizeStandardStream)
            {
                var miniView
                    = new StreamView(GetSectorChain(directoryEntry.StartSector, SectorType.Mini), Sector.MinisectorSize,
                        directoryEntry.Size,
                        SourceStream);

                var br = new BinaryReader(miniView);

                result = br.ReadBytes((int) directoryEntry.Size);
                br.Close();
            }
            else
            {
                var sView
                    = new StreamView(GetSectorChain(directoryEntry.StartSector, SectorType.Normal), GetSectorSize(),
                        directoryEntry.Size,
                        SourceStream);

                result = new byte[(int) directoryEntry.Size];

                sView.Read(result, 0, result.Length);
            }

            return result;
        }
Ejemplo n.º 3
0
        private static string GetFileNameFromAttachDescStream(CFStream stream)
        {
            // https://msdn.microsoft.com/en-us/library/ee157577(v=exchg.80).aspx
            if (stream == null) return null;
            var ad = new AttachDescStream(stream);
            
            if (!string.IsNullOrWhiteSpace(ad.LongFileName)) 
                return ad.LongFileName;
            if (!string.IsNullOrWhiteSpace(ad.DisplayName))
                return ad.DisplayName;

            if (!string.IsNullOrWhiteSpace(ad.FileName))
                return ad.FileName;

            return null;
        }