Example #1
0
void COptions::SetXmlValue(unsigned int nID, wxString value)
{
	if (!m_pXmlFile)
		return;

	// No checks are made about the validity of the value, that's done in SetOption

	char *utf8 = ConvUTF8(value);
	if (!utf8)
		return;

	TiXmlElement *settings = m_pXmlFile->GetElement()->FirstChildElement("Settings");
	if (!settings)
	{
		TiXmlNode *node = m_pXmlFile->GetElement()->LinkEndChild(new TiXmlElement("Settings"));
		if (!node)
		{
			delete [] utf8;
			return;
		}
		settings = node->ToElement();
		if (!settings)
		{
			delete [] utf8;
			return;
		}
	}
	else
	{
		TiXmlNode *node = 0;
		while ((node = settings->IterateChildren("Setting", node)))
		{
			TiXmlElement *setting = node->ToElement();
			if (!setting)
				continue;

			const char *attribute = setting->Attribute("name");
			if (!attribute)
				continue;
			if (strcmp(attribute, options[nID].name))
				continue;

			//setting->RemoveAttribute("type");
			setting->Clear();
			//setting->SetAttribute("type", (options[nID].type == string) ? "string" : "number");
			setting->LinkEndChild(new TiXmlText(utf8));

			delete [] utf8;
			return;
		}
	}
	wxASSERT(options[nID].name[0]);
	TiXmlElement *setting = new TiXmlElement("Setting");
	setting->SetAttribute("name", options[nID].name);
	//setting->SetAttribute("type", (options[nID].type == string) ? "string" : "number");
	setting->LinkEndChild(new TiXmlText(utf8));
	settings->LinkEndChild(setting);

	delete [] utf8;
}
Example #2
0
TiXmlElement* ObjectBase::SerializeObject()
{
	TiXmlElement *element = new TiXmlElement("object");
	element->SetAttribute("class", _STDSTR( GetClassName() ));

	for (unsigned int i=0; i< GetPropertyCount(); i++)
	{
		shared_ptr<Property> prop = GetProperty(i);
		TiXmlElement *prop_element = new TiXmlElement("property");
		prop_element->SetAttribute("name", _STDSTR(prop->GetName() ));

		TiXmlText* prop_value = new TiXmlText( _STDSTR(prop->GetValue()));
		prop_element->LinkEndChild(prop_value);
		element->LinkEndChild(prop_element);
	}

	for (unsigned int i=0 ; i < GetChildCount() ; i++)
	{
		shared_ptr<ObjectBase> child = GetChild(i);
		TiXmlElement * child_element = child->SerializeObject();
		element->LinkEndChild(child_element);
	}

	return element;
}
Example #3
0
void gen_catfee_xml(std::vector<FeeCatXML*>& feeCat)
{
	// Make xml: <?xml ..><Hello>World</Hello>
	TiXmlDocument doc;
	TiXmlDeclaration * decl = new TiXmlDeclaration("1.0", "", "");
	TiXmlElement * element = new TiXmlElement("import");

	//TiXmlText * text = new TiXmlText("World");
	element->SetAttribute("mode", "synchronize");
	doc.LinkEndChild(decl);
	doc.LinkEndChild(element);

	{
		
		for (std::vector < FeeCatXML* >::iterator iter = feeCat.begin();
			iter != feeCat.end(); iter++) {
			TiXmlElement * feescats = new TiXmlElement("clientfeecat");
			element->LinkEndChild(feescats);
			FeeCatXML *feeCat =  *iter;

			TiXmlElement * id = new TiXmlElement("id");
			TiXmlElement * name = new TiXmlElement("name");
		
			feescats->LinkEndChild(id);
			feescats->LinkEndChild(name);
		
			id->LinkEndChild(new TiXmlText((feeCat->id).c_str() ));
			name->LinkEndChild(new TiXmlText( (feeCat->name).c_str() ));

		}


		doc.SaveFile("BSBFeeCat.xml");
	}
}
Example #4
0
bool CreateXmlFile(std::string& szFileName)
{//创建xml文件,szFilePath为文件保存的路径,若创建成功返回true,否则false
	try
	{
		//创建一个XML的文档对象。
		TiXmlDocument *myDocument = new TiXmlDocument();
		//创建一个根元素并连接。
		TiXmlElement *RootElement = new TiXmlElement("Persons");
		myDocument->LinkEndChild(RootElement);
		//创建一个Person元素并连接。
		TiXmlElement *PersonElement = new TiXmlElement("Person");
		RootElement->LinkEndChild(PersonElement);
		//设置Person元素的属性。
		PersonElement->SetAttribute("ID", "1");
		//创建name元素、age元素并连接。
		TiXmlElement *NameElement = new TiXmlElement("name");
		TiXmlElement *AgeElement = new TiXmlElement("age");
		PersonElement->LinkEndChild(NameElement);
		PersonElement->LinkEndChild(AgeElement);
		//设置name元素和age元素的内容并连接。
		TiXmlText *NameContent = new TiXmlText("周星星");
		TiXmlText *AgeContent = new TiXmlText("22");
		NameElement->LinkEndChild(NameContent);
		AgeElement->LinkEndChild(AgeContent);
		std::string fullPath = GetAppPath();
		fullPath += "\\";
		fullPath += szFileName;
		myDocument->SaveFile(fullPath.c_str());//保存到文件
	}
	catch (std::string& e)
	{
		return false;
	}
	return true;
}
void printModule(PMODULEENTRY32 entry, TiXmlElement* process)
{
    TiXmlElement* node = new TiXmlElement("module");

	TiXmlElement* item = new TiXmlElement("HANDLE");
	item->SetAttribute("value", (DWORD)entry->hModule);
	node->LinkEndChild(item);

	item = new TiXmlElement("Address");
	char szBuffer[1024] = {0};
	sprintf(szBuffer, "0x%08X", entry->modBaseAddr);
	item->SetAttribute("value", szBuffer);
	node->LinkEndChild(item);

	item = new TiXmlElement("Size");
	item->SetAttribute("value", entry->modBaseSize);
	node->LinkEndChild(item);

	item = new TiXmlElement("Name");
	memset(szBuffer, 0, 1024);
	if (WideCharToMultiByte(
		CP_ACP,
		NULL,
		entry->szModule,
		wcslen(entry->szModule),
		szBuffer,
		1024,
		NULL,
		NULL) > 0)
	{
		item->SetAttribute("value", szBuffer);
		node->LinkEndChild(item);
	}
	else
		delete item;

	item = new TiXmlElement("Path");
	memset(szBuffer, 0, 1024);
	if (WideCharToMultiByte(
		CP_ACP,
		NULL,
		entry->szExePath,
		wcslen(entry->szExePath),
		szBuffer,
		1024,
		NULL,
		NULL) > 0)
	{
		item->SetAttribute("value", szBuffer);
		node->LinkEndChild(item);
	}
	else
		delete item;

	process->LinkEndChild(node);
}
TiXmlElement* CGlobalLightSettings::xml()
{
	TiXmlElement* xmlLightSettings = new TiXmlElement( GetType().c_str() );

	TiXmlElement* xmlAmbientColor = new TiXmlElement("AmbientColor");
	xmlAmbientColor->LinkEndChild( xmlText( m_colAmbient ) );
	xmlLightSettings->LinkEndChild( xmlAmbientColor );

	return xmlLightSettings;
}
Example #7
0
/**
* Saves the enemy to an XML file
* @param pDoc the file to save to
*/
void Enemy::save(TiXmlDocument& pDoc) {

	TiXmlElement * enemy = new TiXmlElement( "enemy" );  
	pDoc.RootElement()->LinkEndChild( enemy );

	TiXmlElement* type = new TiXmlElement( "type" ); 
	if(mSensorData == "meleeEnemy") {
		type->LinkEndChild( new TiXmlText( "2" ));
	}
	else if(mSensorData == "bombEnemy") {
		type->LinkEndChild( new TiXmlText( "1" ));
	}
	enemy->LinkEndChild( type );

	string x = Constants::convertInt(mBody->GetPosition().x);

	TiXmlElement* xPos = new TiXmlElement( "xPos" );  
	xPos->LinkEndChild( new TiXmlText( x.c_str() ));
	enemy->LinkEndChild( xPos );

	string y = Constants::convertInt(mBody->GetPosition().y);

	TiXmlElement* yPos = new TiXmlElement( "yPos" );  
	yPos->LinkEndChild( new TiXmlText( y.c_str() ));
	enemy->LinkEndChild( yPos );

	TiXmlElement* pat1 = new TiXmlElement( "patrolA" );  
	pat1->LinkEndChild( new TiXmlText( Constants::convertInt(mPatSave1).c_str() ));
	enemy->LinkEndChild( pat1 );

	TiXmlElement* pat2 = new TiXmlElement( "patrolB" );  
	pat2->LinkEndChild( new TiXmlText( Constants::convertInt(mPatSave2).c_str() ));
	enemy->LinkEndChild( pat2 );
}
TiXmlElement* Brothel::SaveBrothelXML( TiXmlElement* pRoot )
{
    TiXmlElement* pBrothel = new TiXmlElement( "Brothel" );
    pRoot->LinkEndChild( pBrothel );
    pBrothel->SetAttribute( "Name", m_Name );
    
    // save variables for sex restrictions
    pBrothel->SetAttribute( "RestrictAnal", m_RestrictAnal );
    pBrothel->SetAttribute( "RestrictBDSM", m_RestrictBDSM );
    pBrothel->SetAttribute( "RestrictBeast", m_RestrictBeast );
    pBrothel->SetAttribute( "RestrictGroup", m_RestrictGroup );
    pBrothel->SetAttribute( "RestrictNormal", m_RestrictNormal );
    pBrothel->SetAttribute( "RestrictLesbian", m_RestrictLesbian );
    
    pBrothel->SetAttribute( "AdvertisingBudget", m_AdvertisingBudget );
    pBrothel->SetAttribute( "Bar", m_Bar );
    pBrothel->SetAttribute( "Fame", m_Fame );
    pBrothel->SetAttribute( "GamblingHall", m_GamblingHall );
    pBrothel->SetAttribute( "Happiness", m_Happiness );
    pBrothel->SetAttribute( "HasBarStaff", m_HasBarStaff );
    pBrothel->SetAttribute( "id", m_id );
    pBrothel->SetAttribute( "HasGambStaff", m_HasGambStaff );
    pBrothel->SetAttribute( "NumRooms", m_NumRooms );
    pBrothel->SetAttribute( "Filthiness", m_Filthiness );
    pBrothel->SetAttribute( "SecurityLevel", m_SecurityLevel );
    
    m_Finance.saveGoldXML( pBrothel );
    
    // save building qualities
#if 0
    //building qualities appears to be unimplemented, why waste space
    TiXmlElement* pBuildingQualities = new TiXmlElement( "BuildingQualities" );
    pBrothel->LinkEndChild( pBuildingQualities );
    SaveJobsXML( pBuildingQualities, m_BuildingQuality );
#endif
    
    // Save Girls
    TiXmlElement* pGirls = new TiXmlElement( "Girls" );
    pBrothel->LinkEndChild( pGirls );
    Girl* girl = m_Girls;
    
    while( girl )
    {
        girl->SaveGirlXML( pGirls );
        girl = girl->m_Next;
    }
    
    /*
    *       save the building setup
    */
    //this was commented out before the conversion to XML
    //current->building.save(ofs, current->m_Name);
    return pBrothel;
}
Example #9
0
void CMainDlg::AddUserInfoToCrashDescriptorXML(CString sEmail, CString sDesc)
{ 
  USES_CONVERSION;

  HZIP hz = CreateZip(m_sZipName, NULL);
  
  TStrStrMap::iterator cur = m_pUDFiles.begin();
  unsigned int i;
  for (i = 0; i < m_pUDFiles.size(); i++, cur++)
  {
    CString sFileName = cur->first.c_str();
    sFileName = sFileName.Mid(sFileName.ReverseFind('\\')+1);
    if(sFileName.CompareNoCase(_T("crashrpt.xml"))==0)
    {
      TiXmlDocument doc;
  
      bool bLoad = doc.LoadFile(cur->first.c_str());
      if(!bLoad)
        return;

      TiXmlNode* root = doc.FirstChild("CrashRpt");
      if(!root)
        return;

      // Write user e-mail

      TiXmlElement* email = new TiXmlElement("UserEmail");
      root->LinkEndChild(email);

      LPSTR lpszEmail = T2A(sEmail.GetBuffer(0));
      TiXmlText* email_text = new TiXmlText(lpszEmail);
      email->LinkEndChild(email_text);              

      // Write problem description

      TiXmlElement* desc = new TiXmlElement("ProblemDescription");
      root->LinkEndChild(desc);

      LPSTR lpszDesc = T2A(sDesc.GetBuffer(0));
      TiXmlText* desc_text = new TiXmlText(lpszDesc);
      desc->LinkEndChild(desc_text);              

      doc.SaveFile();      
    }

	LPTSTR lptszFilePath = A2T((char*)cur->first.c_str());
    ZRESULT zr = ZipAdd(hz, sFileName, lptszFilePath);
    ATLASSERT(zr==ZR_OK); 
	zr;
  }  

  CloseZip(hz);
}
void CDeicingAndAnticingsXMLGenerator::FormatPrecipitationType(CPrecipitationtype* _type,TiXmlElement* _element)
{
	TiXmlElement* PrecipitationTYNode = new TiXmlElement(_type->GetName()) ;
	_element->LinkEndChild(PrecipitationTYNode) ;

	CString str ; 
	str.Format(_T("%0.2f"),_type->GetHoldOverTime()) ;
	TiXmlElement* HoldTime = new TiXmlElement(_T("HoldoverTime")) ;
	TiXmlText* name = new TiXmlText(str) ;
	HoldTime->LinkEndChild(name) ;

	str.Format(_T("%s"),_type->GetInspection()->getDistName()) ;
	TiXmlElement* InSpectionTime = new TiXmlElement(_T("InspectionTime")) ;
	name = new TiXmlText(str) ;
	InSpectionTime->LinkEndChild(name) ;

	str.Format(_T("%0.2f"),_type->GetDeIceTime()) ;
	TiXmlElement* listfluid = new TiXmlElement(_T("De-icefluid")) ;
	name = new TiXmlText(str) ;
	listfluid->LinkEndChild(name) ;

	str.Format(_T("%0.2f"),_type->GetAntiIceTime()) ;
	TiXmlElement*  Antilistfluid = new TiXmlElement(_T("Anti-icefluid")) ;
	name = new TiXmlText(str) ;
	Antilistfluid->LinkEndChild(name) ;

	PrecipitationTYNode->LinkEndChild(HoldTime) ;
	PrecipitationTYNode->LinkEndChild(InSpectionTime) ;
	PrecipitationTYNode->LinkEndChild(listfluid) ;
	PrecipitationTYNode->LinkEndChild(Antilistfluid) ;

}
Example #11
0
bool ETHEntity::WriteToXMLFile(TiXmlElement *pHeadRoot) const
{
	TiXmlElement *pEntity = new TiXmlElement(GS_L("Entity"));
	pHeadRoot->LinkEndChild(pEntity);

	TiXmlElement *pElement;

	// if it has a specific name, save it
	if (m_properties.entityName != GS_L(""))
	{
		pElement = new TiXmlElement(GS_L("EntityName"));
		pElement->LinkEndChild(new TiXmlText(m_properties.entityName));
		pEntity->LinkEndChild(pElement);
	}

	if (m_v4Color != ETH_DEFAULT_COLOR)
	{
		pElement = new TiXmlElement(GS_L("Color"));
		pEntity->LinkEndChild(pElement); 
		pElement->SetDoubleAttribute(GS_L("r"), m_v4Color.x);
		pElement->SetDoubleAttribute(GS_L("g"), m_v4Color.y);
		pElement->SetDoubleAttribute(GS_L("b"), m_v4Color.z);
		pElement->SetDoubleAttribute(GS_L("a"), m_v4Color.w);
	}

	pElement = new TiXmlElement(GS_L("Position"));
	pEntity->LinkEndChild(pElement);
	{
		const Vector3 pos(m_controller->GetPos());
		pElement->SetDoubleAttribute(GS_L("x"), pos.x);
		pElement->SetDoubleAttribute(GS_L("y"), pos.y);
		pElement->SetDoubleAttribute(GS_L("z"), pos.z);
		pElement->SetDoubleAttribute(GS_L("angle"), m_controller->GetAngle());
		
	}
	pEntity->SetAttribute(GS_L("id"), m_id);
	pEntity->SetAttribute(GS_L("spriteFrame"), m_spriteFrame);

	if (m_spriteFrame > 0)
		pEntity->SetDoubleAttribute(GS_L("spriteFrame"), m_spriteFrame);

	if (m_properties.castShadow)
		pEntity->SetDoubleAttribute(GS_L("shadowZ"), m_shadowZ);

	if (m_hide != ETH_FALSE)
		pEntity->SetAttribute(GS_L("hide"), m_hide);

	m_properties.WriteToXMLFile(pEntity);
	return true;
}
Example #12
0
string strMiscWarning;
bool fTestNet = false;
bool fNoListen = false;
bool fLogTimestamps = false;
CMedianFilter<int64> vTimeOffsets(200,0);
bool fReopenDebugLog = false;

