#include <cpPlugins/Interface/Plugins.h>
#include <cpPlugins/OS/DLLManager.h>
-#include <cpPlugins/Interface/Dirent.h>
-#include <cpExtensions/Utility.h>
-#include <regex>
+#include <cpPlugins/OS/DirContents.h>
+#include <cpPlugins/Utility.h>
// -------------------------------------------------------------------------
cpPlugins::Interface::Plugins::
AddEnvironments( const std::string& env )
{
std::vector< std::string > directories;
- cpExtensions::Tokenize( directories, env, cpPlugins_ENV_SEPARATOR );
+ cpPlugins::Tokenize( directories, env, cpPlugins_ENV_SEPARATOR );
for( auto dir = directories.begin( ); dir != directories.end( ); ++dir )
- this->m_Paths.insert( cpExtensions::CanonicalPath( *dir ) );
+ this->m_Paths.insert( cpPlugins::CanonicalPath( *dir ) );
}
// -------------------------------------------------------------------------
std::stringstream fname;
fname << *d << cpPlugins_PATH_SEPARATOR << cpPlugins_CONFIG;
std::string buffer;
- if( cpExtensions::Read( buffer, fname.str( ) ) )
+ if( cpPlugins::Read( buffer, fname.str( ) ) )
{
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 );
+ std::string lib = cpPlugins::CanonicalPath( *l );
if( lib != "" )
{
if( this->m_Libraries.find( lib ) == this->m_Libraries.end( ) )
{
std::stringstream fname, envs;
fname << dir;
- if( !cpExtensions::IsPathSeparator( dir.back( ) ) )
- fname << cpExtensions_PATH_SEPARATOR;
+ if( !cpPlugins::IsPathSeparator( dir.back( ) ) )
+ fname << cpPlugins_PATH_SEPARATOR;
fname << cpPlugins_PATHS;
std::string buffer;
- if( cpExtensions::Read( buffer, fname.str( ) ) )
+ if( cpPlugins::Read( buffer, fname.str( ) ) )
{
std::istringstream input( buffer );
for( std::string line; std::getline( input, line ); )
std::stringstream fname;
fname << dir;
- if( !cpExtensions::IsPathSeparator( dir.back( ) ) )
- fname << cpExtensions_PATH_SEPARATOR;
+ if( !cpPlugins::IsPathSeparator( dir.back( ) ) )
+ fname << cpPlugins_PATH_SEPARATOR;
fname << cpPlugins_PATHS;
- if( !cpExtensions::Write( buffer.str( ), fname.str( ) ) )
+ if( !cpPlugins::Write( buffer.str( ), fname.str( ) ) )
throw std::runtime_error( "Error writing environment file." );
}
LoadFile( const std::string& fname )
{
// Resolve canonical filename
- std::string can_name = cpExtensions::CanonicalPath( fname );
+ std::string can_name = cpPlugins::CanonicalPath( fname );
if( can_name == "" )
throw std::runtime_error(
std::string( "Loading file: can't find library \"" ) +
// Get filter creator
TCreator creator = ( TCreator )(
- cpPlugins::OS::DLLManager::GetFunctionHandle( hnd, category + "_" + name )
+ cpPlugins::OS::DLLManager::GetFunctionHandle(
+ hnd, category + "_" + name
+ )
);
if( creator == NULL )
{
{
std::stringstream dir;
dir << *i;
- if( !cpExtensions::IsPathSeparator( i->back( ) ) )
- dir << cpExtensions_PATH_SEPARATOR;
+ if( !cpPlugins::IsPathSeparator( i->back( ) ) )
+ dir << cpPlugins_PATH_SEPARATOR;
dir << fname.str( );
try
{
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
}
// -------------------------------------------------------------------------