author | pohly <pohly> | 2004-08-24 20:52:45 (UTC) |
---|---|---|
committer | pohly <pohly> | 2004-08-24 20:52:45 (UTC) |
commit | 73253e93327cf4ef0932de1b4afb56af22a0f37e (patch) (side-by-side diff) | |
tree | 1c9a7a6dd3341e036a894d348a3372525d29acec /noncore/apps/opie-reader/Aportis.cpp | |
parent | e90847c784c48bd21bf8768cb38edb853b832697 (diff) | |
download | opie-73253e93327cf4ef0932de1b4afb56af22a0f37e.zip opie-73253e93327cf4ef0932de1b4afb56af22a0f37e.tar.gz opie-73253e93327cf4ef0932de1b4afb56af22a0f37e.tar.bz2 |
updated source to opie-reader 0.7g
Diffstat (limited to 'noncore/apps/opie-reader/Aportis.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/apps/opie-reader/Aportis.cpp | 109 |
1 files changed, 95 insertions, 14 deletions
diff --git a/noncore/apps/opie-reader/Aportis.cpp b/noncore/apps/opie-reader/Aportis.cpp index 06f44a4..7528e78 100644 --- a/noncore/apps/opie-reader/Aportis.cpp +++ b/noncore/apps/opie-reader/Aportis.cpp @@ -2,8 +2,9 @@ #include <string.h> #include "Aportis.h" #include "my_list.h" #include "Bkmks.h" +#include "static.h" Aportis::Aportis() : peanutfile(false) { /*printf("constructing:%x\n",fin);*/ } void Aportis::dePeanut(int& ch) @@ -27,16 +28,16 @@ CList<Bkmk>* Aportis::getbkmklist() for (int i = nRecs; i < nRecs2; i++) { char name[17]; name[16] = '\0'; -// odebug << "Record:" << i << ", Length:" << recordlength(i) << "" << oendl; +// qDebug("Record:%d, Length:%u",i,recordlength(i)); gotorecordnumber(i); fread(name,1,16,fin); unsigned long lcn; fread(&lcn,sizeof(lcn),1,fin); lcn ^= 0xa5a5a5a5; lcn = SwapLong(lcn); -// odebug << "Bookmark:" << name << ":" << lcn << "" << oendl; +// qDebug("Bookmark:%s:%u", name,lcn); tchar tname[17]; memset(tname, 0, sizeof(tname)); for (int i = 0; name[i] != 0; i++) { @@ -93,36 +94,55 @@ CList<Bkmk>* Aportis::getbkmklist() int Aportis::OpenFile(const char *src) { // printf("In openfile\n"); int ret = 0; + html = false; + mobiimagerec = 0; + if (!Cpdb::openpdbfile(src)) return -1; - if (!Cpdb::openfile(src)) return -1; - - if (head.creator != 0x64414552 // 'dAER' - || head.type != 0x74584554) // 'tXET') + if (head.creator == 0x64414552 // 'dAER' + || head.type == 0x74584554) // 'tXET') { - - if (memcmp(&head.creator, "PPrs", 4) == 0 && memcmp(&head.type, "PNRd", 4) == 0) + } + else if (memcmp(&head.creator, "PPrs", 4) == 0 && memcmp(&head.type, "PNRd", 4) == 0) { peanutfile = true; } + else if (memcmp(&head.creator, "MOBI", 4) == 0 && memcmp(&head.type, "BOOK", 4) == 0) + { + html = true; + unsigned char vsn; + fseek(fin, recordpos(0)+39, SEEK_SET); + fread(&vsn, 1, sizeof(vsn), fin); + qDebug("Mobi version:%x", vsn); + if (vsn > 2) + { + fseek(fin, recordpos(0)+110, SEEK_SET); + fread(&mobiimagerec, 1, sizeof(mobiimagerec), fin); + mobiimagerec = ntohs(mobiimagerec)-1; + } + } else { return -2; } - } nRecs2 = nRecs = SwapWord(head.recordList.numRecords) - 1; - fseek(fin,0,SEEK_END); - dwLen = ftell(fin); + + struct stat _stat; + stat(src,&_stat); + dwLen = _stat.st_size; + + //fseek(fin,0,SEEK_END); + //dwLen = ftell(fin); if (peanutfile) { PeanutHeader hdr0; gotorecordnumber(0); fread(&hdr0, sizeof(hdr0), 1, fin); -// odebug << "Version:" << ntohs(hdr0.Version) << "" << oendl; +// qDebug("Version:%x", ntohs(hdr0.Version)); if (hdr0.Version && 0x0200) { bCompressed = 2; } @@ -140,8 +160,9 @@ int Aportis::OpenFile(const char *src) tDocRecord0 hdr0; fread(&hdr0, sizeof(hdr0), 1, fin); bCompressed = SwapWord(hdr0.wVersion); if (bCompressed!=1 && bCompressed!=2 && bCompressed != 4) { + qDebug("ERROR:Unrecognised compression type in Aportis:%u", bCompressed); ret = bCompressed; bCompressed = 2; } switch (bCompressed) @@ -163,8 +184,9 @@ int Aportis::OpenFile(const char *src) case 1: case 2: default: nRecs = SwapWord(hdr0.wNumRecs); + if (mobiimagerec == 0 || mobiimagerec > nRecs2) mobiimagerec = nRecs; dwTLen = SwapLong(hdr0.dwStoryLen); BlockSize = SwapWord(hdr0.wRecSize); if (BlockSize == 0) { @@ -173,17 +195,49 @@ int Aportis::OpenFile(const char *src) } } } - + qDebug("Mobi image rec:%u", mobiimagerec); // this is the main record buffer // it knows how to stretch to accomodate the decompress currentrec = 0; cbptr = 0; outptr = 0; refreshbuffer(); -// odebug << "Number of records:[" << nRecs << "," << nRecs2 << "]" << oendl; + if (!html) + { + int c; + char htmltag[] = "<HTML>"; + char *p = htmltag; + while (1) + { + c = getch(); + char ch = *p++; + if (ch == 0) + { + html = true; + break; + } + if (c != ch) + { + html = false; + break; + } + } + currentrec = 0; + cbptr = 0; + outptr = 0; + refreshbuffer(); + } + /* + for (int i = 0; i < nRecs2; i++) + { + qDebug("Record:%u - %u bytes at position %x", i, recordlength(i), recordpos(i)); + } + */ + + qDebug("Number of records:[%u,%u]", nRecs, nRecs2); return ret; } int Aportis::getch() @@ -371,4 +425,31 @@ bool Aportis::refreshbuffer() else { return false; } } + +#include <qimage.h> + +QImage* Aportis::getPicture(unsigned long tgt) +{ + unsigned short tgtrec = tgt+mobiimagerec; + if (tgtrec > nRecs2) return NULL; + size_t cur = ftell(fin); + unsigned short reclen = recordlength(tgtrec); + gotorecordnumber(tgtrec); + UInt8* imgbuffer = new UInt8[reclen]; + fread(imgbuffer, 1, reclen, fin); + QByteArray arr; + arr.assign((const char*)imgbuffer, reclen); + + QImage* qimage = new QImage(arr); + fseek(fin, cur, SEEK_SET); + + return qimage; +} + +#ifndef __STATIC +extern "C" +{ + CExpander* newcodec() { return new Aportis; } +} +#endif |