bool CHMPlugin::readDescription(const std::string &path, BookDescription &description) const { ZLFile file(path); shared_ptr<ZLInputStream> stream = file.inputStream(); if (stream.isNull() || !stream->open()) { return false; } CHMFileInfo chmFile(path); if (!chmFile.init(*stream)) { return false; } CHMFileInfo::FileNames names = chmFile.sectionNames(stream); if (names.empty()) { return false; } /* shared_ptr<ZLInputStream> entryStream = chmFile.entryStream(stream, names.Start); if (entryStream.isNull()) { entryStream = chmFile.entryStream(stream, names.Home); } if (entryStream.isNull()) { entryStream = chmFile.entryStream(stream, names.TOC); } / * if (entryStream.isNull()) { chmFile.entryStream(stream, names.Index); } * / if (entryStream.isNull()) { return false; } */ CHMTextStream textStream(chmFile, stream); detectEncodingAndLanguage(description, textStream); if (description.encoding().empty()) { return false; } return true; }
bool CHMPlugin::readMetaInfo(Book &book) const { const ZLFile &file = book.file(); shared_ptr<ZLInputStream> stream = file.inputStream(); if (stream.isNull() || !stream->open()) { return false; } CHMFileInfo chmFile(file); if (!chmFile.init(*stream)) { return false; } CHMFileInfo::FileNames names = chmFile.sectionNames(stream); if (names.empty()) { return false; } /* shared_ptr<ZLInputStream> entryStream = chmFile.entryStream(stream, names.Start); if (entryStream.isNull()) { entryStream = chmFile.entryStream(stream, names.Home); } if (entryStream.isNull()) { entryStream = chmFile.entryStream(stream, names.TOC); } / * if (entryStream.isNull()) { chmFile.entryStream(stream, names.Index); } * / if (entryStream.isNull()) { return false; } */ CHMTextStream textStream(chmFile, stream); detectEncodingAndLanguage(book, textStream); if (book.encoding().empty()) { return false; } return true; }
bool CHelpSystemCore::SearchCHMs(const CString &path) { // Retrieive full path with wildcard and full path without wildcard. CString fullPathWildcard; CString fullPath; // Construct full path with wildcard. int pos = DLLModuleName.ReverseFind('\\'); if (pos < 0) { // Invalid path. return false; } fullPathWildcard = DLLModuleName.Left(pos + 1); fullPathWildcard += path; // Retrieveing full path without wildcard. pos = fullPathWildcard.ReverseFind('\\'); if (pos < 0) { // Invalid path (shouldn't actually get here). return false; } fullPath = fullPathWildcard.Left(pos + 1); // Search and load CHM files. bool bIsFound = false; WIN32_FIND_DATA fdData; HANDLE hFind = FindFirstFile(fullPathWildcard, &fdData); if (hFind != INVALID_HANDLE_VALUE) { do { if ((fdData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0) { CString fileName = fullPath + fdData.cFileName; // Here (const char *) cast is used, because chm::chmfile // supports std::string only. std::auto_ptr<chm::chmfile> chmFile( new chm::chmfile((const char *)(fileName)) ); if (chmFile->is_open()) { // The CHM is open and valid. CString name(fdData.cFileName); // Remove extension. int ppos = name.ReverseFind('.'); if (ppos >= 0) { name.Delete(ppos, name.GetLength()); } name.MakeLower(); if (m_chmNames.find(name) == m_chmNames.end()) { bIsFound = true; m_chmList.push_back(CChm(fileName, chmFile)); CHMLIST::iterator item = m_chmList.end(); --item; m_chmNames.insert(std::make_pair(name, item)); } else { // TODO: Warning, CHM with such name already exists. } } } } while (FindNextFile(hFind, &fdData)); } return bIsFound; }