std::stringstream dir;
dir << cpExtensions::CanonicalPath( *i );
if( dir.str( ) != "" )
- {
- if( !cpExtensions::IsPathSeparator( dir.str( ).back( ) ) )
- dir << cpExtensions_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
+ this->m_Paths.insert( dir.str( ) );
} // rof
}
void cpPlugins::Interface::Plugins::
SaveEnvironments( const std::string& dir ) const
{
- if( this->m_Paths.size( ) > 0 )
- {
- std::stringstream buffer;
- auto i = this->m_Paths.begin( );
- for( auto i = this->m_Paths.begin( ); i != this->m_Paths.end( ); ++i )
- buffer << *i << std::endl;
+ std::stringstream buffer;
+ for( auto i = this->m_Paths.begin( ); i != this->m_Paths.end( ); ++i )
+ buffer << *i << std::endl;
- std::stringstream fname;
- fname << dir;
- if( !cpExtensions::IsPathSeparator( dir.back( ) ) )
- fname << cpExtensions_PATH_SEPARATOR;
- fname << cpPlugins_PATHS;
- if( !cpExtensions::Write( buffer.str( ), fname.str( ) ) )
- throw std::runtime_error( "Error writing environment file." );
- }
- else
- throw std::runtime_error( "No paths to save." );
+ std::stringstream fname;
+ fname << dir;
+ if( !cpExtensions::IsPathSeparator( dir.back( ) ) )
+ fname << cpExtensions_PATH_SEPARATOR;
+ fname << cpPlugins_PATHS;
+ if( !cpExtensions::Write( buffer.str( ), fname.str( ) ) )
+ throw std::runtime_error( "Error writing environment file." );
}
// -------------------------------------------------------------------------
void cpPlugins::Interface::Plugins::
OpenEnvironments( const std::string& dir )
{
- std::stringstream fname;
- fname << dir;
- if( !cpExtensions::IsPathSeparator( dir.back( ) ) )
- fname << cpExtensions_PATH_SEPARATOR;
- fname << cpPlugins_PATHS;
- std::string buffer;
- if( cpExtensions::Read( buffer, fname.str( ) ) )
+ std::vector< std::string > tokens;
+ cpExtensions::Tokenize( tokens, dir, cpPlugins_ENV_SEPARATOR );
+ for( auto tIt = tokens.begin( ); tIt != tokens.end( ); ++tIt )
{
- std::istringstream input( buffer );
- std::stringstream paths;
- for( std::string line; std::getline( input, line ); )
- paths << line << cpPlugins_ENV_SEPARATOR;
- this->AddEnvironments( paths.str( ) );
- }
- else
- throw std::runtime_error( "Error opening environment file." );
+ std::stringstream fname;
+ fname << *tIt;
+ 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 );
+ std::stringstream paths;
+ for( std::string line; std::getline( input, line ); )
+ paths << line << cpPlugins_ENV_SEPARATOR;
+ this->AddEnvironments( paths.str( ) );
+ }
+ else
+ {
+ bool success = true;
+ try
+ {
+ this->LoadDirectory( dir );
+ }
+ catch( ... )
+ {
+ success = false;
+
+ } // yrt
+ if( success )
+ this->AddEnvironments( dir );
+
+ } // fi
+
+ } // rof
}
// -------------------------------------------------------------------------
Plugins( )
: Superclass( )
{
+#ifdef cpPlugins_OS_Windows
+ char* p;
+ size_t size;
+ _dupenv_s( &p, &size, cpPlugins_PATHS );
+#else // cpPlugins_OS_Windows
char* p = std::getenv( cpPlugins_PATHS );
+#endif // cpPlugins_OS_Windows
std::stringstream str;
if( p != NULL )
str << p << cpPlugins_ENV_SEPARATOR;
str << ".";
- this->AddEnvironments( str.str( ) );
+ this->OpenEnvironments( str.str( ) );
+
+ // Try to read locally defined paths
+ /* TODO
+ std::vector< std::string > tokens;
+ cpExtensions::Tokenize( tokens, str.str( ), cpPlugins_ENV_SEPARATOR );
+ for( auto t = tokens.begin( ); t != tokens.end( ); ++t )
+ {
+ try
+ {
+ this->OpenEnvironments( *t );
+ }
+ catch( ... ) { }
+
+ } // rof
+ */
}
// -------------------------------------------------------------------------