示例#1
0
U32 LLControlGroup::saveToFile(const std::string& filename, BOOL nondefault_only)
{
    LLSD settings;
    int num_saved = 0;
    for (ctrl_name_table_t::iterator iter = mNameTable.begin();
            iter != mNameTable.end(); iter++)
    {
        LLControlVariable* control = iter->second;
        if (!control)
        {
            llwarns << "Tried to save invalid control: " << iter->first << llendl;
        }

        if( control && control->isPersisted() )
        {
            if (!(nondefault_only && (control->isSaveValueDefault())))
            {
                settings[iter->first]["Type"] = typeEnumToString(control->type());
                settings[iter->first]["Comment"] = control->getComment();
                settings[iter->first]["Value"] = control->getSaveValue();
                ++num_saved;
            }
            else
            {
                // Debug spam
                // llinfos << "Skipping " << control->getName() << llendl;
            }
        }
    }
    llofstream file;
    file.open(filename);
    if (file.is_open())
    {
        LLSDSerialize::toPrettyXML(settings, file);
        file.close();
        llinfos << "Saved to " << filename << llendl;
    }
    else
    {
        // This is a warning because sometime we want to use settings files which can't be written...
        llwarns << "Unable to open settings file: " << filename << llendl;
        return 0;
    }
    return num_saved;
}
U32 LLControlGroup::saveToFile(const std::string& filename, BOOL nondefault_only)
{
	LLSD settings;
	int num_saved = 0;
	for (ctrl_name_table_t::iterator iter = mNameTable.begin();
		 iter != mNameTable.end(); iter++)
	{
		LLControlVariable* control = iter->second;
		if (!control)
		{
			LL_WARNS("Settings") << "Tried to save invalid control: " << iter->first << LL_ENDL;
		}
		else if( control->shouldSave(nondefault_only) )
		{
			settings[iter->first]["Type"] = typeEnumToString(control->type());
			settings[iter->first]["Comment"] = control->getComment();
			settings[iter->first]["Value"] = control->getSaveValue();
			settings[iter->first]["Backup"] = control->isBackupable();		// <FS:Zi> Backup Settings
			++num_saved;
		}
	}
	llofstream file;
	file.open(filename.c_str());
	if (file.is_open())
	{
		LLSDSerialize::toPrettyXML(settings, file);
		file.close();
		LL_INFOS("Settings") << "Saved to " << filename << LL_ENDL;
	}
	else
	{
        // This is a warning because sometime we want to use settings files which can't be written...
		LL_WARNS("Settings") << "Unable to open settings file: " << filename << LL_ENDL;
		return 0;
	}
	return num_saved;
}