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.

210 lines
6.0 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #include <windows.h>
  7. #include "CreateModWizard.h"
  8. #include "sdklauncher_main.h"
  9. #include "filesystem_tools.h"
  10. #include "sdklauncherdialog.h"
  11. #include "configs.h"
  12. #include <vgui_controls/WizardSubPanel.h>
  13. #include <vgui_controls/DirectorySelectDialog.h>
  14. #include <vgui/ivgui.h>
  15. #include <vgui/iinput.h>
  16. #include <ctype.h>
  17. #include <io.h>
  18. #include <direct.h>
  19. #include "ModWizard_Intro.h"
  20. #include "ModWizard_GetModInfo.h"
  21. #include "ModWizard_CopyFiles.h"
  22. #include "ModWizard_Finished.h"
  23. #include "ModWizard_TemplateOptions.h"
  24. extern char g_engineDir[50];
  25. using namespace vgui;
  26. // Set to true when the mod wizard completes successfully.
  27. bool g_bModWizardFinished = false;
  28. bool CreateFullDirectory( const char *pDirName )
  29. {
  30. CUtlVector<char*> dirs;
  31. const char *separators[2] = {"\\", "/"};
  32. Q_SplitString2( pDirName, separators, ARRAYSIZE( separators ), dirs );
  33. if ( dirs.Count() == 0 )
  34. return false;
  35. char dirName[512];
  36. Q_strncpy( dirName, dirs[0], sizeof( dirName ) );
  37. for ( int i=1; i < dirs.Count(); i++ )
  38. {
  39. Q_AppendSlash( dirName, sizeof( dirName ) );
  40. Q_strncat( dirName, dirs[i], sizeof( dirName ), COPY_ALL_CHARACTERS );
  41. if ( _access( dirName, 0 ) != 0 )
  42. if ( _mkdir( dirName ) != 0 )
  43. return false;
  44. }
  45. dirs.PurgeAndDeleteElements();
  46. return true;
  47. }
  48. bool CreateSubdirectory( const char *pDirName, const char *pSubdirName )
  49. {
  50. char str[512];
  51. Q_strncpy( str, pDirName, sizeof( str ) );
  52. Q_AppendSlash( str, sizeof( str ) );
  53. Q_strncat( str, pSubdirName, sizeof( str ), COPY_ALL_CHARACTERS );
  54. return CreateFullDirectory( str );
  55. }
  56. void RunCreateModWizard( bool bRunFromCommandLine )
  57. {
  58. CCreateModWizard *pWizard = new CCreateModWizard( g_pMainFrame, "CreateModWizard", NULL, bRunFromCommandLine );
  59. pWizard->Run();
  60. }
  61. bool DoCopyFile( const char *pInputFilename, const char *pOutputFilename )
  62. {
  63. return CopyWithReplacements( pInputFilename, NULL, 0, "%s", pOutputFilename );
  64. }
  65. void SetModWizardStatusCode( unsigned long inputCode )
  66. {
  67. DWORD code = inputCode;
  68. HKEY hKey;
  69. // Changed to HKEY_CURRENT_USER from HKEY_LOCAL_MACHINE
  70. if ( RegCreateKeyEx( HKEY_CURRENT_USER, "Software\\Valve\\SourceSDK", 0, 0, 0, KEY_ALL_ACCESS, NULL, &hKey, NULL ) == ERROR_SUCCESS )
  71. {
  72. RegSetValueEx( hKey, "ModWizard_StatusCode", 0, REG_DWORD, (unsigned char*)&code, sizeof( code ) );
  73. RegCloseKey( hKey );
  74. }
  75. }
  76. void NoteModWizardFinished()
  77. {
  78. g_bModWizardFinished = true;
  79. }
  80. // --------------------------------------------------------------------------------------------------------------------- //
  81. // CFinalStatusWindow
  82. // --------------------------------------------------------------------------------------------------------------------- //
  83. class CFinalStatusWindow : public vgui::Frame
  84. {
  85. public:
  86. typedef vgui::Frame BaseClass;
  87. CFinalStatusWindow( vgui::Panel *parent, const char *pName, const char *pOutputDirName, const char *pOutputModGamedirName )
  88. : BaseClass( parent, pName )
  89. {
  90. m_pLabel = new vgui::Label( this, "MessageLabel", "" );
  91. LoadControlSettings( "FinalStatusWindow.res" );
  92. char msg[512];
  93. Q_snprintf( msg, sizeof( msg ), "Files copied successfully!\n\n"
  94. "- The source code is in '%ssrc'.\n"
  95. "- You can run the base mod by running '%srunmod.bat'.\n"
  96. "- You can run the HL2 mod by running '%srunhl2.bat'.\n"
  97. "- There is also a new item in your game list."
  98. , pOutputDirName, pOutputDirName, pOutputDirName );
  99. m_pLabel->SetText( msg );
  100. }
  101. private:
  102. vgui::Label *m_pLabel;
  103. };
  104. // --------------------------------------------------------------------------------------------------------------------- //
  105. // CreateModWizard implementation.
  106. // --------------------------------------------------------------------------------------------------------------------- //
  107. CCreateModWizard::CCreateModWizard( vgui::Panel *parent, const char *name, KeyValues *pKeyValues, bool bRunFromCommandLine )
  108. : BaseClass( parent, name )
  109. {
  110. m_bRunFromCommandLine = bRunFromCommandLine;
  111. m_pKeyValues = pKeyValues;
  112. SetBounds(0, 0, 480, 360);
  113. WizardSubPanel *subPanel = new CModWizardSubPanel_Intro( this, "CModWizardSubPanel_Intro" );
  114. subPanel->SetVisible( false );
  115. subPanel = new CModWizardSubPanel_GetModInfo( this, "CModWizardSubPanel_GetModInfo" );
  116. subPanel->SetVisible( false );
  117. subPanel = new CModWizardSubPanel_TemplateOptions( this, "CModWizardSubPanel_TemplateOptions" );
  118. subPanel->SetVisible( false );
  119. // Tell the config manager which games to put in the config by default
  120. if ( !V_strcmp( g_engineDir, "orangebox" ) )
  121. {
  122. subPanel = new CModWizardSubPanel_CopyFiles_Source2009( this, "CModWizardSubPanel_CopyFiles" );
  123. }
  124. else if ( !V_strcmp( g_engineDir, "source2007" ) )
  125. {
  126. subPanel = new CModWizardSubPanel_CopyFiles_Source2007( this, "CModWizardSubPanel_CopyFiles" );
  127. }
  128. else
  129. {
  130. subPanel = new CModWizardSubPanel_CopyFiles_Source2006( this, "CModWizardSubPanel_CopyFiles" );
  131. }
  132. subPanel->SetVisible( false );
  133. subPanel = new CModWizardSubPanel_Finished( this, "CModWizardSubPanel_Finished" );
  134. subPanel->SetVisible( false );
  135. }
  136. CCreateModWizard::~CCreateModWizard()
  137. {
  138. if ( m_bRunFromCommandLine )
  139. {
  140. g_bAppQuit = true;
  141. if ( g_bModWizardFinished )
  142. SetModWizardStatusCode( 2 );
  143. else
  144. SetModWizardStatusCode( 3 );
  145. }
  146. }
  147. void CCreateModWizard::Run()
  148. {
  149. // Set the CompletionCode in the registry to say that we've started.
  150. g_bModWizardFinished = false;
  151. SetModWizardStatusCode( 1 );
  152. CModWizardSubPanel_Intro *pIntro = (CModWizardSubPanel_Intro*)FindChildByName( "CModWizardSubPanel_Intro" );
  153. if ( !pIntro )
  154. Error( "Missing CModWizardSubPanel_Intro panel." );
  155. if ( g_bAutoHL2Mod )
  156. {
  157. pIntro->m_pModHL2Button->SetSelected( true );
  158. BaseClass::Run( dynamic_cast<WizardSubPanel *>( FindChildByName( "CModWizardSubPanel_GetModInfo" ) ) );
  159. }
  160. else
  161. {
  162. BaseClass::Run( dynamic_cast<WizardSubPanel *>(pIntro) );
  163. }
  164. MoveToCenterOfScreen();
  165. Activate();
  166. vgui::input()->SetAppModalSurface( GetVPanel() );
  167. }