X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;ds=sidebyside;f=lib%2FcpPlugins%2FInterface%2FPlugins.cxx;h=eabd53ef905e45048dd4530530b360b014a2bb43;hb=d8ebffc6ece697ddf7b358946ef5d9c9cd7191fe;hp=c114404b1e332602749ebca4f24f045120e0c20c;hpb=211cd32b53b9739923f6c5135a704ce1852deca1;p=cpPlugins.git diff --git a/lib/cpPlugins/Interface/Plugins.cxx b/lib/cpPlugins/Interface/Plugins.cxx index c114404..eabd53e 100644 --- a/lib/cpPlugins/Interface/Plugins.cxx +++ b/lib/cpPlugins/Interface/Plugins.cxx @@ -1,8 +1,7 @@ #include #include -#include +#include #include -#include // ------------------------------------------------------------------------- cpPlugins::Interface::Plugins:: @@ -106,63 +105,24 @@ LoadEnvironments( ) std::istringstream input( buffer ); for( std::string line; std::getline( input, line ); ) { - std::vector< std::string > tokens; - cpExtensions::Tokenize( tokens, line, "|" ); - if( tokens.size( ) == 2 ) + auto pos = line.find( "*" ); + if( pos != std::string::npos ) { - std::string pth = tokens[ 0 ]; - std::string lib = tokens[ 1 ]; - if( lib.find( "*" ) != std::string::npos ) - { - std::string ext( cpPlugins_LIB_EXT ); - DIR* dir; - struct dirent* ent; - if( ( dir = opendir( pth.c_str( ) ) ) != NULL ) - { - while( ( ent = readdir( dir ) ) != NULL ) - { - std::string fname( ent->d_name ); - long pos = long( fname.size( ) ) - long( ext.size( ) ); - if( pos > 0 ) - { - if( fname.substr( pos ) == ext ) - { - std::regex re( lib ); - std::smatch match; - if( std::regex_search( fname, match, re ) && match.size( ) >= 1 ) - { - std::stringstream str; - str - << pth << cpPlugins_PATH_SEPARATOR << fname; - libs.insert( str.str( ) ); - } // fi - - } // fi - - } // fi - - } // elihw - closedir( dir ); - - } // fi - } - else - { - std::stringstream str; - str - << pth << cpPlugins_PATH_SEPARATOR << cpPlugins_LIB_PREFIX - << lib << cpPlugins_LIB_EXT; - libs.insert( str.str( ) ); - - } // fi - - } // fi + std::string dname, fname; + cpPlugins::OS::SplitPath( dname, fname, line ); + auto files = cpPlugins::OS::LoadDirContents( dname, false, fname ); + for( auto fIt = files.begin( ); fIt != files.end( ); ++fIt ) + libs.insert( *fIt ); + } + else + libs.insert( line ); } // rof } // fi } // rof + for( auto l = libs.begin( ); l != libs.end( ); ++l ) { std::string lib = cpExtensions::CanonicalPath( *l ); @@ -306,7 +266,9 @@ LoadFile( const std::string& fname ) // Get filter creator TCreator creator = ( TCreator )( - cpPlugins::OS::DLLManager::GetFunctionHandle( hnd, category + "_" + name ) + cpPlugins::OS::DLLManager::GetFunctionHandle( + hnd, category + "_" + name + ) ); if( creator == NULL ) { @@ -373,28 +335,18 @@ LoadPlugin( const std::string& pname ) void cpPlugins::Interface::Plugins:: LoadDirectory( const std::string& dirname ) { - DIR* dir; - struct dirent* ent; - if( ( dir = opendir( dirname.c_str( ) ) ) != NULL ) + std::stringstream pat; + pat << "*" << cpPlugins_LIB_EXT; + auto libs = cpPlugins::OS::LoadDirContents( dirname, false, pat.str( ) ); + for( auto lIt = libs.begin( ); lIt != libs.end( ); ++lIt ) { - while( ( ent = readdir( dir ) ) != NULL ) + try { - try - { - std::stringstream fname; - fname << dirname << cpExtensions_PATH_SEPARATOR << ent->d_name; - this->LoadFile( fname.str( ) ); - } - catch( ... ) { } - - } // elihw - closedir( dir ); - } - else - throw std::runtime_error( - std::string( "Could not load directory " ) + - std::string( "\"" ) + dirname + std::string( "\"" ) - ); + this->LoadFile( *lIt ); + } + catch( ... ) { } + + } // rof } // -------------------------------------------------------------------------