- safetitle = SafeFileName(title);
- fi = fsys.OpenFile(safetitle + wxT(".cached"));
- if (fi == NULL) fi = fsys.OpenFile(m_TempPath + safetitle + wxT(".cached"));
- if ((fi == NULL) || (m_TempPath == wxEmptyString)) {
- LoadMSProject(bookr, fsys, indexfile, contfile);
- if (m_TempPath != wxEmptyString) {
- wxFileOutputStream *outs = new wxFileOutputStream(m_TempPath + safetitle + wxT(".cached"));
- SaveCachedBook(bookr, outs);
- delete outs;
+ // 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 ||
+ fi -> GetModificationTime() < bookfile.GetModificationTime() ||
+ !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;
+ }