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.

237 lines
5.1 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. //=============================================================================
  4. #include <windows.h>
  5. // Valve includes
  6. #include "itemtest/itemtest.h"
  7. #include "p4lib/ip4.h"
  8. #include "tier0/icommandline.h"
  9. // Local includes
  10. #include "itemtestapp.h"
  11. #include "runexe.h"
  12. // Last include
  13. #include <tier0/memdbgon.h>
  14. //=============================================================================
  15. //
  16. //=============================================================================
  17. class CItemTestConApp : public CItemTestApp
  18. {
  19. typedef CItemTestApp BaseClass;
  20. public:
  21. // Methods of IApplication
  22. virtual bool Create();
  23. virtual int Main();
  24. protected:
  25. static bool DoSteamId();
  26. static bool DoHelp();
  27. };
  28. //-----------------------------------------------------------------------------
  29. //
  30. //-----------------------------------------------------------------------------
  31. DEFINE_CONSOLE_STEAM_APPLICATION_OBJECT( CItemTestConApp );
  32. //-----------------------------------------------------------------------------
  33. //
  34. //-----------------------------------------------------------------------------
  35. bool CItemTestConApp::Create()
  36. {
  37. AppSystemInfo_t appSystems[] =
  38. {
  39. { "", "" } // Required to terminate the list
  40. };
  41. if ( FindParam( kDev ) && !FindParam( kNoP4 ) )
  42. {
  43. AppModule_t p4Module = LoadModule( "p4lib.dll" );
  44. AddSystem( p4Module, P4_INTERFACE_VERSION );
  45. }
  46. return AddSystems( appSystems );
  47. }
  48. //-----------------------------------------------------------------------------
  49. //
  50. //-----------------------------------------------------------------------------
  51. bool View( CAsset &asset )
  52. {
  53. CUtlString sBinDir;
  54. if ( !CItemUpload::GetBinDirectory( sBinDir ) )
  55. {
  56. Warning( "Cannot determine bin directory\n" );
  57. return false;
  58. }
  59. CSmartPtr< CTargetMDL > pTargetMDL = asset.GetTargetMDL();
  60. if ( !pTargetMDL.IsValid() )
  61. {
  62. Warning( "No target MDL\n" );
  63. return false;
  64. }
  65. CUtlString sMdlPath;
  66. if ( !pTargetMDL->GetOutputPath( sMdlPath ) )
  67. {
  68. Warning( "Cannot determine path to MDL\n" );
  69. return false;
  70. }
  71. CFmtStrMax sHlmvCmd;
  72. if ( CItemUpload::GetDevMode() )
  73. {
  74. sHlmvCmd.sprintf( "\"%s\\hlmv.exe\" \"%s\"", sBinDir.Get(), sMdlPath.Get() );
  75. }
  76. else
  77. {
  78. CUtlString sVProjectDir;
  79. if ( CItemUpload::GetVProjectDir( sVProjectDir ) )
  80. {
  81. sHlmvCmd.sprintf( "\"%s\\hlmv.exe\" -allowdebug -game \"%s\" -nop4 \"%s\"", sBinDir.Get(), sVProjectDir.Get(), sMdlPath.Get() );
  82. }
  83. else
  84. {
  85. Warning( "Cannot determine VPROJECT (gamedir)\n" );
  86. return false;
  87. }
  88. }
  89. char szBinLaunchDir[ MAX_PATH ];
  90. V_ExtractFilePath( sBinDir.String(), szBinLaunchDir, ARRAYSIZE( szBinLaunchDir ) );
  91. return CItemUpload::RunCommandLine( sHlmvCmd.String(), szBinLaunchDir, false );
  92. }
  93. //-----------------------------------------------------------------------------
  94. //
  95. //-----------------------------------------------------------------------------
  96. bool Explore( CAsset &asset )
  97. {
  98. CUtlString sBinDir;
  99. if ( !CItemUpload::GetBinDirectory( sBinDir ) )
  100. {
  101. Warning( "Cannot determine bin directory\n" );
  102. return false;
  103. }
  104. CUtlString sDir;
  105. asset.GetAbsoluteDir( sDir, NULL, &asset );
  106. char szBuf[ MAX_PATH ];
  107. V_FixupPathName( szBuf, ARRAYSIZE( szBuf ), sDir.Get() );
  108. char szBinLaunchDir[ MAX_PATH ];
  109. V_ExtractFilePath( sBinDir.String(), szBinLaunchDir, ARRAYSIZE( szBinLaunchDir ) );
  110. ShellExecute( NULL, "explore", NULL, NULL, szBuf, SW_SHOWNORMAL );
  111. return true;
  112. }
  113. //-----------------------------------------------------------------------------
  114. //
  115. //-----------------------------------------------------------------------------
  116. int CItemTestConApp::Main()
  117. {
  118. if ( DoHelp() )
  119. return 0;
  120. if ( DoSteamId() )
  121. return 0;
  122. CItemUpload::InitManifest();
  123. // If launched with -batch stay in console app and run from parameters specified on the command line only
  124. const bool bListMats = FindParam( kListMats );
  125. if ( bListMats || FindParam( kBatch ) )
  126. {
  127. CAssetTF assetTF;
  128. if ( !ProcessCommandLine( &assetTF, bListMats ) )
  129. return 1;
  130. if ( !bListMats )
  131. {
  132. if ( !assetTF.Compile() )
  133. {
  134. Warning( "Error! Compile Failed\n" );
  135. return 1;
  136. }
  137. Msg( "Compile OK!\n" );
  138. if ( FindParam( kView ) )
  139. {
  140. View( assetTF );
  141. }
  142. if ( FindParam( kExplore ) )
  143. {
  144. Explore( assetTF );
  145. }
  146. }
  147. }
  148. else
  149. {
  150. // If launched without -batch then launch the .exe with the same name in the same directory as this .com executable
  151. RunExe();
  152. }
  153. return 0;
  154. }
  155. //-----------------------------------------------------------------------------
  156. //
  157. //-----------------------------------------------------------------------------
  158. bool CItemTestConApp::DoHelp()
  159. {
  160. if ( !FindParam( kHelp ) )
  161. return false;
  162. PrintHelp();
  163. return true;
  164. }
  165. //-----------------------------------------------------------------------------
  166. //
  167. //-----------------------------------------------------------------------------
  168. bool CItemTestConApp::DoSteamId()
  169. {
  170. if ( !FindParam( kSteamId ) )
  171. return false;
  172. CUtlString sSteamId;
  173. if ( CItemUpload::GetSteamId( sSteamId ) )
  174. {
  175. Msg( "%s\n", sSteamId.String() );
  176. }
  177. else
  178. {
  179. Warning( "Error! Couldn't determine SteamId\n" );
  180. }
  181. return true;
  182. }