示例#1
0
        public Metadata(FileStream fs)
        {
            fs.Seek(0, SeekOrigin.Begin);
            PDB        = new PDBHeader(fs);
            PDH        = new PalmDOCHeader(fs);
            mobiHeader = new MobiHead(fs, PDB.MobiHeaderSize);
            // Use ASIN of the first book in the mobi
            _ASIN = mobiHeader.exthHeader.ASIN != "" ? mobiHeader.exthHeader.ASIN : mobiHeader.exthHeader.ASIN2;

            // Start at end of first book records, search for a second (KF8) and use it instead (for combo books)
            for (int i = PDH.RecordCount; i < PDB.NumRecords - 1; i++)
            {
                uint recSize = PDB._recInfo[i + 1].RecordDataOffset - PDB._recInfo[i].RecordDataOffset;
                if (recSize < 8)
                {
                    continue;
                }
                byte[] buffer = new byte[recSize];
                fs.Seek(PDB._recInfo[i].RecordDataOffset, SeekOrigin.Begin);
                fs.Read(buffer, 0, buffer.Length);
                if (Encoding.ASCII.GetString(buffer, 0, 8) == "BOUNDARY")
                {
                    _startRecord = i + 2;
                    PDH          = new PalmDOCHeader(fs);
                    mobiHeader   = new MobiHead(fs, PDB.MobiHeaderSize);
                    break;
                }
            }
        }
示例#2
0
        public Metadata(FileStream fs)
        {
            fs.Seek(0, SeekOrigin.Begin);
            PDB = new PDBHeader(fs);
            PDH = new PalmDOCHeader(fs);
            mobiHeader = new MobiHead(fs, PDB.MobiHeaderSize);
            // Use ASIN of the first book in the mobi
            _ASIN = mobiHeader.exthHeader.ASIN != "" ? mobiHeader.exthHeader.ASIN : mobiHeader.exthHeader.ASIN2;

            // Start at end of first book records, search for a second (KF8) and use it instead (for combo books)
            for (int i = PDH.RecordCount; i < PDB.NumRecords - 1; i++)
            {
                uint recSize = PDB._recInfo[i + 1].RecordDataOffset - PDB._recInfo[i].RecordDataOffset;
                if (recSize < 8) continue;
                byte[] buffer = new byte[recSize];
                fs.Seek(PDB._recInfo[i].RecordDataOffset, SeekOrigin.Begin);
                fs.Read(buffer, 0, buffer.Length);
                if (Encoding.ASCII.GetString(buffer, 0, 8) == "BOUNDARY")
                {
                    _startRecord = i + 2;
                    PDH = new PalmDOCHeader(fs);
                    mobiHeader = new MobiHead(fs, PDB.MobiHeaderSize);
                    break;
                }
            }
        }
示例#3
0
        private void Initialize(FileStream fs)
        {
            fs.Seek(0, SeekOrigin.Begin);
            PDB        = new PDBHeader(fs);
            PDH        = new PalmDOCHeader(fs);
            mobiHeader = new MobiHead(fs, PDB.MobiHeaderSize);
            // Use ASIN of the first book in the mobi
            int coverOffset = mobiHeader.exthHeader.CoverOffset;
            int firstImage  = -1;

            // Start at end of first book records, search for a second (KF8) and use it instead (for combo books)
            for (int i = PDH.RecordCount; i < PDB.NumRecords - 1; i++)
            {
                uint recSize = PDB._recInfo[i + 1].RecordDataOffset - PDB._recInfo[i].RecordDataOffset;
                if (recSize < 8)
                {
                    continue;
                }
                byte[] buffer = new byte[recSize];
                fs.Seek(PDB._recInfo[i].RecordDataOffset, SeekOrigin.Begin);
                fs.Read(buffer, 0, buffer.Length);
                string imgtype = coverOffset == -1 ? "" : get_image_type(buffer);
                if (imgtype != "")
                {
                    if (firstImage == -1)
                    {
                        firstImage = i;
                    }
                    if (i == firstImage + coverOffset)
                    {
                        using (MemoryStream ms = new MemoryStream(buffer))
                            coverImage = new Bitmap(ms);
                    }
                }
                else if (Encoding.ASCII.GetString(buffer, 0, 8) == "BOUNDARY")
                {
                    _startRecord = i + 2;
                    PDH          = new PalmDOCHeader(fs);
                    mobiHeader   = new MobiHead(fs, PDB.MobiHeaderSize);
                    break;
                }
            }
        }