From: Leonardo Florez-Valencia Date: Tue, 28 Jun 2016 16:42:40 +0000 (-0500) Subject: ... X-Git-Tag: v0.1~127 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=183830055f401d334889eb83527a000129e45cad;p=cpPlugins.git ... --- diff --git a/appli/PipelineEditor/PipelineEditorMainWindow.cxx b/appli/PipelineEditor/PipelineEditorMainWindow.cxx index 20ddc16..5057790 100644 --- a/appli/PipelineEditor/PipelineEditorMainWindow.cxx +++ b/appli/PipelineEditor/PipelineEditorMainWindow.cxx @@ -26,12 +26,31 @@ PipelineEditorMainWindow( ); // Slots <-> signals - _QT_CONNECT_ACTION( Open ); - _QT_CONNECT_ACTION( Save ); - _QT_CONNECT_ACTION( Close ); - _QT_CONNECT_ACTION( LoadPluginFile ); - _QT_CONNECT_ACTION( LoadPluginDirectory ); - _QT_CONNECT_ACTION( ShowPlugins ); + this->connect( + this->m_UI->ActionOpen, SIGNAL( triggered( ) ), + this, SLOT( _InteractiveLoadWorkspace( ) ) + ); + this->connect( + this->m_UI->ActionSave, SIGNAL( triggered( ) ), + this, SLOT( _InteractiveSaveWorkspace( ) ) + ); + // TODO: _QT_CONNECT_ACTION( Close ); + this->connect( + this->m_UI->ActionLoadPluginFile, SIGNAL( triggered( ) ), + this, SLOT( _InteractiveLoadPlugins( ) ) + ); + this->connect( + this->m_UI->ActionLoadPluginDirectory, SIGNAL( triggered( ) ), + this, SLOT( _InteractiveLoadPluginsFromPath( ) ) + ); + this->connect( + this->m_UI->ActionShowPlugins, SIGNAL( triggered( ) ), + this, SLOT( _ShowPlugins( ) ) + ); + this->connect( + this->m_UI->ActionAddEnvironmentPath, SIGNAL( triggered( ) ), + this, SLOT( _InteractiveAddEnviromentPaths( ) ) + ); } // ------------------------------------------------------------------------- @@ -41,45 +60,4 @@ PipelineEditorMainWindow:: delete this->m_UI; } -// ------------------------------------------------------------------------- -void PipelineEditorMainWindow:: -_ActionOpen( ) -{ - this->_InteractiveLoadWorkspace( ); -} - -// ------------------------------------------------------------------------- -void PipelineEditorMainWindow:: -_ActionSave( ) -{ - this->_InteractiveSaveWorkspace( ); -} - -// ------------------------------------------------------------------------- -void PipelineEditorMainWindow:: -_ActionClose( ) -{ -} - -// ------------------------------------------------------------------------- -void PipelineEditorMainWindow:: -_ActionLoadPluginFile( ) -{ - this->_InteractiveLoadPlugins( ); -} - -// ------------------------------------------------------------------------- -void PipelineEditorMainWindow:: -_ActionLoadPluginDirectory( ) -{ - this->_InteractiveLoadPluginsFromPath( ); -} - -// ------------------------------------------------------------------------- -void PipelineEditorMainWindow:: -_ActionShowPlugins( ) -{ - this->_ShowPlugins( ); -} - // eof - $RCSfile$ diff --git a/appli/PipelineEditor/PipelineEditorMainWindow.h b/appli/PipelineEditor/PipelineEditorMainWindow.h index aa88f1e..81f7680 100644 --- a/appli/PipelineEditor/PipelineEditorMainWindow.h +++ b/appli/PipelineEditor/PipelineEditorMainWindow.h @@ -27,14 +27,6 @@ public: ); virtual ~PipelineEditorMainWindow( ); -protected slots: - void _ActionOpen( ); - void _ActionSave( ); - void _ActionClose( ); - void _ActionLoadPluginFile( ); - void _ActionLoadPluginDirectory( ); - void _ActionShowPlugins( ); - /* void _ActionBackgroundMPR( ); void _ActionBackground3D( ); diff --git a/appli/PipelineEditor/PipelineEditorMainWindow.ui b/appli/PipelineEditor/PipelineEditorMainWindow.ui index 0da8432..b5242a9 100644 --- a/appli/PipelineEditor/PipelineEditorMainWindow.ui +++ b/appli/PipelineEditor/PipelineEditorMainWindow.ui @@ -94,6 +94,7 @@ + @@ -152,6 +153,14 @@ Ctrl+Shift+S + + + &Manage enviroment paths + + + Ctrl+F9 + + diff --git a/appli/examples/plugins/example_plugins_GuessPlugins.cxx b/appli/examples/plugins/example_plugins_GuessPlugins.cxx index 16a42e3..77a7494 100644 --- a/appli/examples/plugins/example_plugins_GuessPlugins.cxx +++ b/appli/examples/plugins/example_plugins_GuessPlugins.cxx @@ -7,7 +7,7 @@ int main( int argc, char* argv[] ) cpPlugins::Interface interface; try { - interface.LoadEnvironment( ); + interface.LoadEnvironments( ); interface.GuessPlugins( ); } catch( std::exception& err ) diff --git a/appli/examples/plugins/example_plugins_LoadDirectory.cxx b/appli/examples/plugins/example_plugins_LoadDirectory.cxx index 7bd093f..af1a6bd 100644 --- a/appli/examples/plugins/example_plugins_LoadDirectory.cxx +++ b/appli/examples/plugins/example_plugins_LoadDirectory.cxx @@ -16,7 +16,7 @@ int main( int argc, char* argv[] ) cpPlugins::Interface interface; try { - interface.LoadEnvironment( ); + interface.LoadEnvironments( ); interface.LoadDirectory( directory ); } catch( std::exception& err ) diff --git a/appli/examples/plugins/example_plugins_LoadFile.cxx b/appli/examples/plugins/example_plugins_LoadFile.cxx index 8749aef..dc2b0b8 100644 --- a/appli/examples/plugins/example_plugins_LoadFile.cxx +++ b/appli/examples/plugins/example_plugins_LoadFile.cxx @@ -16,7 +16,7 @@ int main( int argc, char* argv[] ) cpPlugins::Interface interface; try { - interface.LoadEnvironment( ); + interface.LoadEnvironments( ); interface.LoadFile( library_file ); } catch( std::exception& err ) diff --git a/appli/examples/plugins/example_plugins_LoadPlugin.cxx b/appli/examples/plugins/example_plugins_LoadPlugin.cxx index 8334e2e..d92f459 100644 --- a/appli/examples/plugins/example_plugins_LoadPlugin.cxx +++ b/appli/examples/plugins/example_plugins_LoadPlugin.cxx @@ -16,7 +16,7 @@ int main( int argc, char* argv[] ) cpPlugins::Interface interface; try { - interface.LoadEnvironment( ); + interface.LoadEnvironments( ); interface.LoadPlugin( plugin ); } catch( std::exception& err ) diff --git a/appli/examples/plugins/example_plugins_ReadImage.cxx b/appli/examples/plugins/example_plugins_ReadImage.cxx index 43a00a7..41dbb6a 100644 --- a/appli/examples/plugins/example_plugins_ReadImage.cxx +++ b/appli/examples/plugins/example_plugins_ReadImage.cxx @@ -15,7 +15,7 @@ int main( int argc, char* argv[] ) cpPlugins::Interface interface; try { - interface.LoadEnvironment( ); + interface.LoadEnvironments( ); interface.GuessPlugins( ); } catch( std::exception& err ) diff --git a/lib/cpBaseQtApplication/MainWindow.cxx b/lib/cpBaseQtApplication/MainWindow.cxx index d70d4c0..46312b1 100644 --- a/lib/cpBaseQtApplication/MainWindow.cxx +++ b/lib/cpBaseQtApplication/MainWindow.cxx @@ -3,6 +3,7 @@ #include #include #include +#include #include #include #include @@ -51,15 +52,16 @@ MainWindow( if( i.exists( ) ) { this->m_ExecutionPath = i.canonicalPath( ).toStdString( ); - try - { - this->m_Interface.OpenEnvironments( this->m_ExecutionPath ); - this->m_Interface.UpdateEnvironments( this->m_ExecutionPath ); - } + try { this->m_Interface.AddEnvironments( this->m_ExecutionPath ); } + catch( ... ) { } + try { this->m_Interface.OpenEnvironments( this->m_ExecutionPath ); } + catch( ... ) { } + try { this->m_Interface.SaveEnvironments( this->m_ExecutionPath ); } catch( ... ) { } } else this->m_ExecutionPath = ""; + this->UpdateEnvironment( ); this->m_Workspace.SetInterface( &( this->m_Interface ) ); } @@ -75,7 +77,7 @@ UpdateEnvironment( ) { try { - this->m_Interface.LoadEnvironment( ); + this->m_Interface.LoadEnvironments( ); this->m_Interface.GuessPlugins( ); } catch( std::exception& err ) @@ -147,6 +149,17 @@ _ClearWorkspace( ) this->m_Workspace.Clear( ); } +// ------------------------------------------------------------------------- +void cpBaseQtApplication::MainWindow:: +_AddEnvironments( const std::string& environments ) +{ + try { this->m_Interface.AddEnvironments( environments ); } + catch( ... ) { } + try { this->m_Interface.SaveEnvironments( this->m_ExecutionPath ); } + catch( ... ) { } + this->UpdateEnvironment( ); +} + // ------------------------------------------------------------------------- void cpBaseQtApplication::MainWindow:: _LoadPlugins( const std::string& filename ) @@ -249,26 +262,6 @@ _UpdateLoadedPlugins( ) ); } -// ------------------------------------------------------------------------- -void cpBaseQtApplication::MainWindow:: -_ShowPlugins( ) -{ - auto paths = this->m_Interface.GetPaths( ); - auto plugins = this->m_Interface.GetPlugins( ); - std::stringstream info; - info << "----- PATHS -----" << std::endl; - for( auto i = paths.begin( ); i != paths.end( ); ++i ) - info << " " << *i << std::endl; - info << std::endl << "----- PLUGINS -----" << std::endl; - for( auto i = plugins.begin( ); i != plugins.end( ); ++i ) - info << " " << *i << std::endl; - QMessageBox::information( - this, - "Loaded libraries and plugins information", - info.str( ).c_str( ) - ); -} - // ------------------------------------------------------------------------- void cpBaseQtApplication::MainWindow:: _Block( ) @@ -485,6 +478,26 @@ _InteractiveLoadPluginsFromPath( ) this->_LoadPluginsFromPath( d.selectedFiles( ).begin( )->toStdString( ) ); } +// ------------------------------------------------------------------------- +void cpBaseQtApplication::MainWindow:: +_ShowPlugins( ) +{ + auto paths = this->m_Interface.GetPaths( ); + auto plugins = this->m_Interface.GetPlugins( ); + std::stringstream info; + info << "----- PATHS -----" << std::endl; + for( auto i = paths.begin( ); i != paths.end( ); ++i ) + info << " " << *i << std::endl; + info << std::endl << "----- PLUGINS -----" << std::endl; + for( auto i = plugins.begin( ); i != plugins.end( ); ++i ) + info << " " << *i << std::endl; + QMessageBox::information( + this, + "Loaded libraries and plugins information", + info.str( ).c_str( ) + ); +} + // ------------------------------------------------------------------------- void cpBaseQtApplication::MainWindow:: _InteractiveLoadWorkspace( ) @@ -518,6 +531,26 @@ _InteractiveSaveWorkspace( ) this->_SaveWorkspace( dlg.selectedFiles( ).begin( )->toStdString( ) ); } +// ------------------------------------------------------------------------- +void cpBaseQtApplication::MainWindow:: +_InteractiveAddEnviromentPaths( ) +{ + PathsDialog dlg( this ); + dlg.addPaths( this->m_Interface.GetPaths( ) ); + if( dlg.exec( ) ) + { + auto paths = dlg.getPaths( ); + for( auto p = paths.begin( ); p != paths.end( ); ++p ) + { + try { this->m_Interface.AddEnvironments( *p ); } + catch( ... ) { } + + } // rof + this->UpdateEnvironment( ); + + } // fi +} + // ------------------------------------------------------------------------- void cpBaseQtApplication::MainWindow:: _ExecFilter( const std::string& filter_name ) diff --git a/lib/cpBaseQtApplication/MainWindow.h b/lib/cpBaseQtApplication/MainWindow.h index 7c7bcf9..c68aac9 100644 --- a/lib/cpBaseQtApplication/MainWindow.h +++ b/lib/cpBaseQtApplication/MainWindow.h @@ -57,10 +57,10 @@ namespace cpBaseQtApplication cpBaseQtApplication::Editor* editor ); void _ClearWorkspace( ); + void _AddEnvironments( const std::string& environments ); void _LoadPlugins( const std::string& filename ); void _LoadPluginsFromPath( const std::string& path ); void _UpdateLoadedPlugins( ); - void _ShowPlugins( ); void _Block( ); void _UnBlock( ); @@ -72,8 +72,10 @@ namespace cpBaseQtApplication protected slots: void _InteractiveLoadPlugins( ); void _InteractiveLoadPluginsFromPath( ); + void _ShowPlugins( ); void _InteractiveLoadWorkspace( ); void _InteractiveSaveWorkspace( ); + void _InteractiveAddEnviromentPaths( ); void _ExecFilter( const std::string& filter_name ); void _ShowData( const std::string& filter_name, const std::string& output_name diff --git a/lib/cpBaseQtApplication/PathsDialog.cxx b/lib/cpBaseQtApplication/PathsDialog.cxx new file mode 100644 index 0000000..66f6dab --- /dev/null +++ b/lib/cpBaseQtApplication/PathsDialog.cxx @@ -0,0 +1,71 @@ +#include + +#include +#include + +// ------------------------------------------------------------------------- +cpBaseQtApplication::PathsDialog:: +PathsDialog( QWidget* parent, Qt::WindowFlags flags ) + : QDialog( parent, flags ), + m_UI( new Ui::PathsDialog ) +{ + this->m_UI->setupUi( this ); + this->connect( + this->m_UI->AddButton, SIGNAL( clicked( ) ), + this, SLOT( _addPath( ) ) + ); + this->connect( + this->m_UI->RemoveButton, SIGNAL( clicked( ) ), + this, SLOT( _removePath( ) ) + ); +} + +// ------------------------------------------------------------------------- +cpBaseQtApplication::PathsDialog:: +~PathsDialog( ) +{ + delete this->m_UI; +} + +// ------------------------------------------------------------------------- +void cpBaseQtApplication::PathsDialog:: +addPaths( const std::set< std::string >& paths ) +{ + QStringList lst; + for( auto i = paths.begin( ); i != paths.end( ); ++i ) + lst << i->c_str( ); + this->m_UI->Paths->addItems( lst ); +} + +// ------------------------------------------------------------------------- +std::set< std::string > cpBaseQtApplication::PathsDialog:: +getPaths( ) const +{ + std::set< std::string > paths; + for( int c = 0; c < this->m_UI->Paths->count( ); ++c ) + paths.insert( this->m_UI->Paths->item( c )->text( ).toStdString( ) ); + return( paths ); +} + +// ------------------------------------------------------------------------- +void cpBaseQtApplication::PathsDialog:: +_addPath( ) +{ + auto res = + QFileDialog::getExistingDirectory( this, "Choose a directory", "." ); + if( res.toStdString( ) != "" ) + this->m_UI->Paths->addItem( res ); +} + +// ------------------------------------------------------------------------- +void cpBaseQtApplication::PathsDialog:: +_removePath( ) +{ + /* TODO + auto items = this->m_UI->Paths->selectedItems( ); + if( items.size( ) == 1 ) + this->m_UI->Paths->removeItemWidget( items[ 0 ] ); + */ +} + +// eof - $RCSfile$ diff --git a/lib/cpBaseQtApplication/PathsDialog.h b/lib/cpBaseQtApplication/PathsDialog.h new file mode 100644 index 0000000..4161555 --- /dev/null +++ b/lib/cpBaseQtApplication/PathsDialog.h @@ -0,0 +1,45 @@ +#ifndef __CPBASEQTAPPLICATION__PATHSDIALOG__H__ +#define __CPBASEQTAPPLICATION__PATHSDIALOG__H__ + +#include +#include +#include +#include +#include + +// ------------------------------------------------------------------------- +namespace Ui +{ + class PathsDialog; +} + +// ------------------------------------------------------------------------- +namespace cpBaseQtApplication +{ + /** + */ + class cpBaseQtApplication_EXPORT PathsDialog + : public QDialog + { + Q_OBJECT; + + public: + explicit PathsDialog( QWidget* parent = 0, Qt::WindowFlags flags = 0 ); + virtual ~PathsDialog( ); + + void addPaths( const std::set< std::string >& paths ); + std::set< std::string > getPaths( ) const; + + protected slots: + void _addPath( ); + void _removePath( ); + + protected: + Ui::PathsDialog* m_UI; + }; + +} // ecapseman + +#endif // __CPBASEQTAPPLICATION__PATHSDIALOG__H__ + +// eof - $RCSfile$ diff --git a/lib/cpBaseQtApplication/PathsDialog.ui b/lib/cpBaseQtApplication/PathsDialog.ui new file mode 100644 index 0000000..b938343 --- /dev/null +++ b/lib/cpBaseQtApplication/PathsDialog.ui @@ -0,0 +1,119 @@ + + + PathsDialog + + + + 0 + 0 + 400 + 300 + + + + Dialog + + + + 1 + + + 1 + + + + + + + + + + + + + 25 + 25 + + + + + 25 + 25 + + + + - + + + + + + + + 25 + 25 + + + + + 25 + 25 + + + + + + + + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + buttonBox + accepted() + PathsDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + PathsDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/lib/cpPlugins/LoadDynamicLibrariesFunctions.cxx b/lib/cpPlugins/DLLManager.cxx similarity index 96% rename from lib/cpPlugins/LoadDynamicLibrariesFunctions.cxx rename to lib/cpPlugins/DLLManager.cxx index 9aeafee..4a95fb2 100644 --- a/lib/cpPlugins/LoadDynamicLibrariesFunctions.cxx +++ b/lib/cpPlugins/DLLManager.cxx @@ -1,4 +1,4 @@ -#include +#include #ifdef cpPlugins_SYS_WINDOWS # include diff --git a/lib/cpPlugins/LoadDynamicLibrariesFunctions.h b/lib/cpPlugins/DLLManager.h similarity index 66% rename from lib/cpPlugins/LoadDynamicLibrariesFunctions.h rename to lib/cpPlugins/DLLManager.h index 0fa1df5..a054928 100644 --- a/lib/cpPlugins/LoadDynamicLibrariesFunctions.h +++ b/lib/cpPlugins/DLLManager.h @@ -1,5 +1,5 @@ -#ifndef __CPPLUGINS__LOADDYNAMICLIBRARIESFUNCTIONS__H__ -#define __CPPLUGINS__LOADDYNAMICLIBRARIESFUNCTIONS__H__ +#ifndef __CPPLUGINS__DLLMANAGER__H__ +#define __CPPLUGINS__DLLMANAGER__H__ #include @@ -17,6 +17,6 @@ namespace cpPlugins } // ecapseman -#endif // __CPPLUGINS__LOADDYNAMICLIBRARIESFUNCTIONS__H__ +#endif // __CPPLUGINS__DLLMANAGER__H__ // eof - $RCSfile$ diff --git a/lib/cpPlugins/Interface.cxx b/lib/cpPlugins/Interface.cxx index f898e7b..1f78e27 100644 --- a/lib/cpPlugins/Interface.cxx +++ b/lib/cpPlugins/Interface.cxx @@ -1,6 +1,6 @@ #include #include -#include +#include #include #include @@ -13,7 +13,7 @@ Interface( ) if( p != NULL ) str << p << cpPlugins_SEPARATOR; str << "."; - this->UpdateEnvironments( str.str( ) ); + this->AddEnvironments( str.str( ) ); } // ------------------------------------------------------------------------- @@ -23,17 +23,19 @@ cpPlugins::Interface:: } // ------------------------------------------------------------------------- -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 ) @@ -42,71 +44,79 @@ GetLibraries( ) const } // ------------------------------------------------------------------------- -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; @@ -115,10 +125,8 @@ LoadEnvironment( ) 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" ) @@ -162,10 +170,10 @@ SaveEnvironments( const std::string& dir ) const 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 @@ -178,15 +186,17 @@ OpenEnvironments( const std::string& dir ) { 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." ); @@ -375,13 +385,8 @@ GuessPlugins( ) { 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 } diff --git a/lib/cpPlugins/Interface.h b/lib/cpPlugins/Interface.h index 86c46b9..ee3fa0c 100644 --- a/lib/cpPlugins/Interface.h +++ b/lib/cpPlugins/Interface.h @@ -25,20 +25,22 @@ namespace cpPlugins void* LibraryHandle; TCreator Creator; }; - typedef std::map< std::string, std::map< std::string, TCreatorData > > TFilters; + typedef std::map< std::string, TCreatorData > TFilterData; + typedef std::map< std::string, TFilterData > TFilters; + typedef std::set< std::string > TStrings; public: Interface( ); virtual ~Interface( ); - const std::set< std::string >& GetPaths( ) const; - std::set< std::string > GetLibraries( ) const; - std::set< std::string > GetPlugins( ) const; - std::set< std::string > GetCategories( ) const; - std::set< std::string > GetFilters( const std::string& category ) const; + const TStrings& GetPaths( ) const; + TStrings GetLibraries( ) const; + TStrings GetPlugins( ) const; + TStrings GetCategories( ) const; + TStrings GetFilters( const std::string& category ) const; - void UpdateEnvironments( const std::string& new_environment ); - void LoadEnvironment( ); + void AddEnvironments( const std::string& new_environment ); + void LoadEnvironments( ); void SaveEnvironments( const std::string& dir ) const; void OpenEnvironments( const std::string& dir ); @@ -52,48 +54,10 @@ namespace cpPlugins ); protected: - std::set< std::string > m_Paths; + TStrings m_Paths; TLibraries m_Libraries; TLibraries m_Plugins; - TFilters m_Filters; - - - /* TODO - const TFilters& GetFilters( ); - - void UpdatePaths( ); - void GuessAccesiblePlugins( ); - void LoadPlugin( const std::string& name ); - void LoadPluginDir( const std::string& dirname ); - void LoadPluginFile( const std::string& filename ); - void UnloadAll( ); - - ProcessObject::Pointer Create( - const std::string& category, const std::string& name - ); - std::string GetPluginName( - const std::string& category, const std::string& name - ) const; - std::string GetPluginName( const ProcessObject* obj ) const; - std::set< std::string > GetPlugins( ) const; - - protected: - static void* _DLOpen( const std::string& fname, std::string& error ); - static const char* _DLGetName( void* hnd ); - static TFilters _DLGetFilters( void* hnd ); - static TCreator _DLGetCreator( - void* hnd, const std::string& category, const std::string& name - ); - static void _DLClose( void* hnd ); - - protected: - std::vector< std::string > m_Paths; - TDynLibraries m_DynLibraries; - TDynFilters m_DynFilters; - TFilters m_Filters; - - static unsigned int InterfacesCount; - */ + TFilters m_Filters; }; } // ecapseman diff --git a/lib/cpPlugins/Utilities.h b/lib/cpPlugins/Utilities.h index ff033b4..d4eff53 100644 --- a/lib/cpPlugins/Utilities.h +++ b/lib/cpPlugins/Utilities.h @@ -113,9 +113,7 @@ namespace cpPlugins const std::string& buffer, const std::string& fname ) { - std::ofstream file_stream( - CanonicalPath( fname ).c_str( ), std::ofstream::binary - ); + std::ofstream file_stream( fname.c_str( ), std::ofstream::binary ); if( !file_stream ) return( false ); file_stream.write( buffer.c_str( ), buffer.size( ) );