Changeset 210
- Timestamp:
- 11/10/09 19:32:07 (2 years ago)
- Location:
- trunk/service
- Files:
-
- 2 edited
-
NSClient++.cpp (modified) (5 diffs)
-
StdAfx.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/service/NSClient++.cpp
r209 r210 25 25 //#ifdef DEBUG 26 26 #include <crtdbg.h> 27 #include "boost/filesystem.hpp" 27 28 //#endif 28 29 #endif … … 200 201 201 202 203 bool is_module( std::wstring file ) 204 { 205 return boost::ends_with(file, _T(".dll")); 206 } 202 207 /** 203 208 * Application startup point … … 370 375 LOG_MESSAGE_STD(_T("Looking at plugins in: ") + pluginPath); 371 376 372 WIN32_FIND_DATA wfd; 373 HANDLE hFind = FindFirstFile((pluginPath + _T("*.dll")).c_str(), &wfd); 374 if (hFind != INVALID_HANDLE_VALUE) { 375 do { 376 std::wstring file = wfd.cFileName; 377 NSCPlugin *plugin = new NSCPlugin(pluginPath + _T("\\") + file); 378 std::wstring name = _T("<unknown>"); 379 std::wstring description = _T("<unknown>"); 380 try { 381 plugin->load_dll(); 382 name = plugin->getName(); 383 description = plugin->getDescription(); 384 } catch(const NSPluginException& e) { 385 LOG_ERROR_STD(_T("Exception raised: ") + e.error_ + _T(" in module: ") + e.file_); 386 } catch (std::exception e) { 387 LOG_ERROR_STD(_T("exception loading plugin: ") + strEx::string_to_wstring(e.what())); 388 } catch (...) { 389 LOG_ERROR_STD(_T("Unknown exception loading plugin")); 377 boost::filesystem::wdirectory_iterator end_itr; // default construction yields past-the-end 378 for ( boost::filesystem::wdirectory_iterator itr( pluginPath ); itr != end_itr; ++itr ) { 379 if ( !is_directory(itr->status()) ) { 380 std::wstring file= itr->leaf(); 381 if (is_module(pluginPath + _T("\\") + file)) { 382 NSCPlugin *plugin = new NSCPlugin(pluginPath + _T("\\") + file); 383 std::wstring name = _T("<unknown>"); 384 std::wstring description = _T("<unknown>"); 385 try { 386 plugin->load_dll(); 387 name = plugin->getName(); 388 description = plugin->getDescription(); 389 } catch(const NSPluginException& e) { 390 LOG_ERROR_STD(_T("Exception raised: ") + e.error_ + _T(" in module: ") + e.file_); 391 } catch (std::exception e) { 392 LOG_ERROR_STD(_T("exception loading plugin: ") + strEx::string_to_wstring(e.what())); 393 } catch (...) { 394 LOG_ERROR_STD(_T("Unknown exception loading plugin")); 395 } 396 LOG_MESSAGE_STD(_T("* ") + name + _T(" (") + file + _T(")")); 397 std::list<std::wstring> list = strEx::splitEx(description, _T("\n")); 398 for (std::list<std::wstring>::const_iterator cit = list.begin(); cit != list.end(); ++cit) { 399 LOG_MESSAGE_STD(_T(" ") + *cit); 400 } 390 401 } 391 LOG_MESSAGE_STD(_T("* ") + name + _T(" (") + file + _T(")")); 392 std::list<std::wstring> list = strEx::splitEx(description, _T("\n")); 393 for (std::list<std::wstring>::const_iterator cit = list.begin(); cit != list.end(); ++cit) { 394 LOG_MESSAGE_STD(_T(" ") + *cit); 395 } 396 } while (FindNextFile(hFind, &wfd)); 397 } else { 398 LOG_CRITICAL(_T("No plugin was found!")); 399 } 400 FindClose(hFind); 402 } 403 } 404 return false; 401 405 } else if ( _wcsicmp( _T("version"), argv[1]+1 ) == 0 ) { 402 406 g_bConsoleLog = true; … … 541 545 NSClientT::plugin_info_list NSClientT::get_all_plugins() { 542 546 plugin_info_list ret; 543 std::wstring modPath = getBasePath() + _T("modules\\");544 545 WIN32_FIND_DATA wfd;546 HANDLE hFind = FindFirstFile((modPath + _T("*.dll")).c_str(), &wfd);547 if (hFind != INVALID_HANDLE_VALUE) {548 do{549 plugin_info_type info;550 info.dll = wfd.cFileName;551 try {552 LOG_DEBUG_STD(_T("Attempting to fake load: ") + wfd.cFileName);553 NSCPlugin plugin(modPath + wfd.cFileName);554 plugin.load_dll();555 plugin.load_plugin(NSCAPI::dontStart);556 info.name = plugin.getName();557 info.description = plugin.getDescription();558 plugin.unload();559 } catch (NSPluginException e) {560 LOG_CRITICAL_STD(_T("Error loading: ") + e.file_ + _T(" root cause: ") + e.error_);561 } catch (...) {562 LOG_CRITICAL_STD(_T("Unknown Error loading: ") + wfd.cFileName);563 }564 ret.push_back(info);565 } while (FindNextFile(hFind, &wfd));566 }567 FindClose(hFind);547 std::wstring pluginPath = getBasePath() + _T("modules\\"); 548 boost::filesystem::wdirectory_iterator end_itr; // default construction yields past-the-end 549 for ( boost::filesystem::wdirectory_iterator itr( pluginPath ); itr != end_itr; ++itr ) { 550 if ( !is_directory(itr->status()) ) { 551 std::wstring file= itr->leaf(); 552 if (is_module(pluginPath + _T("\\") + file)) { 553 plugin_info_type info; 554 info.dll = itr->leaf(); 555 try { 556 LOG_DEBUG_STD(_T("Attempting to fake load: ") + file); 557 NSCPlugin plugin(pluginPath + _T("\\") + file); 558 plugin.load_dll(); 559 plugin.load_plugin(NSCAPI::dontStart); 560 info.name = plugin.getName(); 561 info.description = plugin.getDescription(); 562 plugin.unload(); 563 } catch (NSPluginException e) { 564 LOG_CRITICAL_STD(_T("Error loading: ") + e.file_ + _T(" root cause: ") + e.error_); 565 } catch (...) { 566 LOG_CRITICAL_STD(_T("Unknown Error loading: ") + file); 567 } 568 ret.push_back(info); 569 } 570 } 571 } 568 572 return ret; 569 573 } … … 573 577 std::wstring modPath = getBasePath() + _T("modules\\"); 574 578 575 WIN32_FIND_DATA wfd; 576 HANDLE hFind = FindFirstFile((modPath + _T("*.dll")).c_str(), &wfd); 577 if (hFind != INVALID_HANDLE_VALUE) { 578 do { 579 if (settings_manager::get_settings()->has_key(MAIN_MODULES_SECTION, wfd.cFileName)) { 580 if (settings_manager::get_settings()->get_string(MAIN_MODULES_SECTION, wfd.cFileName) == _T("disabled")) { 579 boost::filesystem::wdirectory_iterator end_itr; // default construction yields past-the-end 580 for ( boost::filesystem::wdirectory_iterator itr( modPath ); itr != end_itr; ++itr ) { 581 if ( !is_directory(itr->status()) ) { 582 std::wstring file= itr->leaf(); 583 if (is_module(modPath + _T("\\") + file)) { 584 if (settings_manager::get_settings()->has_key(MAIN_MODULES_SECTION, file)) { 585 if (settings_manager::get_settings()->get_string(MAIN_MODULES_SECTION, file) == _T("disabled")) { 586 try { 587 LOG_DEBUG_STD(_T("Attempting to fake load: ") + file); 588 NSCPlugin plugin(modPath + file); 589 plugin.load_dll(); 590 plugin.load_plugin(mode); 591 plugin.unload(); 592 } catch (NSPluginException e) { 593 LOG_CRITICAL_STD(_T("Error loading: ") + e.file_ + _T(" root cause: ") + e.error_); 594 } catch (...) { 595 LOG_CRITICAL_STD(_T("Unknown Error loading: ") + file); 596 } 597 } 598 } else { 599 std::wstring desc; 581 600 try { 582 LOG_DEBUG_STD(_T("Attempting to fake load: ") + wfd.cFileName); 583 NSCPlugin plugin(modPath + wfd.cFileName); 601 NSCPlugin plugin(modPath + file); 584 602 plugin.load_dll(); 585 603 plugin.load_plugin(mode); 604 desc = plugin.getName() + _T(" - "); 605 desc += plugin.getDescription(); 586 606 plugin.unload(); 587 607 } catch (NSPluginException e) { 608 desc += _T("unknown module"); 588 609 LOG_CRITICAL_STD(_T("Error loading: ") + e.file_ + _T(" root cause: ") + e.error_); 589 610 } catch (...) { 590 LOG_CRITICAL_STD(_T("Unknown Error loading: ") + wfd.cFileName); 611 desc += _T("unknown module"); 612 LOG_CRITICAL_STD(_T("Unknown Error loading: ") + file); 591 613 } 592 } 593 } else { 594 std::wstring desc; 595 try { 596 NSCPlugin plugin(modPath + wfd.cFileName); 597 plugin.load_dll(); 598 plugin.load_plugin(mode); 599 desc = plugin.getName() + _T(" - "); 600 desc += plugin.getDescription(); 601 plugin.unload(); 602 } catch (NSPluginException e) { 603 desc += _T("unknown module"); 604 LOG_CRITICAL_STD(_T("Error loading: ") + e.file_ + _T(" root cause: ") + e.error_); 605 } catch (...) { 606 desc += _T("unknown module"); 607 LOG_CRITICAL_STD(_T("Unknown Error loading: ") + wfd.cFileName); 608 } 609 settings_manager::get_core()->register_key(MAIN_MODULES_SECTION, wfd.cFileName, Settings::SettingsCore::key_string, desc, desc, _T("disabled"), false); 610 } 611 } while (FindNextFile(hFind, &wfd)); 612 } 613 FindClose(hFind); 614 settings_manager::get_core()->register_key(MAIN_MODULES_SECTION, file, Settings::SettingsCore::key_string, desc, desc, _T("disabled"), false); 615 } 616 } 617 } 618 } 614 619 } 615 620 -
trunk/service/StdAfx.h
r207 r210 47 47 #include <memory> 48 48 49 #include <boost/algorithm/string.hpp> 49 50 #ifdef MEMCHECK 50 51 #include <vld.h>
Note: See TracChangeset
for help on using the changeset viewer.







