[Amis-vcs] SF.net SVN: amis: [2221] branches/amis3
Brought to you by:
julienq,
marisademeglio
From: <mar...@us...> - 2007-11-05 20:22:51
|
Revision: 2221 http://amis.svn.sourceforge.net/amis/?rev=2221&view=rev Author: marisademeglio Date: 2007-11-05 12:22:52 -0800 (Mon, 05 Nov 2007) Log Message: ----------- Started using new file searcher. No more annoying command prompt! Modified Paths: -------------- branches/amis3/AmisCore/include/dtb/Dtb.h branches/amis3/AmisCore/include/dtb/DtbFileSet.h branches/amis3/AmisCore/include/util/SearchForFiles.h branches/amis3/AmisCore/src/dtb/Dtb.cpp branches/amis3/AmisCore/src/dtb/DtbFileSet.cpp branches/amis3/AmisCore/src/util/SearchForFiles.cpp branches/amis3/AmisGuiMFC2/include/DtbWithHooks.h branches/amis3/AmisGuiMFC2/src/DtbWithHooks.cpp branches/amis3/AmisGuiMFC2/src/SearchForFilesMFC.cpp Modified: branches/amis3/AmisCore/include/dtb/Dtb.h =================================================================== --- branches/amis3/AmisCore/include/dtb/Dtb.h 2007-11-05 16:19:49 UTC (rev 2220) +++ branches/amis3/AmisCore/include/dtb/Dtb.h 2007-11-05 20:22:52 UTC (rev 2221) @@ -31,6 +31,7 @@ #include "dtb/smil/SmilMediaGroup.h" #include "dtb/DtbFileSet.h" #include "ambulant/net/url.h" +#include "util/SearchForFiles.h" namespace amis { @@ -62,7 +63,8 @@ wstring getUid(); amis::dtb::BookmarkSet* getBookmarks(); amis::dtb::CustomTestSet* getCustomTestSet(); - + void setFileSearcher(amis::util::SearchForFiles*); + amis::util::SearchForFiles* getFileSearcher(); string searchFullText(wstring); amis::dtb::smil::SmilTree* getSmilTree(); string searchFullTextNext(); @@ -102,6 +104,7 @@ wstring mLastSearchString; string mLastSearchResult; string mLastSearchedTextFile; + amis::util::SearchForFiles* mpFileSearcher; int mDaisyVersion; bool mbIsProtected; ProtectedBookKeyHandlerFunctionPtr mpCallbackForPreprocessingBookKey; Modified: branches/amis3/AmisCore/include/dtb/DtbFileSet.h =================================================================== --- branches/amis3/AmisCore/include/dtb/DtbFileSet.h 2007-11-05 16:19:49 UTC (rev 2220) +++ branches/amis3/AmisCore/include/dtb/DtbFileSet.h 2007-11-05 20:22:52 UTC (rev 2221) @@ -26,6 +26,7 @@ #include <string> #include "AmisCore.h" #include "ambulant/net/url.h" +#include "util/SearchForFiles.h" using namespace std; @@ -39,7 +40,7 @@ DtbFileSet(); ~DtbFileSet(); //!initialize with NCC or OPF filepath - void initWithNccOrOpf(const ambulant::net::url*); + void initWithNccOrOpf(const ambulant::net::url*, amis::util::SearchForFiles*); //utility functions static bool isNccFile(const ambulant::net::url*); static bool isOpfFile(const ambulant::net::url*); @@ -65,7 +66,7 @@ private: string calculateSafeBookmarksFilename(wstring); - void findTextFiles(); + void findTextFiles(amis::util::SearchForFiles*); ambulant::net::url mNavFilepath; ambulant::net::url mBookDirectory; @@ -76,6 +77,7 @@ ambulant::net::url mSmilFilepath; ambulant::net::url mProtectedNavFilepath; ambulant::net::url mProtectedBookKeyFilepath; + amis::util::SearchForFiles* mpFileSearcher; UrlList mTextFiles; }; } Modified: branches/amis3/AmisCore/include/util/SearchForFiles.h =================================================================== --- branches/amis3/AmisCore/include/util/SearchForFiles.h 2007-11-05 16:19:49 UTC (rev 2220) +++ branches/amis3/AmisCore/include/util/SearchForFiles.h 2007-11-05 20:22:52 UTC (rev 2221) @@ -37,16 +37,24 @@ void addSearchCriteria(std::string); amis::StdStringList getSearchCriteria(); void clearSearchCriteria(); - bool matchesCriteria(std::string); + bool matchesSearchCriteria(std::string); - //this function should be called by implementations of SearchForFiles + void addSearchExclusionCriteria(std::string); + amis::StdStringList getSearchExclusionCriteria(); + void clearSearchExclusionCriteria(); + bool matchesSearchExclusionCriteria(std::string); + + //this function should ONLY be called by implementations of SearchForFiles void addSearchResult(const ambulant::net::url*); + amis::UrlList getSearchResults(); void clearSearchResults(); private: + bool matchesList(std::string, amis::StdStringList); bool mbIsRecursive; amis::StdStringList mCriteria; + amis::StdStringList mExclusions; amis::UrlList mResults; }; } Modified: branches/amis3/AmisCore/src/dtb/Dtb.cpp =================================================================== --- branches/amis3/AmisCore/src/dtb/Dtb.cpp 2007-11-05 16:19:49 UTC (rev 2220) +++ branches/amis3/AmisCore/src/dtb/Dtb.cpp 2007-11-05 20:22:52 UTC (rev 2221) @@ -49,6 +49,7 @@ mpTitle = NULL; mpTextSmilMap = NULL; mpCustomTests = NULL; + mpFileSearcher = NULL; mUid.erase(); mDaisyVersion = 0; mpCallbackForPreprocessingBookKey = NULL; @@ -60,6 +61,7 @@ } //delete objects +//we are purposely not deleting mpFileSearcher void amis::dtb::Dtb::cleanUpObjects() { mbIsProtected = false; @@ -131,6 +133,14 @@ { return mpCustomTests; } +void amis::dtb::Dtb::setFileSearcher(amis::util::SearchForFiles* fileSearcher) +{ + mpFileSearcher = fileSearcher; +} +amis::util::SearchForFiles* amis::dtb::Dtb::getFileSearcher() +{ + return mpFileSearcher; +} //-------------------------------------------------- //wrapper for opening files @@ -153,7 +163,7 @@ mpFiles = NULL; mpFiles = new amis::dtb::DtbFileSet(); - mpFiles->initWithNccOrOpf(fileUrl); + mpFiles->initWithNccOrOpf(fileUrl, mpFileSearcher); mpFiles->setBookmarksDirectory(bookmarksDirectory); if (DtbFileSet::isNccFile(fileUrl)) Modified: branches/amis3/AmisCore/src/dtb/DtbFileSet.cpp =================================================================== --- branches/amis3/AmisCore/src/dtb/DtbFileSet.cpp 2007-11-05 16:19:49 UTC (rev 2220) +++ branches/amis3/AmisCore/src/dtb/DtbFileSet.cpp 2007-11-05 20:22:52 UTC (rev 2221) @@ -45,7 +45,7 @@ mTextFiles.clear(); } -void amis::dtb::DtbFileSet::initWithNccOrOpf(const ambulant::net::url* filepath) +void amis::dtb::DtbFileSet::initWithNccOrOpf(const ambulant::net::url* filepath, amis::util::SearchForFiles* fileSearcher) { /* this shows off a bug in the url code...but when it's fixed, this is an easier way to calculate the book directory @@ -57,6 +57,7 @@ std::string book_dir = temp_url.get_url(); book_dir += "/"; mBookDirectory = ambulant::net::url::from_url(book_dir); + mpFileSearcher = fileSearcher; if (isNccFile(filepath)) { @@ -64,9 +65,7 @@ //these should be set to "" .. however you do that with ambulant::net::url objects //this->mOpfFilepath; //this->mResourceFilepath; - - //this brings up the annoying command terminal - findTextFiles(); + findTextFiles(fileSearcher); } else if (isOpfFile(filepath)) { @@ -230,8 +229,8 @@ stored in the order it was created, and i don't know how to get at the key (text-src) by itself (maybe map_iter.first)? -another note: the process called by this function which searches the directory spawns an annoying (temporary) pop-up command line window*/ -void amis::dtb::DtbFileSet::findTextFiles() +*/ +void amis::dtb::DtbFileSet::findTextFiles(amis::util::SearchForFiles* fileSearcher) { //searching won't work on network-based books yet if (mBookDirectory.is_local_file() == false) return; @@ -241,27 +240,16 @@ //if we are not dealing with an OPF, then we have to look for the text files ourself if (this->mOpfFilepath.is_empty_path()) { - FindFilesInPath file_searcher(mBookDirectory.get_file(), "*.html"); - - StdStringList::const_iterator it; - bool b_check_ncc = true; - for(it = file_searcher.c_FileList.begin(); it != file_searcher.c_FileList.end();++it) - { - if (b_check_ncc) - { - string tmp = amis::util::FilePathTools::getFileName(*it); - if (tmp.compare("ncc.html") == 0) - { - b_check_ncc = false; - //if there is more than one file, skip the rest of the loop - //we don't need to copy the ncc file if there are other text files present - if (file_searcher.c_FileList.size() > 1) continue; - } - } + //we want to find the HTML files that are not NCC files + mpFileSearcher->addSearchCriteria(".html"); + mpFileSearcher->addSearchExclusionCriteria("ncc.html"); + mpFileSearcher->setRecursiveSearch(true); + mpFileSearcher->startSearch(mBookDirectory.get_file()); + + mTextFiles = mpFileSearcher->getSearchResults(); - ambulant::net::url fileurl = ambulant::net::url::from_filename((*it)); - mTextFiles.push_back(fileurl); - } + //if we didn't find any text files, then use the nav file as our text file + if (mTextFiles.size() == 0) mTextFiles.push_back(this->mNavFilepath); } } Modified: branches/amis3/AmisCore/src/util/SearchForFiles.cpp =================================================================== --- branches/amis3/AmisCore/src/util/SearchForFiles.cpp 2007-11-05 16:19:49 UTC (rev 2220) +++ branches/amis3/AmisCore/src/util/SearchForFiles.cpp 2007-11-05 20:22:52 UTC (rev 2221) @@ -28,6 +28,8 @@ amis::util::SearchForFiles::SearchForFiles() { mbIsRecursive = true; + mCriteria.clear(); + mExclusions.clear(); } amis::util::SearchForFiles::~SearchForFiles() { @@ -59,21 +61,45 @@ { return mCriteria; } -bool amis::util::SearchForFiles::matchesCriteria(std::string data) +void amis::util::SearchForFiles::addSearchExclusionCriteria(std::string criterion) { + std::string criterion_lower = criterion; + //make lower case + std::transform(criterion_lower.begin(), criterion_lower.end(), criterion_lower.begin(), (int(*)(int))tolower); + mExclusions.push_back(criterion_lower); +} + +amis::StdStringList amis::util::SearchForFiles::getSearchExclusionCriteria() +{ + return mExclusions; +} +void amis::util::SearchForFiles::clearSearchExclusionCriteria() +{ + mExclusions.clear(); +} +bool amis::util::SearchForFiles::matchesSearchCriteria(std::string data) +{ + return matchesList(data, mCriteria); +} +bool amis::util::SearchForFiles::matchesSearchExclusionCriteria(std::string data) +{ + return matchesList(data, mExclusions); +} + +bool amis::util::SearchForFiles::matchesList(std::string data, StdStringList list) +{ std::string data_lower = data; //make lower case std::transform(data_lower.begin(), data_lower.end(), data_lower.begin(), (int(*)(int))tolower); - for (int i=0; i<mCriteria.size(); i++) + for (int i=0; i<list.size(); i++) { - if (data_lower.find(mCriteria[i]) != std::string::npos) return true; + if (data_lower.find(list[i]) != std::string::npos) return true; } - if (mCriteria.size() > 0) return false; + if (list.size() > 0) return false; //if there are no criteria, everything is always a match else return true; } - void amis::util::SearchForFiles::clearSearchCriteria() { mCriteria.clear(); Modified: branches/amis3/AmisGuiMFC2/include/DtbWithHooks.h =================================================================== --- branches/amis3/AmisGuiMFC2/include/DtbWithHooks.h 2007-11-05 16:19:49 UTC (rev 2220) +++ branches/amis3/AmisGuiMFC2/include/DtbWithHooks.h 2007-11-05 20:22:52 UTC (rev 2221) @@ -25,6 +25,7 @@ #include "dtb/Dtb.h" +#include "SearchForFilesMFC.h" namespace amis { @@ -61,6 +62,9 @@ void addToRecentBooks(); void makeAllNavContainerLabelsHumanReadable(); void makeNavContainerLabelHumanReadable(nav::NavContainer*); + + //this object is instantiated and destroyed by this class, but otherwise is managed by the base class + amis::util::SearchForFilesMFC* mpFileSearcherTmp; private: static DtbWithHooks* pinstance; }; Modified: branches/amis3/AmisGuiMFC2/src/DtbWithHooks.cpp =================================================================== --- branches/amis3/AmisGuiMFC2/src/DtbWithHooks.cpp 2007-11-05 16:19:49 UTC (rev 2220) +++ branches/amis3/AmisGuiMFC2/src/DtbWithHooks.cpp 2007-11-05 20:22:52 UTC (rev 2221) @@ -31,6 +31,7 @@ #include "ambulant/net/url.h" #include "ambulant/smil2/test_attrs.h" + using namespace amis::dtb; DtbWithHooks* DtbWithHooks::pinstance = 0; @@ -56,14 +57,20 @@ DtbWithHooks::DtbWithHooks() { + mpFileSearcherTmp = NULL; + mpFileSearcherTmp = new amis::util::SearchForFilesMFC(); + setFileSearcher(mpFileSearcherTmp); } DtbWithHooks::~DtbWithHooks() { + if (mpFileSearcherTmp != NULL) delete mpFileSearcherTmp; } bool DtbWithHooks::open(const ambulant::net::url* filename, const ambulant::net::url* bookmarksPath) { + getFileSearcher()->clearSearchResults(); + //call the base class if (!Dtb::open(filename, bookmarksPath)) return false; Modified: branches/amis3/AmisGuiMFC2/src/SearchForFilesMFC.cpp =================================================================== --- branches/amis3/AmisGuiMFC2/src/SearchForFilesMFC.cpp 2007-11-05 16:19:49 UTC (rev 2220) +++ branches/amis3/AmisGuiMFC2/src/SearchForFilesMFC.cpp 2007-11-05 20:22:52 UTC (rev 2221) @@ -60,7 +60,9 @@ CString filename; int files_found = 0; - BOOL b_is_working = finder.FindFile(path); + CString cstr_path = path; + cstr_path.Append(_T("*.*")); + BOOL b_is_working = finder.FindFile(cstr_path); while (b_is_working) { b_is_working = finder.FindNextFile(); @@ -82,14 +84,16 @@ else { filename = finder.GetFileName(); - - if (matchesCriteria(T2A(filename))) + std::string str_filename = T2A(filename); + if (matchesSearchCriteria(str_filename) && !matchesSearchExclusionCriteria(str_filename)) { files_found++; //save the file path CString file_path = finder.GetFilePath(); std::string file_path_string = T2A(file_path); - ambulant::net::url file_path_url = ambulant::net::url::from_url(file_path_string); + //TODO + //we assume that the search returns local files + ambulant::net::url file_path_url = ambulant::net::url::from_filename(file_path_string); addSearchResult(&file_path_url); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |