.cached format of help books is now endian-independent; also changed lookup logic for .cached files
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@5512 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
parent
eaf40b230e
commit
f35822af10
@ -127,12 +127,11 @@ class WXDLLEXPORT wxHtmlSearchStatus
|
|||||||
wxString m_Keyword, m_Name;
|
wxString m_Keyword, m_Name;
|
||||||
wxChar *m_LastPage;
|
wxChar *m_LastPage;
|
||||||
wxHtmlContentsItem* m_ContentsItem;
|
wxHtmlContentsItem* m_ContentsItem;
|
||||||
bool m_Active; // search is not finished
|
bool m_Active; // search is not finished
|
||||||
int m_CurIndex; // where we are now
|
int m_CurIndex; // where we are now
|
||||||
int m_MaxIndex; // number of files we search
|
int m_MaxIndex; // number of files we search
|
||||||
// For progress bar: 100*curindex/maxindex = % complete
|
// For progress bar: 100*curindex/maxindex = % complete
|
||||||
}
|
};
|
||||||
;
|
|
||||||
|
|
||||||
class WXDLLEXPORT wxHtmlHelpData : public wxObject
|
class WXDLLEXPORT wxHtmlHelpData : public wxObject
|
||||||
{
|
{
|
||||||
@ -153,7 +152,8 @@ class WXDLLEXPORT wxHtmlHelpData : public wxObject
|
|||||||
// Adds new book. 'book' is location of .htb file (stands for "html book").
|
// Adds new book. 'book' is location of .htb file (stands for "html book").
|
||||||
// See documentation for details on its format.
|
// See documentation for details on its format.
|
||||||
// Returns success.
|
// Returns success.
|
||||||
bool AddBookParam(const wxString& title, const wxString& contfile,
|
bool AddBookParam(const wxFSFile& bookfile,
|
||||||
|
const wxString& title, const wxString& contfile,
|
||||||
const wxString& indexfile = wxEmptyString,
|
const wxString& indexfile = wxEmptyString,
|
||||||
const wxString& deftopic = wxEmptyString,
|
const wxString& deftopic = wxEmptyString,
|
||||||
const wxString& path = wxEmptyString);
|
const wxString& path = wxEmptyString);
|
||||||
@ -190,8 +190,7 @@ class WXDLLEXPORT wxHtmlHelpData : public wxObject
|
|||||||
// Reads binary book
|
// Reads binary book
|
||||||
bool SaveCachedBook(wxHtmlBookRecord *book, wxOutputStream *f);
|
bool SaveCachedBook(wxHtmlBookRecord *book, wxOutputStream *f);
|
||||||
// Writes binary book
|
// Writes binary book
|
||||||
}
|
};
|
||||||
;
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -55,18 +55,6 @@ static char* ReadLine(char *line, char *buf)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static wxString SafeFileName(const wxString& s)
|
|
||||||
{
|
|
||||||
wxString res = s;
|
|
||||||
res.Replace(wxT(":"), wxT("_"), TRUE);
|
|
||||||
res.Replace(wxT(" "), wxT("_"), TRUE);
|
|
||||||
res.Replace(wxT("/"), wxT("_"), TRUE);
|
|
||||||
res.Replace(wxT("\\"), wxT("_"), TRUE);
|
|
||||||
res.Replace(wxT("#"), wxT("_"), TRUE);
|
|
||||||
res.Replace(wxT("."), wxT("_"), TRUE);
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static int LINKAGEMODE IndexCompareFunc(const void *a, const void *b)
|
static int LINKAGEMODE IndexCompareFunc(const void *a, const void *b)
|
||||||
{
|
{
|
||||||
@ -260,28 +248,56 @@ bool wxHtmlHelpData::LoadMSProject(wxHtmlBookRecord *book, wxFileSystem& fsys, c
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#if wxUSE_UNICODE
|
||||||
|
|
||||||
|
#define READ_STRING(f, s, lng) { char tmpc; for (int i = 0; i < lng; i++) { f -> Read(&tmpc, 1); s[i] = (wxChar)tmpc;} }
|
||||||
|
#define WRITE_STRING(f, s, lng) { char tmpc; for (int i = 0; i < lng; i++) { tmpc = (char)s[i]; f -> Write(&tmpc, 1);} }
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
#define READ_STRING(f, s, lng) f -> Read(s, lng * sizeof(char));
|
||||||
|
#define WRITE_STRING(f, s, lng) f -> Write(s, lng * sizeof(char));
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#define CURRENT_CACHED_BOOK_VERSION 1
|
||||||
|
|
||||||
bool wxHtmlHelpData::LoadCachedBook(wxHtmlBookRecord *book, wxInputStream *f)
|
bool wxHtmlHelpData::LoadCachedBook(wxHtmlBookRecord *book, wxInputStream *f)
|
||||||
{
|
{
|
||||||
int i, st;
|
int i, st;
|
||||||
int x;
|
wxInt32 x;
|
||||||
|
wxInt32 version;
|
||||||
|
|
||||||
|
/* load header - version info : */
|
||||||
|
|
||||||
|
f -> Read(&x, sizeof(x));
|
||||||
|
version = wxINT32_SWAP_ON_BE(x);
|
||||||
|
|
||||||
|
if (version != CURRENT_CACHED_BOOK_VERSION) return FALSE;
|
||||||
|
// NOTE: when adding new version, please ensure backward compatibility!
|
||||||
|
|
||||||
/* load contents : */
|
/* load contents : */
|
||||||
|
|
||||||
f -> Read(&x, sizeof(x));
|
f -> Read(&x, sizeof(x));
|
||||||
st = m_ContentsCnt;
|
st = m_ContentsCnt;
|
||||||
m_ContentsCnt += x;
|
m_ContentsCnt += wxINT32_SWAP_ON_BE(x);
|
||||||
m_Contents = (wxHtmlContentsItem*) realloc(m_Contents, (m_ContentsCnt / wxHTML_REALLOC_STEP + 1) * wxHTML_REALLOC_STEP * sizeof(wxHtmlContentsItem));
|
m_Contents = (wxHtmlContentsItem*) realloc(m_Contents,
|
||||||
|
(m_ContentsCnt / wxHTML_REALLOC_STEP + 1) *
|
||||||
|
wxHTML_REALLOC_STEP * sizeof(wxHtmlContentsItem));
|
||||||
for (i = st; i < m_ContentsCnt; i++) {
|
for (i = st; i < m_ContentsCnt; i++) {
|
||||||
f -> Read(&x, sizeof(x));
|
f -> Read(&x, sizeof(x));
|
||||||
m_Contents[i].m_Level = x;
|
m_Contents[i].m_Level = wxINT32_SWAP_ON_BE(x);
|
||||||
f -> Read(&x, sizeof(x));
|
|
||||||
m_Contents[i].m_ID = x;
|
|
||||||
f -> Read(&x, sizeof(x));
|
f -> Read(&x, sizeof(x));
|
||||||
|
m_Contents[i].m_ID = wxINT32_SWAP_ON_BE(x);
|
||||||
|
f -> Read(&x, sizeof(x)); x = wxINT32_SWAP_ON_BE(x);
|
||||||
m_Contents[i].m_Name = new wxChar[x];
|
m_Contents[i].m_Name = new wxChar[x];
|
||||||
f -> Read(m_Contents[i].m_Name, x*sizeof(wxChar));
|
READ_STRING(f, m_Contents[i].m_Name, x);
|
||||||
f -> Read(&x, sizeof(x));
|
f -> Read(&x, sizeof(x)); x = wxINT32_SWAP_ON_BE(x);
|
||||||
m_Contents[i].m_Page = new wxChar[x];
|
m_Contents[i].m_Page = new wxChar[x];
|
||||||
f -> Read(m_Contents[i].m_Page, x*sizeof(wxChar));
|
READ_STRING(f, m_Contents[i].m_Page, x);
|
||||||
m_Contents[i].m_Book = book;
|
m_Contents[i].m_Book = book;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -289,15 +305,16 @@ bool wxHtmlHelpData::LoadCachedBook(wxHtmlBookRecord *book, wxInputStream *f)
|
|||||||
|
|
||||||
f -> Read(&x, sizeof(x));
|
f -> Read(&x, sizeof(x));
|
||||||
st = m_IndexCnt;
|
st = m_IndexCnt;
|
||||||
m_IndexCnt += x;
|
m_IndexCnt += wxINT32_SWAP_ON_BE(x);
|
||||||
m_Index = (wxHtmlContentsItem*) realloc(m_Index, (m_IndexCnt / wxHTML_REALLOC_STEP + 1) * wxHTML_REALLOC_STEP * sizeof(wxHtmlContentsItem));
|
m_Index = (wxHtmlContentsItem*) realloc(m_Index, (m_IndexCnt / wxHTML_REALLOC_STEP + 1) *
|
||||||
|
wxHTML_REALLOC_STEP * sizeof(wxHtmlContentsItem));
|
||||||
for (i = st; i < m_IndexCnt; i++) {
|
for (i = st; i < m_IndexCnt; i++) {
|
||||||
f -> Read(&x, sizeof(x));
|
f -> Read(&x, sizeof(x)); x = wxINT32_SWAP_ON_BE(x);
|
||||||
m_Index[i].m_Name = new wxChar[x];
|
m_Index[i].m_Name = new wxChar[x];
|
||||||
f -> Read(m_Index[i].m_Name, x*sizeof(wxChar));
|
READ_STRING(f, m_Index[i].m_Name, x);
|
||||||
f -> Read(&x, sizeof(x));
|
f -> Read(&x, sizeof(x)); x = wxINT32_SWAP_ON_BE(x);
|
||||||
m_Index[i].m_Page = new wxChar[x];
|
m_Index[i].m_Page = new wxChar[x];
|
||||||
f -> Read(m_Index[i].m_Page, x*sizeof(wxChar));
|
READ_STRING(f, m_Index[i].m_Page, x);
|
||||||
m_Index[i].m_Book = book;
|
m_Index[i].m_Book = book;
|
||||||
}
|
}
|
||||||
return TRUE;
|
return TRUE;
|
||||||
@ -307,40 +324,47 @@ bool wxHtmlHelpData::LoadCachedBook(wxHtmlBookRecord *book, wxInputStream *f)
|
|||||||
bool wxHtmlHelpData::SaveCachedBook(wxHtmlBookRecord *book, wxOutputStream *f)
|
bool wxHtmlHelpData::SaveCachedBook(wxHtmlBookRecord *book, wxOutputStream *f)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
int x;
|
wxInt32 x;
|
||||||
|
|
||||||
|
/* save header - version info : */
|
||||||
|
|
||||||
|
x = wxINT32_SWAP_ON_BE(CURRENT_CACHED_BOOK_VERSION);
|
||||||
|
f -> Write(&x, sizeof(x));
|
||||||
|
|
||||||
/* save contents : */
|
/* save contents : */
|
||||||
|
|
||||||
x = 0;
|
x = 0;
|
||||||
for (i = 0; i < m_ContentsCnt; i++) if (m_Contents[i].m_Book == book && m_Contents[i].m_Level > 0) x++;
|
for (i = 0; i < m_ContentsCnt; i++) if (m_Contents[i].m_Book == book && m_Contents[i].m_Level > 0) x++;
|
||||||
|
x = wxINT32_SWAP_ON_BE(x);
|
||||||
f -> Write(&x, sizeof(x));
|
f -> Write(&x, sizeof(x));
|
||||||
for (i = 0; i < m_ContentsCnt; i++) {
|
for (i = 0; i < m_ContentsCnt; i++) {
|
||||||
if (m_Contents[i].m_Book != book || m_Contents[i].m_Level == 0) continue;
|
if (m_Contents[i].m_Book != book || m_Contents[i].m_Level == 0) continue;
|
||||||
x = m_Contents[i].m_Level;
|
x = wxINT32_SWAP_ON_BE(m_Contents[i].m_Level);
|
||||||
f -> Write(&x, sizeof(x));
|
f -> Write(&x, sizeof(x));
|
||||||
x = m_Contents[i].m_ID;
|
x = wxINT32_SWAP_ON_BE(m_Contents[i].m_ID);
|
||||||
f -> Write(&x, sizeof(x));
|
f -> Write(&x, sizeof(x));
|
||||||
x = wxStrlen(m_Contents[i].m_Name) + 1;
|
x = wxINT32_SWAP_ON_BE(wxStrlen(m_Contents[i].m_Name) + 1);
|
||||||
f -> Write(&x, sizeof(x));
|
f -> Write(&x, sizeof(x));
|
||||||
f -> Write(m_Contents[i].m_Name, x*sizeof(wxChar));
|
WRITE_STRING(f, m_Contents[i].m_Name, x);
|
||||||
x = wxStrlen(m_Contents[i].m_Page) + 1;
|
x = wxINT32_SWAP_ON_BE(wxStrlen(m_Contents[i].m_Page) + 1);
|
||||||
f -> Write(&x, sizeof(x));
|
f -> Write(&x, sizeof(x));
|
||||||
f -> Write(m_Contents[i].m_Page, x*sizeof(wxChar));
|
WRITE_STRING(f, m_Contents[i].m_Page, x);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* save index : */
|
/* save index : */
|
||||||
|
|
||||||
x = 0;
|
x = 0;
|
||||||
for (i = 0; i < m_IndexCnt; i++) if (m_Index[i].m_Book == book && m_Index[i].m_Level > 0) x++;
|
for (i = 0; i < m_IndexCnt; i++) if (m_Index[i].m_Book == book && m_Index[i].m_Level > 0) x++;
|
||||||
|
x = wxINT32_SWAP_ON_BE(x);
|
||||||
f -> Write(&x, sizeof(x));
|
f -> Write(&x, sizeof(x));
|
||||||
for (i = 0; i < m_IndexCnt; i++) {
|
for (i = 0; i < m_IndexCnt; i++) {
|
||||||
if (m_Index[i].m_Book != book || m_Index[i].m_Level == 0) continue;
|
if (m_Index[i].m_Book != book || m_Index[i].m_Level == 0) continue;
|
||||||
x = wxStrlen(m_Index[i].m_Name) + 1;
|
x = wxINT32_SWAP_ON_BE(wxStrlen(m_Index[i].m_Name) + 1);
|
||||||
f -> Write(&x, sizeof(x));
|
f -> Write(&x, sizeof(x));
|
||||||
f -> Write(m_Index[i].m_Name, x*sizeof(wxChar));
|
WRITE_STRING(f, m_Index[i].m_Name, x);
|
||||||
x = wxStrlen(m_Index[i].m_Page) + 1;
|
x = wxINT32_SWAP_ON_BE(wxStrlen(m_Index[i].m_Page) + 1);
|
||||||
f -> Write(&x, sizeof(x));
|
f -> Write(&x, sizeof(x));
|
||||||
f -> Write(m_Index[i].m_Page, x*sizeof(wxChar));
|
WRITE_STRING(f, m_Index[i].m_Page, x);
|
||||||
}
|
}
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
@ -351,22 +375,22 @@ void wxHtmlHelpData::SetTempDir(const wxString& path)
|
|||||||
if (path == wxEmptyString) m_TempPath = path;
|
if (path == wxEmptyString) m_TempPath = path;
|
||||||
else {
|
else {
|
||||||
if (wxIsAbsolutePath(path)) m_TempPath = path;
|
if (wxIsAbsolutePath(path)) m_TempPath = path;
|
||||||
else m_TempPath = wxGetCwd() + "/" + path;
|
else m_TempPath = wxGetCwd() + _T("/") + path;
|
||||||
|
|
||||||
if (m_TempPath[m_TempPath.Length() - 1] != '/')
|
if (m_TempPath[m_TempPath.Length() - 1] != _T('/'))
|
||||||
m_TempPath << "/";
|
m_TempPath << _T('/');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool wxHtmlHelpData::AddBookParam(const wxString& title, const wxString& contfile,
|
bool wxHtmlHelpData::AddBookParam(const wxFSFile& bookfile,
|
||||||
|
const wxString& title, const wxString& contfile,
|
||||||
const wxString& indexfile, const wxString& deftopic,
|
const wxString& indexfile, const wxString& deftopic,
|
||||||
const wxString& path)
|
const wxString& path)
|
||||||
{
|
{
|
||||||
wxFileSystem fsys;
|
wxFileSystem fsys;
|
||||||
wxFSFile *fi;
|
wxFSFile *fi;
|
||||||
wxHtmlBookRecord *bookr;
|
wxHtmlBookRecord *bookr;
|
||||||
wxString safetitle;
|
|
||||||
|
|
||||||
if (! path.IsEmpty())
|
if (! path.IsEmpty())
|
||||||
fsys.ChangePathTo(path, TRUE);
|
fsys.ChangePathTo(path, TRUE);
|
||||||
@ -387,20 +411,34 @@ bool wxHtmlHelpData::AddBookParam(const wxString& title, const wxString& contfil
|
|||||||
int cont_start = m_ContentsCnt++;
|
int cont_start = m_ContentsCnt++;
|
||||||
|
|
||||||
// Try to find cached binary versions:
|
// Try to find cached binary versions:
|
||||||
safetitle = SafeFileName(title);
|
// 1. save file as book, but with .hhp.cached extension
|
||||||
fi = fsys.OpenFile(safetitle + wxT(".cached"));
|
// 2. same as 1. but in temp path
|
||||||
if (fi == NULL) fi = fsys.OpenFile(m_TempPath + safetitle + wxT(".cached"));
|
// 3. otherwise or if cache load failed, load it from MS.
|
||||||
if ((fi == NULL) || (m_TempPath == wxEmptyString)) {
|
|
||||||
LoadMSProject(bookr, fsys, indexfile, contfile);
|
fi = fsys.OpenFile(bookfile.GetLocation() + wxT(".cached"));
|
||||||
if (m_TempPath != wxEmptyString) {
|
|
||||||
wxFileOutputStream *outs = new wxFileOutputStream(m_TempPath + safetitle + wxT(".cached"));
|
if (fi == NULL ||
|
||||||
SaveCachedBook(bookr, outs);
|
fi -> GetModificationTime() < bookfile.GetModificationTime() ||
|
||||||
delete outs;
|
!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 ||
|
||||||
|
fi -> GetModificationTime() < bookfile.GetModificationTime() ||
|
||||||
|
!LoadCachedBook(bookr, fi -> GetStream()))
|
||||||
|
{
|
||||||
|
LoadMSProject(bookr, fsys, indexfile, contfile);
|
||||||
|
if (m_TempPath != wxEmptyString)
|
||||||
|
{
|
||||||
|
wxFileOutputStream *outs = new wxFileOutputStream(m_TempPath +
|
||||||
|
wxFileNameFromPath(bookfile.GetLocation()) + wxT(".cached"));
|
||||||
|
SaveCachedBook(bookr, outs);
|
||||||
|
delete outs;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
LoadCachedBook(bookr, fi -> GetStream());
|
|
||||||
delete fi;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (fi != NULL) delete fi;
|
||||||
|
|
||||||
// Now store the contents range
|
// Now store the contents range
|
||||||
bookr->SetContentsRange(cont_start, m_ContentsCnt);
|
bookr->SetContentsRange(cont_start, m_ContentsCnt);
|
||||||
@ -462,7 +500,6 @@ bool wxHtmlHelpData::AddBook(const wxString& book)
|
|||||||
buff[sz] = 0;
|
buff[sz] = 0;
|
||||||
s -> Read(buff, sz);
|
s -> Read(buff, sz);
|
||||||
lineptr = buff;
|
lineptr = buff;
|
||||||
delete fi;
|
|
||||||
|
|
||||||
do {
|
do {
|
||||||
lineptr = ReadLine(lineptr, linebuf);
|
lineptr = ReadLine(lineptr, linebuf);
|
||||||
@ -478,7 +515,9 @@ bool wxHtmlHelpData::AddBook(const wxString& book)
|
|||||||
} while (lineptr != NULL);
|
} while (lineptr != NULL);
|
||||||
delete[] buff;
|
delete[] buff;
|
||||||
|
|
||||||
return AddBookParam(title, contents, index, start, fsys.GetPath());
|
bool rtval = AddBookParam(*fi, title, contents, index, start, fsys.GetPath());
|
||||||
|
delete fi;
|
||||||
|
return rtval;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -587,19 +626,14 @@ wxHtmlSearchStatus::wxHtmlSearchStatus(wxHtmlHelpData* data, const wxString& key
|
|||||||
|
|
||||||
bool wxHtmlSearchStatus::Search()
|
bool wxHtmlSearchStatus::Search()
|
||||||
{
|
{
|
||||||
wxFileSystem fsys;
|
|
||||||
wxFSFile *file;
|
wxFSFile *file;
|
||||||
int i = m_CurIndex; // shortcut
|
int i = m_CurIndex; // shortcut
|
||||||
bool found = FALSE;
|
bool found = FALSE;
|
||||||
wxChar *thepage;
|
wxChar *thepage;
|
||||||
|
|
||||||
if (!m_Active) {
|
if (!m_Active) {
|
||||||
// sanity check. Illegal use, but we'll try to prevent a crash anyway
|
// sanity check. Illegal use, but we'll try to prevent a crash anyway
|
||||||
#if !defined(__VISAGECPP__)
|
|
||||||
wxASSERT(0);
|
|
||||||
#else
|
|
||||||
wxASSERT(m_Active);
|
wxASSERT(m_Active);
|
||||||
#endif
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -622,6 +656,7 @@ bool wxHtmlSearchStatus::Search()
|
|||||||
}
|
}
|
||||||
else m_LastPage = thepage;
|
else m_LastPage = thepage;
|
||||||
|
|
||||||
|
wxFileSystem fsys;
|
||||||
file = fsys.OpenFile(m_Data->m_Contents[i].m_Book -> GetBasePath() + thepage);
|
file = fsys.OpenFile(m_Data->m_Contents[i].m_Book -> GetBasePath() + thepage);
|
||||||
if (file)
|
if (file)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user