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.

271 lines
7.2 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: Dialog for selecting game configurations
  4. //
  5. //=====================================================================================//
  6. #include <windows.h>
  7. #include <vgui/IVGui.h>
  8. #include <vgui/IInput.h>
  9. #include <vgui/ISystem.h>
  10. #include <vgui_controls/ComboBox.h>
  11. #include <vgui_controls/MessageBox.h>
  12. #include <vgui_controls/FileOpenDialog.h>
  13. #include <KeyValues.h>
  14. #include "CMDErrorPanel.h"
  15. #include "CMDModulePanel.h"
  16. #include "isqlwrapper.h"
  17. #include "CMDRipperMain.h"
  18. // memdbgon must be the last include file in a .cpp file!!!
  19. #include <tier0/memdbgon.h>
  20. using namespace vgui;
  21. CMDRipperMain *g_pCMDRipperMain = NULL;
  22. extern ISQLWrapper *g_pSqlWrapper;
  23. class CModalPreserveMessageBox : public vgui::MessageBox
  24. {
  25. public:
  26. CModalPreserveMessageBox(const char *title, const char *text, vgui::Panel *parent)
  27. : vgui::MessageBox( title, text, parent )
  28. {
  29. m_PrevAppFocusPanel = vgui::input()->GetAppModalSurface();
  30. }
  31. ~CModalPreserveMessageBox()
  32. {
  33. vgui::input()->SetAppModalSurface( m_PrevAppFocusPanel );
  34. }
  35. public:
  36. vgui::VPANEL m_PrevAppFocusPanel;
  37. };
  38. //-----------------------------------------------------------------------------
  39. // Purpose: Utility function to pop up a VGUI message box
  40. //-----------------------------------------------------------------------------
  41. void VGUIMessageBox( vgui::Panel *pParent, const char *pTitle, const char *pMsg, ... )
  42. {
  43. char msg[4096];
  44. va_list marker;
  45. va_start( marker, pMsg );
  46. Q_vsnprintf( msg, sizeof( msg ), pMsg, marker );
  47. va_end( marker );
  48. vgui::MessageBox *dlg = new CModalPreserveMessageBox( pTitle, msg, pParent );
  49. dlg->DoModal();
  50. dlg->Activate();
  51. dlg->RequestFocus();
  52. }
  53. //-----------------------------------------------------------------------------
  54. // Constructor
  55. //-----------------------------------------------------------------------------
  56. CMDRipperMain::CMDRipperMain( Panel *parent, const char *name ) : BaseClass( parent, name ), m_bChanged( false )
  57. {
  58. Assert( !g_pCMDRipperMain );
  59. g_pCMDRipperMain = this;
  60. Sys_LoadInterface( "sqlwrapper", INTERFACEVERSION_ISQLWRAPPER, &hSQLWrapper, (void **)&sqlWrapperFactory );
  61. Assert( hSQLWrapper != NULL );
  62. Assert( sqlWrapperFactory != NULL );
  63. sqlWrapper = sqlWrapperFactory->Create( "cserr", "steamweb-sql", "root", "" );
  64. if ( !sqlWrapper )
  65. {
  66. ivgui()->DPrintf( "SQLWrapper is NULL" );
  67. }
  68. Assert( sqlWrapper != NULL );
  69. g_pSqlWrapper = sqlWrapper;
  70. SetSize(800, 600);
  71. SetMinimumSize(500, 200);
  72. SetMinimizeButtonVisible( true );
  73. m_pMenuBar = new vgui::MenuBar( this, "Main Menu Bar" );
  74. m_pMenuBar->SetPos( 5, 26 );
  75. m_pMenuBar->SetSize( 690, 28 );
  76. Menu *pFileMenu = new Menu(NULL, "File");
  77. pFileMenu->AddMenuItem( "&Open", new KeyValues( "Open" ), this );
  78. m_pMenuBar->AddMenu( "&File", pFileMenu );
  79. Menu *pErrorMenu = new Menu(NULL, "Error");
  80. pErrorMenu->AddMenuItem( "&Error", new KeyValues("Error"), this);
  81. m_pMenuBar->AddMenu( "&Error", pErrorMenu );
  82. m_pErrorPanel = new CMDErrorPanel( this, "MDError Panel" );
  83. m_pErrorPanel->AddActionSignalTarget( this );
  84. m_pModulePanel = new CMDModulePanel( this, "MDModule Panel" );
  85. m_pModulePanel->AddActionSignalTarget( this );
  86. m_pErrorPanel->AddActionSignalTarget( m_pModulePanel );
  87. m_pDetailPanel = new CMDDetailPanel( this, "MDDetail Panel" );
  88. m_pErrorPanel->AddActionSignalTarget( this );
  89. LoadControlSettings( "MDRipperMain.res" );
  90. m_pErrorPanel->SetVisible( false );
  91. m_pModulePanel->SetVisible( false );
  92. m_pDetailPanel->SetVisible( false );
  93. }
  94. //-----------------------------------------------------------------------------
  95. // Destructor
  96. //-----------------------------------------------------------------------------
  97. CMDRipperMain::~CMDRipperMain()
  98. {
  99. g_pCMDRipperMain = NULL;
  100. }
  101. //-----------------------------------------------------------------------------
  102. // Purpose: Kills the whole app on close
  103. //-----------------------------------------------------------------------------
  104. void CMDRipperMain::OnClose( void )
  105. {
  106. BaseClass::OnClose();
  107. ivgui()->Stop();
  108. sqlWrapper->FreeResult();
  109. sqlWrapperFactory->Free( sqlWrapper );
  110. Sys_UnloadModule( hSQLWrapper );
  111. }
  112. /*
  113. //-----------------------------------------------------------------------------
  114. // Purpose: Select the item from the list (updating the environment variable as well)
  115. // Input : index - item to select
  116. //-----------------------------------------------------------------------------
  117. void CMDRipperMain::SetGlobalConfig( const char *modDir )
  118. {
  119. // Set our environment variable
  120. SetVConfigRegistrySetting( GAMEDIR_TOKEN, modDir );
  121. }
  122. */
  123. //-----------------------------------------------------------------------------
  124. // Purpose: Parse commands coming in from the VGUI dialog
  125. //-----------------------------------------------------------------------------
  126. void CMDRipperMain::OnCommand( const char *command )
  127. {
  128. if ( Q_stricmp( command, "Open" ) == 0 )
  129. {
  130. OnOpen();
  131. }
  132. else if ( Q_stricmp( command, "Error" ) == 0 )
  133. {
  134. OnError();
  135. }
  136. BaseClass::OnCommand( command );
  137. }
  138. bool CMDRipperMain::RequestInfo( KeyValues *outputData )
  139. {
  140. const char * szName = outputData->GetName();
  141. if ( !Q_stricmp( szName, "DragDrop" ))
  142. {
  143. bool bAccept = false;
  144. if ( !Q_stricmp( outputData->GetString( "type" ), "Files" ) )
  145. {
  146. // Make sure we only get .mdmp files
  147. KeyValues *pFiles = outputData->FindKey( "list", false );
  148. if ( pFiles )
  149. {
  150. const char *pszFile = pFiles->GetString( "0" );
  151. const char *pszExtension = Q_strrchr( pszFile, '.' );
  152. if ( pszExtension )
  153. {
  154. if ( !Q_stricmp( pszExtension, ".mdmp" ) )
  155. {
  156. outputData->SetPtr( "AcceptPanel", ( Panel * )this );
  157. bAccept = true;
  158. }
  159. }
  160. }
  161. }
  162. return ( bAccept );
  163. }
  164. return ( BaseClass::RequestInfo( outputData ) );
  165. }
  166. void CMDRipperMain::OnOpen()
  167. {
  168. FileOpenDialog *pFileDialog = new FileOpenDialog ( this, "File Open", true);
  169. pFileDialog->AddActionSignalTarget(this);
  170. pFileDialog->AddFilter( "*.mdmp", "MiniDumps", true );
  171. pFileDialog->DoModal( true );
  172. }
  173. void CMDRipperMain::OnError()
  174. {
  175. m_pErrorPanel->NewQuery();
  176. m_pErrorPanel->SetVisible( true );
  177. m_pErrorPanel->MoveToFront();
  178. Repaint();
  179. }
  180. void CMDRipperMain::OnFileSelected( const char *filename )
  181. {
  182. m_pModulePanel->Create( filename );
  183. m_pModulePanel->SetVisible( true );
  184. Repaint();
  185. }
  186. void CMDRipperMain::OnDetail( KeyValues *data )
  187. {
  188. char URL[1024] = "";
  189. strcat( URL, "http://steamweb/cserr_detailsnograph.php?errorid=" );
  190. strcat( URL, data->GetString( "errorID" ) );
  191. m_pDetailPanel->OpenURL( URL );
  192. m_pDetailPanel->SetVisible( true );
  193. m_pDetailPanel->MoveToFront();
  194. Repaint();
  195. }
  196. void CMDRipperMain::OnRefresh()
  197. {
  198. Repaint();
  199. }
  200. void CMDRipperMain::OnLookUp( KeyValues *data )
  201. {
  202. m_pDetailPanel->OpenURL( data->GetString( "url" ) );
  203. m_pDetailPanel->SetVisible( true );
  204. m_pDetailPanel->MoveToFront();
  205. Repaint();
  206. }
  207. void CMDRipperMain::OnDragDrop( KeyValues *pData )
  208. {
  209. KeyValues *pFiles = pData->FindKey( "list", false );
  210. if ( pFiles )
  211. {
  212. DWORD dwIndex = 0;
  213. const char *pszFile = NULL;
  214. char szIndex[ 64 ] = { 0 };
  215. do
  216. {
  217. Q_snprintf( szIndex, sizeof ( szIndex ), "%d", dwIndex );
  218. pszFile = pFiles->GetString( szIndex );
  219. ivgui()->DPrintf( "Got file [%s]", pszFile );
  220. OnFileSelected( pszFile );
  221. dwIndex++;
  222. }
  223. while ( g_pFullFileSystem->FileExists( pszFile ) );
  224. }
  225. }