bool SavePlist(const char * szPlistFile, CCObject * pObject) { TiXmlDocument doc; TiXmlDeclaration * pDeclaration = new TiXmlDeclaration("1.0","UTF-8",""); doc.LinkEndChild(pDeclaration); TiXmlElement * pRoot = new TiXmlElement("plist"); XMLHelper::Exchange_String(pRoot, "version", "1.0", true); doc.LinkEndChild(pRoot); RecurseSave(pRoot, pObject); if (!SaveXMLFile(szPlistFile, doc)) { return false; } return true; }
HRESULT CKADmerge::SetValueByPattern(string sElementPattern, string sAttributePattern, string sValue, string sLogFile) { HRESULT hRes = 0; if(sLogFile != "") { // open log file OpenLog(sLogFile, sDescription + " " + m_sFileName); } IXMLDOMNode * pElemNode = NULL; IXMLDOMNode * pAttrNode = NULL; _bstr_t bElementPattern(sElementPattern.c_str()); try { // get element node hRes = m_pXMLKad->selectSingleNode(bElementPattern, &pElemNode); if(hRes == S_FALSE) { hRes = S_FALSE; throw string("node access error"); } if(sAttributePattern.length()) { // get attribute node by pattern string _bstr_t bAttributePattern(sAttributePattern.c_str()); hRes = pElemNode->selectSingleNode(bAttributePattern, &pAttrNode); if(hRes == S_FALSE) { throw string("node access error"); } // set attribute value _bstr_t bAttlanguage(sValue.c_str()); VARIANT vAttlanguage; vAttlanguage.vt = VT_BSTR; V_BSTR(&vAttlanguage) = bAttlanguage.copy(); hRes = pAttrNode->put_nodeValue(vAttlanguage); VariantClear(&vAttlanguage); } else { // set element value hRes = SetValue(pElemNode, sValue); } if(hRes == S_OK) { SaveXMLFile(m_sFileName, m_pXMLKad); // log changes Log("SetValueByPattern - Set value succeeded: Element '" + sElementPattern + " - Attribute " + sAttributePattern + "' to: " + sValue); } //delete pwAttlanguage; if(FAILED(hRes)) { hRes = S_FALSE; throw string("value error"); } } catch(string str) { hRes = S_FALSE; // log changes Log("SetValueByPattern - Set value failed: Element '" + sElementPattern + " - Attribute " + sAttributePattern + "' to: " + sValue); Log("ERROR: " + str); } if(pElemNode != NULL) pElemNode->Release(); if(pAttrNode != NULL) pAttrNode->Release(); // close log file CloseLog(); return hRes; }
HRESULT CKADmerge::Merge(string sAddOnFileName, BOOL bOverwrite, string sLogFile) { HRESULT hRes = 0; IXMLDOMDocument * pXMLAddOn = NULL; if(sLogFile != "") { // open log file OpenLog(sLogFile, sDescription + " " + m_sFileName + " with " + sAddOnFileName); } try { // load AddOn file hRes = LoadXMLFile(sAddOnFileName, &pXMLAddOn); IXMLDOMElement * pKadRoot = NULL; hRes = GetRootElement(m_pXMLKad, &pKadRoot); if(hRes == S_FALSE) { // create root element hRes = GetRootElement(pXMLAddOn, &pKadRoot); if(hRes == S_FALSE) { throw string("ERROR: could not get addon kad root element: " + sAddOnFileName); } _bstr_t bTagName(GetName(pKadRoot).c_str()); hRes = m_pXMLKad->createElement(bTagName, &pKadRoot); hRes = m_pXMLKad->putref_documentElement(pKadRoot); // log changes Log("Create Root-Element: " + GetName(pKadRoot) ); m_bIsDirty = TRUE; } if(pKadRoot) pKadRoot->Release(); IXMLDOMNode * pXMLKadNode = NULL; IXMLDOMNode * pXMLAddOnNode = NULL; hRes = GetRootElement(m_pXMLKad, &pXMLKadNode); hRes = GetRootElement(pXMLAddOn, &pXMLAddOnNode); // copy nodes hRes = CopyNode(&pXMLKadNode, &pXMLAddOnNode, bOverwrite, ""); if(pXMLKadNode != NULL) pXMLKadNode->Release(); if(pXMLAddOnNode != NULL) pXMLAddOnNode->Release(); if(m_bIsDirty) { hRes = SaveXMLFile(m_sFileName, m_pXMLKad); m_bIsDirty = FALSE; } } catch(string str) { Log(str); hRes = S_FALSE; } if(pXMLAddOn != NULL) pXMLAddOn->Release(); // close log file CloseLog(); return hRes; }