Team Fortress 2 Source Code as on 22/4/2020
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.

85 lines
2.9 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: Conversion for general wierd files.
  4. //
  5. //=====================================================================================//
  6. #include "MakeGameData.h"
  7. //-----------------------------------------------------------------------------
  8. // The DX Support file is a very fat expensive KV file, causes a run-time startup slowdown.
  9. // Becauase it normally lives in the game\bin directory, it can't be in the zip or preloaded.
  10. // Thus, it gets reprocessed into just the trivial 360 portion and placed into the platform.zip
  11. // Yes, it's evil.
  12. //-----------------------------------------------------------------------------
  13. bool ProcessDXSupportConfig( bool bWriteToZip )
  14. {
  15. if ( !g_bIsPlatformZip )
  16. {
  17. // only relevant when building platform zip, otherwise no-op
  18. return false;
  19. }
  20. const char *pConfigName = "dxsupport.cfg";
  21. char szTempPath[MAX_PATH];
  22. char szSourcePath[MAX_PATH];
  23. V_ComposeFileName( g_szModPath, "../bin", szTempPath, sizeof( szTempPath ) );
  24. V_ComposeFileName( szTempPath, pConfigName, szSourcePath, sizeof( szSourcePath ) );
  25. CUtlBuffer sourceBuf( 0, 0, CUtlBuffer::TEXT_BUFFER );
  26. if ( !g_pFullFileSystem->ReadFile( szSourcePath, NULL, sourceBuf ) )
  27. {
  28. Msg( "Error! Couldn't open file '%s'!\n", pConfigName );
  29. return false;
  30. }
  31. KeyValues *pKV = new KeyValues( "" );
  32. if ( !pKV->LoadFromBuffer( "dxsupport.cfg", sourceBuf ) )
  33. {
  34. Msg( "Error! Couldn't parse config file '%s'!\n", pConfigName );
  35. pKV->deleteThis();
  36. return false;
  37. }
  38. // only care about the xbox specific dxlevel 98 block
  39. KeyValues *pXboxSubKey = NULL;
  40. for ( KeyValues *pSubKey = pKV->GetFirstSubKey(); pSubKey != NULL && pXboxSubKey == NULL; pSubKey = pSubKey->GetNextKey() )
  41. {
  42. // descend each sub block
  43. for ( KeyValues *pKey = pSubKey->GetFirstSubKey(); pKey != NULL && pXboxSubKey == NULL; pKey = pKey->GetNextKey() )
  44. {
  45. if ( !V_stricmp( pKey->GetName(), "name" ) && pKey->GetInt( (const char *)NULL ) == 98 )
  46. {
  47. pXboxSubKey = pSubKey;
  48. }
  49. }
  50. }
  51. if ( !pXboxSubKey )
  52. {
  53. Msg( "Error! Couldn't find expected dxlevel 98 in config file '%s'!\n", pConfigName );
  54. pKV->deleteThis();
  55. return false;
  56. }
  57. CUtlBuffer kvBuffer( 0, 0, CUtlBuffer::TEXT_BUFFER );
  58. kvBuffer.Printf( "\"dxsupport\"\n" );
  59. kvBuffer.Printf( "{\n" );
  60. kvBuffer.Printf( "\t\"0\"\n" );
  61. kvBuffer.Printf( "\t{\n" );
  62. for ( KeyValues *pKey = pXboxSubKey->GetFirstSubKey(); pKey != NULL; pKey = pKey->GetNextKey() )
  63. {
  64. kvBuffer.Printf( "\t\t\"%s\" \"%s\"\n", pKey->GetName(), pKey->GetString( (const char *)NULL ) );
  65. }
  66. kvBuffer.Printf( "\t}\n" );
  67. kvBuffer.Printf( "}\n" );
  68. CUtlBuffer targetBuf( 0, 0, CUtlBuffer::TEXT_BUFFER | CUtlBuffer::CONTAINS_CRLF );
  69. kvBuffer.ConvertCRLF( targetBuf );
  70. // only appears in zip file
  71. bool bSuccess = WriteBufferToFile( pConfigName, targetBuf, bWriteToZip, WRITE_TO_DISK_NEVER );
  72. pKV->deleteThis();
  73. return bSuccess;
  74. }