示例#1
0
文件: MainDlg.cpp 项目: doo/CrashRpt
void CMainDlg::AddUserInfoToCrashDescriptorXML(CString sEmail, CString sDesc)
{ 
  strconv_t strconv;

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

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

  // Write user e-mail

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

  LPCSTR lpszEmail = strconv.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);

  LPCSTR lpszDesc = strconv.t2a(sDesc.GetBuffer(0));
  TiXmlText* desc_text = new TiXmlText(lpszDesc);
  desc->LinkEndChild(desc_text);              

  doc.SaveFile();        
}
示例#2
0
void XMLConfiguration::set_value(const string& section, const string& object, const string& value)
{
	bool section_found = false;
	bool object_found = false;
	
	TiXmlNode* child = 0;
	
	TiXmlNode* nephew = 0;
	
	if(m_document->NoChildren()==false)
	{
		
		while((!section_found) && ( child = m_document->IterateChildren( child ) ))
		{
			if(string(child->Value())==section)
			{
				section_found = true;
			}
		}
	}
		
	if(section_found == false)
	{
		LOG_INFO("XMLConfiguration: no section "<<section<<" found, creating.");
		child = new TiXmlElement( section.c_str() );
		m_document->LinkEndChild( child );
	}
	
	if(child->NoChildren()==false)
	{
		
		while((!object_found) &&( nephew = child->IterateChildren( nephew ) ))
		{
			if(string(nephew->Value())==object)
			{
				object_found = true;
			}
		}
	}
	
	if(object_found == false)
	{
		LOG_INFO("XMLConfiguration: no object "<<section<<"/"<<object<<" found, creating.");
		nephew = new TiXmlElement( object.c_str() );
		child->LinkEndChild( nephew );
	}
	
	nephew->Clear();
	
	TiXmlText* text_element = new TiXmlText( value.c_str() );
	nephew->LinkEndChild( text_element );
	
}
示例#3
0
文件: MainDlg.cpp 项目: doo/CrashRpt
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);
}
示例#4
0
void WriteToXml(string& strXml, vector<bool>& vecType,string& FileName)
{
	COriFileOperate oriFile(FileName);
	size_t nVecSize = vecType.size();
	if (strXml.find("chinese_simple") != -1)
	{
		for (size_t i=1;i<nVecSize;++i)
		{
			vecType[i] = false;
		}
	}
	char* szNumOrStrInfo = new char[nVecSize+1];
	for (size_t i = 0; i < nVecSize; i++)
	{
		if (vecType[i])
		{
			szNumOrStrInfo[i] = 'n';
		}
		else
		{
			szNumOrStrInfo[i] = 's';
		}
	}
	szNumOrStrInfo[nVecSize] = '\0';
	TiXmlDocument* pXmlDoc = new TiXmlDocument;
	pXmlDoc->InsertEndChild(TiXmlElement("config"));
	TiXmlNode* pXmlNode = pXmlDoc->FirstChild("config");
	pXmlNode->InsertEndChild(TiXmlElement("TableType"));
	TiXmlElement* pXmlElem = pXmlNode->FirstChildElement("TableType");
	pXmlElem->InsertEndChild(TiXmlText("S"));
	string str = szNumOrStrInfo;
	string str1 = oriFile.GetDataByRowCol(0,0);
	transform(str1.begin(),str1.end(),str1.begin(),toupper);
	for(uint32 i=1;i<=str.size();i++)
	{
		TiXmlElement* cxn = new TiXmlElement("Col");
		pXmlNode->LinkEndChild(cxn);
	//	cxn->SetAttribute("ColNum",i);
		if(str1!="NOTE:")
		{
			cxn->SetAttribute("Name",oriFile.GetDataByRowCol(0,i-1).c_str());
		}
		else
		{
			cxn->SetAttribute("Name",oriFile.GetDataByRowCol(1,i-1).c_str());
		}
		string ss;
		stringstream temp;
		temp<<szNumOrStrInfo[i-1];
		temp>>ss;
		cxn->SetAttribute("Type",ss);
	}

	pXmlDoc->SaveFile(strXml);

	delete pXmlDoc;
	pXmlDoc = NULL;
	delete[] szNumOrStrInfo;
	szNumOrStrInfo = NULL;
}
示例#5
0
/**
 * Transform a StringNode to a XML node.
 *
 * @param node		A settings tree node representing a string node.
 * @param parent	The parent node of the XML document.
 */
Void XmlSettingsTree::settingsTreeToXml( StringNode& node, TiXmlNode& parent ) {
	TiXmlElement* 	element	= new TiXmlElement( XMLSETTINGSTREE_STRING_ELEMENT );
	TiXmlText* 		text 	= new TiXmlText( node.getValue().c_str() );

	element->LinkEndChild( text );
	parent.LinkEndChild( element );
}
示例#6
0
/**
 * Transform a IntegerNode to a XML node.
 *
 * @param node		A settings tree node representing a integer node.
 * @param parent	The parent node of the XML document.
 */
 Void XmlSettingsTree::settingsTreeToXml( IntegerNode& node, TiXmlNode& parent ) {
	TiXmlElement* 	element	= new TiXmlElement( XMLSETTINGSTREE_INTEGER_ELEMENT );
	TiXmlText* 		text 	= new TiXmlText( TextUtils::doubleToString( node.getValue(), 0 ).c_str() );

	element->LinkEndChild( text );
	parent.LinkEndChild( element );
}
示例#7
0
  //----------------------------------------------------------------------------
  bool XmlConfig::setParameter( const std::string& key,
                                const std::string& val,
                                const std::string& type )
  {
    if( !_config )
      return false;

    std::cout << "setParameter(key = " << key
                         << ", val = " << val
                         << ", type = " << type
                         << ")"
                         << std::endl;

    //resolve parts of identifier (Renderer:FeatureX) and find in config
    std::string valname;
    TiXmlNode* container = parseIdentifier(key, valname, true);

    if( key.length() > valname.length() + 1 )
    {
      std::string component_name =
        key.substr(0, key.length() - valname.length() - 1);
      Configurable* comp = findComponent(component_name);
      if( !comp )
        LOG_ERROR("No such component: " << component_name);
      else
        comp->setParameter(valname, val, type);
    }

    //check if exists
    TiXmlNode* node = container->FirstChild(valname);
    TiXmlElement* arg = 0;
    if( node )
    {
      arg = node->ToElement();

      //check if it matches
      int res = checkTypeMatch(key, arg, type);
      if(res == 1)
        arg->SetAttribute("type", type);
      else if(res == 0)
        return false;

    }
    else
    {
      //create new one
      arg = new TiXmlElement( valname );
      container->LinkEndChild(arg);
      arg->SetAttribute("type", type);
    }

    arg->SetAttribute("val", val);

    _dirty_write = true;

    saveFile(); // TODO check if multiple variables changed within small
                //      time window

    return true;
  }
