#include <cpPlugins/Interface/Plugins.h>
#include <cpPlugins/OS/DLLManager.h>
-#include <cpPlugins/Interface/Dirent.h>
+#include <cpPlugins/OS/DirContents.h>
#include <cpExtensions/Utility.h>
-#include <regex>
// -------------------------------------------------------------------------
cpPlugins::Interface::Plugins::
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 );
if( lib != "" )
{
if( this->m_Libraries.find( lib ) == this->m_Libraries.end( ) )
-{
- std::string error = "";
- void* hnd = cpPlugins::OS::DLLManager::Load( lib, error );
- if( hnd != NULL )
- this->m_Libraries[ lib ] = hnd;
+ {
+ std::string error = "";
+ void* hnd = cpPlugins::OS::DLLManager::Load( lib, error );
+ if( hnd != NULL )
+ this->m_Libraries[ lib ] = hnd;
-} // fi
+ } // fi
} // fi
if( !cpExtensions::IsPathSeparator( dir.back( ) ) )
fname << cpExtensions_PATH_SEPARATOR;
fname << cpPlugins_PATHS;
- std::string buffer;
- if( cpExtensions::Read( buffer, fname.str( ) ) )
- {
- std::istringstream input( buffer );
- for( std::string line; std::getline( input, line ); )
- envs << line << cpPlugins_ENV_SEPARATOR;
+ std::string buffer;
+ if( cpExtensions::Read( buffer, fname.str( ) ) )
+ {
+ std::istringstream input( buffer );
+ for( std::string line; std::getline( input, line ); )
+ envs << line << cpPlugins_ENV_SEPARATOR;
- } // fi
- if( envs.str( ).size( ) > 0 )
- this->AddEnvironments( envs.str( ) );
+ } // fi
+ if( envs.str( ).size( ) > 0 )
+ this->AddEnvironments( envs.str( ) );
}
// -------------------------------------------------------------------------
// Get filter creator
TCreator creator = ( TCreator )(
- cpPlugins::OS::DLLManager::GetFunctionHandle( hnd, category + "_" + name )
+ cpPlugins::OS::DLLManager::GetFunctionHandle(
+ hnd, category + "_" + name
+ )
);
if( creator == NULL )
{
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
}
// -------------------------------------------------------------------------