示例#1
0
        /// <summary>
        /// Returns mini FAT table
        /// </summary>
        public XlsFat GetMiniFAT(XlsRootDirectory rootDir)
        {
            if (m_minifat != null)
            {
                return(m_minifat);
            }

            //if no minifat then return null
            if (MiniFatSectorCount == 0 || MiniSectorSize == 0xFFFFFFFE)
            {
                return(null);
            }

            int         miniSectorSize = MiniSectorSize;
            List <uint> sectors        = new List <uint>(MiniFatSectorCount);

            //find the sector where the minifat starts
            var miniFatStartSector = BitConverter.ToUInt32(m_bytes, 0x3c);

            sectors.Add(miniFatStartSector);
            //lock (m_file)
            //{
            //	//work out the file location of minifat then read each sector
            //	var miniFatStartOffset = (miniFatStartSector + 1)*SectorSize;
            //	var miniFatSize = MiniFatSectorCount * SectorSize;
            //	m_file.Seek(miniFatStartOffset, SeekOrigin.Begin);

            //	byte[] sectorBuff = new byte[SectorSize];

            //	for (var i = 0; i < MiniFatSectorCount; i += SectorSize)
            //	{
            //		m_file.Read(sectorBuff, 0, 4);
            //		var secId = BitConverter.ToUInt32(sectorBuff, 0);
            //		sectors.Add(secId);
            //	}
            //}

            m_minifat = new XlsFat(this, sectors, this.MiniSectorSize, true, rootDir);
            return(m_minifat);
        }
示例#2
0
 public void CalculateMiniFat(XlsRootDirectory rootDir)
 {
     m_minifat = m_hdr.GetMiniFAT(rootDir);
 }
示例#3
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());
                }
#if LEGACY
                rd.Close();
#else
                ((IDisposable)rd).Dispose();
#endif

                ms.Dispose();
            }
        }