示例#8
0
void ArchiveTemplate::ToXml(TiXmlNode& node)
{
	FakeUtf8String strName = m_strName;
	FakeUtf8String strParams = m_strParams;
	FakeUtf8String strConfig = m_strConfig;

	FakeUtf8String strFormatUID = GUID2STR(m_uidFormat);
	FakeUtf8String strPluginUID = GUID2STR(m_uidPlugin);
	FakeUtf8String strModuleUID = GUID2STR(m_uidModule);

	node.ToElement()->SetAttribute("name", strName);

	//нечего мусорить в xml

	if ( !strParams.IsEmpty() )
	{
		TiXmlElement* xmlParams = new TiXmlElement("params");

		xmlParams->LinkEndChild(new TiXmlText(strParams));
		node.LinkEndChild(xmlParams);
	}

	if ( !strConfig.IsEmpty() )
	{
		TiXmlElement* xmlConfig = new TiXmlElement("config");

		xmlConfig->LinkEndChild(new TiXmlText(strConfig));
		node.LinkEndChild(xmlConfig);
	}

	TiXmlElement* xmlFormatUID = new TiXmlElement("fid");

	xmlFormatUID->LinkEndChild(new TiXmlText(strFormatUID));
	node.LinkEndChild(xmlFormatUID);

	TiXmlElement* xmlPluginUID = new TiXmlElement("pid");

	xmlPluginUID->LinkEndChild(new TiXmlText(strPluginUID));
	node.LinkEndChild(xmlPluginUID);

	TiXmlElement* xmlModuleUID = new TiXmlElement("mid");
	
	xmlModuleUID->LinkEndChild(new TiXmlText(strModuleUID));
	node.LinkEndChild(xmlModuleUID);
}
示例#9
0
/**
 * Transform a ArrayNode to a XML node.
 *
 * @param node		A settings tree node representing an array node.
 * @param parent	The parent node of the XML document.
 */
Void XmlSettingsTree::settingsTreeToXml( ArrayNode& node, TiXmlNode& parent ) {
	TiXmlElement* element = new TiXmlElement( XMLSETTINGSTREE_ARRAY_ELEMENT );
	
	for( Int i = 0; i < node.countChildren(); i++ ) {
		settingsTreeToXml( node[i], *element);
	}

	parent.LinkEndChild( element );
}
示例#10
0
/**
 * Transform a BooleanNode to a XML node.
 *
 * @param node		A settings tree node representing a boolean node.
 * @param parent	The parent node of the XML document.
 */
Void XmlSettingsTree::settingsTreeToXml( BooleanNode& node, TiXmlNode& parent ) {
	TiXmlElement* element;

	if( node.getValue() ) {
		element	= new TiXmlElement( XMLSETTINGSTREE_BOOLEANTRUE_ELEMENT );
	} else {
		element	= new TiXmlElement( XMLSETTINGSTREE_BOOLEANFALSE_ELEMENT );
	}

	parent.LinkEndChild( element );
}
示例#11
0
void CXmlConfig::Set(const char* szParElemName,const char* szChildElemName, const char* szElemTexName)
{
	vector<const char*> vecParElemNames;
	vecParElemNames.push_back( szParElemName );
	TiXmlNode *pParentNode = this->GetNode(vecParElemNames, false);

	TiXmlElement *pSetElement  = new TiXmlElement(szChildElemName);
	TiXmlText	 *pElementText = new TiXmlText(szElemTexName);
	pSetElement->LinkEndChild(pElementText);
	pParentNode->LinkEndChild(pSetElement);
}
示例#12
0
void CXmlConfig::AttribSet(const char* szParElemName,const char* szChildElemName)
{
	vector<const char*> vecParElemNames;
	vecParElemNames.push_back( szParElemName );
	TiXmlNode *pParentNode = this->GetNode(vecParElemNames, false);
	if( pParentNode == NULL )
		pParentNode = m_pRoot;

	TiXmlElement *pSetElement = new TiXmlElement(szChildElemName);
	pParentNode->LinkEndChild(pSetElement);
}
示例#13
0
TiXmlNode* WriteXmlNode(const std::string& tag, const std::string& data, bool cdata)
{

    TiXmlNode* node = new TiXmlElement(tag);
    TiXmlText* text = new TiXmlText(data);
    text->SetCDATA(cdata);

    node->LinkEndChild(text);

    return node;

}
示例#14
0
  int tixmldocument_write(lua_State *L) {
    TiXmlDocument *xmldoc;
    TiXmlDocument_ud* xmldoc_userdata = (TiXmlDocument_ud *) luaL_checkudata(L, 1, "TiXmlDocument");
    xmldoc = xmldoc_userdata->xmldoc;
    const char *path = luaL_checkstring(L, 2); // path
    const char *value = luaL_checkstring(L, 3); // new value

    lua_pop(L, 3);

    char *attr_name;
    TiXmlNode *node = find_node(path, xmldoc->RootElement(), &attr_name);

    if (node) {
      if (attr_name) {
	if (node->Type() == TiXmlNode::ELEMENT) {
	  TiXmlElement *elt_node = dynamic_cast<TiXmlElement *>(node);

	  if (elt_node->Attribute(attr_name)) {
	    elt_node->SetAttribute(attr_name, value);
	    delete attr_name;
	    lua_pushboolean(L, 1);
	    return 1;
	  }
	}
	luaL_error(L, "invalid attribute: %s", attr_name);
	delete attr_name;
	return 0;
      } else {
	TiXmlNode *n = node->FirstChild();
	if (n) {
	  if (n->Type()==TiXmlNode::TEXT) {
	    n->SetValue(value);
	  } else {
	    return luaL_error(L, "%s does not point to a text node", path);
	  }
	} else {
	  // create the text child
	  TiXmlText *new_text_node = new TiXmlText(value);
	  // and add it
	  node->LinkEndChild(new_text_node);
	}
      }

      lua_pushboolean(L, 1);
      return 1;
    } else {
      return luaL_error(L, "path not found: %s", path);
    }
  }
