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.

252 lines
7.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 "inputsystem/iinputsystem.h"
  15. #include "tier0/icommandline.h"
  16. #include "filesystem_init.h"
  17. #include "CMDRipperMain.h"
  18. #include "isqlwrapper.h"
  19. // memdbgon must be the last include file in a .cpp file!!!
  20. #include <tier0/memdbgon.h>
  21. #define MDRIPPER_MAIN_PATH_ID "MAIN"
  22. #define MDRIPPER_WRITE_PATH "DEFAULT_WRITE_PATH"
  23. CMDRipperMain *g_pMainFrame = 0;
  24. ISQLWrapper *g_pSqlWrapper;
  25. // Dummy window
  26. static WNDCLASS staticWndclass = { NULL };
  27. static ATOM staticWndclassAtom = 0;
  28. static HWND staticHwnd = 0;
  29. // List of our game configs, as read from the gameconfig.txt file
  30. //CGameConfigManager g_ConfigManager;
  31. //CUtlVector<CGameConfig *> g_Configs;
  32. HANDLE g_dwChangeHandle = NULL;
  33. //-----------------------------------------------------------------------------
  34. // Purpose:
  35. // Output : const char
  36. //-----------------------------------------------------------------------------
  37. const char *GetBaseDirectory( void )
  38. {
  39. static char path[MAX_PATH] = {0};
  40. if ( path[0] == 0 )
  41. {
  42. GetModuleFileName( (HMODULE)GetAppInstance(), path, sizeof( path ) );
  43. Q_StripLastDir( path, sizeof( path ) ); // Get rid of the filename.
  44. Q_StripTrailingSlash( path );
  45. }
  46. return path;
  47. }
  48. //-----------------------------------------------------------------------------
  49. // Purpose: Message handler for dummy app
  50. //-----------------------------------------------------------------------------
  51. static LRESULT CALLBACK messageProc( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
  52. {
  53. // See if we've gotten a VPROJECT change
  54. if ( msg == WM_SETTINGCHANGE )
  55. {
  56. if ( g_pMainFrame != NULL )
  57. {
  58. // Reset the list and pop an error if they've chosen something we don't understand
  59. //g_pMainFrame->PopulateConfigList();
  60. }
  61. }
  62. return ::DefWindowProc(hwnd,msg,wparam,lparam);
  63. }
  64. //-----------------------------------------------------------------------------
  65. // Purpose: Creates a dummy window that handles windows messages
  66. //-----------------------------------------------------------------------------
  67. void CreateMessageWindow( void )
  68. {
  69. // Make and register a very simple window class
  70. memset(&staticWndclass, 0, sizeof(staticWndclass));
  71. staticWndclass.style = 0;
  72. staticWndclass.lpfnWndProc = messageProc;
  73. staticWndclass.hInstance = GetModuleHandle(NULL);
  74. staticWndclass.lpszClassName = "minidumpRipper_Window";
  75. staticWndclassAtom = ::RegisterClass( &staticWndclass );
  76. // Create an empty window just for message handling
  77. staticHwnd = CreateWindowEx(0, "minidumpRipper_Window", "Hidden Window", 0, 0, 0, 1, 1, NULL, NULL, GetModuleHandle(NULL), NULL);
  78. }
  79. //-----------------------------------------------------------------------------
  80. // Purpose:
  81. //-----------------------------------------------------------------------------
  82. void ShutdownMessageWindow( void )
  83. {
  84. // Kill our windows instance
  85. ::DestroyWindow( staticHwnd );
  86. ::UnregisterClass("minidumpRipper_Window", ::GetModuleHandle(NULL));
  87. }
  88. //-----------------------------------------------------------------------------
  89. // Purpose: Setup all our VGUI info
  90. //-----------------------------------------------------------------------------
  91. bool InitializeVGUI( void )
  92. {
  93. vgui::ivgui()->SetSleep(false);
  94. // Init the surface
  95. vgui::Panel *pPanel = new vgui::Panel( NULL, "TopPanel" );
  96. pPanel->SetVisible(true);
  97. vgui::surface()->SetEmbeddedPanel(pPanel->GetVPanel());
  98. // load the scheme
  99. vgui::scheme()->LoadSchemeFromFile( "resource/sourcescheme.res", NULL );
  100. // localization
  101. g_pVGuiLocalize->AddFile( "resource/platform_%language%.txt" );
  102. g_pVGuiLocalize->AddFile( "resource/vgui_%language%.txt" );
  103. g_pVGuiLocalize->AddFile( "mdmpRipper_english.txt" );
  104. // Start vgui
  105. vgui::ivgui()->Start();
  106. // add our main window
  107. g_pMainFrame = new CMDRipperMain( pPanel, "CMDRipperMain" );
  108. // show main window
  109. g_pMainFrame->MoveToCenterOfScreen();
  110. g_pMainFrame->Activate();
  111. g_pMainFrame->SetSizeable( true );
  112. g_pMainFrame->SetMenuButtonVisible( true );
  113. g_pSqlWrapper = g_pMainFrame->GetSqlWrapper();
  114. return true;
  115. }
  116. //-----------------------------------------------------------------------------
  117. // Purpose: Stop VGUI
  118. //-----------------------------------------------------------------------------
  119. void ShutdownVGUI( void )
  120. {
  121. delete g_pMainFrame;
  122. }
  123. //-----------------------------------------------------------------------------
  124. // The application object
  125. //-----------------------------------------------------------------------------
  126. class CMDRipperApp : public CVguiSteamApp
  127. {
  128. typedef CVguiSteamApp BaseClass;
  129. public:
  130. // Methods of IApplication
  131. virtual bool Create();
  132. virtual bool PreInit();
  133. virtual int Main();
  134. virtual void PostShutdown();
  135. virtual void Destroy() {}
  136. };
  137. DEFINE_WINDOWED_STEAM_APPLICATION_OBJECT( CMDRipperApp );
  138. //-----------------------------------------------------------------------------
  139. // The application object
  140. //-----------------------------------------------------------------------------
  141. bool CMDRipperApp::Create()
  142. {
  143. AppSystemInfo_t appSystems[] =
  144. {
  145. { "inputsystem.dll", INPUTSYSTEM_INTERFACE_VERSION },
  146. { "vgui2.dll", VGUI_IVGUI_INTERFACE_VERSION },
  147. { "", "" } // Required to terminate the list
  148. };
  149. return AddSystems( appSystems );
  150. }
  151. //-----------------------------------------------------------------------------
  152. // Purpose: Entry point
  153. //-----------------------------------------------------------------------------
  154. bool CMDRipperApp::PreInit()
  155. {
  156. if ( !BaseClass::PreInit() )
  157. return false;
  158. // Create a window to capture messages
  159. CreateMessageWindow();
  160. FileSystem_SetErrorMode( FS_ERRORMODE_AUTO );
  161. // We only want to use the gameinfo.txt that is in the bin\vconfig directory.
  162. char dirName[MAX_PATH];
  163. Q_strncpy( dirName, GetBaseDirectory(), sizeof( dirName ) );
  164. Q_AppendSlash( dirName, sizeof( dirName ) );
  165. Q_strncat( dirName, "minidumpRipper", sizeof( dirName ), COPY_ALL_CHARACTERS );
  166. if ( !BaseClass::SetupSearchPaths( dirName, true, true ) )
  167. {
  168. ::MessageBox( NULL, "Error", "Unable to initialize file system\n", MB_OK );
  169. return false;
  170. }
  171. // the "base dir" so we can scan mod name
  172. g_pFullFileSystem->AddSearchPath(GetBaseDirectory(), MDRIPPER_MAIN_PATH_ID);
  173. // the main platform dir
  174. g_pFullFileSystem->AddSearchPath("platform","PLATFORM", PATH_ADD_TO_HEAD);
  175. g_pFullFileSystem->AddSearchPath(".\\minidumpRipper\\",MDRIPPER_WRITE_PATH, PATH_ADD_TO_HEAD);
  176. return true;
  177. }
  178. void CMDRipperApp::PostShutdown()
  179. {
  180. // Stop our message window
  181. ShutdownMessageWindow();
  182. BaseClass::PostShutdown();
  183. }
  184. //-----------------------------------------------------------------------------
  185. // Purpose: Entry point
  186. //-----------------------------------------------------------------------------
  187. int CMDRipperApp::Main()
  188. {
  189. // Run app frame loop
  190. if ( !InitializeVGUI() )
  191. return 0;
  192. // Run the app
  193. while (vgui::ivgui()->IsRunning())
  194. {
  195. Sleep( 10 );
  196. vgui::ivgui()->RunFrame();
  197. }
  198. ShutdownVGUI();
  199. return 1;
  200. }