#include <creaImageIOTreeHandlerImageAdder.h>
-#include <creaWx.h>
-#include <wx/dir.h>
-#include <wx/filename.h>
+#include <creaImageIOSystem.h>
+#include "boost/filesystem.hpp"
+#include <boost/filesystem/operations.hpp>
+#include <boost/utility.hpp>
-using namespace crea;
+
+namespace fs = boost::filesystem;
+using boost::filesystem::path;
+using boost::next;
+using boost::prior;
+
+
+//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)
{
+ mTimestampHandler->AddFile((*i), fs::last_write_time(*i), time(0));
mProgress.IncNumberScannedFiles();
if (IsHandledFile(*i))
{
{
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)
{
+ GimmickDebugMessage(4,"Scanning '"<<dirpath<<"'"<<std::endl);
mProgress.IncNumberScannedDirs();
- std::string fileName;
- std::string dirName = dirpath;
-
- 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;
+ if ( !fs::exists( dirpath ) ) return;
+ time_t lastModif=fs::last_write_time(dirpath);
- bool cont = dir.GetFirst(&filename, wxEmptyString,
- wxDIR_FILES | wxDIR_HIDDEN );
- while ( cont )
+ fs::directory_iterator end_itr; // default construction yields past-the-end
+ for ( fs::directory_iterator itr( dirpath );
+ itr != end_itr;
+ ++itr )
{
- mProgress.IncNumberScannedFiles();
-
- wxFileName wxffn(dir.GetName(),filename);
- std::string ffn = wx2std(wxffn.GetFullPath());
- if (IsHandledFile(ffn))
+ // If is directory & recurse : do recurse
+ if ( fs::is_directory(itr->status()) )
{
- mProgress.IncNumberHandledFiles();
- AddFile( ffn );
+ if (recursive)
+ {
+ AddDirectoryRecursor( itr->string(), recursive);
+ }
}
- mProgressSignal(mProgress);
- cont = ( dir.GetNext(&filename) && (!mProgress.GetStop()) );
- }
-
- // Recurse into subdirs
- if ( recursive )
- {
- cont = dir.GetFirst(&filename, wxEmptyString,
- wxDIR_DIRS | wxDIR_HIDDEN );
- while ( cont )
+ else
{
- wxFileName wxffn(dir.GetName(),filename);
- std::string ffn = wx2std(wxffn.GetFullPath());
- AddDirectoryRecursor( ffn, recursive);
- cont = dir.GetNext(&filename);
+ std::string parent_id;
+ bool valid=mTimestampHandler->AddDirectory(dirpath, itr->string(), lastModif, time(0));
+ if(valid)
+ {
+ mProgress.IncNumberScannedFiles();
+ if (IsHandledFile(itr->string()))
+ {
+ mProgress.IncNumberHandledFiles();
+ AddFile( itr->string() );
+ mTreeHandler->GetTopLevelNodeId("FullFileName",itr->string(),parent_id);
+ mTimestampHandler->SetAttribute("TopLevelNodeId",parent_id,"PATH",itr->string());
+ }
+ mProgressSignal(mProgress);
+ if (mProgress.GetStop())
+ {
+ //itr = end_itr;
+ break;
+ }
+ }
+ mTimestampHandler->SetAttribute("TopLevelNodeId",parent_id,"PATH",dirpath);
}
}
-
+
}
//=======================================================================