private XlsDirectoryEntry ReadDirectoryEntry(BinaryReader reader)
        {
            var result     = new XlsDirectoryEntry();
            var name       = reader.ReadBytes(64);
            var nameLength = reader.ReadUInt16();

            if (nameLength > 0)
            {
                result.EntryName = Encoding.Unicode.GetString(name, 0, nameLength).TrimEnd('\0');
            }

            result.EntryType         = (STGTY)reader.ReadByte();
            result.EntryColor        = (DECOLOR)reader.ReadByte();
            result.LeftSiblingSid    = reader.ReadUInt32();
            result.RightSiblingSid   = reader.ReadUInt32();
            result.ChildSid          = reader.ReadUInt32();
            result.ClassId           = new Guid(reader.ReadBytes(16));
            result.UserFlags         = reader.ReadUInt32();
            result.CreationTime      = DateTime.FromFileTime(reader.ReadInt64());
            result.LastWriteTime     = DateTime.FromFileTime(reader.ReadInt64());
            result.StreamFirstSector = reader.ReadUInt32();
            result.StreamSize        = reader.ReadUInt32();
            result.PropType          = reader.ReadUInt32();
            result.IsEntryMiniStream = result.StreamSize < Header.MiniStreamCutoff;
            return(result);
        }
Esempio n. 2
0
        private byte[] ReadCompoundDocument(Stream stream)
        {
            var document = new XlsDocument(stream);
            XlsDirectoryEntry workbookEntry = document.FindEntry(DirectoryEntryWorkbook) ?? document.FindEntry(DirectoryEntryBook);

            if (workbookEntry == null)
            {
                throw new ExcelReaderException(Errors.ErrorStreamWorkbookNotFound);
            }

            if (workbookEntry.EntryType != STGTY.STGTY_STREAM)
            {
                throw new ExcelReaderException(Errors.ErrorWorkbookIsNotStream);
            }

            return(document.ReadStream(stream, workbookEntry.StreamFirstSector, (int)workbookEntry.StreamSize, workbookEntry.IsEntryMiniStream));
        }
        /// <summary>
        /// Creates Root Directory catalog from XlsHeader
        /// </summary>
        /// <param name="hdr">XlsHeader object</param>
        public XlsRootDirectory(XlsHeader hdr)
        {
            XlsStream stream = new XlsStream(hdr, hdr.RootDirectoryEntryStart, false, null);

            byte[]                   array = stream.ReadStream();
            byte[]                   tmp;
            XlsDirectoryEntry        entry;
            List <XlsDirectoryEntry> entries = new List <XlsDirectoryEntry>();

            for (int i = 0; i < array.Length; i += XlsDirectoryEntry.Length)
            {
                tmp = new byte[XlsDirectoryEntry.Length];
                Buffer.BlockCopy(array, i, tmp, 0, tmp.Length);
                entries.Add(new XlsDirectoryEntry(tmp, hdr));
            }
            m_entries = entries;
            for (int i = 0; i < entries.Count; i++)
            {
                entry = entries[i];

                //Console.WriteLine("Directory Entry:{0} type:{1}, firstsector:{2}, streamSize:{3}, isEntryMiniStream:{4}", entry.EntryName, entry.EntryType.ToString(), entry.StreamFirstSector, entry.StreamSize, entry.IsEntryMiniStream);
                if (m_root == null && entry.EntryType == STGTY.STGTY_ROOT)
                {
                    m_root = entry;
                }
                if (entry.ChildSid != (uint)FATMARKERS.FAT_FreeSpace)
                {
                    entry.Child = entries[(int)entry.ChildSid];
                }
                if (entry.LeftSiblingSid != (uint)FATMARKERS.FAT_FreeSpace)
                {
                    entry.LeftSibling = entries[(int)entry.LeftSiblingSid];
                }
                if (entry.RightSiblingSid != (uint)FATMARKERS.FAT_FreeSpace)
                {
                    entry.RightSibling = entries[(int)entry.RightSiblingSid];
                }
            }
            stream.CalculateMiniFat(this);
        }