1 #include <creaImageIOImageFinder.h>
4 #include <wx/filename.h>
10 //====================================================================
12 ImageFinder::ImageFinder(TreeHandler* tree)
17 ImageFinder::~ImageFinder()
20 //====================================================================
22 //=====================================================================
23 bool ImageFinder::IsHandledFile( const std::string& filename)
25 return (mReader.CanRead(filename,""));
27 //=====================================================================
29 //=====================================================================
30 bool ImageFinder::AddFiles( const std::vector<std::string>& filenames)
31 // wxProgressDialog* progress,
32 // UpdateSummary& summary)
35 unsigned int nbf = filenames.size();
36 std::vector<std::string>::const_iterator i;
37 for (i=filenames.begin();i!=filenames.end();++i)
39 // summary.scanned_files++;
40 if (IsHandledFile(*i))
42 // summary.handled_images++;
43 AddFile(*i);//,summary);
47 std::string mess("Adding ");
49 if (!progress->Update( (int)(summary.added_images*999./nbf),
52 // Some file was added hence we must return true !
53 summary.cancelled_by_user = true;
63 //=====================================================================
65 //=====================================================================
66 bool ImageFinder::AddFile( const std::string& filename )
67 // UpdateSummary& summary)
70 std::map< std::string, std::string> attr;
71 mTreeHandler->GetTree().GetDescriptor().BuildAttributeMap(attr);
73 mReader.ReadAttributes(filename,attr);
75 // image->SetFieldValue("FullFileName",filename);
77 int lev = mTreeHandler->AddBranch(attr);
79 // TO DO : update the summary according to lev
83 //=====================================================================
85 //=====================================================================
87 * \brief Explore a directory with possibility of recursion
88 * return number of files read
89 * @param dirpath directory to explore
90 * @param recursive whether we want recursion or not
92 void ImageFinder::ParseDirectory( const std::string &dirpath,
93 std::vector<std::string> &Filenames,
95 // wxProgressDialog* progress,
96 // UpdateSummary& summary)
102 std::string mess("Parsing ");
104 progress->Pulse(std2wx(mess));
107 std::string fileName;
108 std::string dirName = dirpath;
110 // summary.scanned_dirs++;
112 wxDir dir( std2wx(dirpath) );
114 if ( !dir.IsOpened() )
116 // deal with the error here - wxDir would already log an error message
117 // explaining the exact reason of the failure
123 bool cont = dir.GetFirst(&filename, wxEmptyString, wxDIR_FILES | wxDIR_HIDDEN );
127 if ((progress)&&( sw.Time() >= 250 ))
129 // std::cout << "PULSE"<<std::endl;
131 if (!progress->Pulse())
133 summary.cancelled_by_user = true;
138 // summary.scanned_files++;
139 wxFileName wxffn(dir.GetName(),filename);
140 std::string ffn = wx2std(wxffn.GetFullPath());
141 // std::cout << ffn << std::endl;
142 if (mReader.CanRead(ffn,""))
144 Filenames.push_back( ffn );
145 // summary.handled_images++;
147 cont = dir.GetNext(&filename);
150 // Recurse into subdirs
153 cont = dir.GetFirst(&filename, wxEmptyString, wxDIR_DIRS | wxDIR_HIDDEN );
157 wxFileName wxffn(dir.GetName(),filename);
158 std::string ffn = wx2std(wxffn.GetFullPath());
160 // std::cout << "dir="<< ffn<< std::endl;
167 // if (summary.cancelled_by_user) break;
169 cont = dir.GetNext(&filename);
174 //=======================================================================
177 //=====================================================================
178 bool ImageFinder::AddDirectory( const std::string& directory,
180 // wxProgressDialog* progress,
181 // UpdateSummary& summary
184 // std::cout << "** ImageFinder::AddDirectory"
185 // << " '"<<directory<<"'"<<std::endl;
186 // std::cout << "------ Parsing directory ------"<<std::endl;
193 for (int swi=0;swi<10;swi++)
202 bool was_canceled_by_user(false);
204 std::vector<std::string> filenames;
205 ParseDirectory( directory,
212 if ( summary.cancelled_by_user )
217 summary.parse_time = sw.Time();
220 summary.added_images = 0;
222 unsigned int nbf = filenames.size(); // , nf = 0;
223 std::vector<std::string>::iterator i;
224 for (i=filenames.begin();i!=filenames.end();++i)
226 AddFile(*i); //,summary);
230 std::string mess("Adding ");
232 if (!progress->Update( (int)(summary.added_images*999./nbf),
235 // Some file was added hence we must return true !
236 summary.cancelled_by_user = true;
249 summary.total_time = sw.Time();
250 summary.file_scan_time = msw[1].Time();
251 summary.update_database_time = msw[2].Time();
252 summary.update_structs_time =
255 summary.file_scan_time -
256 summary.update_database_time;
260 //=====================================================================