Changeset d05c3f0 in nscp for service/NSClient++.cpp
- Timestamp:
- 11/15/09 17:20:03 (4 years ago)
- Branches:
- master, 0.4.0, 0.4.1, 0.4.2
- Children:
- 92c4b5b
- Parents:
- 3eedfa6
- File:
-
- 1 edited
-
service/NSClient++.cpp (modified) (14 diffs)
Legend:
- Unmodified
- Added
- Removed
-
service/NSClient++.cpp
r818b54e rd05c3f0 84 84 85 85 static bool start(unsigned long dwSessionId) { 86 std::wstring program = mainClient.getBasePath() + _T("\\") + 87 SETTINGS_GET_STRING_CORE(settings_def::SYSTRAY_EXE); 88 std::wstring cmdln = _T("\"") + program + _T("\" -channel __") + strEx::itos(dwSessionId) + _T("__"); 89 return tray_starter::startTrayHelper(dwSessionId, program, cmdln); 86 boost::filesystem::wpath program = mainClient.getBasePath() / SETTINGS_GET_STRING_CORE(settings_def::SYSTRAY_EXE); 87 std::wstring cmdln = _T("\"") + program.string() + _T("\" -channel __") + strEx::itos(dwSessionId) + _T("__"); 88 return tray_starter::startTrayHelper(dwSessionId, program.string(), cmdln); 90 89 } 91 90 … … 205 204 206 205 207 bool is_module( std::wstringfile )206 bool is_module(boost::filesystem::wpath file ) 208 207 { 209 return boost::ends_with(file , _T(".dll"));208 return boost::ends_with(file.string(), _T(".dll")) || boost::ends_with(file.string(), _T(".so")); 210 209 } 211 210 /** … … 390 389 return 0; 391 390 } else if ( wcscasecmp( _T("about"), argv[1]+1 ) == 0 ) { 392 g_bConsoleLog = true; 393 LOG_MESSAGE(SZAPPNAME _T(" (C) Michael Medin - michael<at>medin<dot>name")); 394 LOG_MESSAGE(_T("Version: ") SZVERSION); 395 LOG_MESSAGE(_T("Architecture: ") SZARCH); 396 397 std::wstring pluginPath = mainClient.getBasePath() + _T("modules\\"); 398 LOG_MESSAGE_STD(_T("Looking at plugins in: ") + pluginPath); 399 400 boost::filesystem::wdirectory_iterator end_itr; // default construction yields past-the-end 401 for ( boost::filesystem::wdirectory_iterator itr( pluginPath ); itr != end_itr; ++itr ) { 402 if ( !is_directory(itr->status()) ) { 403 std::wstring file= itr->leaf(); 404 if (is_module(pluginPath + _T("\\") + file)) { 405 NSCPlugin *plugin = new NSCPlugin(pluginPath + _T("\\") + file); 406 std::wstring name = _T("<unknown>"); 407 std::wstring description = _T("<unknown>"); 408 try { 409 plugin->load_dll(); 410 name = plugin->getName(); 411 description = plugin->getDescription(); 412 } catch(const NSPluginException& e) { 413 LOG_ERROR_STD(_T("Exception raised: ") + e.error_ + _T(" in module: ") + e.file_); 414 } catch (std::exception e) { 415 LOG_ERROR_STD(_T("exception loading plugin: ") + strEx::string_to_wstring(e.what())); 416 } catch (...) { 417 LOG_ERROR_STD(_T("Unknown exception loading plugin")); 418 } 419 LOG_MESSAGE_STD(_T("* ") + name + _T(" (") + file + _T(")")); 420 std::list<std::wstring> list = strEx::splitEx(description, _T("\n")); 421 for (std::list<std::wstring>::const_iterator cit = list.begin(); cit != list.end(); ++cit) { 422 LOG_MESSAGE_STD(_T(" ") + *cit); 391 try { 392 g_bConsoleLog = true; 393 LOG_MESSAGE(SZAPPNAME _T(" (C) Michael Medin - michael<at>medin<dot>name")); 394 LOG_MESSAGE(_T("Version: ") SZVERSION); 395 LOG_MESSAGE(_T("Architecture: ") SZARCH); 396 397 boost::filesystem::wpath pluginPath = (boost::filesystem::wpath)mainClient.getBasePath() / _T("modules"); 398 LOG_MESSAGE_STD(_T("Looking at plugins in: ") + pluginPath.string()); 399 400 boost::filesystem::wdirectory_iterator end_itr; // default construction yields past-the-end 401 for ( boost::filesystem::wdirectory_iterator itr( pluginPath ); itr != end_itr; ++itr ) { 402 if ( !is_directory(itr->status()) ) { 403 std::wstring file= itr->leaf(); 404 LOG_MESSAGE_STD(_T("Found: ") + file); 405 if (is_module(pluginPath / file)) { 406 NSCPlugin *plugin = new NSCPlugin(pluginPath / file); 407 std::wstring name = _T("<unknown>"); 408 std::wstring description = _T("<unknown>"); 409 try { 410 plugin->load_dll(); 411 name = plugin->getName(); 412 description = plugin->getDescription(); 413 } catch(const NSPluginException& e) { 414 LOG_ERROR_STD(_T("Exception raised: ") + e.error_ + _T(" in module: ") + e.file_); 415 } catch (std::exception e) { 416 LOG_ERROR_STD(_T("exception loading plugin: ") + strEx::string_to_wstring(e.what())); 417 } catch (...) { 418 LOG_ERROR_STD(_T("Unknown exception loading plugin")); 419 } 420 LOG_MESSAGE_STD(_T("* ") + name + _T(" (") + file + _T(")")); 421 std::list<std::wstring> list = strEx::splitEx(description, _T("\n")); 422 for (std::list<std::wstring>::const_iterator cit = list.begin(); cit != list.end(); ++cit) { 423 LOG_MESSAGE_STD(_T(" ") + *cit); 424 } 423 425 } 424 426 } 425 427 } 428 LOG_MESSAGE_STD(_T("Done listing plugins from: ") + pluginPath.string()); 429 return true; 430 } catch (std::exception &e) { 431 LOG_ERROR_STD(_T("Exception: ") + to_wstring(e.what())); 432 } catch (...) { 433 LOG_ERROR_STD(_T("Unknown Exception: ")); 426 434 } 427 435 return false; … … 568 576 NSClientT::plugin_info_list NSClientT::get_all_plugins() { 569 577 plugin_info_list ret; 570 std::wstring pluginPath = getBasePath() + _T("modules\\");578 boost::filesystem::wpath pluginPath = getBasePath() / boost::filesystem::wpath(_T("modules")); 571 579 boost::filesystem::wdirectory_iterator end_itr; // default construction yields past-the-end 572 580 for ( boost::filesystem::wdirectory_iterator itr( pluginPath ); itr != end_itr; ++itr ) { 573 581 if ( !is_directory(itr->status()) ) { 574 std::wstringfile= itr->leaf();575 if (is_module(pluginPath + _T("\\") +file)) {582 boost::filesystem::wpath file= itr->leaf(); 583 if (is_module(pluginPath / file)) { 576 584 plugin_info_type info; 577 585 info.dll = itr->leaf(); 578 586 try { 579 LOG_DEBUG_STD(_T("Attempting to fake load: ") + file );580 NSCPlugin plugin(pluginPath + _T("\\") +file);587 LOG_DEBUG_STD(_T("Attempting to fake load: ") + file.string()); 588 NSCPlugin plugin(pluginPath / file); 581 589 plugin.load_dll(); 582 590 plugin.load_plugin(NSCAPI::dontStart); … … 587 595 LOG_CRITICAL_STD(_T("Error loading: ") + e.file_ + _T(" root cause: ") + e.error_); 588 596 } catch (...) { 589 LOG_CRITICAL_STD(_T("Unknown Error loading: ") + file );597 LOG_CRITICAL_STD(_T("Unknown Error loading: ") + file.string()); 590 598 } 591 599 ret.push_back(info); … … 598 606 599 607 void NSClientT::load_all_plugins(int mode) { 600 std::wstring modPath = getBasePath() + _T("modules\\");608 boost::filesystem::wpath modPath = getBasePath() / boost::filesystem::wpath(_T("modules")); 601 609 602 610 boost::filesystem::wdirectory_iterator end_itr; // default construction yields past-the-end 603 611 for ( boost::filesystem::wdirectory_iterator itr( modPath ); itr != end_itr; ++itr ) { 604 612 if ( !is_directory(itr->status()) ) { 605 std::wstringfile= itr->leaf();606 if (is_module(modPath + _T("\\") +file)) {607 if (settings_manager::get_settings()->has_key(MAIN_MODULES_SECTION, file )) {608 if (settings_manager::get_settings()->get_string(MAIN_MODULES_SECTION, file ) == _T("disabled")) {613 boost::filesystem::wpath file= itr->leaf(); 614 if (is_module(modPath / file)) { 615 if (settings_manager::get_settings()->has_key(MAIN_MODULES_SECTION, file.string())) { 616 if (settings_manager::get_settings()->get_string(MAIN_MODULES_SECTION, file.string()) == _T("disabled")) { 609 617 try { 610 LOG_DEBUG_STD(_T("Attempting to fake load: ") + file );611 NSCPlugin plugin(modPath +file);618 LOG_DEBUG_STD(_T("Attempting to fake load: ") + file.string()); 619 NSCPlugin plugin(modPath / file); 612 620 plugin.load_dll(); 613 621 plugin.load_plugin(mode); … … 616 624 LOG_CRITICAL_STD(_T("Error loading: ") + e.file_ + _T(" root cause: ") + e.error_); 617 625 } catch (...) { 618 LOG_CRITICAL_STD(_T("Unknown Error loading: ") + file );626 LOG_CRITICAL_STD(_T("Unknown Error loading: ") + file.string()); 619 627 } 620 628 } … … 622 630 std::wstring desc; 623 631 try { 624 NSCPlugin plugin(modPath +file);632 NSCPlugin plugin(modPath / file); 625 633 plugin.load_dll(); 626 634 plugin.load_plugin(mode); … … 633 641 } catch (...) { 634 642 desc += _T("unknown module"); 635 LOG_CRITICAL_STD(_T("Unknown Error loading: ") + file );643 LOG_CRITICAL_STD(_T("Unknown Error loading: ") + file.string()); 636 644 } 637 settings_manager::get_core()->register_key(MAIN_MODULES_SECTION, file , Settings::SettingsCore::key_string, desc, desc, _T("disabled"), false);645 settings_manager::get_core()->register_key(MAIN_MODULES_SECTION, file.string(), Settings::SettingsCore::key_string, desc, desc, _T("disabled"), false); 638 646 } 639 647 } … … 846 854 } 847 855 try { 848 loadPlugin(getBasePath() + _T("modules\\") +(*cit));856 loadPlugin(getBasePath() / boost::filesystem::wpath(_T("modules")) / boost::filesystem::wpath(*cit)); 849 857 } catch(const NSPluginException& e) { 850 LOG_ERROR_STD(_T("Exception raised: ") + e.error_ + _T("in module: ") + e.file_);858 LOG_ERROR_STD(_T("Exception raised: '") + e.error_ + _T("' in module: ") + e.file_); 851 859 //return false; 852 860 } catch (std::exception e) { … … 1068 1076 } 1069 1077 try { 1070 plugin_type plugin = loadPlugin(getBasePath() + _T("modules\\") + module); 1071 LOG_DEBUG_STD(_T("Loading plugin: ") + plugin->getName() + _T("...")); 1072 plugin->load_plugin(NSCAPI::dontStart); 1073 return plugin->commandLineExec(command, argLen, args); 1074 } catch (NSPluginException e) { 1075 LOG_MESSAGE_STD(_T("Module (") + e.file_ + _T(") was not found: ") + e.error_); 1076 } 1077 try { 1078 plugin_type plugin = loadPlugin(getBasePath() + _T("modules\\") + module + _T(".dll")); 1078 plugin_type plugin = loadPlugin(getBasePath() / boost::filesystem::wpath(_T("modules")) / boost::filesystem::wpath(module)); 1079 1079 LOG_DEBUG_STD(_T("Loading plugin: ") + plugin->getName() + _T("...")); 1080 1080 plugin->load_plugin(NSCAPI::dontStart); … … 1208 1208 * @param file The DLL file 1209 1209 */ 1210 NSClientT::plugin_type NSClientT::loadPlugin(const std::wstringfile) {1210 NSClientT::plugin_type NSClientT::loadPlugin(const boost::filesystem::wpath file) { 1211 1211 return addPlugin(new NSCPlugin(file)); 1212 1212 } … … 1522 1522 } 1523 1523 } 1524 std::wstringNSClientT::getBasePath(void) {1524 boost::filesystem::wpath NSClientT::getBasePath(void) { 1525 1525 boost::unique_lock<boost::timed_mutex> lock(internalVariables, boost::get_system_time() + boost::posix_time::seconds(5)); 1526 1526 if (!lock.owns_lock()) { … … 1538 1538 basePath = path.substr(0, pos) + _T("\\"); 1539 1539 delete [] buffer; 1540 #else 1541 basePath = to_wstring(boost::filesystem::initial_path().string()); 1540 1542 #endif 1541 1543 try {
Note: See TracChangeset
for help on using the changeset viewer.








