Пример #1
0
 public XlsStream(XlsHeader hdr, uint startSector)
 {
     m_file = hdr.FileStream;
     m_fat = hdr.FAT;
     m_hdr = hdr;
     m_startSector = startSector;
 }
Пример #2
0
 /// <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);
     byte[] array = stream.ReadStream();
     List<XlsDirectoryEntry> entries = new List<XlsDirectoryEntry>();
     for (int i = 0; i < array.Length; i += XlsDirectoryEntry.Length)
     {
         byte[] tmp = new byte[XlsDirectoryEntry.Length];
         Buffer.BlockCopy(array, i, tmp, 0, tmp.Length);
         entries.Add(new XlsDirectoryEntry(tmp));
     }
     m_entries = entries;
     for (int i = 0; i < entries.Count; i++)
     {
         XlsDirectoryEntry entry = entries[i];
         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];
         }
     }
 }
Пример #3
0
 /// <summary>
 /// Constructs FAT table from list of sectors
 /// </summary>
 /// <param name="hdr">XlsHeader</param>
 /// <param name="sectors">Sectors list</param>
 public XlsFat(XlsHeader hdr, List<uint> sectors)
 {
     m_hdr = hdr;
     m_sectors_for_fat = sectors.Count;
     uint prevSector = 0;
     int sectorSize = hdr.SectorSize;
     byte[] buff = new byte[sectorSize];
     Stream file = hdr.FileStream;
     using (MemoryStream ms = new MemoryStream(sectorSize * m_sectors_for_fat))
     {
         lock (file)
         {
             for (int i = 0; i < sectors.Count; i++)
             {
                 uint sector = sectors[i];
                 if (prevSector == 0 || (sector - prevSector) != 1)
                 {
                     file.Seek((sector + 1) * sectorSize, SeekOrigin.Begin);
                 }
                 prevSector = sector;
                 file.Read(buff, 0, sectorSize);
                 ms.Write(buff, 0, sectorSize);
             }
         }
         ms.Seek(0, SeekOrigin.Begin);
         BinaryReader rd = new BinaryReader(ms);
         m_sectors = (int)ms.Length / 4;
         m_fat = new List<uint>(m_sectors);
         for (int i = 0; i < m_sectors; i++)
         {
             m_fat.Add(rd.ReadUInt32());
         }
         rd.Close();
         ms.Close();
     }
 }
Пример #4
0
 /// <summary>
 /// Reads Excel header from Stream
 /// </summary>
 /// <param name="file">Stream with Excel file</param>
 /// <returns>XlsHeader representing specified file</returns>
 public static XlsHeader ReadHeader(Stream file)
 {
     XlsHeader hdr = new XlsHeader(file);
     lock (file)
     {
         file.Seek(0, SeekOrigin.Begin);
         file.Read(hdr.m_bytes, 0, 512);
     }
     if (!hdr.IsSignatureValid)
     {
         throw new InvalidHeaderException("Invalid file signature");
     }
     if (hdr.ByteOrder != 0xFFFE)
     {
         throw new FormatException("Invalid byte order specified");
     }
     return hdr;
 }
Пример #5
0
 public XlsBiffStream(XlsHeader hdr, uint streamStart)
     : base(hdr, streamStart)
 {
     bytes = base.ReadStream();
     m_size = bytes.Length;
     m_offset = 0;
 }