AppRet CConfReader::loadLogo(CRect &rt, int &fontSize, COLORREF &color) { if ( m_rootelement == NULL ) { return Ret_ERR; } TiXmlElement* element = m_rootelement->FirstChildElement("logo"); AppRet ret = loadRect(element, rt); if ( Ret_OK != ret ) { return ret; } TiXmlElement* fontElement = element->FirstChildElement("font"); int r, g, b; ret = loadFont(fontElement, r, g, b, fontSize); if ( Ret_OK != ret ) { return ret; } color = RGB(r,g,b); if ( fontElement ) { fontElement->Clear(); } if (element) { element->Clear(); } return Ret_OK; }
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; }
bool SData::SaveCache() { std::string strCacheFile; TiXmlDocument xml_doc; TiXmlElement *pRootElement = NULL; TiXmlElement *pTokenElement = NULL; strCacheFile = GetFilePath("cache.xml"); if (!xml_doc.LoadFile(strCacheFile)) { XBMC->Log(LOG_ERROR, "failed to load \"%s\"", strCacheFile.c_str()); return false; } pRootElement = xml_doc.RootElement(); if (strcmp(pRootElement->Value(), "cache") != 0) { XBMC->Log(LOG_ERROR, "invalid xml doc. root tag 'cache' not found"); return false; } pTokenElement = pRootElement->FirstChildElement("token"); pTokenElement->Clear(); pTokenElement->LinkEndChild(new TiXmlText(m_identity.token)); strCacheFile = GetFilePath("cache.xml"); if (!xml_doc.SaveFile(strCacheFile)) { XBMC->Log(LOG_ERROR, "failed to save \"%s\"", strCacheFile.c_str()); return false; } return true; }
void COptions::SetXmlValue(unsigned int nID, wxString const& value) { if (!m_pXmlFile) return; // No checks are made about the validity of the value, that's done in SetOption wxScopedCharBuffer utf8 = value.utf8_str(); if (!utf8) return; TiXmlElement *settings = CreateSettingsXmlElement(); if (settings) { TiXmlElement *setting = 0; for (setting = settings->FirstChildElement("Setting"); setting; setting = setting->NextSiblingElement("Setting")) { const char *attribute = setting->Attribute("name"); if (!attribute) continue; if (!strcmp(attribute, options[nID].name)) break; } if (setting) { setting->Clear(); } else { setting = new TiXmlElement("Setting"); setting->SetAttribute("name", options[nID].name); settings->LinkEndChild(setting); } setting->LinkEndChild(new TiXmlText(utf8)); } }
//路径|节点|子节点|属性 //C:\Documents and Settings\All Users\Application Data\Storm\config.xml //localplayhist //item //url //C:\Documents and Settings\Administrator\桌面\0812_195706.3gp BOOL CSpecialApp::CleanStorm_Clean(int Itype,LPCTSTR lpcszAppPath) { CString strPath = lpcszAppPath; g_regClean.ConvetPath(strPath); CSimpleArray<CString> vec_String; int iCount = SplitCString1(strPath,vec_String,'|'); if(iCount<2) { return FALSE; } TiXmlDocument xmlDoc; //获得文件夹名称改变其属性 iCount = vec_String[0].ReverseFind('\\'); CString strTmp; if (iCount>0) { strTmp = vec_String[0].Mid(0,iCount); } DWORD dwErrCode=0; if(FALSE == SetFileAttributes(strTmp, FILE_ATTRIBUTE_NORMAL)) { dwErrCode=GetLastError(); } USES_CONVERSION; FILE* lpFile = _tfopen(vec_String[0], _T("a+b")); if ( lpFile != NULL ) { xmlDoc.LoadFile(lpFile); fclose(lpFile); if ( xmlDoc.Error() == 0 ) { OutputDebugString(_T("\n打开文件成功\n")); TiXmlElement* rootNode = xmlDoc.RootElement(); if (rootNode !=NULL) { TiXmlElement* nodeGeneral = rootNode->FirstChildElement(W2A(vec_String[1])); if ( nodeGeneral != NULL ) { // rootNode->RemoveChild(nodeGeneral); nodeGeneral->Clear(); xmlDoc.SaveFile(W2A(vec_String[0])); } } } } return TRUE; }
void wxsProject::WriteConfiguration(TiXmlElement* element) { TiXmlElement* SmithElement = element->FirstChildElement("wxsmith"); if ( !m_GUI && m_Resources.empty() && m_UnknownConfig.NoChildren() && m_UnknownResources.NoChildren() ) { // Nothing to write if ( SmithElement ) { element->RemoveChild(SmithElement); } return; } if ( !SmithElement ) { SmithElement = element->InsertEndChild(TiXmlElement("wxsmith"))->ToElement(); } SmithElement->Clear(); SmithElement->SetAttribute("version",CurrentVersionStr); // saving GUI item if ( m_GUI ) { TiXmlElement* GUIElement = SmithElement->InsertEndChild(TiXmlElement("gui"))->ToElement(); GUIElement->SetAttribute("name",cbU2C(m_GUI->GetName())); m_GUI->WriteConfig(GUIElement); } // saving resources if ( !m_Resources.empty() || !m_UnknownResources.NoChildren() ) { TiXmlElement* ResElement = SmithElement->InsertEndChild(TiXmlElement("resources"))->ToElement(); size_t Count = m_Resources.Count(); for ( size_t i=0; i<Count; i++ ) { const wxString& Name = m_Resources[i]->GetResourceName(); const wxString& Type = m_Resources[i]->GetResourceType(); TiXmlElement* Element = ResElement->InsertEndChild(TiXmlElement(cbU2C(Type)))->ToElement(); // TODO: Check value returned from WriteConfig m_Resources[i]->WriteConfig(Element); Element->SetAttribute("name",cbU2C(Name)); } // Saving all unknown resources for ( TiXmlNode* Node = m_UnknownResources.FirstChild(); Node; Node=Node->NextSibling() ) { SmithElement->InsertEndChild(*Node); } } // Saving all unknown configuration nodes for ( TiXmlNode* Node = m_UnknownConfig.FirstChild(); Node; Node=Node->NextSibling() ) { SmithElement->InsertEndChild(*Node); } }
bool xmlManager::removeALLChild(std::string parent) { TiXmlElement * node = getNode(parent); if (node == NULL) return false; node->Clear(); return true; }
/** Change the database informations in the xml file * * \param host The hostname of the postgres server * \param dbName The database name * \param user The user name * \param pwd The user password * */ void RainbruRPG::Server::xmlServerConf:: setDatabase(const std::string& host,const std::string& dbName, const std::string& user,const std::string& pwd){ TiXmlElement* childNode = root->FirstChild( "Database" )->ToElement(); if (childNode){ childNode->Clear(); childNode->SetAttribute("hostname", host.c_str()); childNode->SetAttribute("dbname", dbName.c_str()); childNode->SetAttribute("user", user.c_str()); childNode->SetAttribute("pwd", pwd.c_str()); } }
/** Set the server options * * \param ip The IP adress of the server * \param port The UDP port used by the server * \param ftp The FTP control channel port used by the server * \param maxClients The maxClient option * \param type The server's type * */ void RainbruRPG::Server::xmlServerConf:: setServerOption(const std::string& ip, int port, int ftp,int maxClients, int type){ TiXmlElement* childNode = root->FirstChild( "Options" )->ToElement(); if (childNode){ childNode->Clear(); childNode->SetAttribute("ip", ip.c_str()); childNode->SetAttribute("port", port); childNode->SetAttribute("ftp", ftp); childNode->SetAttribute("maxClient", maxClients); childNode->SetAttribute("type", type); } }
bool wxsItemResData::RebuildXrcFile() { // First - opening file TiXmlDocument Doc; TiXmlElement* Resources = nullptr; TiXmlElement* Object = nullptr; if ( TinyXML::LoadDocument(m_XrcFileName,&Doc) ) { Resources = Doc.FirstChildElement("resource"); } if ( !Resources ) { Doc.Clear(); Doc.InsertEndChild(TiXmlDeclaration("1.0","utf-8","")); Resources = Doc.InsertEndChild(TiXmlElement("resource"))->ToElement(); Resources->SetAttribute("xmlns","http://www.wxwidgets.org/wxxrc"); } // Searching for object representing this resource for ( Object = Resources->FirstChildElement("object"); Object; Object = Object->NextSiblingElement("object") ) { if ( cbC2U(Object->Attribute("name")) == m_ClassName ) { Object->Clear(); while ( Object->FirstAttribute() ) { Object->RemoveAttribute(Object->FirstAttribute()->Name()); } break; } } if ( !Object ) { Object = Resources->InsertEndChild(TiXmlElement("object"))->ToElement(); } // The only things left are: to dump item into object ... m_RootItem->XmlWrite(Object,true,false); Object->SetAttribute("name",cbU2C(m_ClassName)); for ( int i=0; i<GetToolsCount(); i++ ) { TiXmlElement* ToolElement = Object->InsertEndChild(TiXmlElement("object"))->ToElement(); m_Tools[i]->XmlWrite(ToolElement,true,false); } // ... and save back the file return TinyXML::SaveDocument(m_XrcFileName,&Doc); }
/** Set the server modes * * \param play The status of the play mode * \param edit The status of the edit mode * \param flood The status of the flood mode * */ void RainbruRPG::Server::xmlServerConf:: setServerMode(bool play, bool edit, bool flood){ const char* txtPlay=StringConv::getSingleton().btoc(play); const char* txtEdit=StringConv::getSingleton().btoc(edit); const char* txtFlood=StringConv::getSingleton().btoc(flood); TiXmlElement* childNode = root->FirstChild( "Modes" )->ToElement(); if (childNode){ childNode->Clear(); childNode->SetAttribute("play", txtPlay); childNode->SetAttribute("editor", txtEdit); childNode->SetAttribute("flood", txtFlood); } }
AppRet CConfReader::loadFrame(CRect &rt) { if ( m_rootelement == NULL ) { return Ret_ERR; } TiXmlElement* element = m_rootelement->FirstChildElement("frame"); AppRet ret = loadRect(element, rt); if (element) { element->Clear(); } return ret; }
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(); } if (COptions::Get()->GetOptionVal(OPTION_DEFAULT_KIOSKMODE) == 2) return; 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); }
/*! * /brief 修改指定节点的文本。 * * /param XmlFile xml文件全路径。 * /param strNodeName 指定的节点名。 * /param strText 重新设定的文本的值 * /return 是否成功。true为成功,false表示失败。 */ bool xml_ModifyNode_Text(TiXmlElement *pRootEle, std::string strNodeName, std::string strText) { if (NULL == pRootEle) { return false; } TiXmlElement *pNode = NULL; xml_GetNodePointerByName(pRootEle, strNodeName, pNode); if (NULL != pNode) { pNode->Clear(); // 首先清除所有文本 // 然后插入文本,保存文件 TiXmlText *pValue = new TiXmlText(strText); pNode->LinkEndChild(pValue); return true; } else return false; }
/*********************************************************************************************************** * 程序作者:赵进军 * 函数功能:更新XML文件中指定节点名的节点Text * 参数说明: * strNodeName:需要更新的节点指针的名称 * nodeIndex:需要更新的节点的位置 * newStr:更新后的节点的内容 * 注意事项:null * 修改日期:2015/12/13 15:09:00 ***********************************************************************************************************/ bool OperationProfile_XML::UpdateProfileIndexText(char* delNodeName, int nodeIndex, char* newStr) { if (nodeIndex >= groupNodeCount) printf("当前更新的节点位置不存在!"); if (!OperationProfile_XML::XMLExits()) return false; TiXmlDocument* myDocument = new TiXmlDocument(); if (NULL == myDocument) return false; myDocument->LoadFile(IOperationProfile::ProfileAddress); TiXmlElement* pRootEle = myDocument->RootElement(); if (NULL == pRootEle) return false; TiXmlElement *pNode = NULL; if (arrayIndex != 0) arrayIndex = 0; if (!GetNodePointerByName(pRootEle, delNodeName, pNode, nodeIndex)) return false; if (pRootEle == pNode) return false; if (NULL != pNode) { pNode->Clear(); TiXmlText *AgeContent = new TiXmlText(newStr); if (pNode->LinkEndChild(AgeContent)) { myDocument->SaveFile(IOperationProfile::ProfileAddress); return true; } else return false; } else { return false; } return false; }
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; }
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 == 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->InsertEndChild(TiXmlElement("RecentServers"))->ToElement(); pElement->Clear(); for (std::list<CServer>::const_iterator iter = m_mostRecentServers.begin(); iter != m_mostRecentServers.end(); iter++) { TiXmlElement* pServer = pElement->InsertEndChild(TiXmlElement("Server"))->ToElement(); SetServer(pServer, *iter); } wxString error; m_XmlFile.Save(&error); }
//-------------------------------------------------------------- void ofxMagneticApp::__resetCalibration() { // Get XML TiXmlHandle hDoc(&__calibrationXML); TiXmlElement* pCalibration = hDoc.FirstChild("calibration").ToElement(); // Update grid parameters and clear points pCalibration->SetAttribute("columns", ofToString(__calibrationColumns)); pCalibration->SetAttribute("rows", ofToString(__calibrationRows)); pCalibration->Clear(); // Iterate through rows for (int i = 0; i < __calibrationRows; i++) { // Iterate through columns for (int j = 0; j < __calibrationColumns; j++) { // Create point TiXmlElement* pPoint = new TiXmlElement("point"); // Set value (0.0000 - 1.0000) pPoint->SetAttribute("x", ofToString(((float)(((float)__captureWidth / (float)(__calibrationColumns - 1)) * j)) / (float)__captureWidth)); pPoint->SetAttribute("y", ofToString(((float)(((float)__captureHeight / (float)(__calibrationRows - 1)) * i)) / (float)__captureHeight)); // Add point to <calibration> node pCalibration->LinkEndChild(pPoint); } } // Reset calibration settings __calibrationPoint = 0; __calibrationStartTime = ofGetElapsedTimeMillis(); // Learn background (will reset warp map) __bLearnBackground = true; }
void ProjectConfiguration::XmlWrite(TiXmlElement* Node,cbProject* Project) { TiXmlElement* LibFinder = Node->FirstChildElement("lib_finder"); if ( !LibFinder ) LibFinder = Node->InsertEndChild(TiXmlElement("lib_finder"))->ToElement(); LibFinder->Clear(); if ( m_DisableAuto ) { LibFinder->SetAttribute("disable_auto","1"); } for ( size_t i=0; i<m_GlobalUsedLibs.Count(); i++ ) { LibFinder->InsertEndChild(TiXmlElement("lib"))->ToElement()->SetAttribute("name",cbU2C(m_GlobalUsedLibs[i])); } for ( wxMultiStringMap::iterator i=m_TargetsUsedLibs.begin(); i!=m_TargetsUsedLibs.end(); ++i ) { if ( !Project->GetBuildTarget(i->first) ) continue; wxArrayString& Libs = i->second; if ( Libs.Count() ) { TiXmlElement* TargetElem = LibFinder->InsertEndChild(TiXmlElement("target"))->ToElement(); TargetElem->SetAttribute("name",cbU2C(i->first)); for ( size_t i=0; i<Libs.Count(); i++ ) { TargetElem->InsertEndChild(TiXmlElement("lib"))->ToElement()->SetAttribute("name",cbU2C(Libs[i])); } } } if ( !LibFinder->FirstAttribute() && !LibFinder->FirstChild() ) { // LibFinder is empty, let's delete it so it doesn't trash here Node->RemoveChild(LibFinder); } }
/** @details * Uloží do XML nastavení kláves hráčů. * @param rootEl root element xml souboru */ void Config::set_players_(TiXmlElement * rootEl) { if(!players_changed_) return; string el_name; TiXmlElement * playerEl; TiXmlElement new_bind("bind"); for(Uint16 player_num=0 ; player_num<players_.size() ; ++player_num ) { el_name = "player"+x2string(player_num); playerEl = subElement(rootEl, el_name.c_str()); playerEl->Clear(); for(Uint16 action_num=0 ; action_num<players_[player_num].size() ; ++action_num) { new_bind.SetAttribute("action", action2name_( static_cast<KEY_ACTIONS>(action_num) )); new_bind.SetAttribute("key", keyNames_.key2name( players_[player_num][action_num]) ); playerEl->InsertEndChild(new_bind); } } players_changed_ = false; }
void EnvVars::OnProjectLoadingHook(cbProject* project, TiXmlElement* elem, bool loading) { #if TRACE_ENVVARS Manager::Get()->GetLogManager()->DebugLog(F(_T("OnProjectLoadingHook"))); #endif if (loading) { TiXmlElement* node = elem->FirstChildElement("envvars"); if (node) { m_ProjectSets[project] = cbC2U(node->Attribute("set")); if (m_ProjectSets[project].IsEmpty()) // no envvar set to apply setup return; if (!nsEnvVars::EnvvarSetExists(m_ProjectSets[project])) EnvvarSetWarning(m_ProjectSets[project]); } } else { // Hook called when saving project file. // since rev4332, the project keeps a copy of the <Extensions> element // and re-uses it when saving the project (so to avoid losing entries in it // if plugins that use that element are not loaded atm). // so, instead of blindly inserting the element, we must first check it's // not already there (and if it is, clear its contents) TiXmlElement* node = elem->FirstChildElement("envvars"); if (!node) node = elem->InsertEndChild(TiXmlElement("envvars"))->ToElement(); node->Clear(); if (!m_ProjectSets[project].IsEmpty()) node->SetAttribute("set", cbU2C(m_ProjectSets[project])); } }// OnProjectLoadingHook
/*! \brief Load / save project hook. When CodeBlocks loads and saves a file, we hook into the process here and load or save our parameters. \param project CodeBlocks project instance. \param elem XML element of root node. \param loading Flag set whether load / save, true = loading, false = saving. */ void OpenOCDDriver::OnProjectLoadingHook(cbProject* project, TiXmlElement* elem, bool loading) { if (loading) { TiXmlElement* node = elem->FirstChildElement("gdbremote"); if (node) { TiXmlElement *device = node->FirstChildElement("hardware"); m_Interface = cbC2U(device->Attribute("interface")); m_Option = cbC2U(device->Attribute("option")); m_JTAGSpeed = cbC2U(device->Attribute("jtagspeed")); m_GDBPort = atoi(device->Attribute("gdbport")); m_ConfigFile = cbC2U(device->Attribute("configfile")); wxString strAuto = cbC2U(device->Attribute("auto")); m_TelnetPort = atoi(device->Attribute("telnetport")); m_TCLPort = atoi(device->Attribute("tclport")); if (strAuto == _T("true")) m_Auto = true; else m_Auto = false; // Now get advanced options. TiXmlElement *advopts = node->FirstChildElement("advintopts"); if (advopts) { TiXmlAttribute *attr = advopts->FirstAttribute(); while (attr) { // Populate hash map with attributes. wxString key = cbC2U(attr->Name()); wxString value = cbC2U(attr->Value()); m_AdvOpts[key] = value; attr = attr->Next(); } } } else { m_Interface = _T("parport"); m_Option = _T("wiggler"); m_JTAGSpeed = _T("0"); m_ConfigFile = _T("openocd.cfg"); m_Auto = true; m_TelnetPort = 4444; m_GDBPort = 2000; m_TCLPort = 6666; m_AdvOpts.clear(); } } else { TiXmlElement* node = elem->FirstChildElement("gdbremote"); if (!node) node = elem->InsertEndChild(TiXmlElement("gdbremote"))->ToElement(); node->Clear(); TiXmlElement *device = node->InsertEndChild(TiXmlElement("hardware"))->ToElement(); device->SetAttribute("interface", cbU2C(m_Interface)); device->SetAttribute("option", cbU2C(m_Option)); device->SetAttribute("jtagspeed", cbU2C(m_JTAGSpeed)); device->SetAttribute("gdbport", m_GDBPort); device->SetAttribute("configfile", cbU2C(m_ConfigFile)); if (m_Auto == true) device->SetAttribute("auto", "true"); else device->SetAttribute("auto", "false"); device->SetAttribute("telnetport", m_TelnetPort); device->SetAttribute("tclport", m_TCLPort); // Write advanced options TiXmlElement *advopts = node->InsertEndChild(TiXmlElement("advintopts"))->ToElement(); AdvOptsHash::iterator it; for( it = m_AdvOpts.begin(); it != m_AdvOpts.end(); ++it ) { wxString key = it->first, value = it->second; // do something useful with key and value advopts->SetAttribute(cbU2C(key), cbU2C(value)); } } }
int _tmain(int argc, _TCHAR* argv[]) { fetch_proxy_from_web("www.cnproxy.com", "http://www.cnproxy.com/proxyedu1.html"); fetch_proxy_from_web("www.cnproxy.com", "http://www.cnproxy.com/proxyedu2.html"); evaluate_proxy(); //fstream f("proxy_list.txt", ios::out | ios::trunc); //for(multimap<double, std::string>::iterator it = final_proxy_list.begin(); it!=final_proxy_list.end(); ++it ) // f << it->second << endl; //f.close(); /// write it into firefox switch proxy add-on std::string file_path = std::getenv ("APPDATA"); file_path.append("\\Mozilla\\Firefox\\Profiles\\rx4zwdfi.default\\localstore.rdf"); TiXmlDocument doc( file_path.c_str() ); if(!doc.LoadFile()) { std::cout << "file not exist" << endl; assert(0); } TiXmlElement * general_elem = 0; TiXmlElement * elem = 0; TiXmlElement * temp_elem = 0; general_elem = doc.FirstChildElement(); ///remove all old proxies items elem = general_elem->FirstChildElement(); while(elem) { if(elem->Attribute("NS1:networkProxyType") != 0) { temp_elem = elem; elem = elem->NextSiblingElement(); general_elem->RemoveChild(temp_elem); } else elem = elem->NextSiblingElement(); } ///clear general entry list for proxy items elem = general_elem->FirstChildElement(); while(elem) { std::string elem_value = elem->Value(); if(elem_value == "RDF:Seq") { elem->Clear(); break; } else elem = elem->NextSiblingElement(); } ///now we have elem as RDF:Seq node, we add entry our own entry list into it int i = 0; for(multimap<double, std::string>::iterator it = final_proxy_list.begin(); it!=final_proxy_list.end(); ++it ) { TiXmlElement entry_elem("RDF:li"); entry_elem.SetAttribute("RDF:resource", i); elem->InsertEndChild(entry_elem); TiXmlElement actual_elem("RDF:Description"); char buffer[256]; sprintf(buffer, "cnproxy-%02d", i); actual_elem.SetAttribute("NS1:name", buffer); actual_elem.SetAttribute("RDF:about", i); actual_elem.SetAttribute("NS1:networkProxyType", "1"); std::vector<std::string> ip_port; qtk::misc::qString::TokenizeString(it->second, ":", ip_port); actual_elem.SetAttribute("NS1:networkProxyHTTP", ip_port[0]); actual_elem.SetAttribute("NS1:networkProxyHTTP_Port", ip_port[1]); actual_elem.SetAttribute("NS1:networkProxySOCKSVersion", "4"); actual_elem.SetAttribute("NS1:networkProxySSL", ""); actual_elem.SetAttribute("NS1:networkProxySSL_Port", ""); actual_elem.SetAttribute("NS1:networkProxyFTP", ""); actual_elem.SetAttribute("NS1:networkProxyFTP_Port", ""); actual_elem.SetAttribute("NS1:networkProxyGopher", ""); actual_elem.SetAttribute("NS1:networkProxyGopher_Port", ""); actual_elem.SetAttribute("NS1:networkProxySOCKS", ""); actual_elem.SetAttribute("NS1:networkProxySOCKS_Port", ""); actual_elem.SetAttribute("NS1:networkProxyNone", ""); actual_elem.SetAttribute("NS1:networkProxyAutoconfigURL", ""); general_elem->InsertEndChild(actual_elem); i++; } ///finally, add JAP TiXmlElement entry_elem("RDF:li"); entry_elem.SetAttribute("RDF:resource", "JAP"); elem->InsertEndChild(entry_elem); TiXmlElement actual_elem("RDF:Description"); actual_elem.SetAttribute("NS1:name", "JAP"); actual_elem.SetAttribute("RDF:about", "JAP"); actual_elem.SetAttribute("NS1:networkProxyType", "1"); actual_elem.SetAttribute("NS1:networkProxyHTTP", "127.0.0.1"); actual_elem.SetAttribute("NS1:networkProxyHTTP_Port", "4001"); actual_elem.SetAttribute("NS1:networkProxySOCKSVersion", "4"); actual_elem.SetAttribute("NS1:networkProxySSL", ""); actual_elem.SetAttribute("NS1:networkProxySSL_Port", ""); actual_elem.SetAttribute("NS1:networkProxyFTP", ""); actual_elem.SetAttribute("NS1:networkProxyFTP_Port", ""); actual_elem.SetAttribute("NS1:networkProxyGopher", ""); actual_elem.SetAttribute("NS1:networkProxyGopher_Port", ""); actual_elem.SetAttribute("NS1:networkProxySOCKS", ""); actual_elem.SetAttribute("NS1:networkProxySOCKS_Port", ""); actual_elem.SetAttribute("NS1:networkProxyNone", ""); actual_elem.SetAttribute("NS1:networkProxyAutoconfigURL", ""); general_elem->InsertEndChild(actual_elem); doc.SaveFile(file_path.c_str()); return 0; }
bool tinyXMLPrase() { bool succeed = false; //ת»»¿í×Ö½Úµ½char setlocale(LC_ALL, "zh-CN"); size_t len = wcslen(strFile) + 1; size_t converted = 0; char *CStr; CStr = (char*)malloc(len*sizeof(char)*2); wcstombs_s(&converted, CStr, len*2, strFile, len*2); TiXmlDocument * myDocument = new TiXmlDocument(CStr); myDocument->LoadFile(); if (myDocument->Error()) { MessageBox(theHWND, L"XML¶Áȡʧ°Ü", L"´íÎó", 0); return false; } try { TiXmlElement * RootElement = myDocument->RootElement(); for (TiXmlElement * TestCase = RootElement->FirstChildElement(); TestCase != NULL; TestCase = TestCase->NextSiblingElement()) { int ID; TestCase->QueryIntAttribute("ID", &ID); if (ID != SETTING_XML_TESTCASE) { TestCase->Clear(); continue; } succeed = true; for (TiXmlElement * DataNode = TestCase->FirstChildElement(); DataNode != NULL; DataNode = DataNode->NextSiblingElement()) { if (strcmp(DataNode->Value(), "Entity") == 0) { if (strcmp(DataNode->Attribute("Type"), "Line") == 0) { Line * line = (Line *)mempool->Alloc(sizeof(Line)); for (TiXmlElement * pointNode = DataNode->FirstChildElement(); pointNode != NULL; pointNode = pointNode->NextSiblingElement()) { if (strcmp(pointNode->Value(), "StartPoint") == 0) { sscanf_s(pointNode->GetText(), "%hd,%hd", &line->x1, &line->y1); } else if (strcmp(pointNode->Value(), "EndPoint") == 0) { sscanf_s(pointNode->GetText(), "%hd,%hd", &line->x2, &line->y2); } } lineList.push_back(line); } else if (strcmp(DataNode->Attribute("Type"), "Circle") == 0) { Circle * circle = (Circle *)mempool->Alloc(sizeof(Circle));; for (TiXmlElement * pointNode = DataNode->FirstChildElement(); pointNode != NULL; pointNode = pointNode->NextSiblingElement()) { if (strcmp(pointNode->Value(), "CenterPoint") == 0) { sscanf_s(pointNode->GetText(), "%hd,%hd", &circle->x, &circle->y); } else if (strcmp(pointNode->Value(), "Radius") == 0) { sscanf_s(pointNode->GetText(), "%hd", &circle->r); } } circleList.push_back(circle); } } else if (strcmp(DataNode->Value(), "Boundary") == 0) { for (TiXmlElement * pointNode = DataNode->FirstChildElement(); pointNode != NULL; pointNode = pointNode->NextSiblingElement()) { if (strcmp(pointNode->Value(), "Vertex") != 0) continue; Point * point = (Point *)mempool->Alloc(sizeof(Point)); sscanf_s(pointNode->GetText(), "%hd,%hd", &point->x, &point->y); polygonList.push_back(point); } } else { //Òì³££¬»¹ÊǺöÂÔÁË°É } } } } catch (...) { myDocument->Clear(); delete(myDocument); MessageBox(theHWND, L"δ֪´íÎó", L"´íÎó", 0); return false; } if (!succeed) { myDocument->Clear(); delete(myDocument); MessageBox(theHWND, L"ûÓÐÕÒµ½Êý¾Ý½Úµã", L"´íÎó", 0); return false; } myDocument->Clear(); delete(myDocument); return true; }
int main(int argc, char *argv[]) { double myJoints[ROBOT_DOF] = {1,2,3,4,5,6}; double jointsIn[ROBOT_DOF]; robotPose myPose, poseIn; int kukaConnection; RCS_TIMER *cycleBlock = new RCS_TIMER(KUKA_DEFAULT_CYCLE); TiXmlDocument kukaStatus; TiXmlHandle toSendHandle(&kukaStatus); TiXmlElement *cartesianStatus; TiXmlElement *cartesianUpdate; TiXmlElement *jointStatus; TiXmlElement *jointUpdate; TiXmlElement *IPOCUpdate; int nchars; TiXmlElement *cartesian; int debug = 0; int option; int counter = 0; double jointMotorScale[ROBOT_DOF], cmdMotorScale[ROBOT_DOF]; jointMotorScale[0] = 80.; jointMotorScale[1] = 100.; jointMotorScale[2] = 80.; jointMotorScale[3] = 80.; jointMotorScale[4] = 80.; jointMotorScale[5] = 40.5; cmdMotorScale[0] = 1.4; cmdMotorScale[1] = 1.74; cmdMotorScale[2] = 1.4; cmdMotorScale[3] = 1.4; cmdMotorScale[4] = 1.4; cmdMotorScale[5] = 0.87; while (true) { option = getopt(argc, argv, ":d"); if (option == -1) break; switch (option) { case 'd': debug = 1; break; case ':': fprintf(stderr, "missing value for -%c\n", optopt); return 1; break; default: fprintf (stderr, "unrecognized option -%c\n", optopt); return 1; break; } // switch (option) } // while (true) for getopt if( !kukaStatus.LoadFile(DEFAULT_FROM_KUKA)) { printf( "kukaRobot:: fatal error on load of %s\n", DEFAULT_FROM_KUKA); exit(1); } kukaConnection = ulapi_socket_get_client_id(KUKA_PORT, "localhost"); if( kukaConnection < 0 ) return -1; myPose.x = 0.1; myPose.y = 0.2; myPose.z = 0.3; myPose.xrot = 0.4; myPose.yrot = 0.5; myPose.zrot = 0.6; while(true) { TiXmlDocument kukaCorrections; TiXmlHandle correctionsHandle(&kukaCorrections); std::string str; enum {INBUF_LEN = 2048}; char inbuf[INBUF_LEN]; std::ostringstream s; cartesianStatus = toSendHandle.FirstChild("Rob").FirstChild("Dat").Child(1).ToElement(); IPOCUpdate = toSendHandle.FirstChild("Rob").FirstChild("Dat").Child(9). ToElement(); jointStatus = toSendHandle.FirstChild("Rob").FirstChild("Dat").Child(3).ToElement(); cartesianStatus->SetDoubleAttribute("X", myPose.x); cartesianStatus->SetDoubleAttribute ("Y", myPose.y); cartesianStatus->SetDoubleAttribute ("Z", myPose.z); cartesianStatus->SetDoubleAttribute ("A", myPose.xrot); cartesianStatus->SetDoubleAttribute ("B", myPose.yrot); cartesianStatus->SetDoubleAttribute ("C", myPose.zrot); jointStatus->SetDoubleAttribute("A1", myJoints[0]); jointStatus->SetDoubleAttribute("A2", myJoints[1]); jointStatus->SetDoubleAttribute("A3", myJoints[2]); jointStatus->SetDoubleAttribute("A4", myJoints[3]); jointStatus->SetDoubleAttribute("A5", myJoints[4]); jointStatus->SetDoubleAttribute("A6", myJoints[5]); s << counter++; s << '\0'; TiXmlText *text = new TiXmlText((s.str()).c_str()); IPOCUpdate->Clear(); IPOCUpdate->LinkEndChild(text); // kukaStatus.Print(); str << kukaStatus; ulapi_socket_write(kukaConnection, str.c_str(), str.length()); inbuf[0] = '\0'; nchars = ulapi_socket_read(kukaConnection, inbuf, sizeof(inbuf)-1); if (nchars <= 0) { printf("kukaRobot::status client disconnected\n"); break; } else { inbuf[nchars] = '\0'; } kukaCorrections.Parse(inbuf); if(debug) kukaCorrections.Print(); cartesianUpdate = correctionsHandle.FirstChild("Sen").FirstChild("Dat"). Child(1).ToElement(); jointUpdate = correctionsHandle.FirstChild("Sen").FirstChild("Dat"). Child(2).ToElement(); cartesianUpdate->QueryDoubleAttribute("X", &(poseIn.x)); cartesianUpdate->QueryDoubleAttribute("Y", &(poseIn.y)); cartesianUpdate->QueryDoubleAttribute("Z", &(poseIn.z)); cartesianUpdate->QueryDoubleAttribute("A", &(poseIn.xrot)); cartesianUpdate->QueryDoubleAttribute("B", &(poseIn.yrot)); cartesianUpdate->QueryDoubleAttribute("C", &(poseIn.zrot)); jointUpdate->QueryDoubleAttribute("A1", &(jointsIn[0])); jointUpdate->QueryDoubleAttribute("A2", &(jointsIn[1])); jointUpdate->QueryDoubleAttribute("A3", &(jointsIn[2])); jointUpdate->QueryDoubleAttribute("A4", &(jointsIn[3])); jointUpdate->QueryDoubleAttribute("A5", &(jointsIn[4])); jointUpdate->QueryDoubleAttribute("A6", &(jointsIn[5])); myPose.x += poseIn.x; myPose.y += poseIn.y; myPose.z += poseIn.z; myPose.xrot += poseIn.xrot; myPose.yrot += poseIn.yrot; myPose.zrot += poseIn.zrot; for( int i=0; i<ROBOT_DOF; i++ ) { myJoints[i] += jointsIn[i] * cmdMotorScale[i] / jointMotorScale[i]; if( debug ) printf( "J%d <%lf %lf> ", i+1, myJoints[i], jointsIn[i] ); } if(debug) printf( "\nkukaRobot Status: <%4.2f, %4.2f, %4.2f> <%4.2f, %4.2f, %4.2f>\n\n", myPose.x, myPose.y, myPose.z, myPose.xrot, myPose.yrot, myPose.zrot); cycleBlock->wait(); } }
void COptions::SetOption(int nOptionID, LPCTSTR value, bool save /*=true*/) { CStdString str = value; Init(); switch (nOptionID) { case OPTION_SERVERPORT: case OPTION_TLSPORTS: { std::set<int> portSet; str.TrimLeft(_T(" ,")); int pos = str.FindOneOf(_T(" ,")); while (pos != -1) { int port = _ttoi(str.Left(pos)); if (port >= 1 && port <= 65535) portSet.insert(port); str = str.Mid(pos + 1); str.TrimLeft(_T(" ,")); pos = str.FindOneOf(_T(" ,")); } if (str != _T("")) { int port = _ttoi(str); if (port >= 1 && port <= 65535) portSet.insert(port); } str = _T(""); for (std::set<int>::const_iterator iter = portSet.begin(); iter != portSet.end(); iter++) { CStdString tmp; tmp.Format(_T("%d "), *iter); str += tmp; } str.TrimRight(' '); } break; case OPTION_WELCOMEMESSAGE: { std::vector<CStdString> msgLines; int oldpos = 0; str.Replace(_T("\r\n"), _T("\n")); int pos = str.Find(_T("\n")); CStdString line; while (pos != -1) { if (pos) { line = str.Mid(oldpos, pos - oldpos); line = line.Left(CONST_WELCOMEMESSAGE_LINESIZE); line.TrimRight(_T(" ")); if (msgLines.size() || line != _T("")) msgLines.push_back(line); } oldpos = pos + 1; pos = str.Find(_T("\n"), oldpos); } line = str.Mid(oldpos); if (line != _T("")) { line = line.Left(CONST_WELCOMEMESSAGE_LINESIZE); msgLines.push_back(line); } str = _T(""); for (unsigned int i = 0; i < msgLines.size(); i++) str += msgLines[i] + _T("\r\n"); str.TrimRight(_T("\r\n")); if (str == _T("")) { str = _T("%v"); str += _T("\r\nwritten by Tim Kosse ([email protected])"); str += _T("\r\nPlease visit https://filezilla-project.org/"); } } break; case OPTION_ADMINIPBINDINGS: { CStdString sub; std::list<CStdString> ipBindList; for (unsigned int i = 0; i<_tcslen(value); i++) { TCHAR cur = value[i]; if ((cur < '0' || cur > '9') && cur != '.' && cur != ':') { if (sub == _T("") && cur == '*') { ipBindList.clear(); ipBindList.push_back(_T("*")); break; } if (sub != _T("")) { if (IsIpAddress(sub)) ipBindList.push_back(sub); sub = _T(""); } } else sub += cur; } if (sub != _T("")) { if (IsIpAddress(sub)) ipBindList.push_back(sub); } str = _T(""); for (std::list<CStdString>::iterator iter = ipBindList.begin(); iter!=ipBindList.end(); iter++) if (!IsLocalhost(*iter)) str += *iter + _T(" "); str.TrimRight(_T(" ")); } break; case OPTION_ADMINPASS: if (str != _T("") && str.GetLength() < 6) return; break; case OPTION_MODEZ_DISALLOWED_IPS: case OPTION_IPFILTER_ALLOWED: case OPTION_IPFILTER_DISALLOWED: case OPTION_ADMINIPADDRESSES: { str.Replace('\r', ' '); str.Replace('\n', ' '); str.Replace('\r', ' '); while (str.Replace(_T(" "), _T(" "))); str += _T(" "); CStdString ips; int pos = str.Find(' '); while (pos != -1) { CStdString sub = str.Left(pos); str = str.Mid(pos + 1); str.TrimLeft(' '); if (sub == _T("*")) ips += _T(" ") + sub; else { if (IsValidAddressFilter(sub)) ips += " " + sub; pos = str.Find(' '); } } ips.TrimLeft(' '); str = ips; } break; case OPTION_IPBINDINGS: { std::list<CStdString> ipBindList; str += _T(" "); while (!str.empty()) { int pos = str.Find(' '); if (pos < 0) { break; } CStdString sub = str.Left(pos); str = str.Mid(pos + 1); if (sub == _T("*")) { ipBindList.clear(); ipBindList.push_back(_T("*")); break; } else if (IsIpAddress(sub, true)) { ipBindList.push_back(sub); } } if (ipBindList.empty()) ipBindList.push_back(_T("*")); str.clear(); for (auto const& ip : ipBindList) { str += ip + _T(" "); } str.TrimRight(_T(" ")); } break; case OPTION_CUSTOMPASVIPSERVER: if (str.Find(_T("filezilla.sourceforge.net")) != -1) str = _T("http://ip.filezilla-project.org/ip.php"); break; } { simple_lock lock(m_mutex); m_sOptionsCache[nOptionID-1].bCached = TRUE; m_sOptionsCache[nOptionID-1].nType = 0; m_sOptionsCache[nOptionID-1].str = str; m_OptionsCache[nOptionID-1]=m_sOptionsCache[nOptionID-1]; } if (!save) return; USES_CONVERSION; CStdString xmlFileName = GetExecutableDirectory() + _T("FileZilla Server.xml"); char* bufferA = T2A(xmlFileName); if (!bufferA) return; TiXmlDocument document; if (!document.LoadFile(bufferA)) return; TiXmlElement* pRoot = document.FirstChildElement("FileZillaServer"); if (!pRoot) return; TiXmlElement* pSettings = pRoot->FirstChildElement("Settings"); if (!pSettings) pSettings = pRoot->LinkEndChild(new TiXmlElement("Settings"))->ToElement(); TiXmlElement* pItem; for (pItem = pSettings->FirstChildElement("Item"); pItem; pItem = pItem->NextSiblingElement("Item")) { const char* pName = pItem->Attribute("name"); if (!pName) continue; CStdString name(pName); if (name != m_Options[nOptionID-1].name) continue; break; } if (!pItem) pItem = pSettings->LinkEndChild(new TiXmlElement("Item"))->ToElement(); pItem->Clear(); pItem->SetAttribute("name", ConvToNetwork(m_Options[nOptionID - 1].name).c_str()); pItem->SetAttribute("type", "string"); pItem->LinkEndChild(new TiXmlText(ConvToNetwork(value).c_str())); document.SaveFile(bufferA); }
void COptions::SetOption(int nOptionID, _int64 value, bool save /*=true*/) { switch (nOptionID) { case OPTION_MAXUSERS: if (value < 0) value = 0; break; case OPTION_THREADNUM: if (value < 1) value = 2; else if (value > 50) value = 2; break; case OPTION_TIMEOUT: if (value < 0) value = 120; else if (value > 9999) value = 120; break; case OPTION_NOTRANSFERTIMEOUT: if (value < 600 && value != 0) value = 600; else if (value > 9999) value = 600; break; case OPTION_LOGINTIMEOUT: if (value < 0) value = 60; else if (value > 9999) value = 60; break; case OPTION_ADMINPORT: if (value > 65535) value = 14147; else if (value < 1) value = 14147; break; case OPTION_LOGTYPE: if (value != 0 && value != 1) value = 0; break; case OPTION_LOGLIMITSIZE: if ((value > 999999 || value < 10) && value != 0) value = 100; break; case OPTION_LOGDELETETIME: if (value > 999 || value < 0) value = 14; break; case OPTION_DOWNLOADSPEEDLIMITTYPE: case OPTION_UPLOADSPEEDLIMITTYPE: if (value < 0 || value > 2) value = 0; break; case OPTION_DOWNLOADSPEEDLIMIT: case OPTION_UPLOADSPEEDLIMIT: if (value < 1) value = 1; else if (value > 1048576) value = 1048576; break; case OPTION_BUFFERSIZE: if (value < 256 || value > (1024*1024)) value = 32768; break; case OPTION_BUFFERSIZE2: if (value < 256 || value > (1024*1024*128)) value = 262144; break; case OPTION_CUSTOMPASVIPTYPE: if (value < 0 || value > 2) value = 0; break; case OPTION_MODEZ_USE: if (value < 0 || value > 1) value = 0; break; case OPTION_MODEZ_LEVELMIN: if (value < 0 || value > 8) value = 1; break; case OPTION_MODEZ_LEVELMAX: if (value < 8 || value > 9) value = 9; break; case OPTION_MODEZ_ALLOWLOCAL: if (value < 0 || value > 1) value = 0; break; case OPTION_AUTOBAN_ATTEMPTS: if (value < OPTION_AUTOBAN_ATTEMPTS_MIN) value = OPTION_AUTOBAN_ATTEMPTS_MIN; if (value > OPTION_AUTOBAN_ATTEMPTS_MAX) value = OPTION_AUTOBAN_ATTEMPTS_MAX; break; case OPTION_AUTOBAN_BANTIME: if (value < 1) value = 1; if (value > 999) value = 999; break; } Init(); { simple_lock lock(m_mutex); m_sOptionsCache[nOptionID-1].nType = 1; m_sOptionsCache[nOptionID-1].value = value; m_sOptionsCache[nOptionID-1].bCached = TRUE; m_OptionsCache[nOptionID-1] = m_sOptionsCache[nOptionID - 1]; } if (!save) return; CStdString valuestr; valuestr.Format( _T("%I64d"), value); USES_CONVERSION; CStdString xmlFileName = GetExecutableDirectory() + _T("FileZilla Server.xml"); char* bufferA = T2A(xmlFileName); if (!bufferA) return; TiXmlDocument document; if (!document.LoadFile(bufferA)) return; TiXmlElement* pRoot = document.FirstChildElement("FileZillaServer"); if (!pRoot) return; TiXmlElement* pSettings = pRoot->FirstChildElement("Settings"); if (!pSettings) pSettings = pRoot->LinkEndChild(new TiXmlElement("Settings"))->ToElement(); TiXmlElement* pItem; for (pItem = pSettings->FirstChildElement("Item"); pItem; pItem = pItem->NextSiblingElement("Item")) { const char* pName = pItem->Attribute("name"); if (!pName) continue; CStdString name(pName); if (name != m_Options[nOptionID-1].name) continue; break; } if (!pItem) pItem = pSettings->LinkEndChild(new TiXmlElement("Item"))->ToElement(); pItem->Clear(); pItem->SetAttribute("name", ConvToNetwork(m_Options[nOptionID-1].name).c_str()); pItem->SetAttribute("type", "numeric"); pItem->LinkEndChild(new TiXmlText(ConvToNetwork(valuestr).c_str())); document.SaveFile(bufferA); }
//{Envent Functions void AutoVersioning::OnProjectLoadingHook(cbProject* project, TiXmlElement* elem, bool loading) { if(loading) { // TODO (KILLERBOT) : should we have default values, in case something would be missing ? // OPTI : we could choose not to write out default values in the xml --> smaller cbp avConfig Config; m_IsVersioned[project] = false; // default not active unless we find xml for it const TiXmlElement* Node = elem->FirstChildElement("AutoVersioning"); if (Node) { m_IsVersioned[project] = true; TiXmlHandle Handle(const_cast<TiXmlElement*>(Node)); if(const TiXmlElement* pElem = Handle.FirstChildElement("Scheme").ToElement()) { int Help = 0; if(pElem->QueryIntAttribute("minor_max", &Help) == TIXML_SUCCESS) { Config.Scheme.MinorMax = static_cast<long>(Help); } if(pElem->QueryIntAttribute("build_max", &Help) == TIXML_SUCCESS) { Config.Scheme.BuildMax = static_cast<long>(Help); } if(pElem->QueryIntAttribute("rev_max", &Help) == TIXML_SUCCESS) { Config.Scheme.RevisionMax = static_cast<long>(Help); } if(pElem->QueryIntAttribute("rev_rand_max", &Help) == TIXML_SUCCESS) { Config.Scheme.RevisionRandMax = static_cast<long>(Help); } if(pElem->QueryIntAttribute("build_times_to_increment_minor", &Help) == TIXML_SUCCESS) { Config.Scheme.BuildTimesToIncrementMinor = static_cast<long>(Help); } } if(const TiXmlElement* pElem = Handle.FirstChildElement("Settings").ToElement()) { Config.Settings.Language = pElem->Attribute("language"); Config.Settings.SvnDirectory = pElem->Attribute("svn_directory"); Config.Settings.HeaderPath = pElem->Attribute("header_path"); int Help = 0; if(pElem->QueryIntAttribute("autoincrement", &Help) == TIXML_SUCCESS) { Config.Settings.Autoincrement = Help?true:false; } if(pElem->QueryIntAttribute("date_declarations", &Help) == TIXML_SUCCESS) { Config.Settings.DateDeclarations = Help?true:false; } if(pElem->QueryIntAttribute("use_define", &Help) == TIXML_SUCCESS) { Config.Settings.UseDefine = Help?true:false; } // GJH 03/03/10 Added manifest updating. if(pElem->QueryIntAttribute("update_manifest", &Help) == TIXML_SUCCESS) { Config.Settings.UpdateManifest = Help?true:false; } if(pElem->QueryIntAttribute("do_auto_increment", &Help) == TIXML_SUCCESS) { Config.Settings.DoAutoIncrement = Help?true:false; } if(pElem->QueryIntAttribute("ask_to_increment", &Help) == TIXML_SUCCESS) { Config.Settings.AskToIncrement = Help?true:false; } if(pElem->QueryIntAttribute("svn", &Help) == TIXML_SUCCESS) { Config.Settings.Svn = Help?true:false; } } if(const TiXmlElement* pElem = Handle.FirstChildElement("Code").ToElement()) { Config.Code.HeaderGuard = pElem->Attribute("header_guard"); Config.Code.NameSpace = pElem->Attribute("namespace"); Config.Code.Prefix = pElem->Attribute("prefix"); } if(const TiXmlElement* pElem = Handle.FirstChildElement("Changes_Log").ToElement()) { Config.ChangesLog.AppTitle = pElem->Attribute("app_title"); Config.ChangesLog.ChangesLogPath = pElem->Attribute("changeslog_path"); int Help = 0; if(pElem->QueryIntAttribute("show_changes_editor", &Help) == TIXML_SUCCESS) { Config.ChangesLog.ShowChangesEditor = Help?true:false; } } // do not try to read from version.h, if autoversioning is not enabled for the project, // to avoid error messages if verbose debuglog is on avVersionState VersionState; m_versionHeaderPath = FileNormalize(cbC2U(Config.Settings.HeaderPath.c_str()),project->GetBasePath()); avHeader VersionHeader; if(VersionHeader.LoadFile(m_versionHeaderPath)) { VersionState.Values.Major = VersionHeader.GetValue(_("MAJOR")); VersionState.Values.Minor = VersionHeader.GetValue(_("MINOR")); VersionState.Values.Build = VersionHeader.GetValue(_("BUILD")); VersionState.Values.Revision = VersionHeader.GetValue(_("REVISION")); VersionState.Values.BuildCount = VersionHeader.GetValue(_("BUILDS_COUNT")); VersionState.Status.SoftwareStatus = cbU2C(VersionHeader.GetString(_("STATUS"))); VersionState.Status.Abbreviation = cbU2C(VersionHeader.GetString(_("STATUS_SHORT"))); VersionState.BuildHistory = VersionHeader.GetValue(_("BUILD_HISTORY")); } m_ProjectMap[project] = Config; m_ProjectMapVersionState[project] = VersionState; } } else { // Hook called when saving project file. // since rev4332, the project keeps a copy of the <Extensions> element // and re-uses it when saving the project (so to avoid losing entries in it // if plugins that use that element are not loaded atm). // so, instead of blindly inserting the element, we must first check it's // not already there (and if it is, clear its contents) if(m_IsVersioned[project]) { TiXmlElement* node = elem->FirstChildElement("AutoVersioning"); if (!node) { node = elem->InsertEndChild(TiXmlElement("AutoVersioning"))->ToElement(); } node->Clear(); //Used this instead of GetConfig() since if the project is not activated //before saving, then the m_Project is not updated. //This will happen when having multiple projects opened. avConfig NewConfig = m_ProjectMap[project]; TiXmlElement Scheme("Scheme"); Scheme.SetAttribute("minor_max", NewConfig.Scheme.MinorMax); Scheme.SetAttribute("build_max", NewConfig.Scheme.BuildMax); Scheme.SetAttribute("rev_max", NewConfig.Scheme.RevisionMax); Scheme.SetAttribute("rev_rand_max", NewConfig.Scheme.RevisionRandMax); Scheme.SetAttribute("build_times_to_increment_minor", NewConfig.Scheme.BuildTimesToIncrementMinor); node->InsertEndChild(Scheme); TiXmlElement Settings("Settings"); Settings.SetAttribute("autoincrement", NewConfig.Settings.Autoincrement); Settings.SetAttribute("date_declarations", NewConfig.Settings.DateDeclarations); Settings.SetAttribute("use_define", NewConfig.Settings.UseDefine); // GJH 03/03/10 Added manifest updating. Settings.SetAttribute("update_manifest", NewConfig.Settings.UpdateManifest); Settings.SetAttribute("do_auto_increment", NewConfig.Settings.DoAutoIncrement); Settings.SetAttribute("ask_to_increment", NewConfig.Settings.AskToIncrement); Settings.SetAttribute("language", NewConfig.Settings.Language.c_str()); Settings.SetAttribute("svn", NewConfig.Settings.Svn); Settings.SetAttribute("svn_directory", NewConfig.Settings.SvnDirectory.c_str()); Settings.SetAttribute("header_path", NewConfig.Settings.HeaderPath.c_str()); node->InsertEndChild(Settings); TiXmlElement ChangesLog("Changes_Log"); ChangesLog.SetAttribute("show_changes_editor", NewConfig.ChangesLog.ShowChangesEditor); ChangesLog.SetAttribute("app_title", NewConfig.ChangesLog.AppTitle.c_str()); ChangesLog.SetAttribute("changeslog_path", NewConfig.ChangesLog.ChangesLogPath.c_str()); node->InsertEndChild(ChangesLog); TiXmlElement Code("Code"); Code.SetAttribute("header_guard", NewConfig.Code.HeaderGuard.c_str()); Code.SetAttribute("namespace", NewConfig.Code.NameSpace.c_str()); Code.SetAttribute("prefix", NewConfig.Code.Prefix.c_str()); node->InsertEndChild(Code); } // TODO (KILLERBOT) : what if we decide to not version anymore : how to remove ?? } }// OnProjectLoadingHook