int nsclient_core::settings_client::migrate_to(std::string target) { try { debug_msg("Migrating to: " + expand_context(target)); get_core()->migrate_to(expand_context(target)); return 1; } catch (settings::settings_exception e) { error_msg("Failed to initialize settings: " + e.reason()); } catch (...) { error_msg("FATAL ERROR IN SETTINGS SUBSYTEM"); } return -1; }
bool NSCSettingsImpl::context_exists(std::wstring key) { net::wurl url = net::parse(key); if (url.protocol.empty()) url = net::parse(expand_context(key)); #ifdef WIN32 if (url.protocol == _T("old")) return settings::OLDSettings::context_exists(this, key); if (url.protocol == _T("registry")) return settings::REGSettings::context_exists(this, key); #endif if (url.protocol == _T("ini")) return settings::INISettings::context_exists(this, key); if (url.protocol == _T("dummy")) return true; if (url.protocol == _T("http")) return true; return false; }
bool NSCSettingsImpl::context_exists(std::string key) { key = expand_context(key); net::url url = net::parse(key); #ifdef WIN32 if (url.protocol == "old") return settings::OLDSettings::context_exists(this, key); if (url.protocol == "registry") return settings::REGSettings::context_exists(this, key); #endif if (url.protocol == "ini") return settings::INISettings::context_exists(this, key); if (url.protocol == "dummy") return true; if (url.protocol == "http") return true; if (settings::INISettings::context_exists(this, key)) return true; if (settings::INISettings::context_exists(this, DEFAULT_CONF_INI_BASE + key)) return true; return false; }
////////////////////////////////////////////////////////////////////////// /// Create an instance of a given type. /// Used internally to create instances of various settings types. /// /// @param type the type to create /// @param context the context to use /// @return a new instance of given type. /// /// @author mickem settings::instance_raw_ptr NSCSettingsImpl::create_instance(std::string key) { key = expand_context(key); net::url url = net::parse(key); get_logger()->debug("settings", __FILE__, __LINE__, "Creating instance for: " + url.to_string()); #ifdef WIN32 if (url.protocol == "old") return settings::instance_raw_ptr(new settings::OLDSettings(this, key)); if (url.protocol == "registry") return settings::instance_raw_ptr(new settings::REGSettings(this, key)); #endif if (url.protocol == "ini") return settings::instance_raw_ptr(new settings::INISettings(this, key)); if (url.protocol == "dummy") return settings::instance_raw_ptr(new settings::settings_dummy(this, key)); if (url.protocol == "http") return settings::instance_raw_ptr(new settings::settings_http(this, key)); if (settings::INISettings::context_exists(this, key)) return settings::instance_raw_ptr(new settings::INISettings(this, key)); if (settings::INISettings::context_exists(this, DEFAULT_CONF_INI_BASE + key)) return settings::instance_raw_ptr(new settings::INISettings(this, DEFAULT_CONF_INI_BASE + key)); throw settings::settings_exception("Undefined settings protocol: " + url.protocol); }
////////////////////////////////////////////////////////////////////////// /// Boot the settings subsystem from the given file (boot.ini). /// /// @param file the file to use when booting. /// /// @author mickem void NSCSettingsImpl::boot(std::string key) { std::list<std::string> order; if (!key.empty()) { order.push_back(key); } boot_ = provider_->expand_path(BOOT_CONF_LOCATION); if (boost::filesystem::is_regular_file(boot_)) { get_logger()->debug("settings", __FILE__, __LINE__, "Boot.ini found in: " + boot_.string()); for (int i=0;i<20;i++) { std::string v = get_boot_string("settings", strEx::s::xtos(i), ""); if (!v.empty()) order.push_back(expand_context(v)); } } if (order.size() == 0) { get_logger()->debug("settings", __FILE__, __LINE__, "No entries found looking in (adding default): " + boot_.string()); order.push_back(DEFAULT_CONF_OLD_LOCATION); order.push_back(DEFAULT_CONF_INI_LOCATION); } std::string boot_order; BOOST_FOREACH(const std::string &k, order) { strEx::append_list(boot_order, k, ", "); }
////////////////////////////////////////////////////////////////////////// /// Boot the settings subsystem from the given file (boot.ini). /// /// @param file the file to use when booting. /// /// @author mickem void NSCSettingsImpl::boot(std::wstring key) { std::list<std::wstring> order; if (!key.empty()) { order.push_back(key); } boot_ = provider_->expand_path(BOOT_CONF_LOCATION); if (file_helpers::checks::exists(boot_.string())) { get_logger()->debug(__FILE__, __LINE__, _T("Boot.ini found in: ") + boot_.string()); for (int i=0;i<20;i++) { std::wstring v = get_boot_string(_T("settings"), strEx::itos(i), _T("")); if (!v.empty()) order.push_back(expand_context(v)); } } if (order.size() == 0) { get_logger()->debug(__FILE__, __LINE__, _T("No entries found looking in (adding default): ") + boot_.string()); order.push_back(DEFAULT_CONF_OLD_LOCATION); order.push_back(DEFAULT_CONF_INI_LOCATION); } int i=0; std::wstring boot_order; BOOST_FOREACH(std::wstring k, order) { strEx::append_list(boot_order, k, _T(", ")); }