Diffstat (limited to 'noncore/apps/opie-reader/Aportis.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/apps/opie-reader/Aportis.cpp | 105 |
1 files changed, 94 insertions, 11 deletions
diff --git a/noncore/apps/opie-reader/Aportis.cpp b/noncore/apps/opie-reader/Aportis.cpp index 595b385..1327ff8 100644 --- a/noncore/apps/opie-reader/Aportis.cpp +++ b/noncore/apps/opie-reader/Aportis.cpp @@ -3,4 +3,16 @@ #include "Aportis.h" +#include "my_list.h" +#include "Bkmks.h" -Aportis::Aportis() { /*printf("constructing:%x\n",fin);*/ } +Aportis::Aportis() : peanutfile(false) { /*printf("constructing:%x\n",fin);*/ } + +void Aportis::dePeanut(int& ch) +{ + if (peanutfile && ch != EOF) + { + unsigned char c = ch; + if (peanutfile) c ^= 0xa5; + ch = c; + } +} @@ -8,2 +20,36 @@ CList<Bkmk>* Aportis::getbkmklist() { +/* + if (peanutfile) + { + if (nRecs2 > nRecs) + { + CList<Bkmk>* t = new CList<Bkmk>; + for (int i = nRecs; i < nRecs2; i++) + { + char name[17]; + name[16] = '\0'; + 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); + qDebug("Bookmark:%s:%u", name,lcn); + tchar tname[17]; + memset(tname, 0, sizeof(tname)); + for (int i = 0; name[i] != 0; i++) + { + tname[i] = name[i] ^ 0xa5; + } + t->push_back(Bkmk(tname, NULL, lcn)); + } + return t; + } + else + { + return NULL; + } + } +*/ if (bCompressed != 4) return NULL; @@ -36,3 +82,3 @@ CList<Bkmk>* Aportis::getbkmklist() } - t->push_back(Bkmk(tname,lcn)); + t->push_back(Bkmk(tname, NULL, lcn)); #else @@ -48,3 +94,2 @@ int Aportis::openfile(const char *src) { - // printf("In openfile\n"); @@ -57,5 +102,38 @@ int Aportis::openfile(const char *src) { + + if (memcmp(&head.creator, "PPrs", 4) == 0 && memcmp(&head.type, "PNRd", 4) == 0) + { + peanutfile = true; + } + else + { return -2; } + } + + nRecs2 = nRecs = SwapWord(head.recordList.numRecords) - 1; + fseek(fin,0,SEEK_END); + dwLen = ftell(fin); + + if (peanutfile) + { + PeanutHeader hdr0; + gotorecordnumber(0); + fread(&hdr0, sizeof(hdr0), 1, fin); + qDebug("Version:%x", ntohs(hdr0.Version)); + if (hdr0.Version && 0x0200) + { + bCompressed = 2; + } + else + { + bCompressed = 1; + } + BlockSize = 4096; + nRecs = SwapWord(hdr0.Records)-1; + dwTLen = nRecs*BlockSize; + } + else + { gotorecordnumber(0); @@ -68,7 +146,2 @@ int Aportis::openfile(const char *src) } - - fseek(fin,0,SEEK_END); - dwLen = ftell(fin); - nRecs2 = nRecs = SwapWord(head.recordList.numRecords) - 1; - switch (bCompressed) @@ -92,2 +165,3 @@ int Aportis::openfile(const char *src) default: + nRecs = SwapWord(hdr0.wNumRecs); dwTLen = SwapLong(hdr0.dwStoryLen); @@ -100,2 +174,4 @@ int Aportis::openfile(const char *src) } + } + @@ -108,2 +184,3 @@ int Aportis::openfile(const char *src) refreshbuffer(); + qDebug("Number of records:[%u,%u]", nRecs, nRecs2); return ret; @@ -119,2 +196,3 @@ int Aportis::getch() int c = getc(fin); + dePeanut(c); dwRecLen--; @@ -131,3 +209,3 @@ int Aportis::getch() currentpos++; - unsigned int c; + int c; @@ -135,2 +213,3 @@ int Aportis::getch() c = getc(fin); + dePeanut(c); dwRecLen--; @@ -154,3 +233,5 @@ int Aportis::getch() { - circbuf[cbptr = (cbptr+1)%2048] = getc(fin); + int c = getc(fin); + dePeanut(c); + circbuf[cbptr = (cbptr+1)%2048] = c; } @@ -162,3 +243,5 @@ int Aportis::getch() c <<= 8; - c += getc(fin); + int c1 = getc(fin); + dePeanut(c1); + c += c1; dwRecLen--; |