示例#15
0
BOOL CCrashInfoReader::AddUserInfoToCrashDescriptionXML(CString sEmail, CString sDesc)
{ 
  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;

  // Write user e-mail

  TiXmlElement* email = new TiXmlElement("UserEmail");
  root->LinkEndChild(email);
  
  TiXmlText* email_text = new TiXmlText(strconv.t2utf8(sEmail));
  email->LinkEndChild(email_text);              

  // Write problem description

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

  TiXmlText* desc_text = new TiXmlText(strconv.t2utf8(sDesc));
  desc->LinkEndChild(desc_text);              

  bool bSave = doc.SaveFile(); 
  if(!bSave)
    return FALSE;
  return TRUE;
}
示例#16
0
bool Parameter::Write2XML(TiXmlNode& root)
{
	TiXmlElement *elem=NULL;
	if (Type==Const)
	{
		elem = new TiXmlElement("Parameter");
		elem->SetAttribute("Type","Const");
	}
	else elem = root.ToElement();
	if (elem==NULL) return false;
	elem->SetAttribute("name",sName.c_str());
	elem->SetAttribute("Sweep",bSweep);
	elem->SetDoubleAttribute("value",dValue);
	if (Type==Const) root.LinkEndChild(elem);
	return true;
}
示例#17
0
void CXmlConfig::AttribSet(const vector<const char*>& szParElemNames, const char* szChildElemName, const vector<string>& vecAttribValueName, const vector<string>& vecAttribValueValue)
{
	TiXmlNode *pParentNode = this->GetNode(szParElemNames, false);
	if( pParentNode == NULL )
		pParentNode = m_pRoot;

	TiXmlElement *pSetElement = new TiXmlElement(szChildElemName);
	pParentNode->LinkEndChild(pSetElement);

	size_t size = vecAttribValueName.size();
	for (size_t i = 0; i < size; ++i )
	{
		string name  = vecAttribValueName[i];
		string value = vecAttribValueValue[i];
		pSetElement->SetAttribute(name.c_str(), value.c_str());
	}
}
示例#18
0
/**
 * Transform a DictionaryNode to a XML node.
 *
 * @param node		A settings tree node representing a dictionary node.
 * @param parent	The parent node of the XML document.
 */
Void XmlSettingsTree::settingsTreeToXml( DictionaryNode& node, TiXmlNode& parent ) {
	TiXmlElement* 	element 	= new TiXmlElement( XMLSETTINGSTREE_DICTIONARY_ELEMENT );
	TiXmlElement* 	keyElement 	= NULL;
	
	for( node.beginChild(); node.hasMoreChildren(); node.nextChild() ) {
		keyElement 		= new TiXmlElement( XMLSETTINGSTREE_KEY_ELEMENT );
		const String& key = node.nextChildKey();
		TiXmlText* text = new TiXmlText( key.c_str() );
		
		keyElement->LinkEndChild( text );
		element->LinkEndChild( keyElement );
	
		settingsTreeToXml( node.nextChildValue(), *element );
	}

	parent.LinkEndChild( element );
}
    void GD_EXTENSION_API InsertElementIntoAnother(const std::string &refNameOfElementToAdd, const std::string &refNameOfParentElement, const std::string &refNameOfNextElement, RuntimeScene &scene)
    {
        TiXmlNode *parentEle = RefManager::GetInstance(&scene)->GetRef(refNameOfParentElement);
        TiXmlNode *nextEle = RefManager::GetInstance(&scene)->GetRef(refNameOfNextElement);
        TiXmlNode *toBeAddedEle = RefManager::GetInstance(&scene)->GetRef(refNameOfElementToAdd);

        if(!nextEle || nextEle->Parent() != parentEle)
        {
            parentEle->LinkEndChild(toBeAddedEle);
        }
        else
        {
            TiXmlNode *insertedEle = 0;
            insertedEle = parentEle->InsertBeforeChild(nextEle, *toBeAddedEle);
            RefManager::GetInstance(&scene)->SetRef(refNameOfElementToAdd, insertedEle);
        }
    }
示例#20
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;
}
示例#21
0
    void GD_EXTENSION_API InsertElementIntoAnother(const gd::String &refNameOfElementToAdd, const gd::String &refNameOfParentElement, const gd::String &refNameOfNextElement, RuntimeScene &scene)
    {
        TiXmlNode *parentEle = RefManager::Get(&scene)->GetRef(refNameOfParentElement);
        TiXmlNode *nextEle = RefManager::Get(&scene)->GetRef(refNameOfNextElement);
        TiXmlNode *toBeAddedEle = RefManager::Get(&scene)->GetRef(refNameOfElementToAdd);

        if ( parentEle == NULL || toBeAddedEle == NULL )
            return; //These element cannot be invalid
        else
        {
            if(!nextEle || nextEle->Parent() != parentEle)
            {
                parentEle->LinkEndChild(toBeAddedEle);
            }
            else
            {
                TiXmlNode *insertedEle = 0;
                insertedEle = parentEle->InsertBeforeChild(nextEle, *toBeAddedEle);
                RefManager::Get(&scene)->SetRef(refNameOfElementToAdd, insertedEle);
            }

        }
    }
示例#22
0
void CXmlConfig::AttribSet(const char* szParElemName1,const char* szParElemName2, size_t parElemName2Index, const char* szChildElemName, const vector<string>& vecAttribValueName, const vector<string>& vecAttribValueValue)
{
	vector<const char*> vecParElemNames;
	vecParElemNames.push_back( szParElemName1 );
	vecParElemNames.push_back( szParElemName2 );
	TiXmlNode *pParentNode = this->GetNode(vecParElemNames, false);
	if( pParentNode == NULL )
		pParentNode = m_pRoot;

	for ( size_t i = 0; i< parElemName2Index; ++i )
		pParentNode = pParentNode->NextSibling(szParElemName2);

	TiXmlElement *pSetElement = new TiXmlElement(szChildElemName);
	pParentNode->LinkEndChild(pSetElement);

	size_t size = vecAttribValueName.size();
	for (size_t i = 0; i < size; ++i )
	{
		string name  = vecAttribValueName[i];
		string value = vecAttribValueValue[i];
		pSetElement->SetAttribute(name.c_str(), value.c_str());
	}
}
示例#23
0
bool CSettings::Save()
{
	// Are we not flagged as open?
	if(!m_bOpen)
		return false;

	// Are we not flagged as allowed to save the file?
	if(!m_bSave)
		return false;

	// Loop through all values
	for(std::map<String, SettingsValue *>::iterator iter = m_values.begin(); iter != m_values.end(); iter++)
	{
		// Get the setting pointer
		SettingsValue * setting = iter->second;

		// Find all nodes for this value
		bool bFoundNode = false;

		for(TiXmlNode * pNode = m_XMLDocument.RootElement()->FirstChildElement(iter->first.Get()); pNode; pNode = pNode->NextSibling())
		{
			// Is this not an element node?
			if(pNode->Type() != TiXmlNode::ELEMENT)
				continue;

			// Is this not the node we are looking for?
			if(iter->first.Compare(pNode->Value()))
				continue;

			// Is this a list node?
			if(setting->IsList())
			{
				// Remove the node
				m_XMLDocument.RootElement()->RemoveChild(pNode);
			}
			else
			{
				// Clear the node
				pNode->Clear();

				// Get the node value
				String strValue = GetEx(iter->first);

				// Create a new node value
				TiXmlText * pNewNodeValue = new TiXmlText(strValue.Get());

				// Add the new node value to the new node
				pNode->LinkEndChild(pNewNodeValue);
			}

			// Flag as found a node
			bFoundNode = true;
			break;
		}

		// Is this a list value?
		if(setting->IsList())
		{
			// Loop through each list item
			for(std::list<String>::iterator iter2 = setting->listValue.begin(); iter2 != setting->listValue.end(); iter2++)
			{
				// Create a new node
				TiXmlElement * pNewNode = new TiXmlElement(iter->first.Get());

				// Create a new node value
				TiXmlText * pNewNodeValue = new TiXmlText((*iter2).Get());

				// Add the new node value to the new node
				pNewNode->LinkEndChild(pNewNodeValue);

				// Add the new node to the XML document
				m_XMLDocument.RootElement()->LinkEndChild(pNewNode);
			}
		}
		else
		{
			// Do we need to create a new node?
			if(!bFoundNode)
			{
				// Create a new node
				TiXmlElement * pNewNode = new TiXmlElement(iter->first.Get());

				// Get the node value
				String strValue = GetEx(iter->first);

				// Create a new node value
				TiXmlText * pNewNodeValue = new TiXmlText(strValue.Get());

				// Add the new node value to the new node
				pNewNode->LinkEndChild(pNewNodeValue);

				// Add the new node to the XML document
				m_XMLDocument.RootElement()->LinkEndChild(pNewNode);
			}
		}
	}

	// Save the XML document
	return m_XMLDocument.SaveFile();
}
示例#24
0
BOOL CCrashInfoReader::AddFilesToCrashReport(int nReport, std::vector<ERIFileItem> FilesToAdd)
{   
    strconv_t strconv;

    TiXmlDocument doc;

    CString sFileName = m_Reports[nReport].m_sErrorReportDirName + _T("\\crashrpt.xml");

    FILE* f = NULL; 
#if _MSC_VER<1400
    f = _tfopen(sFileName, _T("rb"));
#else
    _tfopen_s(&f, sFileName, _T("rb"));
#endif

    if(f==NULL)
    {    
        return FALSE;
    }

    bool bLoad = doc.LoadFile(f);  
    fclose(f);
    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++)
    { 
        if(m_Reports[0].m_FileItems.find(FilesToAdd[i].m_sDestFile)!=m_Reports[0].m_FileItems.end())
            continue; // Such file item already exists, skip

        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));
		if(FilesToAdd[i].m_bAllowDelete)
			hFileItem.ToElement()->SetAttribute("optional", "1");
        hFileItems.ToElement()->LinkEndChild(hFileItem.ToNode());              

        m_Reports[nReport].m_FileItems[FilesToAdd[i].m_sDestFile] = FilesToAdd[i];

		if(FilesToAdd[i].m_bMakeCopy)
		{
			CString sDestPath = m_Reports[nReport].m_sErrorReportDirName + _T("\\") + FilesToAdd[i].m_sDestFile;
			CopyFile(FilesToAdd[i].m_sSrcFile, sDestPath, TRUE);
			m_Reports[nReport].m_FileItems[FilesToAdd[i].m_sDestFile].m_sSrcFile = sDestPath;
		}
    }