// Init openssl library multithreading support
static CCriticalSection** ppmutexOpenSSL;
void locking_callback(int mode, int i, const char* file, int line)
{
    if (mode & CRYPTO_LOCK) {
        ENTER_CRITICAL_SECTION(*ppmutexOpenSSL[i]);
    } else {
        LEAVE_CRITICAL_SECTION(*ppmutexOpenSSL[i]);
    }
}

// Init
class CInit
{
public:
    CInit()
    {
        // Init openssl library multithreading support
        ppmutexOpenSSL = (CCriticalSection**)OPENSSL_malloc(CRYPTO_num_locks() * sizeof(CCriticalSection*));
        for (int i = 0; i < CRYPTO_num_locks(); i++)
            ppmutexOpenSSL[i] = new CCriticalSection();
        CRYPTO_set_locking_callback(locking_callback);

#ifdef WIN32
        // Seed random number generator with screen scrape and other hardware sources
        RAND_screen();
#endif
TiXmlElement* SceneTransformNode::getSceneNodeValueAsXmlElement() {
	//SceneNode::getSceneNodeAsXmlElement();
	TiXmlElement* element = new TiXmlElement("TransformNode");
	element->SetAttribute("Type",  getType());
	element->LinkEndChild(getSceneNodeTransformValueAsXmlElement());
	return element;
}
Example #14
0
TiXmlNode* TiXmlElement::Clone() const
{
    TiXmlElement* clone = new TiXmlElement( Value() );

    if ( !clone )
        return 0;

    CopyToClone( clone );

    // Clone the attributes, then clone the children.
    TiXmlAttribute* attribute = 0;
    for(	attribute = attributeSet.First();
            attribute;
            attribute = attribute->Next() )
    {
        clone->SetAttribute( attribute->Name(), attribute->Value() );
    }

    TiXmlNode* node = 0;
    for ( node = firstChild; node; node = node->NextSibling() )
    {
        clone->LinkEndChild( node->Clone() );
    }
    return clone;
}
//-----------------------------------------------------------------------------
// <ThermostatMode::WriteXML>
// Save the supported modes
//-----------------------------------------------------------------------------
void ThermostatMode::WriteXML
(
	TiXmlElement* _ccElement
)
{
	if( m_supportedModes.empty() )
	{
		return;
	}

	CommandClass::WriteXML( _ccElement );

	if( GetNodeUnsafe() )
	{
		TiXmlElement* supportedModesElement = new TiXmlElement( "SupportedModes" );
		_ccElement->LinkEndChild( supportedModesElement );

		for( vector<ValueList::Item>::iterator it = m_supportedModes.begin(); it != m_supportedModes.end(); ++it )
		{
			ValueList::Item const& item = *it;

			TiXmlElement* modeElement = new TiXmlElement( "Mode" );
			supportedModesElement->LinkEndChild( modeElement );

			char str[8];
			snprintf( str, 8, "%d", item.m_value );
			modeElement->SetAttribute( "index", str );
			modeElement->SetAttribute( "label", item.m_label.c_str() );
		}
	}
}
Example #16
0
void User::Save(bool force) {
  if (!force) {
    // If no save operation is scheduled, exit now
    if (!scheduledSaveTimer_) return;
    if (!scheduledSaveTimer_->IsRunning()) return;
  }

  settings_->Save();
  wxGetApp().GetPluginManager()->Save();

  TiXmlDocument doc;
  doc.LinkEndChild(new TiXmlDeclaration("1.0", "UTF-8", ""));

  TiXmlElement* xmlRoot = new TiXmlElement("FolderItems");
  xmlRoot->SetAttribute("version", "1.0");
  doc.LinkEndChild(xmlRoot);

  for (int i = 0; i < autoAddExclusions_.size(); i++) {
    XmlUtil::AppendTextElement(xmlRoot, "ExcludedPath", autoAddExclusions_[i]);
  }

  FolderItemVector folderItems = rootFolderItem_->GetChildren();
  for (int i = 0; i < folderItems.size(); i++) {
    FolderItem* folderItem = folderItems.at(i);
    xmlRoot->LinkEndChild(folderItem->ToXml());   
  }

  FilePaths::CreateSettingsDirectory();
  bool saved = doc.SaveFile(FilePaths::GetFolderItemsFile().mb_str());
  if (!saved) ELOG(_T("Could not save file"));
}
Example #17
0
int em::EmXml::AppendRootChildList( const char* szChildName, EmVecMapStr &rVecMapStr )
{
	std::string strResult;
	bool bUpdated = false;
	int iResult = 0;
	int i = 0;

	TiXmlElement *pElemRoot = m_pDoc->RootElement();
	if(pElemRoot == NULL)
	{
		return 0;
	}
	
	if(rVecMapStr.size() == 0)
	{
		return 0;
	}
	
	for(i = 0; i < rVecMapStr.size(); i++)
	{
		TiXmlElement *pElemChildNew = new TiXmlElement(szChildName);
		EmMapStr::const_iterator iterMap;
		for(iterMap = rVecMapStr[i].begin(); iterMap != rVecMapStr[i].end(); iterMap++)
		{
			pElemChildNew->SetAttribute(iterMap->first,iterMap->second);
		}
		
		pElemRoot->LinkEndChild(pElemChildNew);
	}

	m_bUpdated = true;
	return iResult;
}
Example #18
0
TiXmlElement* SceneObjectNode::getSceneNodeValueAsXmlElement() {
	//printf("getSceneNodeAsXmlElement \n");
	TiXmlElement* element = new TiXmlElement("ObjectNode");
	element->LinkEndChild(drawable->getDrawableAsXmlElement());
	//element->LinkEndChild(((Mesh*)(drawable))->getDrawableAsXmlElement());
	return element;
}
TiXmlElement* MasterFile::SaveXML( TiXmlElement* pRoot )
{
    TiXmlElement* pLoadedFiles = new TiXmlElement("Loaded_Files");
    pRoot->LinkEndChild( pLoadedFiles );

    TiXmlElement* pGirlsFiles = new TiXmlElement("Girls_Files");
    pLoadedFiles->LinkEndChild( pGirlsFiles );

    FileFlags::const_iterator it;
    for( it = files.begin(); it != files.end(); ++it )
    {
        TiXmlElement* pFile = new TiXmlElement("File");
        pGirlsFiles->LinkEndChild( pFile );
        pFile->SetAttribute( "Filename", it->first );
    }
    return pLoadedFiles;
}
Example #20
0
bool SData::SaveCache()
{
  XBMC->Log(LOG_DEBUG, "%s", __FUNCTION__);

  std::string strCacheFile;
  bool bFailed(false);
  TiXmlDocument doc;
  TiXmlElement *pRootElement = NULL;
  TiXmlElement *pTokenElement = NULL;

  strCacheFile = Utils::GetFilePath("cache.xml");

  if ((bFailed = !doc.LoadFile(strCacheFile))) {
    XBMC->Log(LOG_ERROR, "%s: failed to load \"%s\"", __FUNCTION__, strCacheFile.c_str());
  } else {
    pRootElement = doc.RootElement();
    if (!pRootElement || strcmp(pRootElement->Value(), "cache") != 0) {
      XBMC->Log(LOG_ERROR, "%s: invalid xml doc. root element 'cache' not found", __FUNCTION__);
      bFailed = true;
    }
  }

  if (bFailed) {
    XBMC->Log(LOG_DEBUG, "%s: creating root element 'cache'", __FUNCTION__);

    pRootElement = new TiXmlElement("cache");
    doc.LinkEndChild(pRootElement);
  }

  pTokenElement = pRootElement->FirstChildElement("token");
  if (!pTokenElement) {
    pTokenElement = new TiXmlElement("token");
    pRootElement->LinkEndChild(pTokenElement);
  }
  pTokenElement->Clear();
  if (m_profile.store_auth_data_on_stb)
    pTokenElement->LinkEndChild(new TiXmlText(m_identity.token));

  if (!doc.SaveFile(strCacheFile)) {
    XBMC->Log(LOG_ERROR, "%s: failed to save \"%s\"", __FUNCTION__, strCacheFile.c_str());
    return false;
  }

  return true;
}
Example #21
0
void CFilterDialog::SaveFilter(TiXmlElement* pElement, const CFilter& filter)
{
	AddTextElement(pElement, "Name", filter.name);
	AddTextElement(pElement, "ApplyToFiles", filter.filterFiles ? _T("1") : _T("0"));
	AddTextElement(pElement, "ApplyToDirs", filter.filterDirs ? _T("1") : _T("0"));
	AddTextElement(pElement, "MatchType", (filter.matchType == CFilter::any) ? _T("Any") : ((filter.matchType == CFilter::none) ? _T("None") : _T("All")));
	AddTextElement(pElement, "MatchCase", filter.matchCase ? _T("1") : _T("0"));

	TiXmlElement* pConditions = pElement->LinkEndChild(new TiXmlElement("Conditions"))->ToElement();
	for (std::vector<CFilterCondition>::const_iterator conditionIter = filter.filters.begin(); conditionIter != filter.filters.end(); ++conditionIter)
	{
		const CFilterCondition& condition = *conditionIter;

		int type;
		switch (condition.type)
		{
		case filter_name:
			type = 0;
			break;
		case filter_size:
			type = 1;
			break;
		case filter_attributes:
			type = 2;
			break;
		case filter_permissions:
			type = 3;
			break;
		case filter_path:
			type = 4;
			break;
		case filter_date:
			type = 5;
			break;
		default:
			wxFAIL_MSG(_T("Unhandled filter type"));
			continue;
		}

		TiXmlElement* pCondition = pConditions->LinkEndChild(new TiXmlElement("Condition"))->ToElement();
		AddTextElement(pCondition, "Type", type);

		if (condition.type == filter_size)
		{
			// Backwards compatibility sucks
			int v = condition.condition;
			if (v == 2)
				v = 3;
			else if (v > 2)
				--v;
			AddTextElement(pCondition, "Condition", v);
		}
		else
			AddTextElement(pCondition, "Condition", condition.condition);
		AddTextElement(pCondition, "Value", condition.strValue);
	}
}
    void GeneticPopulation::dumpBest(string filename, bool includeGenes, bool doGZ) {
        TiXmlDocument doc(filename);

        TiXmlElement *root = new TiXmlElement("Genetics");

        Globals::getSingleton()->dump(root);

        doc.LinkEndChild(root);

        if (!NEAT::Globals::getSingleton()->getParameterValue("OnlySaveFinalPop")) {
            for (int a = 0; a<int(generations.size()) - 1; a++) {

                TiXmlElement *generationElementPtr = new TiXmlElement(generations[a]->getTypeName());

                root->LinkEndChild(generationElementPtr);

                generations[a]->dumpBest(generationElementPtr, includeGenes);
            }
        }
        if (generations.size()) {
            //Always dump everyone from the final generation
            TiXmlElement *generationElementPtr = new TiXmlElement(generations[generations.size() - 1]->getTypeName());
            generations[generations.size() - 1]->dumpBest(generationElementPtr, includeGenes);
            root->LinkEndChild(generationElementPtr);
        }

        //cerr<<"%%%%%%%%%%%%%%%%%%\n";
        //if(generations.size())
        //	cerr<<generations[generations.size()-1]->getIndividualCount();
        //if(generations.size() > 1)
        //	cerr << endl << generations[generations.size()-2]->getIndividualCount();
        //        if(generations.size() > 2) {
        if (generations.size() > 2) {
            generations.erase(generations.begin());
            //cerr << endl << generations[generations.size()-3]->getIndividualCount();
        }
        //cerr<<"\n%%%%%%%%%%%%%%%%%%\n";

        if (doGZ) {
            doc.SaveFileGZ();
        } else {
            doc.SaveFile();
        }
    }
Example #23
0
void Frame::toXML(TiXmlElement* framesNode) {
    TiXmlElement * frameNode = new TiXmlElement("frame");
    frameNode->SetAttribute("id", frame);
    framesNode->LinkEndChild(frameNode);


    TiXmlElement * rectZoneNode = new TiXmlElement("rectZone");
    rectZoneNode->SetAttribute("top", zone.top);
    rectZoneNode->SetAttribute("right", zone.right);
    rectZoneNode->SetAttribute("bottom", zone.bottom);
    rectZoneNode->SetAttribute("left", zone.left);
    frameNode->LinkEndChild(rectZoneNode);

    TiXmlElement * comNode = new TiXmlElement("com");
    comNode->SetAttribute("x", com.X);
    comNode->SetAttribute("y", com.Y);
    comNode->SetAttribute("z", com.Z);
    frameNode->LinkEndChild(comNode);
}
Example #24
0
void CRecentServerList::SetMostRecentServer(const CServer& server)
{
	CInterProcessMutex mutex(MUTEX_MOSTRECENTSERVERS);

	// Make sure list is initialized
	GetMostRecentServers(false);

	bool relocated = false;
	for (std::list<CServer>::iterator iter = m_mostRecentServers.begin(); iter != m_mostRecentServers.end(); iter++)
	{
		if (iter->EqualsNoPass(server))
		{
			m_mostRecentServers.erase(iter);
			m_mostRecentServers.push_front(server);
			relocated = true;
			break;
		}
	}
	if (!relocated)
	{
		m_mostRecentServers.push_front(server);
		if (m_mostRecentServers.size() > 10)
			m_mostRecentServers.pop_back();
	}

	TiXmlElement* pDocument = m_XmlFile.GetElement();
	if (!pDocument)
		return;
	
	TiXmlElement* pElement = pDocument->FirstChildElement("RecentServers");
	if (!pElement)
		pElement = pDocument->LinkEndChild(new TiXmlElement("RecentServers"))->ToElement();

	pElement->Clear();
	for (std::list<CServer>::const_iterator iter = m_mostRecentServers.begin(); iter != m_mostRecentServers.end(); iter++)
	{
		TiXmlElement* pServer = pElement->LinkEndChild(new TiXmlElement("Server"))->ToElement();
		SetServer(pServer, *iter);
	}

	wxString error;
	m_XmlFile.Save(&error);
}
void APIServiceManager::_BuildSingleXMLTag(std::string name, std::string value)
{
    TiXmlElement * tag = new TiXmlElement( name.c_str() );
    tag->LinkEndChild( new TiXmlText( value.c_str() ));

    if( _pXmlElementStack->empty() )
        _pXmlDocOuterTag->LinkEndChild( tag );
    else
        _pXmlElementStack->top()->LinkEndChild( tag );
}
Example #26
0
TiXmlElement * TcxTrack::getTiXml() {
    TiXmlElement * xmlTrack = new TiXmlElement("Track");
    vector<TcxTrackpoint*>::iterator it;
    for ( it=trackpointList.begin() ; it < trackpointList.end(); ++it )
    {
        TcxTrackpoint* trackpoint = *it;
        xmlTrack->LinkEndChild(trackpoint->getTiXml());
    }
    return xmlTrack;
}
//------------------------------------------------------------------------------
//!	Summary:	Called to add a node to the stream using the descriptor
//!				specified by the caller
//!
//!	Parameters:	\li pXmlParent - the parent node
//!				\li pMLProp - the Muthur descriptor
//!
//!	Returns:	the new TinyXml element object
//------------------------------------------------------------------------------
TiXmlElement* CTiXmlStream::Add(TiXmlElement* pTiXmlParent, CMLPropMember* pMLProp)
{
    TiXmlElement*	pTiXmlChild = NULL;
    CMLPropPair*	pAttribute = NULL;
    CMLPropMember*	pChild = NULL;
    bool			bSuccessful = false;

    try
    {
        if((pMLProp != NULL) && (lstrlen(pMLProp->GetName()) > 0))
        {
            //	Create the node for the new element
            pTiXmlChild = new TiXmlElement(pMLProp->GetName());
            if(lstrlen(pMLProp->GetValue()) > 0)
                pTiXmlChild->LinkEndChild(new TiXmlText(pMLProp->GetValue()));

            //	Add to the the parent's child collection
            //
            //	NOTE: This will be NULL if adding the root node
            if(pTiXmlParent != NULL)
            {
                pTiXmlParent->LinkEndChild(pTiXmlChild);
            }

            //	Add the attributes for this element
            pAttribute = pMLProp->GetFirstAttribute();
            while(pAttribute != NULL)
            {
                pTiXmlChild->SetAttribute(pAttribute->GetName(), pAttribute->GetValue());
                pAttribute = pMLProp->GetNextAttribute();
            }

            //	Add the children for this element
            pChild = pMLProp->GetFirstChild();
            while(pChild != NULL)
            {
                Add(pTiXmlChild, pChild);
                pChild = pMLProp->GetNextChild();
            }

            bSuccessful = true;

        }// if((pXmlParent != NULL) && (pMLProp != NULL))
    }
    catch(char *pException)
    {
        _theReporter.Debug("", "Add", "Exception raised adding the XML elment : <%s>", pException ? pException : "NULL");
    }
    catch(...)
    {
        _theReporter.Debug("", "Add", "Exception raised adding the XML elment");
    }

    return bSuccessful ? pTiXmlChild : NULL;
}
Example #28
0
/**
* 将键值对按照类似java中Properties类的xml格式存储 store "key-value" to xml file
* @param filename 要保存的xml文件名
* @return 布尔值,代表操作执行成功与否
*/
bool Properties::storeToXML(const string filename) const
{
	TiXmlDocument doc;
	
	TiXmlDeclarationWithoutStandalone *decl = 
		new TiXmlDeclarationWithoutStandalone("1.0", "UTF-8");
	doc.LinkEndChild(decl);

	TiXmlDoctype *doctype = new TiXmlDoctype();
	doctype->SetValue("properties SYSTEM \"http://java.sun.com/dtd/properties.dtd\"");
	doc.LinkEndChild(doctype);
	
	TiXmlComment *comment1 = new TiXmlComment();
	comment1->SetValue("This file is created by libproperties");
	doc.LinkEndChild(comment1);
	
	TiXmlComment *comment2 = new TiXmlComment();
	comment2->SetValue("read more from http://code.google.com/p/libproperties");
	doc.LinkEndChild(comment2);

	TiXmlElement *propertiesElement = new TiXmlElement("properties");
	doc.LinkEndChild(propertiesElement);

	for (const_iterator it = key_value.begin()
		; it!=key_value.end() ;
		++it
		)
	{
		TiXmlElement *entryElement = new TiXmlElement("entry");
		entryElement->LinkEndChild(new TiXmlText((*it).second));
		#ifdef DEBUG_PROPERTIES_H
	        propertiesElement->Print(stdout, 1);
	        cout << endl;
                #endif
		propertiesElement->LinkEndChild(entryElement);
		entryElement->SetAttribute("key", (*it).first);
	}
		
	bool result = doc.SaveFile(filename);
	doc.Clear();
	return result;
}
Example #29
0
void AddTextElementRaw(TiXmlElement* node, const char* name, const char* value)
{
	wxASSERT(node);
	wxASSERT(value && *value);

	TiXmlElement *element = new TiXmlElement(name);

	element->LinkEndChild(new TiXmlText(value));

	node->LinkEndChild(element);
}
Example #30
0
TiXmlDocument* ObjectBase::Serialize()
{
	TiXmlDocument *document = new TiXmlDocument("document");

	TiXmlDeclaration* dec = new TiXmlDeclaration("1.0", "UTF-8", "yes");
	document->LinkEndChild( dec );

	TiXmlElement* root = new TiXmlElement( "wxFormBuilder_Project" );

	TiXmlElement* fileVersion = new TiXmlElement( "FileVersion" );
	fileVersion->SetAttribute( "major", GlobalData()->m_fbpVerMajor );
	fileVersion->SetAttribute( "minor", GlobalData()->m_fbpVerMinor );

	root->LinkEndChild( fileVersion );

	TiXmlElement *element = SerializeObject();
	root->LinkEndChild(element);
	document->LinkEndChild(root);
	return document;
}