Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

345 lines
8.8 KiB

  1. //========= Copyright � 1996-2006, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: VPC
  4. //
  5. //=====================================================================================//
  6. #include "vpc.h"
  7. #define PROPERTYNAME( X, Y ) { X##_##Y, #X, #Y },
  8. static PropertyName_t s_Xbox360PropertyNames[] =
  9. {
  10. #include "projectgenerator_xbox360.inc"
  11. { -1, NULL, NULL }
  12. };
  13. IBaseProjectGenerator* GetXbox360ProjectGenerator()
  14. {
  15. static CProjectGenerator_Xbox360 *s_pProjectGenerator = NULL;
  16. if ( !s_pProjectGenerator )
  17. {
  18. s_pProjectGenerator = new CProjectGenerator_Xbox360();
  19. }
  20. return s_pProjectGenerator->GetProjectGenerator();
  21. }
  22. CProjectGenerator_Xbox360::CProjectGenerator_Xbox360()
  23. {
  24. m_pVCProjGenerator = new CVCProjGenerator();
  25. m_pVCProjGenerator->SetupGeneratorDefinition( this, "xbox360.def", s_Xbox360PropertyNames );
  26. }
  27. bool CProjectGenerator_Xbox360::WriteFile( CProjectFile *pFile )
  28. {
  29. m_XMLWriter.PushNode( "File" );
  30. m_XMLWriter.Write( CFmtStrMax( "RelativePath=\"%s\"", pFile->m_Name.Get() ) );
  31. m_XMLWriter.Write( ">" );
  32. for ( int i = 0; i < pFile->m_Configs.Count(); i++ )
  33. {
  34. if ( !WriteConfiguration( pFile->m_Configs[i] ) )
  35. return false;
  36. }
  37. m_XMLWriter.PopNode( true );
  38. return true;
  39. }
  40. bool CProjectGenerator_Xbox360::WriteFolder( CProjectFolder *pFolder )
  41. {
  42. m_XMLWriter.PushNode( "Filter" );
  43. m_XMLWriter.Write( CFmtStrMax( "Name=\"%s\"", pFolder->m_Name.Get() ) );
  44. m_XMLWriter.Write( ">" );
  45. for ( int iIndex = pFolder->m_Files.Head(); iIndex != pFolder->m_Files.InvalidIndex(); iIndex = pFolder->m_Files.Next( iIndex ) )
  46. {
  47. if ( !WriteFile( pFolder->m_Files[iIndex] ) )
  48. return false;
  49. }
  50. for ( int iIndex = pFolder->m_Folders.Head(); iIndex != pFolder->m_Folders.InvalidIndex(); iIndex = pFolder->m_Folders.Next( iIndex ) )
  51. {
  52. if ( !WriteFolder( pFolder->m_Folders[iIndex] ) )
  53. return false;
  54. }
  55. m_XMLWriter.PopNode( true );
  56. return true;
  57. }
  58. bool CProjectGenerator_Xbox360::WriteConfiguration( CProjectConfiguration *pConfig )
  59. {
  60. if ( pConfig->m_bIsFileConfig )
  61. {
  62. m_XMLWriter.PushNode( "FileConfiguration" );
  63. }
  64. else
  65. {
  66. m_XMLWriter.PushNode( "Configuration" );
  67. }
  68. const char *pOutputName = "???";
  69. if ( !V_stricmp( pConfig->m_Name.Get(), "debug" ) )
  70. {
  71. pOutputName = "Debug|Xbox 360";
  72. }
  73. else if ( !V_stricmp( pConfig->m_Name.Get(), "release" ) )
  74. {
  75. pOutputName = "Release|Xbox 360";
  76. }
  77. else if ( !V_stricmp( pConfig->m_Name.Get(), "profile" ) )
  78. {
  79. pOutputName = "Profile|Xbox 360";
  80. }
  81. else if ( !V_stricmp( pConfig->m_Name.Get(), "retail" ) )
  82. {
  83. pOutputName = "Retail|Xbox 360";
  84. }
  85. else
  86. {
  87. return false;
  88. }
  89. m_XMLWriter.Write( CFmtStrMax( "Name=\"%s\"", pOutputName ) );
  90. // write configuration properties
  91. for ( int i = 0; i < pConfig->m_PropertyStates.m_PropertiesInOutputOrder.Count(); i++ )
  92. {
  93. int sortedIndex = pConfig->m_PropertyStates.m_PropertiesInOutputOrder[i];
  94. WriteProperty( &pConfig->m_PropertyStates.m_Properties[sortedIndex] );
  95. }
  96. if ( !pConfig->m_bIsFileConfig && pConfig->m_PropertyStates.m_Properties.Count() )
  97. {
  98. WriteProperty( NULL, "UseOfMFC", "-1" );
  99. WriteProperty( NULL, "UseOfATL", "0" );
  100. }
  101. m_XMLWriter.Write( ">" );
  102. if ( !WriteTool( "VCPreBuildEventTool", pConfig->GetPreBuildEventTool() ) )
  103. return false;
  104. if ( !WriteTool( "VCCustomBuildTool", pConfig->GetCustomBuildTool() ) )
  105. return false;
  106. if ( !WriteNULLTool( "VCXMLDataGeneratorTool", pConfig ) )
  107. return false;
  108. if ( !WriteNULLTool( "VCWebServiceProxyGeneratorTool", pConfig ) )
  109. return false;
  110. if ( !WriteNULLTool( "VCMIDLTool", pConfig ) )
  111. return false;
  112. if ( !WriteTool( "VCCLX360CompilerTool", pConfig->GetCompilerTool() ) )
  113. return false;
  114. if ( !WriteNULLTool( "VCManagedResourceCompilerTool", pConfig ) )
  115. return false;
  116. if ( !WriteNULLTool( "VCResourceCompilerTool", pConfig ) )
  117. return false;
  118. if ( !WriteTool( "VCPreLinkEventTool", pConfig->GetPreLinkEventTool() ) )
  119. return false;
  120. if ( !WriteTool( "VCX360LinkerTool", pConfig->GetLinkerTool() ) )
  121. return false;
  122. if ( !WriteTool( "VCLibrarianTool", pConfig->GetLibrarianTool() ) )
  123. return false;
  124. if ( !WriteNULLTool( "VCALinkTool", pConfig ) )
  125. return false;
  126. if ( !WriteTool( "VCX360ImageTool", pConfig->GetXboxImageTool() ) )
  127. return false;
  128. if ( !WriteTool( "VCBscMakeTool", pConfig->GetBrowseInfoTool() ) )
  129. return false;
  130. if ( !WriteTool( "VCX360DeploymentTool", pConfig->GetXboxDeploymentTool() ) )
  131. return false;
  132. if ( !WriteTool( "VCPostBuildEventTool", pConfig->GetPostBuildEventTool() ) )
  133. return false;
  134. if ( !pConfig->m_bIsFileConfig )
  135. {
  136. m_XMLWriter.PushNode( "DebuggerTool" );
  137. m_XMLWriter.PopNode( false );
  138. }
  139. m_XMLWriter.PopNode( true );
  140. return true;
  141. }
  142. bool CProjectGenerator_Xbox360::WriteToXML()
  143. {
  144. m_XMLWriter.PushNode( "VisualStudioProject" );
  145. m_XMLWriter.Write( "ProjectType=\"Visual C++\"" );
  146. m_XMLWriter.Write( "Version=\"8.00\"" );
  147. m_XMLWriter.Write( CFmtStrMax( "Name=\"%s\"", m_pVCProjGenerator->GetProjectName().Get() ) );
  148. m_XMLWriter.Write( CFmtStrMax( "ProjectGUID=\"%s\"", m_pVCProjGenerator->GetGUIDString().Get() ) );
  149. m_XMLWriter.Write( ">" );
  150. m_XMLWriter.PushNode( "Platforms" );
  151. m_XMLWriter.PushNode( "Platform" );
  152. m_XMLWriter.Write( "Name=\"Xbox 360\"" );
  153. m_XMLWriter.PopNode( false );
  154. m_XMLWriter.PopNode( true );
  155. m_XMLWriter.PushNode( "ToolFiles" );
  156. m_XMLWriter.PopNode( true );
  157. CUtlVector< CUtlString > configurationNames;
  158. m_pVCProjGenerator->GetAllConfigurationNames( configurationNames );
  159. // write the root configurations
  160. m_XMLWriter.PushNode( "Configurations" );
  161. for ( int i = 0; i < configurationNames.Count(); i++ )
  162. {
  163. CProjectConfiguration *pConfiguration = NULL;
  164. if ( m_pVCProjGenerator->GetRootConfiguration( configurationNames[i].Get(), &pConfiguration ) )
  165. {
  166. if ( !WriteConfiguration( pConfiguration ) )
  167. return false;
  168. }
  169. }
  170. m_XMLWriter.PopNode( true );
  171. m_XMLWriter.PushNode( "References" );
  172. m_XMLWriter.PopNode( true );
  173. m_XMLWriter.PushNode( "Files" );
  174. CProjectFolder *pRootFolder = m_pVCProjGenerator->GetRootFolder();
  175. for ( int iIndex = pRootFolder->m_Folders.Head(); iIndex != pRootFolder->m_Folders.InvalidIndex(); iIndex = pRootFolder->m_Folders.Next( iIndex ) )
  176. {
  177. if ( !WriteFolder( pRootFolder->m_Folders[iIndex] ) )
  178. return false;
  179. }
  180. for ( int iIndex = pRootFolder->m_Files.Head(); iIndex != pRootFolder->m_Files.InvalidIndex(); iIndex = pRootFolder->m_Files.Next( iIndex ) )
  181. {
  182. if ( !WriteFile( pRootFolder->m_Files[iIndex] ) )
  183. return false;
  184. }
  185. m_XMLWriter.PopNode( true );
  186. m_XMLWriter.PopNode( true );
  187. return true;
  188. }
  189. bool CProjectGenerator_Xbox360::Save( const char *pOutputFilename )
  190. {
  191. if ( !m_XMLWriter.Open( pOutputFilename ) )
  192. return false;
  193. bool bValid = WriteToXML();
  194. m_XMLWriter.Close();
  195. return bValid;
  196. }
  197. bool CProjectGenerator_Xbox360::WriteNULLTool( const char *pToolName, const CProjectConfiguration *pConfig )
  198. {
  199. if ( pConfig->m_bIsFileConfig )
  200. return true;
  201. m_XMLWriter.PushNode( "Tool" );
  202. m_XMLWriter.Write( CFmtStr( "Name=\"%s\"", pToolName ) );
  203. m_XMLWriter.PopNode( false );
  204. return true;
  205. }
  206. bool CProjectGenerator_Xbox360::WriteTool( const char *pToolName, const CProjectTool *pProjectTool )
  207. {
  208. if ( !pProjectTool )
  209. {
  210. // not an error, some tools n/a for a config
  211. return true;
  212. }
  213. m_XMLWriter.PushNode( "Tool" );
  214. m_XMLWriter.Write( CFmtStr( "Name=\"%s\"", pToolName ) );
  215. for ( int i = 0; i < pProjectTool->m_PropertyStates.m_PropertiesInOutputOrder.Count(); i++ )
  216. {
  217. int sortedIndex = pProjectTool->m_PropertyStates.m_PropertiesInOutputOrder[i];
  218. WriteProperty( &pProjectTool->m_PropertyStates.m_Properties[sortedIndex] );
  219. }
  220. m_XMLWriter.PopNode( false );
  221. return true;
  222. }
  223. bool CProjectGenerator_Xbox360::WriteProperty( const PropertyState_t *pPropertyState, const char *pOutputName, const char *pOutputValue )
  224. {
  225. if ( !pPropertyState )
  226. {
  227. m_XMLWriter.Write( CFmtStrMax( "%s=\"%s\"", pOutputName, pOutputValue ) );
  228. return true;
  229. }
  230. if ( !pOutputName )
  231. {
  232. pOutputName = pPropertyState->m_pToolProperty->m_OutputString.Get();
  233. if ( !pOutputName[0] )
  234. {
  235. pOutputName = pPropertyState->m_pToolProperty->m_ParseString.Get();
  236. if ( pOutputName[0] == '$' )
  237. {
  238. pOutputName++;
  239. }
  240. }
  241. }
  242. if ( pPropertyState )
  243. {
  244. switch ( pPropertyState->m_pToolProperty->m_nType )
  245. {
  246. case PT_BOOLEAN:
  247. {
  248. bool bEnabled = Sys_StringToBool( pPropertyState->m_StringValue.Get() );
  249. if ( pPropertyState->m_pToolProperty->m_bInvertOutput )
  250. {
  251. bEnabled ^= 1;
  252. }
  253. m_XMLWriter.Write( CFmtStrMax( "%s=\"%s\"", pOutputName, bEnabled ? "true" : "false" ) );
  254. }
  255. break;
  256. case PT_STRING:
  257. m_XMLWriter.Write( CFmtStrMax( "%s=\"%s\"", pOutputName, m_XMLWriter.FixupXMLString( pPropertyState->m_StringValue.Get() ) ) );
  258. break;
  259. case PT_LIST:
  260. case PT_INTEGER:
  261. m_XMLWriter.Write( CFmtStrMax( "%s=\"%s\"", pOutputName, pPropertyState->m_StringValue.Get() ) );
  262. break;
  263. case PT_IGNORE:
  264. break;
  265. default:
  266. g_pVPC->VPCError( "CProjectGenerator_Xbox360: WriteProperty, %s - not implemented", pOutputName );
  267. }
  268. }
  269. return true;
  270. }