//----------------------------------------------------------------------------- // Purpose: walks a particular files config entry and removes an files not valid for this config //----------------------------------------------------------------------------- bool CVCProjConvert::IterateFileConfigurations( IXMLDOMElement *pFile, CUtlSymbol fileName ) { #ifdef _WIN32 CComPtr<IXMLDOMNodeList> pConfigs; pFile->getElementsByTagName( _bstr_t("FileConfiguration"), &pConfigs); if (pConfigs) { long len = 0; pConfigs->get_length(&len); for ( int i=0; i<len; i++ ) { CComPtr<IXMLDOMNode> pNode; pConfigs->get_item( i, &pNode); if (pNode) { CComQIPtr<IXMLDOMElement> pElem( pNode ); CUtlSymbol configName = GetXMLAttribValue( pElem, "Name"); CUtlSymbol excluded = GetXMLAttribValue( pElem ,"ExcludedFromBuild"); if ( configName.IsValid() && excluded.IsValid() ) { int index = FindConfiguration( configName ); if ( index > 0 && excluded == "TRUE" ) { m_Configurations[index].RemoveFile( fileName ); } } } }//for }//if #elif _LINUX DOMNodeList *nodes = pFile->getElementsByTagName( _bstr_t("FileConfiguration")); if (nodes) { int len = nodes->getLength(); for ( int i=0; i<len; i++ ) { DOMNode *node = nodes->item(i); if (node) { CUtlSymbol configName = GetXMLAttribValue( node, "Name"); CUtlSymbol excluded = GetXMLAttribValue( node ,"ExcludedFromBuild"); if ( configName.IsValid() && excluded.IsValid() ) { int index = FindConfiguration( configName ); if ( index >= 0 && excluded == "TRUE" ) { m_Configurations[index].RemoveFile( fileName ); } } } }//for }//if #endif return true; }
//----------------------------------------------------------------------------- // Purpose: extracts the list of configuration names from the vcproj //----------------------------------------------------------------------------- bool CVCProjConvert::ExtractConfigurations( IXMLDOMDocument *pDoc ) { m_Configurations.RemoveAll(); if (!pDoc) { return false; } #ifdef _WIN32 CComPtr<IXMLDOMNodeList> pConfigs; pDoc->getElementsByTagName( _bstr_t("Configuration"), &pConfigs); if (pConfigs) { long len = 0; pConfigs->get_length(&len); for ( int i=0; i<len; i++ ) { CComPtr<IXMLDOMNode> pNode; pConfigs->get_item( i, &pNode ); if (pNode) { CComQIPtr<IXMLDOMElement> pElem( pNode ); CUtlSymbol configName = GetXMLAttribValue( pElem, "Name" ); if ( configName.IsValid() ) { int newIndex = m_Configurations.AddToTail(); CConfiguration & config = m_Configurations[newIndex]; config.SetName( configName ); ExtractIncludes( pElem, config ); } } } } #elif _LINUX DOMNodeList *nodes = pDoc->getElementsByTagName( _bstr_t("Configuration")); if ( nodes ) { int len = nodes->getLength(); for ( int i=0; i<len; i++ ) { DOMNode *node = nodes->item(i); if (node) { CUtlSymbol configName = GetXMLAttribValue( node, "Name" ); if ( configName.IsValid() ) { int newIndex = m_Configurations.AddToTail(); CConfiguration & config = m_Configurations[newIndex]; config.SetName( configName ); ExtractIncludes( node, config ); } } } } #endif return true; }
void IOPortManager::exportXml(ticpp::Element* pConfig) { IOPortMap_t::iterator it; for (it = portMap_m.begin(); it != portMap_m.end(); it++) { ticpp::Element pElem("ioport"); (*it).second->exportXml(&pElem); pConfig->LinkEndChild(&pElem); } }
//----------------------------------------------------------------------------- // Purpose: extracts the project name from the loaded vcproj //----------------------------------------------------------------------------- bool CVCProjConvert::ExtractProjectName( IXMLDOMDocument *pDoc ) { #ifdef _WIN32 CComPtr<IXMLDOMNodeList> pProj; pDoc->getElementsByTagName( _bstr_t("VisualStudioProject"), &pProj); if (pProj) { long len = 0; pProj->get_length(&len); Assert( len == 1 ); if ( len == 1 ) { CComPtr<IXMLDOMNode> pNode; pProj->get_item( 0, &pNode ); if (pNode) { CComQIPtr<IXMLDOMElement> pElem( pNode ); m_Name = GetXMLAttribValue( pElem, "Name"); } } } #elif _LINUX DOMNodeList *nodes = pDoc->getElementsByTagName( _bstr_t("VisualStudioProject") ); if ( nodes ) { int len = nodes->getLength(); if ( len == 1 ) { DOMNode *node = nodes->item(0); if ( node ) { m_Name = GetXMLAttribValue( node, "Name" ); } } } #endif return true; }
//----------------------------------------------------------------------------- // Purpose: walks the file elements in the vcproj and inserts them into configs //----------------------------------------------------------------------------- bool CVCProjConvert::ExtractFiles( IXMLDOMDocument *pDoc ) { if (!pDoc) { return false; } Assert( m_Configurations.Count() ); // some configs must be loaded first #ifdef _WIN32 CComPtr<IXMLDOMNodeList> pFiles; pDoc->getElementsByTagName( _bstr_t("File"), &pFiles); if (pFiles) { long len = 0; pFiles->get_length(&len); for ( int i=0; i<len; i++ ) { CComPtr<IXMLDOMNode> pNode; pFiles->get_item( i, &pNode); if (pNode) { CComQIPtr<IXMLDOMElement> pElem( pNode ); CUtlSymbol fileName = GetXMLAttribValue(pElem,"RelativePath"); if ( fileName.IsValid() ) { CConfiguration::FileType_e type = GetFileType( fileName.String() ); CConfiguration::CFileEntry fileEntry( fileName.String(), type ); for ( int i = 0; i < m_Configurations.Count(); i++ ) // add the file to all configs { CConfiguration & config = m_Configurations[i]; config.InsertFile( fileEntry ); } IterateFileConfigurations( pElem, fileName ); // now remove the excluded ones } } }//for } #elif _LINUX DOMNodeList *nodes = pDoc->getElementsByTagName( _bstr_t("File") ); if (nodes) { int len = nodes->getLength(); for ( int i=0; i<len; i++ ) { DOMNode *node = nodes->item(i); if (node) { CUtlSymbol fileName = GetXMLAttribValue(node,"RelativePath"); if ( fileName.IsValid() ) { char fixedFileName[ MAX_PATH ]; Q_strncpy( fixedFileName, fileName.String(), sizeof(fixedFileName) ); if ( fixedFileName[0] == '.' && fixedFileName[1] == '\\' ) { Q_memmove( fixedFileName, fixedFileName+2, sizeof(fixedFileName)-2 ); } Q_FixSlashes( fixedFileName ); FindFileCaseInsensitive( fixedFileName, sizeof(fixedFileName) ); CConfiguration::FileType_e type = GetFileType( fileName.String() ); CConfiguration::CFileEntry fileEntry( fixedFileName, type ); for ( int i = 0; i < m_Configurations.Count(); i++ ) // add the file to all configs { CConfiguration & config = m_Configurations[i]; config.InsertFile( fileEntry ); } IterateFileConfigurations( node, fixedFileName ); // now remove the excluded ones } } }//for } #endif return true; }
//----------------------------------------------------------------------------- // Purpose: extracts the list of defines and includes used for this config //----------------------------------------------------------------------------- bool CVCProjConvert::ExtractIncludes( IXMLDOMElement *pDoc, CConfiguration & config ) { config.ResetDefines(); config.ResetIncludes(); if (!pDoc) { return false; } #ifdef _WIN32 CComPtr<IXMLDOMNodeList> pTools; pDoc->getElementsByTagName( _bstr_t("Tool"), &pTools); if (pTools) { long len = 0; pTools->get_length(&len); for ( int i=0; i<len; i++ ) { CComPtr<IXMLDOMNode> pNode; pTools->get_item( i, &pNode ); if (pNode) { CComQIPtr<IXMLDOMElement> pElem( pNode ); CUtlSymbol toolName = GetXMLAttribValue( pElem, "Name" ); if ( toolName == "VCCLCompilerTool" ) { CUtlSymbol defines = GetXMLAttribValue( pElem, "PreprocessorDefinitions" ); char *str = (char *)_alloca( Q_strlen( defines.String() ) + 1 ); Assert( str ); Q_strcpy( str, defines.String() ); // now tokenize the string on the ";" char char *delim = strchr( str, ';' ); char *curpos = str; while ( delim ) { *delim = 0; delim++; if ( Q_stricmp( curpos, "WIN32" ) && Q_stricmp( curpos, "_WIN32" ) && Q_stricmp( curpos, "_WINDOWS") && Q_stricmp( curpos, "WINDOWS")) // don't add WIN32 defines { config.AddDefine( curpos ); } curpos = delim; delim = strchr( delim, ';' ); } if ( Q_stricmp( curpos, "WIN32" ) && Q_stricmp( curpos, "_WIN32" ) && Q_stricmp( curpos, "_WINDOWS") && Q_stricmp( curpos, "WINDOWS")) // don't add WIN32 defines { config.AddDefine( curpos ); } CUtlSymbol includes = GetXMLAttribValue( pElem, "AdditionalIncludeDirectories" ); char *str2 = (char *)_alloca( Q_strlen( includes.String() ) + 1 ); Assert( str2 ); Q_strcpy( str2, includes.String() ); // now tokenize the string on the ";" char delim = strchr( str2, ',' ); curpos = str2; while ( delim ) { *delim = 0; delim++; config.AddInclude( curpos ); curpos = delim; delim = strchr( delim, ',' ); } config.AddInclude( curpos ); } } } } #elif _LINUX DOMNodeList *nodes= pDoc->getElementsByTagName( _bstr_t("Tool")); if (nodes) { int len = nodes->getLength(); for ( int i=0; i<len; i++ ) { DOMNode *node = nodes->item(i); if (node) { CUtlSymbol toolName = GetXMLAttribValue( node, "Name" ); if ( toolName == "VCCLCompilerTool" ) { CUtlSymbol defines = GetXMLAttribValue( node, "PreprocessorDefinitions" ); char *str = (char *)_alloca( Q_strlen( defines.String() ) + 1 ); Assert( str ); Q_strcpy( str, defines.String() ); // now tokenize the string on the ";" char char *delim = strchr( str, ';' ); char *curpos = str; while ( delim ) { *delim = 0; delim++; if ( Q_stricmp( curpos, "WIN32" ) && Q_stricmp( curpos, "_WIN32" ) && Q_stricmp( curpos, "_WINDOWS") && Q_stricmp( curpos, "WINDOWS")) // don't add WIN32 defines { config.AddDefine( curpos ); } curpos = delim; delim = strchr( delim, ';' ); } if ( Q_stricmp( curpos, "WIN32" ) && Q_stricmp( curpos, "_WIN32" ) && Q_stricmp( curpos, "_WINDOWS") && Q_stricmp( curpos, "WINDOWS")) // don't add WIN32 defines { config.AddDefine( curpos ); } CUtlSymbol includes = GetXMLAttribValue( node, "AdditionalIncludeDirectories" ); char *str2 = (char *)_alloca( Q_strlen( includes.String() ) + 1 ); Assert( str2 ); Q_strcpy( str2, includes.String() ); // now tokenize the string on the ";" char char token = ','; delim = strchr( str2, token ); if ( !delim ) { token = ';'; delim = strchr( str2, token ); } curpos = str2; while ( delim ) { *delim = 0; delim++; Q_FixSlashes( curpos ); Q_strlower( curpos ); char fullPath[ MAX_PATH ]; Q_snprintf( fullPath, sizeof(fullPath), "%s/%s", m_BaseDir.String(), curpos ); Q_StripTrailingSlash( fullPath ); config.AddInclude( fullPath ); curpos = delim; delim = strchr( delim, token ); } Q_FixSlashes( curpos ); Q_strlower( curpos ); char fullPath[ MAX_PATH ]; Q_snprintf( fullPath, sizeof(fullPath), "%s/%s", m_BaseDir.String(), curpos ); Q_StripTrailingSlash( fullPath ); config.AddInclude( fullPath ); } } } } #endif return true; }
bool GameConfig::loadXml(const std::string &filename){ //xml doc std::string fixedFn = correctFilepath(filename); TiXmlDocument doc( fixedFn ); if( !doc.LoadFile() ){ std::cerr << __FILE__ << __LINE__ << ": Can't read file: " << fixedFn << std::endl; return 0; } TiXmlHandle hDoc(&doc); TiXmlElement *pElem(NULL); TiXmlHandle root(NULL); TiXmlHandle screenRoot(NULL); // find header pElem = hDoc.FirstChildElement( "Infraelly" ).ToElement(); if( !pElem ){ std::cout << "Config: header not found" << std::endl; return 0; } root = TiXmlHandle(pElem); //logs pElem = root.FirstChildElement( "Logs" ).ToElement(); if( pElem == NULL ){ std::cout << "Config: log element not found" << std::endl; } else { pElem->QueryValueAttribute("log", &logging ); } //Screen resolution pElem = root.FirstChildElement( "Screen" ).ToElement(); if( pElem == NULL ){ std::cout << "Config: screen element not found" << std::endl; } else { screenRoot = root.FirstChildElement( "Screen" ); pElem->QueryValueAttribute("fullscreen", &startFullscreen ); //win TiXmlElement *windElem = screenRoot.FirstChildElement( "Windowed" ).ToElement(); if( windElem == NULL ){ std::cout << "Config: windowed element not found" << std::endl; } else { windElem->QueryIntAttribute("w", &wScreenWidth ); windElem->QueryIntAttribute("h", &wScreenHeight ); windElem->QueryIntAttribute("bpp", &wScreenBpp ); } //fs TiXmlElement *fsElem = screenRoot.FirstChildElement( "Fullscreen" ).ToElement(); if( fsElem == NULL ){ std::cout << "Config: fullscreen element not found" << std::endl; } else { fsElem->QueryIntAttribute("w", &fScreenWidth ); fsElem->QueryIntAttribute("h", &fScreenHeight ); fsElem->QueryIntAttribute("bpp", &fScreenBpp ); } } // Audio pElem = root.FirstChildElement( "Audio" ).ToElement(); if( pElem == NULL ){ std::cout << "Config: audio element not found" << std::endl; } else { pElem->QueryValueAttribute("music", &music ); pElem->QueryValueAttribute("fx", &sound ); pElem->QueryIntAttribute("rate", &audioRate ); pElem->QueryIntAttribute("buffer", &audioBuffSize ); } //Server pElem = root.FirstChildElement( "Server" ).ToElement(); if( pElem == NULL ){ std::cout << "Config: server element not found" << std::endl; } else { pElem->QueryValueAttribute("host", &serverIp ); pElem->QueryIntAttribute("port", &serverPort ); pElem->QueryIntAttribute("maxCon", &maxConnections ); pElem->QueryIntAttribute("threads", &serverThreads ); } return true; }