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.

268 lines
6.1 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //
  7. //=============================================================================//
  8. // UI.cpp : Defines the class behaviors for the application.
  9. //
  10. #include "stdafx.h"
  11. #include "propsht.h"
  12. #include "UI.h"
  13. #include "UIDlg.h"
  14. #include "PersistentString.h"
  15. #ifdef _DEBUG
  16. #define new DEBUG_NEW
  17. #undef THIS_FILE
  18. static char THIS_FILE[] = __FILE__;
  19. #endif
  20. /////////////////////////////////////////////////////////////////////////////
  21. // CUIApp
  22. BEGIN_MESSAGE_MAP(CUIApp, CWinApp)
  23. //{{AFX_MSG_MAP(CUIApp)
  24. // NOTE - the ClassWizard will add and remove mapping macros here.
  25. // DO NOT EDIT what you see in these blocks of generated code!
  26. //}}AFX_MSG
  27. ON_COMMAND(ID_HELP, CWinApp::OnHelp)
  28. END_MESSAGE_MAP()
  29. /////////////////////////////////////////////////////////////////////////////
  30. // CUIApp construction
  31. CUIApp::CUIApp()
  32. {
  33. // Place all significant initialization in InitInstance
  34. pause=false;
  35. pauseSecs=0;
  36. CPersistentString cps("RunBefore");
  37. FirstEverTimeRun=!cps.toBool();
  38. cps=true;
  39. }
  40. /////////////////////////////////////////////////////////////////////////////
  41. // The one and only CUIApp object
  42. CUIApp theApp;
  43. /////////////////////////////////////////////////////////////////////////////
  44. // CUIApp initialization
  45. BOOL CUIApp::InitInstance()
  46. {
  47. // Standard initialization
  48. // If you are not using these features and wish to reduce the size
  49. // of your final executable, you should remove from the following
  50. // the specific initialization routines you do not need.
  51. #ifdef _AFXDLL
  52. Enable3dControls(); // Call this when using MFC in a shared DLL
  53. #else
  54. Enable3dControlsStatic(); // Call this when linking to MFC statically
  55. #endif
  56. persistPlayerStats=false;
  57. useSupportDir=true;
  58. displayMM2=false;
  59. CAllControlsSheet dlg("TFStats");
  60. m_pMainWnd = &dlg;
  61. int nResponse = dlg.DoModal();
  62. if (nResponse == IDOK)
  63. {
  64. // TODO: Place code here to handle when the dialog is
  65. // dismissed with OK
  66. execTFStats();
  67. }
  68. else if (nResponse == IDCANCEL)
  69. {
  70. // TODO: Place code here to handle when the dialog is
  71. // dismissed with Cancel
  72. }
  73. // Since the dialog has been closed, return FALSE so that we exit the
  74. // application, rather than start the application's message pump.
  75. return FALSE;
  76. }
  77. void reporterror31337(LONG i)
  78. {
  79. LPVOID lpMsgBuf;
  80. FormatMessage(
  81. FORMAT_MESSAGE_ALLOCATE_BUFFER |
  82. FORMAT_MESSAGE_FROM_SYSTEM |
  83. FORMAT_MESSAGE_IGNORE_INSERTS,
  84. NULL,
  85. i,
  86. MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
  87. (LPTSTR) &lpMsgBuf,
  88. 0,
  89. NULL
  90. );
  91. // Process any inserts in lpMsgBuf.
  92. // ...
  93. // Display the string.
  94. MessageBox( NULL, (LPCTSTR)lpMsgBuf, "Error", MB_OK | MB_ICONINFORMATION );
  95. // Free the buffer.
  96. LocalFree( lpMsgBuf );
  97. }
  98. string& addSlash(string& tempbuf)
  99. {
  100. if (tempbuf!="")
  101. {
  102. int buflen=tempbuf.length();
  103. if (tempbuf.at(buflen-1) != '\\')
  104. tempbuf+= '\\';
  105. }
  106. return tempbuf;
  107. }
  108. string& removeSlash(string& tempbuf)
  109. {
  110. int buflen=tempbuf.length();
  111. if (buflen > 0 && tempbuf.at(buflen-1) == '\\')
  112. tempbuf.erase(tempbuf.length()-1,1);
  113. return tempbuf;
  114. }
  115. string CUIApp::CTFStatsExec::getExecString()
  116. {
  117. string retval("\"");
  118. retval+=addSlash(TFStatsdirectory);
  119. retval+="TFStatsRT.exe\" \"" ;
  120. retval+=fullpath;
  121. retval+="\" outputDir=\"";
  122. retval+=addSlash(outputdirectory);
  123. retval+=removeSlash(outputsubdir);
  124. retval+="\" ";
  125. retval+="ruleDir=\"";
  126. retval+=removeSlash(ruledirectory);
  127. retval+="\" ";
  128. retval+=" useSupportDir=";
  129. retval+=useSupportDir?"yes":"no";
  130. if (useSupportDir)
  131. {
  132. retval+=" supportDir=\"";
  133. retval+=removeSlash(supportdirectory);
  134. retval+="\" supportHTTPPath=\"";
  135. retval+=removeSlash(supporthttp);
  136. retval+="\"";
  137. }
  138. retval+=" persistPlayerStats=";
  139. retval+=persistPlayerStats?"yes":"no";
  140. if (persistPlayerStats)
  141. {
  142. retval+=" playerDir=\"";
  143. retval+=removeSlash(playerdirectory);
  144. retval+="\" ";
  145. retval+=" playerHTTPPath=\"";
  146. retval+=removeSlash(playerhttp);
  147. retval+="\"";
  148. }
  149. retval+=" eliminateOldPlayers=";
  150. retval+=elimOldPlayers?"yes":"no";
  151. if (elimOldPlayers)
  152. {
  153. retval+=" oldPlayerCutoff=";
  154. char buf[100];
  155. itoa(elimDays,buf,10);
  156. retval+=buf;
  157. retval+=" ";
  158. }
  159. retval+=" displayMM2=";
  160. retval+=displayMM2?"yes":"no";
  161. retval+=" displayStartUpInfo=";
  162. retval+=displayStartupInfo?"yes":"no";
  163. return retval;
  164. }
  165. #include <list>
  166. void CUIApp::execTFStats()
  167. {
  168. std::list<CUIApp::CTFStatsExec>::iterator it;
  169. AllocConsole();
  170. for (it=m_pLogs->begin();it!=m_pLogs->end();++it)
  171. {
  172. CUIApp::CTFStatsExec& c=*it;
  173. it->TFStatsdirectory=m_TFStatsDir;
  174. it->outputdirectory=m_OutDir;
  175. it->ruledirectory=m_RuleDir;
  176. it->supportdirectory=m_SupportDir;
  177. it->playerdirectory=m_PlayerDir;
  178. it->displayMM2=displayMM2;
  179. it->persistPlayerStats=persistPlayerStats;
  180. it->useSupportDir=useSupportDir;
  181. it->supporthttp=m_SupportHTTPPath;
  182. it->playerhttp=m_PlayerHTTPPath;
  183. it->displayStartupInfo=displayStartupInfo;
  184. it->elimOldPlayers=elimOldPlayers;
  185. it->elimDays=elimDays;
  186. string exec=it->getExecString();
  187. //create process takes a non-const char buffer?
  188. char createProcBuf[4000];
  189. memset(createProcBuf,0,4000);
  190. exec.copy(createProcBuf,4000);
  191. PROCESS_INFORMATION pi;
  192. STARTUPINFO si;
  193. memset(&si,0,sizeof(si));
  194. si.cb=sizeof(si);
  195. char buffer[500];
  196. sprintf(buffer,"TFStats is creating a Match report for %s",it->inputfile.c_str());
  197. si.lpTitle=buffer;
  198. SetConsoleTitle(buffer);
  199. BOOL result=CreateProcess(NULL,createProcBuf,NULL,NULL,FALSE,0,NULL,NULL,&si,&pi);
  200. if (pi.hProcess && result)
  201. {
  202. //wait for this one to finish before running next one!
  203. DWORD exitCode=STILL_ACTIVE;
  204. do
  205. {
  206. GetExitCodeProcess(pi.hProcess,&exitCode);
  207. //check every 10th of a second
  208. if (exitCode==STILL_ACTIVE)
  209. Sleep(100);
  210. if (pause)
  211. Sleep(pauseSecs*1000);
  212. } while (exitCode==STILL_ACTIVE);
  213. }
  214. else
  215. {
  216. string badmojo("***ERROR: Could not run \"");
  217. badmojo+=addSlash(it->TFStatsdirectory);
  218. badmojo+="TFStatsRT.exe\"\n\n";
  219. HANDLE hConsOutput=GetStdHandle(STD_OUTPUT_HANDLE);
  220. WriteConsole(hConsOutput,badmojo.c_str(),badmojo.length(),NULL,0);
  221. Sleep(4000);
  222. }
  223. }
  224. FreeConsole();
  225. }