U32 LLControlGroup::loadFromFile(const std::string& filename, bool set_default_values, bool save_values) { if(mIncludedFiles.find(filename) != mIncludedFiles.end()) return 0; //Already included this file. mIncludedFiles.insert(filename); LLSD settings; llifstream infile; infile.open(filename); if(!infile.is_open()) { llwarns << "Cannot find file " << filename << " to load." << llendl; return 0; } S32 ret = LLSDSerialize::fromXML(settings, infile); if (ret <= 0) { infile.close(); llwarns << "Unable to open LLSD control file " << filename << ". Trying Legacy Method." << llendl; return loadFromFileLegacy(filename, TRUE, TYPE_STRING); } U32 validitems = 0; bool hidefromsettingseditor = false; for(LLSD::map_const_iterator itr = settings.beginMap(); itr != settings.endMap(); ++itr) { bool persist = true; std::string const & name = itr->first; LLSD const & control_map = itr->second; if(name == "Include") { if(control_map.isArray()) { #if LL_WINDOWS size_t pos = filename.find_last_of("\\"); #else size_t pos = filename.find_last_of("/"); #endif if(pos!=std::string::npos) { const std::string dir = filename.substr(0,++pos); for(LLSD::array_const_iterator array_itr = control_map.beginArray(); array_itr != control_map.endArray(); ++array_itr) validitems+=loadFromFile(dir+(*array_itr).asString(),set_default_values); } } continue; } if(control_map.has("Persist")) { persist = control_map["Persist"].asInteger(); } // Sometimes we want to use the settings system to provide cheap persistence, but we // don't want the settings themselves to be easily manipulated in the UI because // doing so can cause support problems. So we have this option: if(control_map.has("HideFromEditor")) { hidefromsettingseditor = control_map["HideFromEditor"].asInteger(); } else { hidefromsettingseditor = false; } // If the control exists just set the value from the input file. LLControlVariable* existing_control = getControl(name); if(existing_control) { if(set_default_values) { // Override all previously set properties of this control. // ... except for type. The types must match. eControlType new_type = typeStringToEnum(control_map["Type"].asString()); if(existing_control->isType(new_type)) { existing_control->setDefaultValue(control_map["Value"]); existing_control->setPersist(persist); existing_control->setHiddenFromSettingsEditor(hidefromsettingseditor); existing_control->setComment(control_map["Comment"].asString()); } else { llerrs << "Mismatched type of control variable '" << name << "' found while loading '" << filename << "'." << llendl; } } else if(existing_control->isPersisted()) { existing_control->setValue(control_map["Value"], save_values); } // *NOTE: If not persisted and not setting defaults, // the value should not get loaded. } else { bool IsCOA = control_map.has("IsCOA") && !!control_map["IsCOA"].asInteger(); declareControl(name, typeStringToEnum(control_map["Type"].asString()), control_map["Value"], control_map["Comment"].asString(), persist, hidefromsettingseditor, IsCOA ); } ++validitems; } return validitems; }
U32 LLControlGroup::loadFromFile(const std::string& filename, bool set_default_values, bool revert_if_not_found) { std::string name; LLSD settings; LLSD control_map; llifstream infile; infile.open(filename); if(!infile.is_open()) { llwarns << "Cannot find file " << filename << " to load." << llendl; return 0; } S32 ret = LLSDSerialize::fromXML(settings, infile); if (ret <= 0) { infile.close(); llwarns << "Unable to open LLSD control file " << filename << ". Trying Legacy Method." << llendl; return loadFromFileLegacy(filename, TRUE, TYPE_STRING); } U32 validitems = 0; bool hidefromsettingseditor = false; for(LLSD::map_const_iterator itr = settings.beginMap(); itr != settings.endMap(); ++itr) { bool persist = true; name = (*itr).first; control_map = (*itr).second; if(control_map.has("Persist")) { persist = control_map["Persist"].asInteger(); } // Sometimes we want to use the settings system to provide cheap persistence, but we // don't want the settings themselves to be easily manipulated in the UI because // doing so can cause support problems. So we have this option: if(control_map.has("HideFromEditor")) { hidefromsettingseditor = control_map["HideFromEditor"].asInteger(); } else { hidefromsettingseditor = false; } // If the control exists just set the value from the input file. LLControlVariable* existing_control = getControl(name); if(existing_control) { if(set_default_values) { // Override all previously set properties of this control. // ... except for type. The types must match. eControlType new_type = typeStringToEnum(control_map["Type"].asString()); if(existing_control->isType(new_type)) { existing_control->setDefaultValue(control_map["Value"]); existing_control->setPersist(persist); existing_control->setHiddenFromSettingsEditor(hidefromsettingseditor); existing_control->setComment(control_map["Comment"].asString()); } else { llerrs << "Mismatched type of control variable '" << name << "' found while loading '" << filename << "'." << llendl; } } else if(existing_control->isPersisted()) { existing_control->setValue(control_map["Value"]); } // *NOTE: If not persisted and not setting defaults, // the value should not get loaded. } else { declareControl(name, typeStringToEnum(control_map["Type"].asString()), control_map["Value"], control_map["Comment"].asString(), persist, hidefromsettingseditor ); } ++validitems; } // [KITTY VIEWER] if(revert_if_not_found) { ctrl_name_table_t::iterator control_iter; for (control_iter = mNameTable.begin(); control_iter != mNameTable.end(); ++control_iter) { if(!settings.has((*control_iter).first)) { LLControlVariable* control = (*control_iter).second; if(control->isPersisted() && !control->isDefault()) { control->resetToDefault(true); } } } } // [/KITTY VIEWER] return validitems; }
U32 LLControlGroup::loadFromFile(const std::string& filename, bool set_default_values) { std::string name; LLSD settings; LLSD control_map; llifstream infile; infile.open(filename); if(!infile.is_open()) { llwarns << "Cannot find file " << filename << " to load." << llendl; return 0; } S32 ret = LLSDSerialize::fromXML(settings, infile); if (ret <= 0) { infile.close(); llwarns << "Unable to open LLSD control file " << filename << ". Trying Legacy Method." << llendl; return loadFromFileLegacy(filename, TRUE, TYPE_STRING); } U32 validitems = 0; bool hidefromsettingseditor = false; for(LLSD::map_const_iterator itr = settings.beginMap(); itr != settings.endMap(); ++itr) { bool persist = true; name = (*itr).first; control_map = (*itr).second; if(control_map.has("Persist")) { persist = control_map["Persist"].asInteger(); } // Sometimes we want to use the settings system to provide cheap persistence, but we // don't want the settings themselves to be easily manipulated in the UI because // doing so can cause support problems. So we have this option: // To actually only hide adult settings and the world search url. // Upside of the latter is that it also makes it harder to use the viewer with OpenSim. // And teenagers never would dare ever to touch the settings.xml file. // // For it's anyway useful to be able to change them we should add in future // a possibility to unhide them again, e.g. typing "I'm up to no good" to channel 666, // tripple-rightclick the avatars nose and then play a "I will tell your MUM that you // changed ADULT setting in the DEBUG MENU!" gesture in world. // /* if(control_map.has("HideFromEditor")) { hidefromsettingseditor = control_map["HideFromEditor"].asInteger(); } else { hidefromsettingseditor = false; } */ // [RLVa:KB] - Checked: 2010-06-20 (RLVa-1.1.2a) | Added: RLVa-1.1.2a // HACK-RLVa: bad code but it's just a temporary measure to provide a smooth changeover from the old to the new rebranded settings if ( (name.length() >= 14) && (0 == name.find("RestrainedLife")) ) { // Transparently convert the old settings name to the new one while preserving the user override name = "RestrainedLove" + name.substr(14); } // [/RLVa:KB] // If the control exists just set the value from the input file. LLControlVariable* existing_control = getControl(name); if(existing_control) { if(set_default_values) { // Override all previously set properties of this control. // ... except for type. The types must match. eControlType new_type = typeStringToEnum(control_map["Type"].asString()); if(existing_control->isType(new_type)) { existing_control->setDefaultValue(control_map["Value"]); existing_control->setPersist(persist); existing_control->setHiddenFromSettingsEditor(hidefromsettingseditor); existing_control->setComment(control_map["Comment"].asString()); } else { llerrs << "Mismatched type of control variable '" << name << "' found while loading '" << filename << "'." << llendl; } } else if(existing_control->isPersisted()) { existing_control->setValue(control_map["Value"]); } // *NOTE: If not persisted and not setting defaults, // the value should not get loaded. } else { declareControl(name, typeStringToEnum(control_map["Type"].asString()), control_map["Value"], control_map["Comment"].asString(), persist, hidefromsettingseditor ); } ++validitems; } return validitems; }
U32 LLControlGroup::loadFromFile(const std::string& filename, bool set_default_values, bool save_values) { LLSD settings; llifstream infile; infile.open(filename.c_str()); if(!infile.is_open()) { LL_WARNS("Settings") << "Cannot find file " << filename << " to load." << LL_ENDL; return 0; } if (LLSDParser::PARSE_FAILURE == LLSDSerialize::fromXML(settings, infile)) { infile.close(); LL_WARNS("Settings") << "Unable to parse LLSD control file " << filename << ". Trying Legacy Method." << LL_ENDL; return loadFromFileLegacy(filename, TRUE, TYPE_STRING); } U32 validitems = 0; bool hidefromsettingseditor = false; for(LLSD::map_const_iterator itr = settings.beginMap(); itr != settings.endMap(); ++itr) { LLControlVariable::ePersist persist = LLControlVariable::PERSIST_NONDFT; std::string const & name = itr->first; LLSD const & control_map = itr->second; if(control_map.has("Persist")) { persist = control_map["Persist"].asInteger()? LLControlVariable::PERSIST_NONDFT : LLControlVariable::PERSIST_NO; } // Sometimes we want to use the settings system to provide cheap persistence, but we // don't want the settings themselves to be easily manipulated in the UI because // doing so can cause support problems. So we have this option: if(control_map.has("HideFromEditor")) { hidefromsettingseditor = control_map["HideFromEditor"].asInteger(); } else { hidefromsettingseditor = false; } // If the control exists just set the value from the input file. LLControlVariable* existing_control = getControl(name); if(existing_control) { // set_default_values is true when we're loading the initial, // immutable files from app_settings, e.g. settings.xml. if(set_default_values) { // Override all previously set properties of this control. // ... except for type. The types must match. eControlType new_type = typeStringToEnum(control_map["Type"].asString()); if(existing_control->isType(new_type)) { existing_control->setDefaultValue(control_map["Value"]); existing_control->setPersist(persist); existing_control->setHiddenFromSettingsEditor(hidefromsettingseditor); existing_control->setComment(control_map["Comment"].asString()); } else { LL_ERRS() << "Mismatched type of control variable '" << name << "' found while loading '" << filename << "'." << LL_ENDL; } } else if(existing_control->isPersisted()) { // save_values is specifically false for (e.g.) // SessionSettingsFile and UserSessionSettingsFile -- in other // words, for a file that's supposed to be transient. existing_control->setValue(control_map["Value"], save_values); } // *NOTE: If not persisted and not setting defaults, // the value should not get loaded. } else { // We've never seen this control before. Either we're loading up // the initial set of default settings files (set_default_values) // -- or we're loading user settings last saved by a viewer that // supports a superset of the variables we know. // CHOP-962: if we're loading an unrecognized user setting, make // sure we save it later. If you try an experimental viewer, tweak // a new setting, briefly revert to an old viewer, then return to // the new one, we don't want the old viewer to discard the // setting you changed. if (! set_default_values) { // Using PERSIST_ALWAYS insists that saveToFile() (which calls // LLControlVariable::shouldSave()) must save this control // variable regardless of its value. We can safely set this // LLControlVariable persistent because the 'persistent' flag // is not itself persisted! persist = LLControlVariable::PERSIST_ALWAYS; // We want to mention unrecognized user settings variables // (e.g. from a newer version of the viewer) in the log. But // we also arrive here for Boolean variables generated by // the notifications subsystem when the user checks "Don't // show me this again." These aren't declared in settings.xml; // they're actually named for the notification they suppress. // We don't want to mention those. Apologies, this is a bit of // a hack: we happen to know that user settings go into an // LLControlGroup whose name is "Global". if (getKey() == "Global") { LL_INFOS("LLControlGroup") << "preserving unrecognized " << getKey() << " settings variable " << name << LL_ENDL; } } declareControl(name, typeStringToEnum(control_map["Type"].asString()), control_map["Value"], control_map["Comment"].asString(), persist, hidefromsettingseditor ); } ++validitems; } LL_DEBUGS("Settings") << "Loaded " << validitems << " settings from " << filename << LL_ENDL; return validitems; }
U32 LLControlGroup::loadFromFile(const std::string& filename, bool set_default_values) { std::string name; LLSD settings; LLSD control_map; llifstream infile; infile.open(filename); if(!infile.is_open()) { llwarns << "Cannot find file " << filename << " to load." << llendl; return 0; } S32 ret = LLSDSerialize::fromXML(settings, infile); if (ret <= 0) { infile.close(); llwarns << "Unable to open LLSD control file " << filename << ". Trying Legacy Method." << llendl; return loadFromFileLegacy(filename, TRUE, TYPE_STRING); } U32 validitems = 0; bool persist = false; for(LLSD::map_const_iterator itr = settings.beginMap(); itr != settings.endMap(); ++itr) { name = (*itr).first; control_map = (*itr).second; if(control_map.has("Persist")) { persist = control_map["Persist"].asInteger(); } // If the control exists just set the value from the input file. LLControlVariable* existing_control = getControl(name); if(existing_control) { if(set_default_values) { // Override all previously set properties of this control. // ... except for type. The types must match. eControlType new_type = typeStringToEnum(control_map["Type"].asString()); if(existing_control->isType(new_type)) { existing_control->setDefaultValue(control_map["Value"]); existing_control->setPersist(persist); existing_control->setComment(control_map["Comment"].asString()); } else { llerrs << "Mismatched type of control variable '" << name << "' found while loading '" << filename << "'." << llendl; } } else if(existing_control->isPersisted()) { existing_control->setValue(control_map["Value"]); } // *NOTE: If not persisted and not setting defaults, // the value should not get loaded. } else { declareControl(name, typeStringToEnum(control_map["Type"].asString()), control_map["Value"], control_map["Comment"].asString(), persist ); } ++validitems; } return validitems; }