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,
- cpPlugins::CanonicalPath(
- dir.str( ) + std::string( cpPlugins_CONFIG )
- )
- )
- )
+ if( cpPlugins::ReadFileIntoBuffer( config_file, fname ) )
{
std::istringstream input( config_file );
for( std::string line; std::getline( input, line ); )
);
}
+// -------------------------------------------------------------------------
+void cpPlugins::Interface::
+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 fname;
+ fname << dir;
+ if( cpPlugins::IsPathSeparator( dir.back( ) ) )
+ fname << cpPlugins_PATH_SEPARATOR;
+ fname << cpPlugins_CONFIG;
+ if( !( cpPlugins::WriteBufferToFile( buffer.str( ), fname.str( ) ) ) )
+ throw std::runtime_error( "Error writing environment file." );
+ }
+ else
+ throw std::runtime_error( "No paths to save." );
+}
+
+// -------------------------------------------------------------------------
+void cpPlugins::Interface::
+OpenEnvironments( const std::string& dir )
+{
+ std::stringstream fname;
+ fname << dir;
+ if( cpPlugins::IsPathSeparator( dir.back( ) ) )
+ fname << cpPlugins_PATH_SEPARATOR;
+ fname << cpPlugins_CONFIG;
+ std::string buffer;
+ if( cpPlugins::ReadFileIntoBuffer( buffer, fname.str( ) ) )
+ {
+ std::istringstream input( buffer );
+ for( std::string line; std::getline( input, line ); )
+ this->m_Paths.insert( cpPlugins::CanonicalPath( line ) );
+ }
+ else
+ throw std::runtime_error( "Error opening environment file." );
+}
+
// -------------------------------------------------------------------------
void cpPlugins::Interface::
LoadFile( const std::string& fname )