X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/fcf77487edae715c75f0f802a96e203d88dd56c6..c6f9fb054849dd09b99aeaad9b10b4a12eca0752:/src/html/helpdata.cpp?ds=sidebyside diff --git a/src/html/helpdata.cpp b/src/html/helpdata.cpp index 1864c907e5..c0418b8d39 100644 --- a/src/html/helpdata.cpp +++ b/src/html/helpdata.cpp @@ -9,7 +9,7 @@ // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// -#ifdef __GNUG__ +#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) #pragma implementation "helpdata.h" #endif @@ -85,9 +85,14 @@ wxHtmlHelpIndexCompareFunc(const void *a, const void *b) class HP_Parser : public wxHtmlParser { public: + HP_Parser() { } + wxObject* GetProduct() { return NULL; } + protected: virtual void AddText(const wxChar* WXUNUSED(txt)) {} + + DECLARE_NO_COPY_CLASS(HP_Parser) }; @@ -114,6 +119,8 @@ class HP_TagHandler : public wxHtmlTagHandler bool HandleTag(const wxHtmlTag& tag); void WriteOut(wxHtmlContentsItem*& array, int& size); void ReadIn(wxHtmlContentsItem* array, int size); + + DECLARE_NO_COPY_CLASS(HP_TagHandler) }; @@ -337,7 +344,12 @@ inline static wxChar* CacheReadString(wxInputStream *f) #endif } -#define CURRENT_CACHED_BOOK_VERSION 3 +#define CURRENT_CACHED_BOOK_VERSION 4 + +// Additional flags to detect incompatibilities of the runtime environment: +#define CACHED_BOOK_FORMAT_FLAGS \ + (wxUSE_UNICODE << 0) + bool wxHtmlHelpData::LoadCachedBook(wxHtmlBookRecord *book, wxInputStream *f) { @@ -356,6 +368,9 @@ bool wxHtmlHelpData::LoadCachedBook(wxHtmlBookRecord *book, wxInputStream *f) return FALSE; } + if (CacheReadInt32(f) != CACHED_BOOK_FORMAT_FLAGS) + return FALSE; + /* load contents : */ st = m_ContentsCnt; m_ContentsCnt += CacheReadInt32(f); @@ -393,6 +408,7 @@ bool wxHtmlHelpData::SaveCachedBook(wxHtmlBookRecord *book, wxOutputStream *f) /* save header - version info : */ CacheWriteInt32(f, CURRENT_CACHED_BOOK_VERSION); + CacheWriteInt32(f, CACHED_BOOK_FORMAT_FLAGS); /* save contents : */ for (cnt = 0, i = 0; i < m_ContentsCnt; i++) @@ -498,13 +514,17 @@ bool wxHtmlHelpData::AddBookParam(const wxFSFile& bookfile, fi = fsys.OpenFile(bookfile.GetLocation() + wxT(".cached")); if (fi == NULL || +#if wxUSE_DATETIME fi->GetModificationTime() < bookfile.GetModificationTime() || +#endif // wxUSE_DATETIME !LoadCachedBook(bookr, fi->GetStream())) { if (fi != NULL) delete fi; fi = fsys.OpenFile(m_TempPath + wxFileNameFromPath(bookfile.GetLocation()) + wxT(".cached")); if (m_TempPath == wxEmptyString || fi == NULL || +#if wxUSE_DATETIME fi->GetModificationTime() < bookfile.GetModificationTime() || +#endif // wxUSE_DATETIME !LoadCachedBook(bookr, fi->GetStream())) { LoadMSProject(bookr, fsys, indexfile, contfile); @@ -550,14 +570,24 @@ bool wxHtmlHelpData::AddBookParam(const wxFSFile& bookfile, bool wxHtmlHelpData::AddBook(const wxString& book) { - if (book.Right(4).Lower() == wxT(".zip") || - book.Right(4).Lower() == wxT(".htb") /*html book*/) + wxString extension(book.Right(4).Lower()); + if (extension == wxT(".zip") || +#if wxUSE_LIBMSPACK + extension == wxT(".chm") /*compressed html help book*/ || +#endif + extension == wxT(".htb") /*html book*/) { wxFileSystem fsys; wxString s; bool rt = FALSE; - s = fsys.FindFirst(book + wxT("#zip:") + wxT("*.hhp"), wxFILE); +#if wxUSE_LIBMSPACK + if (extension == wxT(".chm")) + s = fsys.FindFirst(book + wxT("#chm:*.hhp"), wxFILE); + else +#endif + s = fsys.FindFirst(book + wxT("#zip:*.hhp"), wxFILE); + while (!s.IsEmpty()) { if (AddBook(s)) rt = TRUE; @@ -566,60 +596,58 @@ bool wxHtmlHelpData::AddBook(const wxString& book) return rt; } - else - { - wxFSFile *fi; - wxFileSystem fsys; - - wxString title = _("noname"), - safetitle, - start = wxEmptyString, - contents = wxEmptyString, - index = wxEmptyString, - charset = wxEmptyString; - fi = fsys.OpenFile(book); - if (fi == NULL) - { - wxLogError(_("Cannot open HTML help book: %s"), book.c_str()); - return FALSE; - } - fsys.ChangePathTo(book); + wxFSFile *fi; + wxFileSystem fsys; - const wxChar *lineptr; - wxChar linebuf[300]; - wxString tmp; - wxHtmlFilterPlainText filter; - tmp = filter.ReadFile(*fi); - lineptr = tmp.c_str(); + wxString title = _("noname"), + safetitle, + start = wxEmptyString, + contents = wxEmptyString, + index = wxEmptyString, + charset = wxEmptyString; - do - { - lineptr = ReadLine(lineptr, linebuf, 300); - - for (wxChar *ch = linebuf; *ch != wxT('\0') && *ch != wxT('='); ch++) - *ch = tolower(*ch); - - if (wxStrstr(linebuf, _T("title=")) == linebuf) - title = linebuf + wxStrlen(_T("title=")); - if (wxStrstr(linebuf, _T("default topic=")) == linebuf) - start = linebuf + wxStrlen(_T("default topic=")); - if (wxStrstr(linebuf, _T("index file=")) == linebuf) - index = linebuf + wxStrlen(_T("index file=")); - if (wxStrstr(linebuf, _T("contents file=")) == linebuf) - contents = linebuf + wxStrlen(_T("contents file=")); - if (wxStrstr(linebuf, _T("charset=")) == linebuf) - charset = linebuf + wxStrlen(_T("charset=")); - } while (lineptr != NULL); - - wxFontEncoding enc; - if (charset == wxEmptyString) enc = wxFONTENCODING_SYSTEM; - else enc = wxFontMapper::Get()->CharsetToEncoding(charset); - bool rtval = AddBookParam(*fi, enc, - title, contents, index, start, fsys.GetPath()); - delete fi; - return rtval; + fi = fsys.OpenFile(book); + if (fi == NULL) + { + wxLogError(_("Cannot open HTML help book: %s"), book.c_str()); + return FALSE; } + fsys.ChangePathTo(book); + + const wxChar *lineptr; + wxChar linebuf[300]; + wxString tmp; + wxHtmlFilterPlainText filter; + tmp = filter.ReadFile(*fi); + lineptr = tmp.c_str(); + + do + { + lineptr = ReadLine(lineptr, linebuf, 300); + + for (wxChar *ch = linebuf; *ch != wxT('\0') && *ch != wxT('='); ch++) + *ch = tolower(*ch); + + if (wxStrstr(linebuf, _T("title=")) == linebuf) + title = linebuf + wxStrlen(_T("title=")); + if (wxStrstr(linebuf, _T("default topic=")) == linebuf) + start = linebuf + wxStrlen(_T("default topic=")); + if (wxStrstr(linebuf, _T("index file=")) == linebuf) + index = linebuf + wxStrlen(_T("index file=")); + if (wxStrstr(linebuf, _T("contents file=")) == linebuf) + contents = linebuf + wxStrlen(_T("contents file=")); + if (wxStrstr(linebuf, _T("charset=")) == linebuf) + charset = linebuf + wxStrlen(_T("charset=")); + } while (lineptr != NULL); + + wxFontEncoding enc; + if (charset == wxEmptyString) enc = wxFONTENCODING_SYSTEM; + else enc = wxFontMapper::Get()->CharsetToEncoding(charset); + bool rtval = AddBookParam(*fi, enc, + title, contents, index, start, fsys.GetPath()); + delete fi; + return rtval; } wxString wxHtmlHelpData::FindPageByName(const wxString& x)