diff options
Diffstat (limited to 'core/modules.cpp')
-rw-r--r-- | core/modules.cpp | 109 |
1 files changed, 37 insertions, 72 deletions
diff --git a/core/modules.cpp b/core/modules.cpp index 09ee63b..4910d71 100644 --- a/core/modules.cpp +++ b/core/modules.cpp @@ -6,78 +6,43 @@ extern PLUGINLINK pluglink; void load_modules() { - wxStandardPaths *pth = new wxStandardPaths; - wxString path = wxPathOnly(pth->GetExecutablePath()); - delete pth; -#ifdef _WIN32 - path.append((wxChar*)_T("\\plugins")); -#else - path.append((wxChar*)_T("/plugins")); -#endif - wxDir dir(path); -// wxMessageBox(path ,_("path"), wxOK | wxICON_INFORMATION); - - if(!dir.IsOpened()) - { - wxMessageBox(_T("Plugins directory does not exists") ,_T("Error"), wxOK | wxICON_ERROR); - wxLogDebug(_T("Plugins directory does not exists\n")); - return; - } - wxString filename; -#ifdef _WIN32 - if(!dir.GetFirst(&filename, _T("*.dll"), wxDIR_FILES | wxDIR_HIDDEN)) - { - wxMessageBox(_T("Plugins directory does not contain plugins") ,_T("Error"), wxOK | wxICON_ERROR); - wxLogDebug((wxChar*)_T("Plugins directory does not contain plugins\n")); - return; - } - -#else - if(!dir.GetFirst(&filename, _T("*.so"), wxDIR_FILES | wxDIR_HIDDEN)) - { - wxMessageBox(_T("Plugins directory does not contain plugins") ,_T("Error"), wxOK | wxICON_ERROR); - wxLogDebug(_T("Plugins directory does not contain plugins\n")); - return; - } - -#endif - do - { - wxString lib_path = path; -#ifdef _WIN32 - lib_path += _T("\\"); -#else - lib_path += _T("/"); -#endif - lib_path += filename; - wxDynamicLibrary *plug = new wxDynamicLibrary(lib_path); - if(!plug->IsLoaded()) - { - wxMessageBox(_T("Failed to load plugin") ,_T("Error"), wxOK | wxICON_ERROR); - wxLogDebug(_T("Failed to load plugin\n")); - } - bool is_plugin = true; - plugin::exported_functions_s *funcs = new plugin::exported_functions_s; - if((funcs->Load = (load)plug->GetSymbol(_T("load"))) == NULL) - is_plugin = false; - if((funcs->OnModulesLoaded = (on_modules_loaded)plug->GetSymbol(_T("on_modules_loaded"))) == NULL) - is_plugin = false; - if((funcs->Unload = (unload)plug->GetSymbol(_T("unload"))) == NULL) - is_plugin = false; - if((funcs->SetPluginInfo = (set_plugin_info)plug->GetSymbol(_T("set_plugin_info"))) == NULL) - is_plugin = false; - if(!is_plugin) - { - delete plug; - delete funcs; - continue; - } + std::string path = boost::filesystem::initial_path().directory_string(); //need some workaround for windows than called indirectly + path.append("/plugins"); + boost::filesystem::path pth(path); + if(!boost::filesystem::is_directory(pth)) + return; + boost::filesystem::directory_iterator i(pth), end = boost::filesystem::directory_iterator(); + while(i != end) + { + if(boost::filesystem::is_directory((*i).status())) //we not look in subdirectories + continue; + if(!boost::filesystem::status_known((*i).status())) + continue; + bool is_plugin = true; + plugin::exported_functions_s *funcs = new plugin::exported_functions_s; + memset(&funcs,0,sizeof(plugin::exported_functions_s)); + ACE_DLL *dll = new ACE_DLL; + if(dll->open((*i).path().string().c_str()) != -1) + { + if((funcs->Load = (load)dll->symbol("load")) == NULL) + is_plugin = false; + if((funcs->OnModulesLoaded = (on_modules_loaded)dll->symbol("on_modules_loaded")) == NULL) + is_plugin = false; + if((funcs->Unload = (unload)dll->symbol("unload")) == NULL) + is_plugin = false; + if((funcs->SetPluginInfo = (set_plugin_info)dll->symbol("set_plugin_info")) == NULL) + is_plugin = false; + } + if(!is_plugin) + { + delete funcs; + delete dll; + continue; + } PLUGININFO *info = funcs->SetPluginInfo(); - plugins.push_back(new plugin(plug, info, funcs)); - lib_path.clear(); - } - while(dir.GetNext(&filename)); - + plugins.push_back(new plugin(dll, info, funcs)); + ++i; + } } void run_plugins() { //now for testing only @@ -92,7 +57,7 @@ void run_plugins() } } -plugin::plugin(wxDynamicLibrary *lib, PLUGININFO *info, exported_functions_s *funcs) +plugin::plugin(ACE_DLL *lib, PLUGININFO *info, exported_functions_s *funcs) { if(lib) plug = lib; |