bool wxHtmlHelpData::AddBookParam(const wxFSFile& bookfile, wxFontEncoding encoding, const wxString& title, const wxString& contfile, const wxString& indexfile, const wxString& deftopic, const wxString& path) { wxFileSystem fsys; wxFSFile *fi; wxHtmlBookRecord *bookr; int IndexOld = m_index.size(), ContentsOld = m_contents.size(); if (!path.empty()) fsys.ChangePathTo(path, true); size_t booksCnt = m_bookRecords.GetCount(); for (size_t i = 0; i < booksCnt; i++) { if ( m_bookRecords[i].GetBookFile() == bookfile.GetLocation() ) return true; // book is (was) loaded } bookr = new wxHtmlBookRecord(bookfile.GetLocation(), fsys.GetPath(), title, deftopic); wxHtmlHelpDataItem *bookitem = new wxHtmlHelpDataItem; bookitem->level = 0; bookitem->id = 0; bookitem->page = deftopic; bookitem->name = title; bookitem->book = bookr; // store the contents index for later int cont_start = m_contents.size(); m_contents.Add(bookitem); // Try to find cached binary versions: // 1. save file as book, but with .hhp.cached extension // 2. same as 1. but in temp path // 3. otherwise or if cache load failed, load it from MS. 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.empty() || fi == NULL || #if wxUSE_DATETIME fi->GetModificationTime() < bookfile.GetModificationTime() || #endif // wxUSE_DATETIME !LoadCachedBook(bookr, fi->GetStream())) { LoadMSProject(bookr, fsys, indexfile, contfile); if (!m_tempPath.empty()) { wxFileOutputStream *outs = new wxFileOutputStream(m_tempPath + SafeFileName(wxFileNameFromPath(bookfile.GetLocation())) + wxT(".cached")); SaveCachedBook(bookr, outs); delete outs; } } } if (fi != NULL) delete fi; // Now store the contents range bookr->SetContentsRange(cont_start, m_contents.size()); // MS HTML Help files [written by MS HTML Help Workshop] are broken // in that the data are iso-8859-1 (including HTML entities), but must // be interpreted as being in language's windows charset. Correct the // differences here and also convert to wxConvLocal in ANSI build if (encoding != wxFONTENCODING_SYSTEM) { #if wxUSE_UNICODE #define CORRECT_STR(str, conv) \ str = wxString((str).mb_str(wxConvISO8859_1), conv) #else #define CORRECT_STR(str, conv) \ str = wxString((str).wc_str(conv), wxConvLocal) #endif wxCSConv conv(encoding); size_t IndexCnt = m_index.size(); size_t ContentsCnt = m_contents.size(); size_t i; for (i = IndexOld; i < IndexCnt; i++) { CORRECT_STR(m_index[i].name, conv); } for (i = ContentsOld; i < ContentsCnt; i++) { CORRECT_STR(m_contents[i].name, conv); } #undef CORRECT_STR } m_bookRecords.Add(bookr); if (!m_index.empty()) { m_index.Sort(wxHtmlHelpIndexCompareFunc); } return true; }
bool wxHtmlHelpController::AddBook(const wxString& book, bool show_wait_msg) { wxFSFile *fi; wxFileSystem fsys; wxInputStream *s; HtmlBookRecord *bookr; wxString bookFull; int sz; char *buff, *lineptr; char linebuf[300]; wxString title = _("noname"), safetitle, start = wxEmptyString, contents = wxEmptyString, index = wxEmptyString; if (wxIsAbsolutePath(book)) bookFull = book; else bookFull = wxGetCwd() + "/" + book; fi = fsys.OpenFile(bookFull); if (fi == NULL) return FALSE; fsys.ChangePathTo(bookFull); s = fi -> GetStream(); sz = s -> GetSize(); buff = new char[sz+1]; buff[sz] = 0; s -> Read(buff, sz); lineptr = buff; delete fi; while ((lineptr = ReadLine(lineptr, linebuf)) != NULL) { if (strstr(linebuf, "Title=") == linebuf) title = linebuf + strlen("Title="); if (strstr(linebuf, "Default topic=") == linebuf) start = linebuf + strlen("Default topic="); if (strstr(linebuf, "Index file=") == linebuf) index = linebuf + strlen("Index file="); if (strstr(linebuf, "Contents file=") == linebuf) contents = linebuf + strlen("Contents file="); } delete[] buff; bookr = new HtmlBookRecord(fsys.GetPath(), title, start); if (m_ContentsCnt % HTML_REALLOC_STEP == 0) m_Contents = (HtmlContentsItem*) realloc(m_Contents, (m_ContentsCnt + HTML_REALLOC_STEP) * sizeof(HtmlContentsItem)); m_Contents[m_ContentsCnt].m_Level = 0; m_Contents[m_ContentsCnt].m_ID = 0; m_Contents[m_ContentsCnt].m_Page = new char[start.Length() + 1]; strcpy(m_Contents[m_ContentsCnt].m_Page, start.c_str()); m_Contents[m_ContentsCnt].m_Name = new char [title.Length() + 1]; strcpy(m_Contents[m_ContentsCnt].m_Name, title.c_str()); m_Contents[m_ContentsCnt].m_Book = bookr; m_ContentsCnt++; // Try to find cached binary versions: safetitle = SafeFileName(title); fi = fsys.OpenFile(safetitle + ".cached"); if (fi == NULL) fi = fsys.OpenFile(m_TempPath + safetitle + ".cached"); if ((fi == NULL) || (m_TempPath == wxEmptyString)) { LoadMSProject(bookr, fsys, index, contents, show_wait_msg); if (m_TempPath != wxEmptyString) { wxFileOutputStream *outs = new wxFileOutputStream(m_TempPath + safetitle + ".cached"); SaveCachedBook(bookr, outs); delete outs; } } else { LoadCachedBook(bookr, fi -> GetStream()); delete fi; } m_BookRecords.Add(bookr); if (m_IndexCnt > 0) qsort(m_Index, m_IndexCnt, sizeof(HtmlContentsItem), IndexCompareFunc); return TRUE; }