Exemple #1
9
int MetaConfig::flushNodeSrvs(TiXmlHandle *meta)
{
	std::vector<NodeService> tmp;
	TiXmlHandle srvs = meta->FirstChildElement("services");
	if(srvs.Element()){
		TiXmlHandle srv = srvs.FirstChildElement("service");
		while(srv.Element()){
			NodeService ns;
			loadInt(&srv, "gid", ns.gid, -1);
			loadString(&srv, "name", ns.service, "");
			loadString(&srv, "ip", ns.ip, "");
			loadInt(&srv, "port", ns.port, -1);

			if(!(ns.gid != -1 && !ns.service.empty() && !ns.ip.empty() && ns.port != -1)){
				std::cerr << "load service error name:" << ns.service << " ip:" << ns.ip << " port:" << ns.port << " node:" << ns.gid<< std::endl;
				return -1;
			}

			tmp.push_back(ns);
			srv = srv.Element()->NextSibling("service");
		}
		std::sort(tmp.begin(), tmp.end());
		std::unique(tmp.begin(), tmp.end());
	}
	boost::mutex::scoped_lock lock(mtx);
	ndSrvs.swap(tmp);
	return 0;
}
Exemple #2
0
//---------------------------------------------------------
bool ofxXmlSettings::pushTag(string  tag, int which){

	int pos = tag.find(":");

	if(pos > 0){
		tag = tag.substr(0,pos);
	}

	//we only allow to push one tag at a time.
	TiXmlHandle isRealHandle = storedHandle->ChildElement(tag, which);

	if( isRealHandle.Node() ){
		*storedHandle = isRealHandle;
		level++;
		return true;
	}else{
		printf("pushTag - tag not found\n");
	}

	return false;
}
//---------------------------------------------------------
bool ofxXmlSettings::attributeExists(const string& tag, const string& attribute, int which){
	vector<string> tokens = tokenize(tag,":");
	TiXmlHandle tagHandle = storedHandle;
	for (int x = 0; x < (int)tokens.size(); x++) {
		if (x == 0)
			tagHandle = tagHandle.ChildElement(tokens.at(x), which);
		else
			tagHandle = tagHandle.FirstChildElement(tokens.at(x));
	}

	if (tagHandle.ToElement()) {
		TiXmlElement* elem = tagHandle.ToElement();
		
		// Do stuff with the element here
		for (TiXmlAttribute* a = elem->FirstAttribute(); a; a = a->Next()) {
			if (a->Name() == attribute)
				return true;
		}
	}
	return false;
}
//---------------------------------------------------------
void ofXMLSettings::removeTag(string  tag, int which){
	
	vector<string> tokens = tokenize(tag,":");
	
	//no tags so we return
	if( tokens.size() == 0 ) return;
		
	//grab the handle from the level we are at
	//normally this is the doc but could be a pushed node
	TiXmlHandle tagHandle = *storedHandle;
	
	if(which < 0) which = 0;
	
	for(int x=0;x<tokens.size();x++){
	
		//we only support multi tags
		//with same name at root level
		if(x > 0) which = 0;
			
		TiXmlHandle isRealHandle = tagHandle.ChildElement( tokens.at(x), which);
		
		if ( !isRealHandle.Node() ) break;
		else{
			if (x == tokens.size()-1){
				//if we are at the last tag and it exists 
				//we use its parent to remove it - haha
				tagHandle.ToNode()->RemoveChild( isRealHandle.ToNode() );
			}
			tagHandle = isRealHandle;
		}
	}
	
	tokens.clear();
}
bool OutputFile::getIt(ParamQt * p)
{
  int deb=0;
  currentIteration++;
  p->setRho(0);
  p->setTheta(0);
  p->setLL(0);
  TiXmlHandle root(&mDoc);
  TiXmlHandle h = root.FirstChild("outputFile");
  TiXmlHandle hIter = h.Child("Iteration", currentIteration);

  TiXmlElement* t;
  // <Tree>
  t = hIter.FirstChild("Tree").ToElement();
  if (t == NULL) // Can I use hIter to return false?
    return false;
  string s(t->GetText());
  while (s.at(0)==10 || s.at(0)==13) s=s.substr(1,s.length()-1);
  while (s.at(s.size()-1)==10 || s.at(s.size()-1)==13) s=s.substr(0,s.length()-1);
  p->setTreeData(new RecTree(getL(),s,false,false),blocks);

  // <number>, <theta>, <delta>, <rho>, <ll>.
  t = hIter.FirstChild("number").ToElement(); p->setNumber(atol(t->GetText()));
  t = hIter.FirstChild("theta").ToElement();  p->setTheta(p->getTheta() + atof(t->GetText()));
  t = hIter.FirstChild("delta").ToElement();  p->setDelta(atof(t->GetText()));
  t = hIter.FirstChild("rho").ToElement();    p->setRho(p->getRho() + atof(t->GetText()));
  t = hIter.FirstChild("ll").ToElement();     p->setLL(p->getLL() + atof(t->GetText()));

  // <recedge>
  TiXmlElement* parent = hIter.ToElement(); 
  TiXmlElement* child = 0;
  while (child = (TiXmlElement*) parent->IterateChildren("recedge", child))
    {
      int start=0,end=0,efrom=0,eto=0;
      double ato=0,afrom=0;
      t = child->FirstChildElement("start"); start = deb + atoi(t->GetText());
      t = child->FirstChildElement("end"); end = deb + atoi(t->GetText());
      t = child->FirstChildElement("efrom"); efrom = atoi(t->GetText());
      t = child->FirstChildElement("eto"); eto = atoi(t->GetText());
      t = child->FirstChildElement("afrom"); afrom = atof(t->GetText());
      t = child->FirstChildElement("ato"); ato = atof(t->GetText());
      p->getTree()->addRecEdge(afrom,ato,start,end,efrom,eto);
    }
  return true;
}
void TinyXmlServerConfigImp::load(FILE *fp){
	loaded = true;
	TiXmlDocument doc;
	doc.LoadFile(fp);

	TiXmlHandle docH( &doc );
	TiXmlHandle servers = docH.FirstChildElement( "conf" ).FirstChildElement( "servers" );
	if(servers.Element()){
		
		TiXmlHandle server = servers.FirstChildElement(serverElem.data());
		if(server.Element()){
			loadServer(server);
		}else{
			log(Fatal, "%s config not found", serverElem.data());
			exit(-1);
		}
	}else{
		log(Error, "servers element is NULL");
	}

	forEachWatcher0(&IServerConfigWatcher::onConfigRefresh);
}
Exemple #7
0
bool userCheck(std::string createdAtStr, TiXmlHandle timelineRootHandle, TiXmlHandle userRootHandle)
{
  std::string weekday, month, day, time, year, tmpStr;
  long utcOffset, utcLower, utcHigher;
  std::stringstream ss, utcStrstream;
  std::stringstream strstream;
  boost::posix_time::ptime ptime, pt, currentTime, mostRecentTweetTime;
  boost::posix_time::time_duration hourDiff;
  int userCount = 0;

  ///// Checks to see if the UTC Offset of the user is in the Americas ///////////
  if(userRootHandle.FirstChild("user").FirstChild("utc_offset").ToNode())
    {
      utcStrstream << userRootHandle.FirstChild("user").FirstChild("utc_offset").ToElement()->GetText();
      utcStrstream >> utcOffset;
      utcLower = 60*60*(-10);  // This is the time zone for Hawaii
      utcHigher = 60*60*(-5);  // This is the time zone for the Eastern most US
      if(utcOffset >= utcLower && utcOffset <= utcHigher)
	{
	  userCount++;
	}
    }
//---------------------------------------------------------
bool ofxXmlSettings::pushTag(const string&  tag, int which){

	int pos = tag.find(":");

    // Either find the tag specified, or the first tag if colon-seperated.
    string tagToFind((pos > 0) ? tag.substr(0,pos) :tag);
    
	//we only allow to push one tag at a time.
	TiXmlHandle isRealHandle = storedHandle.ChildElement(tagToFind, which);

	if( isRealHandle.ToNode() ){
		storedHandle = isRealHandle;
		level++;
		return true;
	}else{
		printf("pushTag - <");
		printf("%s",tag.c_str());
		printf("> tag not found\n");
	}

	return false;
}
Exemple #9
0
bool statusCheck(TiXmlHandle rootHandle)
{
  std::string status;
  status = rootHandle.FirstChild("text").ToElement()->GetText();

  for(int i = 0; i < status.size(); i++)
    {
      if(!isascii(status[i]))
	return false;
    }


  return true;
}
Exemple #10
0
void PointLumiere::initFromXML(TiXmlHandle hObj){
	double x,y,z;
	TiXmlElement* pElem=hObj.Element();
	Lumiere::initFromXML(hObj);
	pElem->QueryDoubleAttribute("x", &x);
	pElem->QueryDoubleAttribute("y", &y);
	pElem->QueryDoubleAttribute("z", &z);

	this->position.Set(x,y,z);
	this->falloff[0]=1.0;
	this->falloff[1]=0.0;
	this->falloff[2]=0.0;

}
    bool TinyDemarshaller::deserialize( PropertyBag &v )
    {
        Logger::In in("TinyDemarshaller");

        if ( !d->loadOkay )
            return false;

		TiXmlHandle docHandle( &d->doc );
		TiXmlHandle propHandle = docHandle.FirstChildElement( "properties" );

        if ( ! propHandle.Node() ) {
            log(Error) << "No <properties> element found in document!"<< endlog();
            return false;
        }

        detail::Tiny2CPFHandler proc( v );

        if ( proc.populateBag( propHandle.Node() ) == false) {
            deleteProperties( v );
            return false;
        }
        return true;
    }
bool sGang::LoadGangXML( TiXmlHandle hGang )
{
    TiXmlElement* pGang = hGang.ToElement();
    
    if( pGang == nullptr )
    {
        return false;
    }
    
    if( pGang->Attribute( "Name" ) )
    {
        m_Name = pGang->Attribute( "Name" );
    }
    
    // load their skills
    LoadSkillsXML( hGang.FirstChild( "Skills" ), m_Skills );
    
    // load their stats
    LoadStatsXML( hGang.FirstChild( "Stats" ), m_Stats );
    
    pGang->QueryIntAttribute( "Num", &m_Num );
    
    //these may not have been saved
    //if not, the query just does not set the value
    //so the default is used, assuming the gang was properly init
    {
        pGang->QueryValueAttribute<u_int>( "MissionID", &m_MissionID );
        pGang->QueryIntAttribute( "LastMissID", &m_LastMissID );
        
        // load the combat boolean
        pGang->QueryValueAttribute<bool>( "Combat", &m_Combat );
        
        // load the auto recruit boolean
        pGang->QueryValueAttribute<bool>( "AutoRecruit", &m_AutoRecruit );
    }
    return true;
}
bool LoadStatsXML(TiXmlHandle hStats, int stats[], int statMods[], int tempStats[])
{
	TiXmlElement* pStats = hStats.ToElement();
	if (pStats == 0) return false;

	for (int i = 0; i < NUM_STATS; i++)
	{
		TiXmlElement* pStat = pStats->FirstChildElement(XMLifyString(sGirl::stat_names[i]));
		if (pStat)
		{
			int tempInt = 0;
			if (pStat->Attribute("Value"))	pStat->QueryIntAttribute("Value", &tempInt);

			int min = 0, max = 100;
			switch (i)
			{
			case STAT_AGE:
				if (tempInt > 99)		tempInt = 100;
				else if (tempInt > 80)		tempInt = 80;
				else if (tempInt < 18)		tempInt = 18;	// `J` Legal Note: 18 is the Legal Age of Majority for the USA where I live 
				break;
			case STAT_EXP:		max = 32000;	break;
			case STAT_LEVEL:	max = 255;		break;
			case STAT_PCFEAR:		case STAT_PCHATE:	case STAT_PCLOVE:	case STAT_MORALITY:
			case STAT_REFINEMENT:	case STAT_DIGNITY:	case STAT_LACTATION:
				min = -100;		break;
			default:	break;
			}
			if (tempInt < -1000)	tempInt = -1;	// test for null stats and set them to 0
			if (tempInt > max) tempInt = max;
			else if (tempInt < min) tempInt = min;
			stats[i] = tempInt;

			if (statMods)
			{
				tempInt = 0;
				if (pStat->Attribute("Mod"))	pStat->QueryIntAttribute("Mod", &tempInt);
				statMods[i] = tempInt;
			}
			if (tempStats)
			{
				tempInt = 0;
				if (pStat->Attribute("Temp"))	pStat->QueryIntAttribute("Temp", &tempInt);
				tempStats[i] = tempInt;
			}
		}
	}
	return true;
}
Exemple #14
0
int MetaConfig::reload()
{
	
	FILE *fp = fopen(fname.c_str(), "r");
	if(!fp){
		log(Warn, "reload file %s error", fname.c_str());
		return -1;
	}

	TiXmlDocument doc;
	doc.LoadFile(fp);

	TiXmlHandle docH( &doc );
	TiXmlHandle meta = docH.FirstChildElement( "conf" ).FirstChildElement( "servers" ).FirstChildElement("meta");
	if(meta.Element()){
		loadBool(&meta, "sync", bsync, false);
		TiXmlHandle daemon = meta.FirstChildElement("daemon");
		int ret = flushNodeSrvs(&daemon);
		return ret;
	}else{
		fclose(fp);
		return -1;
	}
}
//---------------------------------------------------------
int ofxXmlSettings::getNumAttributes(const string& tag, int which){
	vector<string> tokens = tokenize(tag,":");
	TiXmlHandle tagHandle = storedHandle;
	for (int x = 0; x < (int)tokens.size(); x++) {
		if (x == 0)
			tagHandle = tagHandle.ChildElement(tokens.at(x), which);
		else
			tagHandle = tagHandle.FirstChildElement(tokens.at(x));
	}

	if (tagHandle.ToElement()) {
		TiXmlElement* elem = tagHandle.ToElement();

		// Do stuff with the element here
		TiXmlAttribute* first = elem->FirstAttribute();
		if (first) {
			int count = 1;
			for (TiXmlAttribute* curr = first; curr != elem->LastAttribute(); curr = curr->Next())
				count++;
			return count;
		}
	}
	return 0;
}
//---------------------------------------------------------
bool ofXMLSettings::tagExists(string  tag, int which){
	
	vector<string> tokens = tokenize(tag,":");
	
	bool found = false;
		
	//grab the handle from the level we are at
	//normally this is the doc but could be a pushed node
	TiXmlHandle tagHandle = *storedHandle;
	
	if(which < 0) which = 0;
	
	for(int x=0;x<tokens.size();x++){
	
		//we only support multi tags
		//with same name at root level
		if(x > 0) which = 0;
			
		TiXmlHandle isRealHandle = tagHandle.ChildElement( tokens.at(x), which);
				
		//as soon as we find a tag that doesn't exist
		//we return false;
		if ( !isRealHandle.Node() ){
			found = false;
			break;
		}
		else{
			found = true;
			tagHandle = isRealHandle;
		}
	}

	tokens.clear();

	return found;
}
void TinyXmlConfigHADbd::loadServer(TiXmlHandle &serverH){
	//提取进程所需的数据库id配置
	TiXmlElement *id = serverH.FirstChildElement("default-ora-db-id").Element();
	if(id){
		defaultId = atoi(id->GetText());		
		log(Info, "get Oracle-dbid[%d]\n",  defaultId);		
	}
	id = serverH.FirstChildElement("dbnode_max_connect").Element();
	if(id){
		dbnode_max_connect = atoi(id->GetText());		
		log(Info, "get Oracle-dbnode_max_connect[%d]\n",  dbnode_max_connect);
	}
	else
	{
		dbnode_max_connect=100;
	}
	id = serverH.FirstChildElement("dbnode_time_out_mill").Element();
	if(id){
		dbnode_time_out_mill = atoi(id->GetText());		
		log(Info, "get Oracle-dbnode_time_out_mill[%d]\n",  dbnode_time_out_mill);
	}
	else
	{
		dbnode_time_out_mill=5000;
	}
	id = serverH.FirstChildElement("broker_uri").Element();
	if(id){
		_brokerURI = id->GetText();
		log(Info, "get Oracle-broker_uri[%s]\n",  _brokerURI.c_str());
	}
	else
	{
		_brokerURI.clear();
	}
	memcaches.clear();
	TiXmlElement *mc = serverH.FirstChildElement("memcache").Element();
	while(mc){
		
		std::string host = getStr(mc->FirstChildElement("host"));
		int port = atoi(getStr(mc->FirstChildElement("port")).data());

		memcaches.push_back(make_pair(host, port));
		mc = mc->NextSiblingElement("memcache");
	}

	TiXmlElement *webdbAllow = serverH.FirstChildElement("webdbAllows").FirstChildElement("webdbAllow").Element();
	webdbAllowIps.clear();
	while(webdbAllow){
		const char *ip = webdbAllow->Attribute("ip");

		webdbAllowIps.insert(ip);
		webdbAllow = webdbAllow->NextSiblingElement("webdbAllow");
	}

	TinyXmlServerConfigImp::loadServer(serverH);
}
std::vector<SDL_Surface*> ResourceCache::LoadTextures(
   const TiXmlHandle& hndl,
   const std::string& name,
   const Size size
)
{
   std::vector<SDL_Surface*> textures;

   for (auto elem = hndl.FirstChild(name).Element();
        elem;
        elem = elem->NextSiblingElement(name))
   {
      textures.push_back(LoadTexture(elem->GetText(), size));
   }
   return textures;
}
Exemple #19
0
bool CSmartPlaylist::Load(const CStdString &path)
{
  TiXmlElement *root = OpenAndReadName(path);
  if (!root)
    return false;

  // encoding:
  CStdString encoding;
  XMLUtils::GetEncoding(&m_xmlDoc, encoding);

  TiXmlHandle match = ((TiXmlHandle)root->FirstChild("match")).FirstChild();
  if (match.Node())
    m_matchAllRules = strcmpi(match.Node()->Value(), "all") == 0;
  // now the rules
  TiXmlElement *rule = root->FirstChildElement("rule");
  while (rule)
  {
    // format is:
    // <rule field="Genre" operator="contains">parameter</rule>
    const char *field = rule->Attribute("field");
    const char *oper = rule->Attribute("operator");
    TiXmlNode *parameter = rule->FirstChild();
    if (field && oper)
    { // valid rule
      CStdString utf8Parameter;
      if (parameter)
      {
        if (encoding.IsEmpty()) // utf8
          utf8Parameter = parameter->Value();
        else
          g_charsetConverter.stringCharsetToUtf8(encoding, parameter->Value(), utf8Parameter);
      }
      CSmartPlaylistRule rule;
      rule.TranslateStrings(field, oper, utf8Parameter.c_str());
      m_playlistRules.push_back(rule);
    }
    rule = rule->NextSiblingElement("rule");
  }
  // now any limits
  // format is <limit>25</limit>
  TiXmlHandle limit = ((TiXmlHandle)root->FirstChild("limit")).FirstChild();
  if (limit.Node())
    m_limit = atoi(limit.Node()->Value());
  // and order
  // format is <order direction="ascending">field</order>
  TiXmlElement *order = root->FirstChildElement("order");
  if (order && order->FirstChild())
  {
    const char *direction = order->Attribute("direction");
    if (direction)
      m_orderAscending = strcmpi(direction, "ascending") == 0;
    m_orderField = CSmartPlaylistRule::TranslateField(order->FirstChild()->Value());
  }
  return true;
}
bool LoadTraitsXML(TiXmlHandle hTraits, unsigned char& numTraits, sTrait* traits[], int tempTraits[])
{
	numTraits = 0;
	TiXmlElement* pTraits = hTraits.ToElement();
	if (pTraits == 0) return false;

	//this loop does not need UnXMLifyString, which is a bit of a hack currently
	//however, it's coupled more tightly to traits, and seems to do more processing
	sTrait* pTrait = g_Traits.GetTraitNum(0);
	while (pTrait)
	{
		TiXmlElement* pTraitElement = pTraits->FirstChildElement(XMLifyString(pTrait->m_Name));
		if (pTraitElement)
		{
			int tempInt = 0;
			traits[numTraits] = pTrait;
			if (tempTraits)
			{
				pTraitElement->QueryIntAttribute("Temp", &tempInt); tempTraits[numTraits] = tempInt; tempInt = 0;
			}
			++numTraits;
		}
		pTrait = pTrait->m_Next;
	}

#if 0
	//old loop, not sure which way is better
	//also, this loop method has not been tested
	for (TiXmlElement* pTrait = pTraits->FirstChildElement();
		pTrait != 0;
		pTrait = pTrait->NextSiblingElement())
	{
		std::string traitName = pTrait->ValueStr();
		if (traitName.empty() == false)
		{
			int tempInt = 0;
			traits[numTraits] = g_Traits.GetTrait(UnXMLifyString(traitName));
			if (tempTraits)
			{
				pTrait->QueryIntAttribute("Temp", &tempInt); tempTraits[numTraits] = tempInt; tempInt = 0;
			}
			++numTraits;
		}
	}
#endif
	return true;
}
Exemple #21
0
void 
StateLoader::LoadFunctionEnums(TiXmlHandle &handle, IGlobalState *state) {

	TiXmlElement *pElem;

	std::string name;
	std::string data = "";
	std::string functionName;

	pElem = handle.FirstChild().Element();
	for (; 0 != pElem; pElem = pElem->NextSiblingElement()) {

		TiXmlHandle methodHandle(pElem);
		pElem->QueryStringAttribute("function", &functionName);
		
		LoadEnums(methodHandle, functionName, state);
	}
}
bool cGoldBase::loadGoldXML( TiXmlHandle hGold )
{
    //load default values just in case
    reset();
    
    TiXmlElement* pGold = hGold.ToElement();
    
    if( pGold == nullptr )
    {
        return false;
    }
    
    pGold->QueryDoubleAttribute( "value", &m_value );
    pGold->QueryDoubleAttribute( "income", &m_income );
    pGold->QueryDoubleAttribute( "upkeep", &m_upkeep );
    pGold->QueryDoubleAttribute( "cash_in", &m_cash_in );
    pGold->QueryDoubleAttribute( "cash_out", &m_cash_out );
    return true;
}
bool LoadTrainingXML(TiXmlHandle hTrainings, int training[], int trainingMods[], int trainingTemps[])
{
	TiXmlElement* pTrainings = hTrainings.ToElement();
	if (pTrainings == 0)
	{
		for (int x = 0; x < NUM_TRAININGTYPES; ++x)	// `J` added to set missing trainings to 0
		{
			training[x] = 0;
			trainingMods[x] = 0;
			trainingTemps[x] = 0;
		}
		return false;
	}

	for (int x = 0; x < NUM_TRAININGTYPES; ++x)
	{
		TiXmlElement* pTraining = pTrainings->FirstChildElement(XMLifyString(trainingTypeNames[x]));
		
		if (pTraining)
		{
			int tempInt = 0;
			if (pTraining->Attribute("Train"))	pTraining->QueryIntAttribute("Train", &tempInt);
			if (tempInt < 0)	tempInt = 0; if (tempInt > 100)	tempInt = 100;
			training[x] = tempInt; 
			
			tempInt = 0;
			if (pTraining->Attribute("Mod"))	pTraining->QueryIntAttribute("Mod", &tempInt);
			trainingMods[x] = tempInt;

			tempInt = 0;
			if (pTraining->Attribute("Temp"))	pTraining->QueryIntAttribute("Temp", &tempInt);
			trainingTemps[x] = tempInt;
		}
		else
		{
			training[x] = 0;
			trainingMods[x] = 0;
			trainingTemps[x] = 0;
		}
	}
	return true;
}
Exemple #24
0
bool cRivalManager::LoadRivalsXML(TiXmlHandle hRivalManager)
{
	Free();		// everything should be init even if we failed to load an XML element
	TiXmlElement* pRivalManager = hRivalManager.ToElement();
	if (pRivalManager == 0) return false;

	string message = "";
	m_NumRivals = 0;
	TiXmlElement* pRivals = pRivalManager->FirstChildElement("Rivals");
	if (pRivals)
	{
		for (TiXmlElement* pRival = pRivals->FirstChildElement("Rival"); pRival != 0; pRival = pRival->NextSiblingElement("Rival"))
		{
			cRival* current = new cRival();

			if (pRival->Attribute("Name"))
			{
				current->m_Name = pRival->Attribute("Name");
			}
			pRival->QueryIntAttribute("Power", &current->m_Power);
			pRival->QueryValueAttribute<long>("BribeRate", &current->m_BribeRate);
			pRival->QueryIntAttribute("BusinessesExtort", &current->m_BusinessesExtort);
			pRival->QueryValueAttribute<long>("Gold", &current->m_Gold);
			pRival->QueryIntAttribute("NumBars", &current->m_NumBars);
			pRival->QueryIntAttribute("NumBrothels", &current->m_NumBrothels);
			pRival->QueryIntAttribute("NumGamblingHalls", &current->m_NumGamblingHalls);
			pRival->QueryIntAttribute("NumGirls", &current->m_NumGirls);
			pRival->QueryIntAttribute("NumGangs", &current->m_NumGangs);

			// `J` cleanup rival power for .06.01.17
			if (current->m_Power > 50) current->m_Power = max(0, current->m_NumBrothels * 5) + max(0, current->m_NumGamblingHalls * 2) + max(0, current->m_NumBars * 1);

			message = "loaded rival: ";
			message += current->m_Name;
			g_LogFile.write(message);

			AddRival(current);
		}
	}
	return true;
}
Exemple #25
0
BOOL CCrashInfoReader::AddFilesToCrashDescriptionXML(std::vector<FileItem> FilesToAdd)
{
  strconv_t strconv;

  TiXmlDocument doc;
  
  CString sFileName = g_CrashInfo.m_Reports[0].m_sErrorReportDirName + _T("\\crashrpt.xml");
  bool bLoad = doc.LoadFile(strconv.t2a(sFileName.GetBuffer(0)));
  if(!bLoad)
    return FALSE;

  TiXmlNode* root = doc.FirstChild("CrashRpt");
  if(!root)
    return FALSE;
  
  TiXmlHandle hFileItems = root->FirstChild("FileList");
  if(hFileItems.ToElement()==NULL)
  {
    hFileItems = new TiXmlElement("FileList");
    root->LinkEndChild(hFileItems.ToNode());
  }
  
  unsigned i;
  for(i=0; i<FilesToAdd.size(); i++)
  {    
    TiXmlHandle hFileItem = new TiXmlElement("FileItem");
    hFileItem.ToElement()->SetAttribute("name", strconv.t2utf8(FilesToAdd[i].m_sDestFile));
    hFileItem.ToElement()->SetAttribute("description", strconv.t2utf8(FilesToAdd[i].m_sDesc));
    hFileItems.ToElement()->LinkEndChild(hFileItem.ToNode());              

    m_Reports[0].m_FileItems[FilesToAdd[i].m_sDestFile] = FilesToAdd[i];
  }
  
  bool bSave = doc.SaveFile(); 
  if(!bSave)
    return FALSE;
  return TRUE;
}
Exemple #26
0
bool cCentreManager::LoadDataXML(TiXmlHandle hBrothelManager)
{
	Free();//everything should be init even if we failed to load an XML element
	//watch out, this frees dungeon and rivals too

	TiXmlElement* pBrothelManager = hBrothelManager.ToElement();
	if (pBrothelManager == 0)
	{
		return false;
	}

	string message = "";
	//         ...................................................
	message = "***************** Loading centre ****************";
	g_LogFile.write(message);
	m_NumCentres = 0;
	TiXmlElement* pBrothels = pBrothelManager->FirstChildElement("Centres");
	if (pBrothels)
	{
		for (TiXmlElement* pBrothel = pBrothels->FirstChildElement("Centre");
			pBrothel != 0;
			pBrothel = pBrothel->NextSiblingElement("Centre"))
		{
			sCentre* current = new sCentre();
			bool success = current->LoadCentreXML(TiXmlHandle(pBrothel));
			if (success == true)
			{
				AddBrothel(current);
			}
			else
			{
				delete current;
				continue;
			}

		} // load a centre
	}
	return true;
}
Exemple #27
0
bool CppCheck::DoCppCheckParseXMLv1(TiXmlHandle& Handle)
{
    bool ErrorsPresent = false;

    for (const TiXmlElement* Error = Handle.FirstChildElement("error").ToElement(); Error;
            Error = Error->NextSiblingElement("error"))
    {
        wxString File;
        if (const char* FileValue = Error->Attribute("file"))
            File = wxString::FromAscii(FileValue);
        wxString Line;
        if (const char* LineValue = Error->Attribute("line"))
            Line = wxString::FromAscii(LineValue);
        wxString Id;
        if (const char* IdValue = Error->Attribute("id"))
            Id = wxString::FromAscii(IdValue);
        wxString Severity;
        if (const char* SeverityValue = Error->Attribute("severity"))
            Severity = wxString::FromAscii(SeverityValue);
        wxString Message;
        if (const char* MessageValue = Error->Attribute("msg"))
            Message = wxString::FromAscii(MessageValue);
        const wxString FullMessage = Id + _T(" : ") + Severity + _T(" : ") + Message;

        if (!File.IsEmpty() && !Line.IsEmpty() && !FullMessage.IsEmpty())
        {
            wxArrayString Arr;
            Arr.Add(File);
            Arr.Add(Line);
            Arr.Add(FullMessage);
            m_ListLog->Append(Arr);
            ErrorsPresent = true;
        }
        else if (!Message.IsEmpty())
            AppendToLog(Message); // might be something important like config not found...
    }

    return ErrorsPresent;
}
bool LoadInventoryXML(TiXmlHandle hInventory, sInventoryItem* items[], int& numItems, unsigned char isEquipped[], int quantities[])
{
	numItems = 0;
	TiXmlElement* pInventory = hInventory.ToElement();
	if (pInventory == 0)	return false;

	TiXmlElement* pItems = pInventory->FirstChildElement("Items");
	if (pItems)
	{
		for (TiXmlElement* pItem = pItems->FirstChildElement("Item"); pItem != 0; pItem = pItem->NextSiblingElement("Item"))
		{
			if (pItem->Attribute("Name"))
			{
				sInventoryItem* tempItem = g_InvManager.GetItem(pItem->Attribute("Name"));
				if (tempItem)
				{
					items[numItems] = tempItem;

					if (isEquipped)
					{
						int tempInt = 0;
						if (pItem->Attribute("isEquipped"))	pItem->QueryIntAttribute("isEquipped", &tempInt);
						isEquipped[numItems] = tempInt;
					}

					if (quantities)
					{
						int tempInt = 1;
						if (pItem->Attribute("quantity"))	pItem->QueryIntAttribute("quantity", &tempInt);
						quantities[numItems] = tempInt;
					}
					++numItems;
				}
			}
		}
	}
	return true;
}
Exemple #29
0
int keyset_load_key(TiXmlHandle node, unsigned char* key, unsigned int size, int* valid)
{
	TiXmlElement* elem = node.ToElement();

	if (valid)
		*valid = 0;

	if (!elem)
		return 0;

	const char* text = elem->GetText();
	unsigned int textlen = strlen(text);

	int status = keyset_parse_key(text, textlen, key, size, valid);

	if (status == KEY_ERR_LEN_MISMATCH)
	{
		fprintf(stderr, "Error size mismatch for key \"%s/%s\"\n", elem->Parent()->Value(), elem->Value());
		return 0;
	}
	
	return 1;
}
Exemple #30
0
void 
StateLoader::LoadEnums(TiXmlHandle &hRoot, std::string functionName, IGlobalState *state)
{
	std::string name = "";
	std::string valueString = "";
	TiXmlElement *pElem;

	TiXmlHandle handle(hRoot.FirstChild("enums").Element());

	pElem = handle.FirstChild().Element();
	for (; 0 != pElem; pElem = pElem->NextSiblingElement()) {

		int value, length = 1;
		pElem->QueryStringAttribute("name", &name);
		pElem->QueryStringAttribute("value", &valueString);
		if (pElem->QueryIntAttribute("length", &length) != TIXML_SUCCESS){
			length = 1;
		}
		value = (int)strtol(valueString.c_str(), NULL, 0);

		state->addStateEnum(name, functionName, value, length);
	}
}