X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/f890e2d474d26e47950717c802a3890497615484..236a9de39afa090fdee3cf91cb5364ceca69e3f8:/src/html/helpdata.cpp diff --git a/src/html/helpdata.cpp b/src/html/helpdata.cpp index bc928a7ccb..cb5eb0e862 100644 --- a/src/html/helpdata.cpp +++ b/src/html/helpdata.cpp @@ -34,6 +34,7 @@ #include "wx/busyinfo.h" #include "wx/encconv.h" #include "wx/fontmap.h" +#include "wx/log.h" #include "wx/html/htmlpars.h" #include "wx/html/htmldefs.h" @@ -92,7 +93,7 @@ class HP_TagHandler : public wxHtmlTagHandler wxHtmlBookRecord *m_Book; public: - HP_TagHandler(wxHtmlBookRecord *b) : wxHtmlTagHandler() {m_Book = b; m_Items = NULL; m_ItemsCnt = 0; m_Name = m_Page = wxEmptyString; m_Level = 0; } + HP_TagHandler(wxHtmlBookRecord *b) : wxHtmlTagHandler() {m_Book = b; m_Items = NULL; m_ItemsCnt = 0; m_Name = m_Page = wxEmptyString; m_Level = 0; m_ID = -1; } wxString GetSupportedTags() { return wxT("UL,OBJECT,PARAM"); } bool HandleTag(const wxHtmlTag& tag); void WriteOut(wxHtmlContentsItem*& array, int& size); @@ -221,7 +222,7 @@ bool wxHtmlHelpData::LoadMSProject(wxHtmlBookRecord *book, wxFileSystem& fsys, c HP_TagHandler *handler = new HP_TagHandler(book); parser.AddTagHandler(handler); - f = ( contentsfile.IsEmpty() ? 0 : fsys.OpenFile(contentsfile) ); + f = ( contentsfile.IsEmpty() ? (wxFSFile*) NULL : fsys.OpenFile(contentsfile) ); if (f) { sz = f -> GetStream() -> GetSize(); buf = new char[sz + 1]; @@ -233,8 +234,10 @@ bool wxHtmlHelpData::LoadMSProject(wxHtmlBookRecord *book, wxFileSystem& fsys, c handler -> WriteOut(m_Contents, m_ContentsCnt); delete[] buf; } + else + wxLogError(_("Cannot open contents file: %s"), contentsfile.mb_str()); - f = ( indexfile.IsEmpty() ? 0 : fsys.OpenFile(indexfile) ); + f = ( indexfile.IsEmpty() ? (wxFSFile*) NULL : fsys.OpenFile(indexfile) ); if (f) { sz = f -> GetStream() -> GetSize(); buf = new char[sz + 1]; @@ -246,6 +249,8 @@ bool wxHtmlHelpData::LoadMSProject(wxHtmlBookRecord *book, wxFileSystem& fsys, c handler -> WriteOut(m_Index, m_IndexCnt); delete[] buf; } + else if (!indexfile.IsEmpty()) + wxLogError(_("Cannot open index file: %s"), indexfile.mb_str()); return TRUE; } @@ -278,9 +283,13 @@ bool wxHtmlHelpData::LoadCachedBook(wxHtmlBookRecord *book, wxInputStream *f) f -> Read(&x, sizeof(x)); version = wxINT32_SWAP_ON_BE(x); - if (version != CURRENT_CACHED_BOOK_VERSION) return FALSE; + if (version != CURRENT_CACHED_BOOK_VERSION) + { + wxLogError(_("Incorrect version of HTML help book")); + return FALSE; // NOTE: when adding new version, please ensure backward compatibility! - + } + /* load contents : */ f -> Read(&x, sizeof(x)); @@ -385,6 +394,17 @@ void wxHtmlHelpData::SetTempDir(const wxString& path) } + +static wxString SafeFileName(const wxString& s) +{ + wxString res(s); + res.Replace(wxT("#"), wxT("_")); + res.Replace(wxT(":"), wxT("_")); + res.Replace(wxT("\\"), wxT("_")); + res.Replace(wxT("/"), wxT("_")); + return res; +} + bool wxHtmlHelpData::AddBookParam(const wxFSFile& bookfile, wxFontEncoding encoding, const wxString& title, const wxString& contfile, @@ -437,7 +457,7 @@ bool wxHtmlHelpData::AddBookParam(const wxFSFile& bookfile, if (m_TempPath != wxEmptyString) { wxFileOutputStream *outs = new wxFileOutputStream(m_TempPath + - wxFileNameFromPath(bookfile.GetLocation()) + wxT(".cached")); + SafeFileName(wxFileNameFromPath(bookfile.GetLocation())) + wxT(".cached")); SaveCachedBook(bookr, outs); delete outs; } @@ -517,7 +537,11 @@ bool wxHtmlHelpData::AddBook(const wxString& book) else bookFull = wxGetCwd() + "/" + book; fi = fsys.OpenFile(bookFull); - if (fi == NULL) return FALSE; + if (fi == NULL) + { + wxLogError(_("Cannot open HTML help book: %s"), bookFull.mb_str()); + return FALSE; + } fsys.ChangePathTo(bookFull); s = fi -> GetStream(); sz = s -> GetSize();