#include <creaImageIOTreeHandlerImageAdder.h>
-#include <creaWx.h>
-#include <wx/dir.h>
-#include <wx/filename.h>
+#include <creaImageIOSystem.h>
+#include "boost/filesystem.hpp"
-using namespace crea;
+namespace fs = boost::filesystem;
+
+//using namespace crea;
namespace creaImageIO
{
//=====================================================================
bool TreeHandlerImageAdder::IsHandledFile( const std::string& filename)
{
- return (mReader.CanRead(filename,""));
+ return (mReader.CanRead(filename));
}
//=====================================================================
std::vector<std::string>::const_iterator i;
for (i=filenames.begin();i!=filenames.end();++i)
{
+
mProgress.IncNumberScannedFiles();
if (IsHandledFile(*i))
{
mProgress.IncNumberHandledFiles();
AddFile(*i);
-
-
- /*
- if (progress)
- {
- std::string mess("Adding ");
- mess += *i;
- if (!progress->Update( (int)(summary.added_images*999./nbf),
- std2wx(mess)))
- {
- // Some file was added hence we must return true !
- summary.cancelled_by_user = true;
- break;
- }
- }
- */
}
mProgressSignal(mProgress);
+ if (mProgress.GetStop()) break;
}
}
//=====================================================================
{
mProgress.Reset();
AddDirectoryRecursor( directory, recurse );
+ GimmickDebugMessage(3,mProgress<<std::endl);
}
- //=====================================================================
-
-
-
//=====================================================================
void TreeHandlerImageAdder::AddFile( const std::string& filename )
{
-
+ GimmickDebugMessage(4,"Adding '"<<filename<<"'"<<std::endl);
std::map< std::string, std::string> attr;
mTreeHandler->GetTree().GetDescriptor().BuildAttributeMap(attr);
void TreeHandlerImageAdder::AddDirectoryRecursor(const std::string &dirpath,
bool recursive)
{
- // std::cout << "dir : "<<dirpath << std::endl;
- mProgress.IncNumberScannedDirs();
- /*
- if (progress)
- {
- std::string mess("Parsing ");
- mess += dirpath;
- progress->Pulse(std2wx(mess));
- }
- */
- std::string fileName;
- std::string dirName = dirpath;
+ GimmickDebugMessage(4,"Scanning '"<<dirpath<<"'"<<std::endl);
+ mProgress.IncNumberScannedDirs();
- wxDir dir( std2wx(dirpath) );
-
- if ( !dir.IsOpened() )
- {
- // deal with the error here - wxDir would already log an error message
- // explaining the exact reason of the failure
- return;
- }
-
- wxString filename;
-
- bool cont = dir.GetFirst(&filename, wxEmptyString,
- wxDIR_FILES | wxDIR_HIDDEN );
- while ( cont )
- {
- mProgress.IncNumberScannedFiles();
-
- wxFileName wxffn(dir.GetName(),filename);
- std::string ffn = wx2std(wxffn.GetFullPath());
- // std::cout << "file : "<<ffn << std::endl;
- if (IsHandledFile(ffn))
- {
- mProgress.IncNumberHandledFiles();
- // std::cout << "handled : "<<ffn << std::endl;
- AddFile( ffn );
- }
- // std::cout << "signal " << std::endl;
- mProgressSignal(mProgress);
- // std::cout << "cont " << std::endl;
- cont = ( dir.GetNext(&filename) && (!mProgress.GetStop()) );
- // std::cout << "next" << std::endl;
- }
+ if ( !fs::exists( dirpath ) ) return;
- // Recurse into subdirs
- if ( recursive )
+ fs::directory_iterator end_itr; // default construction yields past-the-end
+ for ( fs::directory_iterator itr( dirpath );
+ itr != end_itr;
+ ++itr )
{
- // std::cout << "recurse " << std::endl;
- cont = dir.GetFirst(&filename, wxEmptyString,
- wxDIR_DIRS | wxDIR_HIDDEN );
- while ( cont )
+ // If is directory & recurse : do recurse
+ if ( fs::is_directory(itr->status()) )
{
- wxFileName wxffn(dir.GetName(),filename);
- std::string ffn = wx2std(wxffn.GetFullPath());
- // std::cout << "goto "<<ffn << std::endl;
- AddDirectoryRecursor( ffn, recursive);
- cont = dir.GetNext(&filename);
+ if (recursive) AddDirectoryRecursor( itr->string(), recursive);
}
+ else
+ {
+ mProgress.IncNumberScannedFiles();
+ if (IsHandledFile(itr->string()))
+ {
+ mProgress.IncNumberHandledFiles();
+ AddFile( itr->string() );
+ }
+ mProgressSignal(mProgress);
+ if (mProgress.GetStop())
+ {
+ itr = end_itr
+// break;
+ }
+ }
}
-
+
}
//=======================================================================