コード例 #1
0
 public XlsBiffStream(XlsHeader hdr, uint streamStart, bool isMini, XlsRootDirectory rootDir, ExcelBinaryReader reader)
     : base(hdr, streamStart, isMini, rootDir)
 {
     this.reader = reader;
     bytes       = base.ReadStream();
     m_size      = bytes.Length;
     m_offset    = 0;
 }
コード例 #2
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="bytes">byte array representing current object</param>
 /// <param name="header"></param>
 public XlsDirectoryEntry(byte[] bytes, XlsHeader header)
 {
     if (bytes.Length < Length)
     {
         throw new BiffRecordException(Errors.ErrorDirectoryEntryArray);
     }
     m_bytes  = bytes;
     m_header = header;
 }
コード例 #3
0
ファイル: XlsStream.cs プロジェクト: useada/ARPG-Game
        public XlsStream(XlsHeader hdr, uint startSector, bool isMini, XlsRootDirectory rootDir)
        {
            m_fileStream  = hdr.FileStream;
            m_fat         = hdr.FAT;
            m_hdr         = hdr;
            m_startSector = startSector;
            m_isMini      = isMini;
            m_rootDir     = rootDir;

            CalculateMiniFat(rootDir);
        }
コード例 #4
0
ファイル: XlsFat.cs プロジェクト: useada/ARPG-Game
        /// <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
                rd.Dispose();
#endif

                ms.Dispose();
            }
        }
コード例 #5
0
ファイル: XlsHeader.cs プロジェクト: useada/ARPG-Game
        /// <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 HeaderException(Errors.ErrorHeaderSignature);
            }
            if (hdr.ByteOrder != 0xFFFE)
            {
                throw new FormatException(Errors.ErrorHeaderOrder);
            }
            return(hdr);
        }
コード例 #6
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, 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);
        }