Ejemplo n.º 1
0
        /// <summary>
        /// Constructs FAT table from list of sectors
        /// </summary>
        /// <param name="hdr">XlsHeader</param>
        /// <param name="sectors">Sectors list</param>
        /// <param name="sizeOfSector"></param>
        /// <param name="isMini"></param>
        /// <param name="rootDir"></param>
        public XlsFat(XlsHeader hdr, List <uint> sectors, int sizeOfSector, bool isMini, XlsRootDirectory rootDir)
        {
            m_isMini          = isMini;
            m_rootDir         = rootDir;
            m_hdr             = hdr;
            m_sectors_for_fat = sectors.Count;
            sizeOfSector      = hdr.SectorSize;
            uint sector = 0, prevSector = 0;

            //calc offset of stream . If mini stream then find mini stream container stream
            //long offset = 0;
            //if (rootDir != null)
            //	offset = isMini ? (hdr.MiniFatFirstSector + 1) * hdr.SectorSize : 0;

            byte[] buff = new byte[sizeOfSector];
            Stream file = hdr.FileStream;

            using (MemoryStream ms = new MemoryStream(sizeOfSector * m_sectors_for_fat))
            {
                lock (file)
                {
                    for (int i = 0; i < sectors.Count; i++)
                    {
                        sector = sectors[i];
                        if (prevSector == 0 || (sector - prevSector) != 1)
                        {
                            file.Seek((sector + 1) * sizeOfSector, SeekOrigin.Begin);
                        }
                        prevSector = sector;
                        file.Read(buff, 0, sizeOfSector);
                        ms.Write(buff, 0, sizeOfSector);
                    }
                }
                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.Dispose();
                ms.Dispose();
            }
        }
Ejemplo n.º 2
0
 public void CalculateMiniFat(XlsRootDirectory rootDir)
 {
     m_minifat = m_hdr.GetMiniFAT(rootDir);
 }