// Creates a new setting and adds it to the destination node CXMLNode *CSettings::CreateSetting(CXMLNode *pDst, const char *szName, const char *szContent) { // Create the node CXMLNode * pNode = pDst->CreateSubNode("setting"); CXMLAttributes *pAttributes = &(pNode->GetAttributes()); // Add the attributes with the corresponding values pAttributes->Create("name")->SetValue(szName); pAttributes->Create("value")->SetValue(szContent); return pNode; }
std::string CServerBrowser::GetServerPassword ( std::string strHost ) { CXMLNode* pConfig = CCore::GetSingletonPtr ()->GetConfig (); CXMLNode* pServerPasswords = pConfig->FindSubNode ( CONFIG_NODE_SERVER_SAVED ); if ( !pServerPasswords ) { pServerPasswords = pConfig ->CreateSubNode ( CONFIG_NODE_SERVER_SAVED ); } //Check if the server password already exists for ( unsigned int i = 0 ; i < pServerPasswords->GetSubNodeCount() ; i++ ) { CXMLAttributes* pAttributes = &(pServerPasswords->GetSubNode(i)->GetAttributes()); if ( pAttributes->Find( "host" ) ) { if ( CXMLAttribute* pHost = pAttributes->Find ( "host" ) ) { std::string strXMLHost = pHost->GetValue(); if ( strXMLHost == strHost ) { CXMLAttribute* pPassword = pAttributes->Create( "password" ); std::string strPassword = pPassword->GetValue(); return strPassword; } } } } return ""; }
void CServerBrowser::SetServerPassword ( std::string strHost, std::string strPassword ) { CXMLNode* pConfig = CCore::GetSingletonPtr ()->GetConfig (); CXMLNode* pServerPasswords = pConfig->FindSubNode ( CONFIG_NODE_SERVER_SAVED ); if ( !pServerPasswords ) { pServerPasswords = pConfig ->CreateSubNode ( CONFIG_NODE_SERVER_SAVED ); } //Check if the server password already exists for ( unsigned int i = 0 ; i < pServerPasswords->GetSubNodeCount() ; i++ ) { CXMLAttributes* pAttributes = &(pServerPasswords->GetSubNode(i)->GetAttributes()); if ( pAttributes->Find( "host" ) ) { if ( CXMLAttribute* pHost = pAttributes->Find ( "host" ) ) { std::string strXMLHost = pHost->GetValue(); if ( strXMLHost == strHost ) { CXMLAttribute* pPassword = pAttributes->Create( "password" ); pPassword->SetValue(strPassword.c_str()); return; } } } } // Otherwise create the node from scratch CXMLNode* pNode = pServerPasswords->CreateSubNode( "server" ); CXMLAttribute* pHostAttribute = pNode->GetAttributes().Create ( "host" ); pHostAttribute->SetValue(strHost.c_str()); CXMLAttribute* pPasswordAttribute = pNode->GetAttributes().Create ( "password" ); pPasswordAttribute->SetValue(strPassword.c_str()); }
/////////////////////////////////////////////////////////////// // // CJoystickManager::GetConfigNode // // Get the main node for load/saving data for the current joypad. // /////////////////////////////////////////////////////////////// CXMLNode* CJoystickManager::GetConfigNode ( bool bCreateIfRequired ) { // Get the root node CXMLNode *pRoot = CCore::GetSingleton ().GetConfig (); if ( !pRoot ) return NULL; // Get the top joypad config node CXMLNode* pSectionNode = pRoot->FindSubNode ( CONFIG_NODE_JOYPAD ); if ( !pSectionNode ) { if ( !bCreateIfRequired ) return NULL; // Non-existant, create a new node pSectionNode = pRoot->CreateSubNode ( CONFIG_NODE_JOYPAD ); } // Get the node for this joystick's GUID CXMLNode* pItemNode = NULL; // Find existing node for( int i=0; true; i++ ) { CXMLNode* pNode = pSectionNode->FindSubNode ( "product", i ); if ( !pNode ) break; CXMLAttributes* pAttributes = &pNode->GetAttributes (); if ( CXMLAttribute* pA = pAttributes->Find ( "guid" ) ) { string value = pA->GetValue (); if ( value == m_DevInfo.strGuid ) { pItemNode = pNode; break; } } } if ( !pItemNode ) { if ( !bCreateIfRequired ) return NULL; // Non-existant, create a new node pItemNode = pSectionNode->CreateSubNode ( "product" ); if ( pItemNode ) { CXMLAttributes* pAttributes = &pItemNode->GetAttributes (); CXMLAttribute* pA = NULL; pA = pAttributes->Create ( "guid" ); pA->SetValue ( m_DevInfo.strGuid.c_str () ); } } return pItemNode; }
/////////////////////////////////////////////////////////////// // // CJoystickManager::SaveToXML // // Save axes mapping for the current joypad. // /////////////////////////////////////////////////////////////// bool CJoystickManager::SaveToXML ( void ) { if ( !IsJoypadValid () ) return false; m_SettingsRevision++; CXMLNode* pMainNode = GetConfigNode ( true ); // Add the current settings if ( pMainNode ) { // Clear our current bind nodes pMainNode->DeleteAllSubNodes (); { // Create a new 'info' node CXMLNode* pNode = pMainNode->CreateSubNode ( "info" ); // If it was created if ( pNode ) { CXMLAttributes* pAttributes = &pNode->GetAttributes (); CXMLAttribute* pA = NULL; pA = pAttributes->Create ( "deadzone" ); pA->SetValue ( m_DevInfo.iDeadZone ); pA = pAttributes->Create ( "saturation" ); pA->SetValue ( m_DevInfo.iSaturation ); pA = pAttributes->Create ( "product_name" ); pA->SetValue ( m_DevInfo.strProductName.c_str () ); } } // Iterate the binds adding them to the XML tree for ( int i = 0 ; i < NUMELMS(m_currentMapping) ; i++ ) { const SMappingLine& line = m_currentMapping[i]; // Create the new 'axis' node CXMLNode* pNode = pMainNode->CreateSubNode ( "axis" ); // If it was created if ( pNode ) { CXMLAttributes* pAttributes = &pNode->GetAttributes (); CXMLAttribute* pA = NULL; pA = pAttributes->Create ( "source_index" ); pA->SetValue ( line.SourceAxisIndex ); pA = pAttributes->Create ( "source_dir" ); pA->SetValue ( line.SourceAxisDir ); pA = pAttributes->Create ( "output_index" ); pA->SetValue ( line.OutputAxisIndex ); pA = pAttributes->Create ( "output_dir" ); pA->SetValue ( line.OutputAxisDir ); pA = pAttributes->Create ( "enabled" ); pA->SetValue ( line.bEnabled ); pA = pAttributes->Create ( "max_value" ); pA->SetValue ( line.MaxValue ); } } return true; } return false; }