#include <cpPlugins/Interface.h>
#include <cpPlugins/Utilities.h>
-#include <cpPlugins/LoadDynamicLibrariesFunctions.h>
+#include <cpPlugins/DLLManager.h>
#include <cpPlugins/dirent.h>
#include <algorithm>
if( p != NULL )
str << p << cpPlugins_SEPARATOR;
str << ".";
- this->UpdateEnvironments( str.str( ) );
+ this->AddEnvironments( str.str( ) );
}
// -------------------------------------------------------------------------
}
// -------------------------------------------------------------------------
-const std::set< std::string >& cpPlugins::Interface::
+const cpPlugins::Interface::
+TStrings& cpPlugins::Interface::
GetPaths( ) const
{
return( this->m_Paths );
}
// -------------------------------------------------------------------------
-std::set< std::string > cpPlugins::Interface::
+cpPlugins::Interface::
+TStrings cpPlugins::Interface::
GetLibraries( ) const
{
- std::set< std::string > res;
+ TStrings res;
for(
auto i = this->m_Libraries.begin( ); i != this->m_Libraries.end( ); ++i
)
}
// -------------------------------------------------------------------------
-std::set< std::string > cpPlugins::Interface::
+cpPlugins::Interface::
+TStrings cpPlugins::Interface::
GetPlugins( ) const
{
- std::set< std::string > res;
+ TStrings res;
for( auto i = this->m_Plugins.begin( ); i != this->m_Plugins.end( ); ++i )
res.insert( i->first );
return( res );
}
// -------------------------------------------------------------------------
-std::set< std::string > cpPlugins::Interface::
+cpPlugins::Interface::
+TStrings cpPlugins::Interface::
GetCategories( ) const
{
- std::set< std::string > res;
+ TStrings res;
for( auto i = this->m_Filters.begin( ); i != this->m_Filters.end( ); ++i )
res.insert( i->first );
return( res );
}
// -------------------------------------------------------------------------
-std::set< std::string > cpPlugins::Interface::
+cpPlugins::Interface::
+TStrings cpPlugins::Interface::
GetFilters( const std::string& category ) const
{
- std::set< std::string > res;
+ TStrings res;
auto cIt = this->m_Filters.find( category );
if( cIt != this->m_Filters.end( ) )
- {
for( auto i = cIt->second.begin( ); i != cIt->second.end( ); ++i )
res.insert( i->first );
-
- } // rof
return( res );
}
// -------------------------------------------------------------------------
void cpPlugins::Interface::
-UpdateEnvironments( const std::string& new_environment )
+AddEnvironments( const std::string& new_environment )
{
std::vector< std::string > tokens;
cpPlugins::TokenizeString( tokens, new_environment, cpPlugins_SEPARATOR );
for( auto i = tokens.begin( ); i != tokens.end( ); ++i )
{
- std::string dir = cpPlugins::CanonicalPath( *i );
- if( dir != "" )
- this->m_Paths.insert( dir );
+ std::stringstream dir;
+ dir << cpPlugins::CanonicalPath( *i );
+ if( dir.str( ) != "" )
+ {
+ if( !cpPlugins::IsPathSeparator( dir.str( ).back( ) ) )
+ dir << cpPlugins_PATH_SEPARATOR;
+ std::stringstream name;
+ name << dir.str( ) << cpPlugins_CONFIG;
+ std::ifstream check( name.str( ).c_str( ), std::ifstream::binary );
+ if( check )
+ this->m_Paths.insert( dir.str( ) );
+ check.close( );
+
+ } // fi
} // rof
}
// -------------------------------------------------------------------------
void cpPlugins::Interface::
-LoadEnvironment( )
+LoadEnvironments( )
{
std::stringstream all_errors;
- for( auto i = this->m_Paths.begin( ); i != this->m_Paths.end( ); ++i )
+ for( auto d = this->m_Paths.begin( ); d != this->m_Paths.end( ); ++d )
{
- std::stringstream dir;
- dir << *i;
- if( !cpPlugins::IsPathSeparator( i->back( ) ) )
- dir << cpPlugins_PATH_SEPARATOR;
- std::string fname = dir.str( ) + std::string( cpPlugins_CONFIG );
- std::string config_file;
- if( cpPlugins::ReadFileIntoBuffer( config_file, fname ) )
+ std::stringstream name;
+ name << *d << cpPlugins_CONFIG;
+ std::string buffer;
+ if( cpPlugins::ReadFileIntoBuffer( buffer, name.str( ) ) )
{
- std::istringstream input( config_file );
+ std::istringstream input( buffer );
for( std::string line; std::getline( input, line ); )
{
std::vector< std::string > tokens;
if( tokens[ 0 ] == "local" )
library_file =
cpPlugins::CanonicalPath(
- dir.str( ) +
- std::string( cpPlugins_LIB_PREFIX ) +
- tokens[ 1 ] +
- std::string( "." ) +
+ *d + std::string( cpPlugins_LIB_PREFIX ) +
+ tokens[ 1 ] + std::string( "." ) +
std::string( cpPlugins_LIB_EXT )
);
else if( tokens[ 0 ] == "global" )
std::stringstream fname;
fname << dir;
- if( cpPlugins::IsPathSeparator( dir.back( ) ) )
+ if( !cpPlugins::IsPathSeparator( dir.back( ) ) )
fname << cpPlugins_PATH_SEPARATOR;
- fname << cpPlugins_CONFIG;
- if( !( cpPlugins::WriteBufferToFile( buffer.str( ), fname.str( ) ) ) )
+ fname << cpPlugins_PATHS;
+ if( !cpPlugins::WriteBufferToFile( buffer.str( ), fname.str( ) ) )
throw std::runtime_error( "Error writing environment file." );
}
else
{
std::stringstream fname;
fname << dir;
- if( cpPlugins::IsPathSeparator( dir.back( ) ) )
+ if( !cpPlugins::IsPathSeparator( dir.back( ) ) )
fname << cpPlugins_PATH_SEPARATOR;
- fname << cpPlugins_CONFIG;
+ fname << cpPlugins_PATHS;
std::string buffer;
if( cpPlugins::ReadFileIntoBuffer( buffer, fname.str( ) ) )
{
std::istringstream input( buffer );
+ std::stringstream paths;
for( std::string line; std::getline( input, line ); )
- this->m_Paths.insert( cpPlugins::CanonicalPath( line ) );
+ paths << line << cpPlugins_SEPARATOR;
+ this->AddEnvironments( paths.str( ) );
}
else
throw std::runtime_error( "Error opening environment file." );
{
for( auto i = this->m_Paths.begin( ); i != this->m_Paths.end( ); ++i )
{
- try
- {
- this->LoadDirectory( *i );
- }
- catch( ... )
- {
- } // yrt
+ try { this->LoadDirectory( *i ); }
+ catch( ... ) { }
} // rof
}