bool CLuaMain::SaveXML(CXMLNode* pRootNode) { list<CXMLFile*>::iterator iter; for (iter = m_XMLFiles.begin(); iter != m_XMLFiles.end(); iter++) { CXMLFile* file = (*iter); if (file) { if (file->GetRootNode() == pRootNode) { return file->Write(); } } } if (m_pResource) { list<CResourceConfigItem*>::iterator iter = m_pResource->ConfigIterBegin(); for (; iter != m_pResource->ConfigIterEnd(); iter++) { CResourceConfigItem* pConfigItem = *iter; if (pConfigItem->GetRoot() == pRootNode) { CXMLFile* pFile = pConfigItem->GetFile(); if (pFile) { return pFile->Write(); } return false; } } } return false; }
/////////////////////////////////////////////////////////////// // // CServerIdManagerImpl::StaticSaveServerIdMap // // // /////////////////////////////////////////////////////////////// void CServerIdManagerImpl::StaticSaveServerIdMap ( void ) { CXMLFile* pConfigFile = g_pCore->GetXML ()->CreateXML ( PathJoin ( g_pClientGame->GetFileCacheRoot(), MTA_SERVERID_LOOKUP_XML ) ); if ( !pConfigFile ) return; pConfigFile->Reset (); CXMLNode* pRoot = pConfigFile->GetRootNode (); if ( !pRoot ) pRoot = pConfigFile->CreateRootNode ( "root" ); // Transfer each item from m_ServerIdMap into the file for ( std::map < CServerIdKey, CServerIdInfo >::iterator it = ms_ServerIdMap.begin () ; it != ms_ServerIdMap.end () ; ++it ) { const SString& strId = it->first.strId; const SString& strDir = it->second.strDir; CXMLNode* pSubNode = pRoot->CreateSubNode ( "id" ); pSubNode->SetTagContent ( strId ); pSubNode->GetAttributes().Create ( "dir" )->SetValue ( strDir ); } pConfigFile->Write (); delete pConfigFile; }
void CLuaMain::SaveXML ( CXMLNode * pRootNode ) { list<CXMLFile *>::iterator iter; for ( iter = m_XMLFiles.begin(); iter != m_XMLFiles.end(); ++iter ) { CXMLFile * file = (*iter); if ( file ) { if ( file->GetRootNode() == pRootNode ) { file->Write(); break; } } } if ( m_pResource ) { list < CResourceFile* > ::iterator iter = m_pResource->IterBegin (); for ( ; iter != m_pResource->IterEnd () ; ++iter ) { CResourceFile* pResourceFile = *iter; if ( pResourceFile->GetType () == CResourceFile::RESOURCE_FILE_TYPE_CONFIG ) { CResourceConfigItem* pConfigItem = static_cast < CResourceConfigItem* > ( pResourceFile ); if ( pConfigItem->GetRoot () == pRootNode ) { CXMLFile* pFile = pConfigItem->GetFile (); if ( pFile ) { pFile->Write (); } break; } } } } }
void CBanManager::SaveBanList ( void ) { // Create the XML file CXMLFile* pFile = g_pServerInterface->GetXML ()->CreateXML ( m_strPath ); if ( pFile ) { // create the root node again as you are outputting all the bans again not just new ones CXMLNode* pRootNode = pFile->CreateRootNode ( "banlist" ); // Check it was created if ( pRootNode ) { // Iterate the ban list adding it to the XML tree CXMLNode* pNode; list < CBan* >::const_iterator iter = m_BanManager.begin (); for ( ; iter != m_BanManager.end (); iter++ ) { pNode = pRootNode->CreateSubNode ( "ban" ); if ( pNode ) { SafeSetValue ( pNode, "nick", (*iter)->GetNick() ); SafeSetValue ( pNode, "ip", (*iter)->GetIP() ); SafeSetValue ( pNode, "serial", (*iter)->GetSerial() ); SafeSetValue ( pNode, "account", (*iter)->GetAccount() ); SafeSetValue ( pNode, "banner", (*iter)->GetBanner() ); SafeSetValue ( pNode, "reason", (*iter)->GetReason() ); SafeSetValue ( pNode, "time", ( unsigned int )(*iter)->GetTimeOfBan() ); if ( (*iter)->GetTimeOfUnban() > 0 ) { SafeSetValue ( pNode, "unban", ( unsigned int )(*iter)->GetTimeOfUnban() ); } } } // Write the XML file pFile->Write (); } // Delete the file pointer delete pFile; } }
/////////////////////////////////////////////////////////////// // // CResourceChecker::CheckMetaFileForIssues // // // /////////////////////////////////////////////////////////////// void CResourceChecker::CheckMetaFileForIssues ( const string& strPath, const string& strFileName, const string& strResourceName ) { // Load the meta file CXMLFile* metaFile = g_pServerInterface->GetXML ()->CreateXML ( strPath.c_str() ); if ( !metaFile ) return; CXMLNode* pRootNode = metaFile->Parse () ? metaFile->GetRootNode () : NULL; if ( !pRootNode ) { delete metaFile; return; } // Ouput warnings... if ( m_bUpgradeScripts == false ) { CheckMetaSourceForIssues ( pRootNode, strFileName, strResourceName, ECheckerMode::WARNINGS ); } else // ..or do an upgrade if ( m_bUpgradeScripts == true ) { bool bHasChanged = false; CheckMetaSourceForIssues ( pRootNode, strFileName, strResourceName, ECheckerMode::UPGRADE, &bHasChanged ); // Has contents changed? if ( bHasChanged ) { // Rename original to xml.old if( !RenameBackupFile( strPath, ".old" ) ) return; // Save new content metaFile->Write (); CLogger::LogPrintf ( "Upgrading %s:%s ...........done\n", strResourceName.c_str (), strFileName.c_str () ); m_upgradedFullPathList.push_back( strPath ); } } delete metaFile; }