#if _MSC_VER<1400
    f = _tfopen(sFileName, _T("w"));
#else
    _tfopen_s(&f, sFileName, _T("w"));
#endif

    if(f==NULL)
        return FALSE;

    bool bSave = doc.SaveFile(f); 
    if(!bSave)
        return FALSE;
    fclose(f);
    return TRUE;
}
示例#25
0
BOOL CCrashInfoReader::RemoveFilesFromCrashReport(int nReport, std::vector<CString> FilesToRemove)
{   
    strconv_t strconv;

    TiXmlDocument doc;

    CString sFileName = m_Reports[nReport].m_sErrorReportDirName + _T("\\crashrpt.xml");

    FILE* f = NULL; 
#if _MSC_VER<1400
    f = _tfopen(sFileName, _T("rb"));
#else
    _tfopen_s(&f, sFileName, _T("rb"));
#endif

    if(f==NULL)
    {    
        return FALSE;
    }

    bool bLoad = doc.LoadFile(f);  
    fclose(f);
    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<FilesToRemove.size(); i++)
    { 
		std::map<CString, ERIFileItem>::iterator it = 
			m_Reports[nReport].m_FileItems.find(FilesToRemove[i]);
		if(it==m_Reports[nReport].m_FileItems.end())
            continue; // Such file item name does not exists, skip

		strconv_t strconv;
		TiXmlHandle hElem = hFileItems.ToElement()->FirstChild(strconv.t2a(FilesToRemove[i]));
		if(hElem.ToElement()!=NULL)
			hFileItems.ToElement()->RemoveChild(hElem.ToElement());              
		        
		if(it->second.m_bMakeCopy)
		{
			Utility::RecycleFile(it->second.m_sSrcFile, TRUE);
		}

		m_Reports[nReport].m_FileItems.erase(it);
    }

#if _MSC_VER<1400
    f = _tfopen(sFileName, _T("w"));
#else
    _tfopen_s(&f, sFileName, _T("w"));
