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.

223 lines
6.1 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: Configuration utility
  4. //
  5. //===========================================================================//
  6. #include <windows.h>
  7. #include <io.h>
  8. #include <stdio.h>
  9. #include <vgui/ILocalize.h>
  10. #include <vgui/ISurface.h>
  11. #include <vgui/IVGui.h>
  12. #include <vgui_controls/Panel.h>
  13. #include "appframework/tier3app.h"
  14. #include "tier0/icommandline.h"
  15. #include "inputsystem/iinputsystem.h"
  16. #include "matsys_controls/QCGenerator.h"
  17. #include "filesystem_init.h"
  18. #include "CQCGenMain.h"
  19. // memdbgon must be the last include file in a .cpp file!!!
  20. #include <tier0/memdbgon.h>
  21. #define QCGENERATOR_MAIN_PATH_ID "MAIN"
  22. #define QCGENERATOR_WRITE_PATH "DEFAULT_WRITE_PATH"
  23. CQCGenMain *g_pMainFrame = 0;
  24. // Dummy window
  25. static WNDCLASS staticWndclass = { NULL };
  26. static ATOM staticWndclassAtom = 0;
  27. static HWND staticHwnd = 0;
  28. // List of our game configs, as read from the gameconfig.txt file
  29. //HANDLE g_dwChangeHandle = NULL;
  30. char pszPath[MAX_PATH];
  31. char pszScene[MAX_PATH];
  32. //-----------------------------------------------------------------------------
  33. // Purpose: Copy a string into a CUtlVector of characters
  34. //-----------------------------------------------------------------------------
  35. void UtlStrcpy( CUtlVector<char> &dest, const char *pSrc )
  36. {
  37. dest.EnsureCount( (int) (strlen( pSrc ) + 1) );
  38. Q_strncpy( dest.Base(), pSrc, dest.Count() );
  39. }
  40. //-----------------------------------------------------------------------------
  41. // Purpose:
  42. // Output : const char
  43. //-----------------------------------------------------------------------------
  44. const char *GetBaseDirectory( void )
  45. {
  46. static char path[MAX_PATH] = {0};
  47. if ( path[0] == 0 )
  48. {
  49. GetModuleFileName( (HMODULE)GetAppInstance(), path, sizeof( path ) );
  50. Q_StripLastDir( path, sizeof( path ) ); // Get rid of the filename.
  51. Q_StripTrailingSlash( path );
  52. }
  53. return path;
  54. }
  55. //-----------------------------------------------------------------------------
  56. // Purpose: Setup all our VGUI info
  57. //-----------------------------------------------------------------------------
  58. void InitializeVGUI( void )
  59. {
  60. vgui::ivgui()->SetSleep(false);
  61. // Init the surface
  62. vgui::Panel *pPanel = new vgui::Panel( NULL, "TopPanel" );
  63. pPanel->SetVisible(true);
  64. vgui::surface()->SetEmbeddedPanel(pPanel->GetVPanel());
  65. // load the scheme
  66. vgui::scheme()->LoadSchemeFromFile( "resource/sourcescheme.res", NULL );
  67. // localization
  68. g_pVGuiLocalize->AddFile( "resource/platform_%language%.txt");
  69. g_pVGuiLocalize->AddFile( "resource/vgui_%language%.txt");
  70. g_pVGuiLocalize->AddFile( "QCGenerator_english.txt");
  71. // Start vgui
  72. vgui::ivgui()->Start();
  73. // add our main window
  74. g_pMainFrame = new CQCGenMain( pPanel, pszPath, pszScene, "CQCGenMain" );
  75. // show main window
  76. g_pMainFrame->MoveToCenterOfScreen();
  77. g_pMainFrame->Activate();
  78. g_pMainFrame->SetSizeable( true );
  79. g_pMainFrame->SetMenuButtonVisible( true );
  80. }
  81. //-----------------------------------------------------------------------------
  82. // Purpose: Stop VGUI
  83. //-----------------------------------------------------------------------------
  84. void ShutdownVGUI( void )
  85. {
  86. delete g_pMainFrame;
  87. }
  88. //-----------------------------------------------------------------------------
  89. // The application object
  90. //-----------------------------------------------------------------------------
  91. class CQCGeneratorApp : public CVguiSteamApp
  92. {
  93. typedef CVguiSteamApp BaseClass;
  94. public:
  95. // Methods of IApplication
  96. virtual bool Create();
  97. virtual bool PreInit();
  98. virtual int Main();
  99. virtual void PostShutdown();
  100. virtual void Destroy() {}
  101. };
  102. DEFINE_WINDOWED_STEAM_APPLICATION_OBJECT( CQCGeneratorApp );
  103. //-----------------------------------------------------------------------------
  104. // The application object
  105. //-----------------------------------------------------------------------------
  106. bool CQCGeneratorApp::Create()
  107. {
  108. AppSystemInfo_t appSystems[] =
  109. {
  110. { "inputsystem.dll", INPUTSYSTEM_INTERFACE_VERSION },
  111. { "vgui2.dll", VGUI_IVGUI_INTERFACE_VERSION },
  112. { "", "" } // Required to terminate the list
  113. };
  114. return AddSystems( appSystems );
  115. }
  116. //-----------------------------------------------------------------------------
  117. // Purpose: Entry point
  118. //-----------------------------------------------------------------------------
  119. bool CQCGeneratorApp::PreInit()
  120. {
  121. if ( !BaseClass::PreInit() )
  122. return false;
  123. FileSystem_SetErrorMode( FS_ERRORMODE_AUTO );
  124. // We only want to use the gameinfo.txt that is in the bin\vconfig directory.
  125. char dirName[MAX_PATH];
  126. Q_strncpy( dirName, GetBaseDirectory(), sizeof( dirName ) );
  127. Q_AppendSlash( dirName, sizeof( dirName ) );
  128. Q_strncat( dirName, "QCGenerator", sizeof( dirName ), COPY_ALL_CHARACTERS );
  129. if ( !BaseClass::SetupSearchPaths( dirName, true, true ) )
  130. {
  131. ::MessageBox( NULL, "Error", "Unable to initialize file system\n", MB_OK );
  132. return false;
  133. }
  134. // the "base dir" so we can scan mod name
  135. g_pFullFileSystem->AddSearchPath( GetBaseDirectory(), QCGENERATOR_MAIN_PATH_ID );
  136. // the main platform dir
  137. g_pFullFileSystem->AddSearchPath( "platform", "PLATFORM", PATH_ADD_TO_HEAD );
  138. g_pFullFileSystem->AddSearchPath( ".\\QCGenerator\\", QCGENERATOR_WRITE_PATH, PATH_ADD_TO_HEAD );
  139. return true;
  140. }
  141. void CQCGeneratorApp::PostShutdown()
  142. {
  143. BaseClass::PostShutdown();
  144. }
  145. //-----------------------------------------------------------------------------
  146. // Purpose: Entry point
  147. //-----------------------------------------------------------------------------
  148. int CQCGeneratorApp::Main()
  149. {
  150. if ( CommandLine()->ParmValue( "-path" ) )
  151. {
  152. Q_strcpy( pszPath, CommandLine()->ParmValue( "-path" ) );
  153. }
  154. else
  155. {
  156. ::MessageBox( NULL, "Usage: QCGenerator.exe -path [path to smd files] -scene [name of scene]\n", "Error", MB_OK );
  157. return 0;
  158. }
  159. if ( CommandLine()->ParmValue( "-scene" ) )
  160. {
  161. Q_strcpy( pszScene, CommandLine()->ParmValue( "-scene" ) );
  162. }
  163. else
  164. {
  165. ::MessageBox( NULL, "Usage: QCGenerator.exe -path [path to smd files] -scene [name of scene]\n", "Error", MB_OK );
  166. return 0;
  167. }
  168. // Run app frame loop
  169. InitializeVGUI();
  170. // Run the app
  171. while (vgui::ivgui()->IsRunning())
  172. {
  173. Sleep( 10 );
  174. vgui::ivgui()->RunFrame();
  175. }
  176. ShutdownVGUI();
  177. return 1;
  178. }