#endif

    if(f==NULL)
        return FALSE;

    bool bSave = doc.SaveFile(f); 
    if(!bSave)
        return FALSE;
    fclose(f);
    return TRUE;
}
示例#26
0
BOOL CCrashInfoReader::AddUserInfoToCrashDescriptionXML(CString sEmail, CString sDesc)
{ 
    strconv_t strconv;

    TiXmlDocument doc;

    CString sFileName = m_Reports[0].m_sErrorReportDirName + _T("\\crashrpt.xml");

    FILE* f = NULL; 
#if _MSC_VER<1400
    f = _tfopen(sFileName, _T("rb"));
#else
    _tfopen_s(&f, sFileName, _T("rb"));
#endif

    if(f==NULL)
        return FALSE;

    bool bLoad = doc.LoadFile(f);
    fclose(f);
    if(!bLoad)
    {    
        return FALSE;
    }

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

    // Write user e-mail

    TiXmlHandle hEmail = NULL;
	
	hEmail = root->FirstChild("UserEmail");
	if(hEmail.ToElement()==NULL)
	{
		hEmail = new TiXmlElement("UserEmail");
		root->LinkEndChild(hEmail.ToElement());		
	}
		
	TiXmlText* email_text = NULL;
	if(hEmail.FirstChild().ToText()!=NULL)
	{
		email_text = hEmail.FirstChild().ToText();
		email_text->SetValue(strconv.w2utf8(sEmail));
	}
	else
	{
		email_text = new TiXmlText(strconv.t2utf8(sEmail));
		hEmail.ToElement()->LinkEndChild(email_text);              
	}
	
    // Write problem description

    TiXmlHandle hDesc = NULL;
	
	hDesc = root->FirstChild("ProblemDescription");
	if(hDesc.ToElement()==NULL)
	{
		hDesc = new TiXmlElement("ProblemDescription");
		root->LinkEndChild(hDesc.ToElement());
	}

    TiXmlText* desc_text = NULL;
	if(hDesc.FirstChild().ToText()!=NULL)
	{
		desc_text = hDesc.FirstChild().ToText();
		desc_text->SetValue(strconv.w2utf8(sDesc));
	}
	else
	{
		desc_text = new TiXmlText(strconv.t2utf8(sDesc));
		hDesc.ToElement()->LinkEndChild(desc_text);              
	}

#if _MSC_VER<1400
    f = _tfopen(sFileName, _T("w"));
#else
    _tfopen_s(&f, sFileName, _T("w"));
#endif

    if(f==NULL)
        return FALSE;

    bool bSave = doc.SaveFile(f); 
    fclose(f);
    if(!bSave)
        return FALSE;
    return TRUE;
}
示例#27
0
void CAppManager::UpdateAppStat(const std::string& AppId)
{
  CStdString fileName = _P("special://profile/apps/apps.xml");
  CStdString strValue, currAppStr;
  CStdString tmp;
  CStdString appsPath = _P("special://home/apps/");
  CAppDescriptor::AppDescriptorsMap installedAppsDesc;

  GetInstalledAppsInternal(installedAppsDesc, appsPath, "", false);

  TiXmlDocument xmlDoc;
  TiXmlElement *pRootElement = NULL;
  TiXmlNode *pTempNode = NULL;
  bool fixDoc = true;

  CLog::Log(LOGINFO, "updating %s's information in apps.xml", AppId.c_str());

  if ( xmlDoc.LoadFile( fileName) )
  {
    pRootElement = xmlDoc.RootElement();
    if (pRootElement)
    {
      strValue = pRootElement->Value();
      if ( strValue == "apps")
      {
        fixDoc = false;
      }
    }
  }

  if (fixDoc)
  {
    if (pRootElement)
    {
      xmlDoc.RemoveChild(pRootElement);
    }
    else
    {
      pTempNode = xmlDoc.FirstChild();
      if (pTempNode > 0)
        xmlDoc.RemoveChild(pTempNode);
    }

    pRootElement = new TiXmlElement( "apps" );
    pRootElement->SetAttribute("version", "1.0");
    xmlDoc.LinkEndChild(pRootElement);
  }

  TiXmlNode *pAppNode = pRootElement->FirstChild("app");
  TiXmlNode *pOpenedCntNode = NULL, *pIdNode = NULL, *pLastOpenedDateNode = NULL;

  while (pAppNode > 0)
  {
    pIdNode = pAppNode->FirstChild("id");
    if (pIdNode && pIdNode->FirstChild())
    {
      currAppStr = pIdNode->FirstChild()->Value();
      if (currAppStr == AppId)
      {
        pLastOpenedDateNode = pAppNode->FirstChild("lastopeneddate");
        pOpenedCntNode = pAppNode->FirstChild("timesopened");
        if (pOpenedCntNode && pOpenedCntNode->FirstChild())
        {

          int openedCnt = atoi (pOpenedCntNode->FirstChild()->Value());
          openedCnt++;
          tmp = BOXEE::BXUtils::IntToString(openedCnt);

          pOpenedCntNode->FirstChild()->SetValue(tmp.c_str());
          //CLog::Log(LOGDEBUG,"    Found name: %s", strName.c_str());
        }
        else
        {
          if (pOpenedCntNode)
          {
            pAppNode->RemoveChild(pOpenedCntNode);
          }
          TiXmlElement * timesOpenedElement = new TiXmlElement( "timesopened" );
          TiXmlText * timesOpenedText = new TiXmlText( "1" );
          timesOpenedElement->LinkEndChild( timesOpenedText );
          pAppNode->LinkEndChild(timesOpenedElement);
        }
        if (pLastOpenedDateNode)
        {
          pAppNode->RemoveChild(pLastOpenedDateNode);
        }

        tmp = BOXEE::BXUtils::IntToString(std::time(NULL));
        TiXmlElement * lastOpenedElement = new TiXmlElement( "lastopeneddate" );
        TiXmlText * lastOpenedText = new TiXmlText(tmp.c_str());
        lastOpenedElement->LinkEndChild( lastOpenedText );
        pAppNode->LinkEndChild(lastOpenedElement);
      }

      CLog::Log(LOGDEBUG, "deleting %s from apps map\n", currAppStr.c_str());
      installedAppsDesc.erase(currAppStr);
    }
    pAppNode = pAppNode->NextSiblingElement("app");

  }

  tmp = BOXEE::BXUtils::IntToString(std::time(NULL));

  CAppDescriptor::AppDescriptorsMap::iterator it = installedAppsDesc.begin();
  for (; it != installedAppsDesc.end(); it++)
  {
    TiXmlElement * appElement = new TiXmlElement( "app" );
    pRootElement->LinkEndChild(appElement);

    TiXmlElement * appIdElement = new TiXmlElement( "id" );
    TiXmlText * appIdText = new TiXmlText(it->first);
    appIdElement->LinkEndChild( appIdText );
    appElement->LinkEndChild(appIdElement);

    TiXmlElement * timesOpenedElement = new TiXmlElement( "timesopened" );
    TiXmlText * timesOpenedText = new TiXmlText( "1" );
    timesOpenedElement->LinkEndChild( timesOpenedText );
    appElement->LinkEndChild(timesOpenedElement);

    TiXmlElement * lastOpenedElement = new TiXmlElement( "lastopeneddate" );
    TiXmlText * lastOpenedText = new TiXmlText(tmp.c_str());
    lastOpenedElement->LinkEndChild( lastOpenedText );
    appElement->LinkEndChild(lastOpenedElement);

    CLog::Log(LOGINFO, "adding %s to app.xml file\n", it->first.c_str());

  }

  xmlDoc.SaveFile();

  m_mapAppNameToStat.clear();
  pRootElement = xmlDoc.RootElement();
  pAppNode = pRootElement->FirstChild("app");

  CLog::Log(LOGDEBUG, "reading apps.xml file");
  // read the content of app.xml file
  while (pAppNode > 0)
  {
    pIdNode = pAppNode->FirstChild("id");
    currAppStr = pIdNode->FirstChild()->Value();
    pLastOpenedDateNode = pAppNode->FirstChild("lastopeneddate");
    pOpenedCntNode = pAppNode->FirstChild("timesopened");
    int lastOpenedTime = 1;
    int timesOpened = 1;
    if (pOpenedCntNode && pLastOpenedDateNode->FirstChild())
    {
      lastOpenedTime = BOXEE::BXUtils::StringToInt(pLastOpenedDateNode->FirstChild()->Value());
    }
    if (pOpenedCntNode && pOpenedCntNode->FirstChild())
    {
      timesOpened = BOXEE::BXUtils::StringToInt(pOpenedCntNode->FirstChild()->Value());
    }
    std::map<CStdString, int> statsMap;
    statsMap["lastopeneddate"] = lastOpenedTime;
    statsMap["timesopened"] = timesOpened;
    m_mapAppNameToStat[currAppStr] = statsMap;
    pAppNode = pAppNode->NextSiblingElement("app");
  }
}
// This method generates an XML file describing the crash
BOOL CErrorReportExporter::CreateCrashDescriptionXML(CErrorReportInfo& eri)
{
	BOOL bStatus = FALSE;
	ERIFileItem fi;
	CString sFileName = eri.GetErrorReportDirName() + _T("\\crashrpt.xml");
	CString sErrorMsg;
	strconv_t strconv;
	TiXmlDocument doc;
	FILE* f = NULL; 
	CString sNum;
	CString sCrashRptVer;
	CString sOSIs64Bit;
	CString sExceptionType;

	fi.m_bMakeCopy = false;
	fi.m_sDesc = _T("±ÀÀ£³ÌÐòÊôÐÔ¼¯");
	fi.m_sDestFile = _T("crashrpt.xml");
	fi.m_sSrcFile = sFileName;
	fi.m_sErrorStatus = sErrorMsg;  
	// Add this file to the list
	eri.AddFileItem(&fi);

	TiXmlNode* root = root = new TiXmlElement("CrashRpt");
	doc.LinkEndChild(root);  
	sCrashRptVer.Format(_T("%d"), CRASHRPT_VER);
	TiXmlHandle(root).ToElement()->SetAttribute("version", strconv.t2utf8(sCrashRptVer));

	TiXmlDeclaration * decl = new TiXmlDeclaration( "1.0", "UTF-8", "" );
	doc.InsertBeforeChild(root, *decl);
	
	AddElemToXML(_T("CrashGUID"), eri.GetCrashGUID(), root);
	AddElemToXML(_T("AppName"), eri.GetAppName(), root);
	AddElemToXML(_T("AppVersion"), eri.GetAppVersion(), root);  
	AddElemToXML(_T("ImageName"), eri.GetImageName(), root);
	AddElemToXML(_T("OperatingSystem"), eri.GetOSName(), root);


	sOSIs64Bit.Format(_T("%d"), eri.IsOS64Bit());
	AddElemToXML(_T("OSIs64Bit"), sOSIs64Bit, root);

	AddElemToXML(_T("GeoLocation"), eri.GetGeoLocation(), root);
	AddElemToXML(_T("SystemTimeUTC"), eri.GetSystemTimeUTC(), root);
		
	if(eri.GetExceptionAddress()!=0)
	{
		sNum.Format(_T("0x%I64x"), eri.GetExceptionAddress());
		AddElemToXML(_T("ExceptionAddress"), sNum, root);

		AddElemToXML(_T("ExceptionModule"), eri.GetExceptionModule(), root);

		sNum.Format(_T("0x%I64x"), eri.GetExceptionModuleBase());
		AddElemToXML(_T("ExceptionModuleBase"), sNum, root);

		AddElemToXML(_T("ExceptionModuleVersion"), eri.GetExceptionModuleVersion(), root);
	}

	sExceptionType.Format(_T("%d"), m_CrashInfo.m_nExceptionType);
	AddElemToXML(_T("ExceptionType"), sExceptionType, root);
	if(m_CrashInfo.m_nExceptionType==CR_SEH_EXCEPTION)
	{
		CString sExceptionCode;
		sExceptionCode.Format(_T("%d"), m_CrashInfo.m_dwExceptionCode);
		AddElemToXML(_T("ExceptionCode"), sExceptionCode, root);
	}
	else if(m_CrashInfo.m_nExceptionType==CR_CPP_SIGFPE)
	{
		CString sFPESubcode;
		sFPESubcode.Format(_T("%d"), m_CrashInfo.m_uFPESubcode);
		AddElemToXML(_T("FPESubcode"), sFPESubcode, root);
	}
	else if(m_CrashInfo.m_nExceptionType==CR_CPP_INVALID_PARAMETER)
	{
		AddElemToXML(_T("InvParamExpression"), m_CrashInfo.m_sInvParamExpr, root);
		AddElemToXML(_T("InvParamFunction"), m_CrashInfo.m_sInvParamFunction, root);
		AddElemToXML(_T("InvParamFile"), m_CrashInfo.m_sInvParamFile, root);

		CString sInvParamLine;
		sInvParamLine.Format(_T("%d"), m_CrashInfo.m_uInvParamLine);
		AddElemToXML(_T("InvParamLine"), sInvParamLine, root);
	}

	CString sGuiResources;
	sGuiResources.Format(_T("%d"), eri.GetGuiResourceCount());
	AddElemToXML(_T("GUIResourceCount"), sGuiResources, root);

	CString sProcessHandleCount;
	sProcessHandleCount.Format(_T("%d"), eri.GetProcessHandleCount());
	AddElemToXML(_T("OpenHandleCount"), sProcessHandleCount, root);

	AddElemToXML(_T("MemoryUsageKbytes"), eri.GetMemUsage(), root);

	if(eri.GetScreenshotInfo().m_bValid)
	{
		TiXmlHandle hScreenshotInfo = new TiXmlElement("ScreenshotInfo");
		root->LinkEndChild(hScreenshotInfo.ToNode());

		TiXmlHandle hVirtualScreen = new TiXmlElement("VirtualScreen");    

		sNum.Format(_T("%d"), eri.GetScreenshotInfo().m_rcVirtualScreen.left);
		hVirtualScreen.ToElement()->SetAttribute("left", strconv.t2utf8(sNum));

		sNum.Format(_T("%d"), eri.GetScreenshotInfo().m_rcVirtualScreen.top);
		hVirtualScreen.ToElement()->SetAttribute("top", strconv.t2utf8(sNum));

		sNum.Format(_T("%d"), eri.GetScreenshotInfo().m_rcVirtualScreen.Width());
		hVirtualScreen.ToElement()->SetAttribute("width", strconv.t2utf8(sNum));

		sNum.Format(_T("%d"), eri.GetScreenshotInfo().m_rcVirtualScreen.Height());
		hVirtualScreen.ToElement()->SetAttribute("height", strconv.t2utf8(sNum));

		hScreenshotInfo.ToNode()->LinkEndChild(hVirtualScreen.ToNode());

		TiXmlHandle hMonitors = new TiXmlElement("Monitors");
		hScreenshotInfo.ToElement()->LinkEndChild(hMonitors.ToNode());                  

		size_t i;
		for(i=0; i<eri.GetScreenshotInfo().m_aMonitors.size(); i++)
		{ 
			MonitorInfo& mi = eri.GetScreenshotInfo().m_aMonitors[i];      
			TiXmlHandle hMonitor = new TiXmlElement("Monitor");

			sNum.Format(_T("%d"), mi.m_rcMonitor.left);
			hMonitor.ToElement()->SetAttribute("left", strconv.t2utf8(sNum));

			sNum.Format(_T("%d"), mi.m_rcMonitor.top);
			hMonitor.ToElement()->SetAttribute("top", strconv.t2utf8(sNum));

			sNum.Format(_T("%d"), mi.m_rcMonitor.Width());
			hMonitor.ToElement()->SetAttribute("width", strconv.t2utf8(sNum));

			sNum.Format(_T("%d"), mi.m_rcMonitor.Height());
			hMonitor.ToElement()->SetAttribute("height", strconv.t2utf8(sNum));

			hMonitor.ToElement()->SetAttribute("file", strconv.t2utf8(Utility::GetFileName(mi.m_sFileName)));

			hMonitors.ToElement()->LinkEndChild(hMonitor.ToNode());                  
		}

		TiXmlHandle hWindows = new TiXmlElement("Windows");
		hScreenshotInfo.ToElement()->LinkEndChild(hWindows.ToNode());                  

		for(i=0; i<eri.GetScreenshotInfo().m_aWindows.size(); i++)
		{ 
			WindowInfo& wi = eri.GetScreenshotInfo().m_aWindows[i];      
			TiXmlHandle hWindow = new TiXmlElement("Window");

			sNum.Format(_T("%d"), wi.m_rcWnd.left);
			hWindow.ToElement()->SetAttribute("left", strconv.t2utf8(sNum));

			sNum.Format(_T("%d"), wi.m_rcWnd.top);
			hWindow.ToElement()->SetAttribute("top", strconv.t2utf8(sNum));

			sNum.Format(_T("%d"), wi.m_rcWnd.Width());
			hWindow.ToElement()->SetAttribute("width", strconv.t2utf8(sNum));

			sNum.Format(_T("%d"), wi.m_rcWnd.Height());
			hWindow.ToElement()->SetAttribute("height", strconv.t2utf8(sNum));

			hWindow.ToElement()->SetAttribute("title", strconv.t2utf8(wi.m_sTitle));

			hWindows.ToElement()->LinkEndChild(hWindow.ToNode());                  
		}
	}

	TiXmlHandle hCustomProps = new TiXmlElement("CustomProps");
	root->LinkEndChild(hCustomProps.ToNode());

	int i;
	for(i=0; i<eri.GetPropCount(); i++)
	{ 
		CString sName;
		CString sVal;
		eri.GetPropByIndex(i, sName, sVal);

		TiXmlHandle hProp = new TiXmlElement("Prop");

		hProp.ToElement()->SetAttribute("name", strconv.t2utf8(sName));
		hProp.ToElement()->SetAttribute("value", strconv.t2utf8(sVal));

		hCustomProps.ToElement()->LinkEndChild(hProp.ToNode());                  
	}

	TiXmlHandle hFileItems = new TiXmlElement("FileList");
	root->LinkEndChild(hFileItems.ToNode());

	for(i=0; i<eri.GetFileItemCount(); i++)
	{    
		ERIFileItem* rfi = eri.GetFileItemByIndex(i);
		TiXmlHandle hFileItem = new TiXmlElement("FileItem");

		hFileItem.ToElement()->SetAttribute("name", strconv.t2utf8(rfi->m_sDestFile));
		hFileItem.ToElement()->SetAttribute("description", strconv.t2utf8(rfi->m_sDesc));
		if(rfi->m_bAllowDelete)
			hFileItem.ToElement()->SetAttribute("optional", "1");
		if(!rfi->m_sErrorStatus.IsEmpty())
			hFileItem.ToElement()->SetAttribute("error", strconv.t2utf8(rfi->m_sErrorStatus));

		hFileItems.ToElement()->LinkEndChild(hFileItem.ToNode());                  
	}

#if _MSC_VER<1400
	f = _tfopen(sFileName, _T("w"));
#else
	_tfopen_s(&f, sFileName, _T("w"));
#endif

	if(f==NULL)
	{
		sErrorMsg = _T("Error opening file for writing");
		goto cleanup;
	}

	doc.useMicrosoftBOM = true;
	bool bSave = doc.SaveFile(f); 
	if(!bSave)
	{
		sErrorMsg = doc.ErrorDesc();
		goto cleanup;
	}

	fclose(f);
	f = NULL;

	bStatus = TRUE;

cleanup:

	if(f)
		fclose(f);

	if(!bStatus)
	{
		eri.GetFileItemByName(fi.m_sDestFile)->m_sErrorStatus = sErrorMsg;
	}

	return bStatus;
}
示例#29
0
// Process a notify event callback.
void ResourceInstance::notifyEventCallback(const UtlString* dialogHandle,
                                           const UtlString* content)
{
   OsSysLog::add(FAC_RLS, PRI_DEBUG,
                 "ResourceInstance::notifyEventCallback mInstanceName = '%s', content = '%s'",
                 mInstanceName.data(), content->data());
   // Set to true if we find publishable data.
   bool publish = false;

   // Set the subscription state to "active".
   mSubscriptionState = "active";

   // Save the content as text for the RFC 4662 resource list events.
   mContent.remove(0);
   mContent.append(*content);
   mContentPresent = TRUE;

   // Dissect the XML for each dialog event and store it in a map
   // so we can construct BroadWorks-style resource list events
   // (which have to have full state).

   // Initialize Tiny XML document object.
   TiXmlDocument xmlDialogEvent;
   TiXmlNode* dialog_info_node;
   if (
       // Load the XML into it.
       xmlDialogEvent.Parse(mContent.data()) &&
       // Find the top element, which should be a <dialog-info>.
       (dialog_info_node = xmlDialogEvent.FirstChild("dialog-info")) != NULL &&
       dialog_info_node->Type() == TiXmlNode::ELEMENT)
   {
      // Check the state attribute.
      const char* p = dialog_info_node->ToElement()->Attribute("state");
      if (p && strcmp(p, "full") == 0)
      {
         // If the state is "full", terminate all non-terminated dialogs.  (XECS-1668)
         terminateXmlDialogs();
         publish = true;
         OsSysLog::add(FAC_RLS, PRI_DEBUG,
                       "ResourceInstance::notifyEventCallback all non-terminated dialogs");
      }

      // Find all the <dialog> elements.
      for (TiXmlNode* dialog_node = 0;
           (dialog_node = dialog_info_node->IterateChildren("dialog",
                                                            dialog_node));
         )
      {
         if (dialog_node->Type() == TiXmlNode::ELEMENT)
         {
            TiXmlElement* dialog_element = dialog_node->ToElement();

            // Determine if the <dialog> is a bogus report of a NAT Keepalive
            // OPTIONS message, as reported by Polycom SPIP firmware 3.1.2.
            // (XTRN-425)  If so, ignore it.

#ifdef NAT_KEEPALIVE_DETECT
            const char* call_id_attr = dialog_element->Attribute("call-id");
            // Reject <dialog>s on the narrowest grounds, that is, only if the
            // call-id attribute is present and contains NAT_KEEPALIVE_SIGNATURE.
            const bool ok =
               !(call_id_attr &&
                 strstr(call_id_attr,
                        NAT_KEEPALIVE_SIGNATURE) != NULL);
#else
            const bool ok = true;
#endif
            if (ok)
            {
               // Now that we've got a <dialog> element, edit it to fit
               // into a consolidated event notice.
               publish = true;

               // Prepend the resource instance name to the 'id'
               // attribute, so it is unique within the <resource>.
               UtlString id(mInstanceName);
               // mInstanceName is guaranteed to not contain ';', because
               // it is a dialog handle that we generate by concatenating
               // the Call-Id and tags using ',' as a separator.  And ';'
               // may not appear in Call-Ids or tags.
               id.append(";");
               id.append(dialog_element->Attribute("id"));
               dialog_element->SetAttribute("id", id.data());

               // Prepare the display name, so we can insert it easily
               // when we generate consolidated events.
               // Find or add the <local> element.
               TiXmlNode* local = dialog_element->FirstChild("local");
               if (!local)
               {
                  local = dialog_element->LinkEndChild(new TiXmlElement("local"));
               }
               // Find or add the <local><identity> element.
               TiXmlNode* identity = local->FirstChild("identity");
               if (!identity)
               {
                  identity =
                     local->LinkEndChild(new TiXmlElement("identity"));
               }
               // Clear the display attribute.
               identity->ToElement()->SetAttribute("display", "");

               // Put the resource URI as the content of the
               // <local><identity> element.
               // First, remove all text children.
               TiXmlNode* child;
               for (TiXmlNode* prev_child = 0;
                    (child = identity->IterateChildren(prev_child));
                  )
               {
                  if (child->Type() == TiXmlNode::TEXT)
                  {
                     identity->RemoveChild(child);
                     // Leave prev_child unchanged.
                  }
                  else
                  {
                     prev_child = child;
                  }
               }
               // Insert a text child containing the URI.
               identity->LinkEndChild(new TiXmlText(getResourceCached()->
                                                    getUri()->data()));

               // Now that we have the XML all nice and pretty, store a copy of
               // it in mXmlDialogs.
               // Clone the XML and create a UtlVoidPtr to wrap it.
               TiXmlElement* alloc_xml = dialog_element->Clone()->ToElement();

               // Look for an earlier version of this dialog in the hash map.
               UtlVoidPtr* p = dynamic_cast <UtlVoidPtr*> (mXmlDialogs.findValue(&id));
               if (p)
               {
                  // Replace the old XML with new XML.
                  delete static_cast <TiXmlElement*> (p->getValue());
                  p->setValue(alloc_xml);
                  OsSysLog::add(FAC_RLS, PRI_DEBUG,
                                "ResourceInstance::notifyEventCallback replaced dialog with id '%s'",
                                id.data());
               }
               else
               {
                  // Check that we don't have too many dialogs.
                  if (mXmlDialogs.entries() <
                      getResourceListServer()->getMaxDialogsInResInst())
                  {
                     mXmlDialogs.insertKeyAndValue(new UtlString(id),
                                                   new UtlVoidPtr(alloc_xml));
                     OsSysLog::add(FAC_RLS, PRI_DEBUG,
                                   "ResourceInstance::notifyEventCallback added dialog with id '%s'",
                                   id.data());
                  }
                  else
                  {
                     // Free alloc_xml, because we aren't saving a pointer to it.
                     delete alloc_xml;
                     OsSysLog::add(FAC_RLS, PRI_ERR,
                                   "ResourceInstance::notifyEventCallback cannot add dialog with id '%s', already %zu in ResourceInstance '%s'",                                id.data(), mXmlDialogs.entries(),
                                   mInstanceName.data());
                  }
               }
            }
            else
            {
               // The <dialog> was rejected because it appears to report
               // a NAT Maintainer OPTIONS message.
               // We log this at DEBUG level because if these appear,
               // there is likely to be one every 20 seconds.
               OsSysLog::add(FAC_RLS, PRI_DEBUG,
                             "ResourceInstance::notifyEventCallback "
                             "ignored <dialog> reporting a NAT Keepalive message "
                             "in subscription dialog handle '%s' - "
                             "see XTRN-426",
                             mInstanceName.data());
            }
         }
      }
   }
   else
   {
      // Report error parsing XML.
      OsSysLog::add(FAC_RLS, PRI_ERR,
                    "ResourceInstance::notifyEventCallback "
                    "Dialog event from '%s' not parsable.",
                    getResourceCached()->getUri()->data());
      OsSysLog::add(FAC_RLS, PRI_INFO,
                    "ResourceInstance::notifyEventCallback "
                    "Dialog event content is '%s'",
                    content->data());
      // Throw away the content, since we cannot generate matching
      // consolidated content.
      mContentPresent = FALSE;
      mContent.remove(0);
      destroyXmlDialogs();
   }

   // Get the change published, if we found <dialog> that was not incorrect.
   if (publish)
   {
      getResourceCached()->setToBePublished(FALSE, getResourceCached()->getUri());
   }
}
示例#30
0
void CTestScript::OnAddCase()
{
    // TODO: 在此添加命令处理程序代码
    CAddNameDlg dlg;
    CString strCaseName;
    if(dlg.DoModal() == IDOK)
    {
        strCaseName = dlg.GetAddName();
        //载入配置文件
        char strfile[128] = "TestCase\\TestCases.xml";
        TiXmlDocument pDoc(strfile);
        if(!pDoc.LoadFile())
        {
            PutDebugString("装载配置文件<TestCases.xml>出错!");
            AfxMessageBox("装载配置文件<TestCases.xml>出错!");
            return;
        }
        //添加控件
        HTREEITEM hRootItem = m_treeTestCase.GetRootItem();
        HTREEITEM hNewItem = m_treeTestCase.InsertItem(strCaseName, hRootItem);
        m_treeTestCase.SetItemData(hNewItem,m_lCaseNum);
        // Xml配置文件
        TiXmlNode *pRootNode = pDoc.FirstChild("Test");
        TiXmlElement* newCaseElem = new TiXmlElement( "case" );                /// 节点元素
        newCaseElem->SetAttribute("name",strCaseName);			 ///节点属性

        TiXmlElement* newStartScript = new TiXmlElement("start");
        TiXmlElement* newEndScript = new TiXmlElement("end");

        tagTestCase *pCase = new tagTestCase;
        pCase->strCaseName = newCaseElem->Attribute("name");
        m_TestCases[m_lCaseNum++] = pCase;

        char strText[256]="";
        sprintf(strText,"所有案例(%d)",m_TestCases.size());
        m_treeTestCase.SetItemText(hRootItem,strText);

        CString strDir = "TestCase\\";
        strDir += strCaseName;
        CreateDirectory(strDir,NULL);

        CString strFileName = strDir + "\\StartTest.lua";

        CFile file;
        file.Open(strFileName,CFile::modeCreate|CFile::modeWrite,NULL);
        file.Close();
        m_treeTestCase.InsertItem(strFileName,hNewItem,NULL);
        newStartScript->SetAttribute("scriptname",strFileName);
        //xml
        newCaseElem->LinkEndChild(newStartScript);
        pCase->strStartScriptName = strFileName;

        strFileName = strDir + "\\EndTest.lua";
        file.Open(strFileName,CFile::modeCreate|CFile::modeWrite,NULL);
        file.Close();
        m_treeTestCase.InsertItem(strFileName,hNewItem,NULL);
        newEndScript->SetAttribute("scriptname",strFileName);
        //xml
        newCaseElem->LinkEndChild(newEndScript);
        pCase->strEndScriptName = strFileName;

        pRootNode->LinkEndChild(newCaseElem);
        //xml 保存
        pDoc.SaveFile(strfile);
        return;
    }
}