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.

182 lines
4.3 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //
  7. //=============================================================================//
  8. // LogSelectProps.cpp : implementation file
  9. //
  10. #include "stdafx.h"
  11. #include "UI.h"
  12. #include "LogSelectProps.h"
  13. #ifdef _DEBUG
  14. #define new DEBUG_NEW
  15. #undef THIS_FILE
  16. static char THIS_FILE[] = __FILE__;
  17. #endif
  18. /////////////////////////////////////////////////////////////////////////////
  19. // CLogSelectProps dialog
  20. CLogSelectProps::CLogSelectProps(CWnd* pParent /*=NULL*/)
  21. : CPropertyPage(CLogSelectProps::IDD),
  22. m_persistLastDirectory(string("LastInputDirectory"))
  23. {
  24. //{{AFX_DATA_INIT(CLogSelectProps)
  25. //}}AFX_DATA_INIT
  26. m_psp.dwFlags &= ~PSP_HASHELP;
  27. alreadyAcknowledged=false;
  28. }
  29. void CLogSelectProps::DoDataExchange(CDataExchange* pDX)
  30. {
  31. CDialog::DoDataExchange(pDX);
  32. //{{AFX_DATA_MAP(CLogSelectProps)
  33. DDX_Control(pDX, IDC_SELECT, m_SelectButton);
  34. DDX_Control(pDX, IDC_REMOVELOG, m_RemoveButton);
  35. DDX_Control(pDX, IDC_LOGS2DO, m_Logs2Do);
  36. //}}AFX_DATA_MAP
  37. }
  38. BEGIN_MESSAGE_MAP(CLogSelectProps, CDialog)
  39. //{{AFX_MSG_MAP(CLogSelectProps)
  40. ON_LBN_SELCHANGE(IDC_LOGS2DO, OnSelchangeLogs2do)
  41. ON_BN_CLICKED(IDC_REMOVELOG, OnRemovelog)
  42. ON_BN_CLICKED(IDC_SELECT, OnSelect)
  43. //}}AFX_MSG_MAP
  44. END_MESSAGE_MAP()
  45. /////////////////////////////////////////////////////////////////////////////
  46. // CLogSelectProps message handlers
  47. void CLogSelectProps::OnSelect()
  48. {
  49. char* fileNameBuf= new char[10000];
  50. memset(fileNameBuf,0,10000);
  51. CFileDialog cfd(TRUE,".log",NULL,0,"Log Files (*.log)|*.log|Text Files (*.txt)|*.txt|All Files (*.*)|*.*||");
  52. cfd.m_ofn.Flags|=OFN_ALLOWMULTISELECT;
  53. cfd.m_ofn.lpstrFile=fileNameBuf;
  54. cfd.m_ofn.nMaxFile=10000;
  55. if (m_persistLastDirectory.toString()!="")
  56. cfd.m_ofn.lpstrInitialDir=m_persistLastDirectory.toString().c_str();
  57. if (cfd.DoModal()==IDOK)
  58. {
  59. POSITION pos=cfd.GetStartPosition();
  60. while(pos)
  61. {
  62. CUIApp::CTFStatsExec* pc=new CUIApp::CTFStatsExec;
  63. CString wow=cfd.GetNextPathName(pos);
  64. //void _splitpath( const char *path, char *drive, char *dir, char *fname, char *ext );
  65. pc->fullpath=wow;
  66. char drvbuf[5];
  67. char dirbuf[10000];
  68. char namebuf[10000];
  69. char extbuf[10000];
  70. char fname[10000];
  71. char inpdir[10000];
  72. _splitpath(pc->fullpath.c_str(),drvbuf,dirbuf,namebuf,extbuf);
  73. sprintf(inpdir,"%s%s",drvbuf,dirbuf);
  74. sprintf(fname,"%s%s",namebuf,extbuf);
  75. pc->outputsubdir=namebuf;
  76. pc->inputfile=fname;
  77. pc->logdirectory=inpdir;
  78. m_persistLastDirectory=inpdir;
  79. int idx=m_Logs2Do.AddString(pc->fullpath.c_str());
  80. m_Logs2Do.SetItemDataPtr(idx,pc);
  81. }
  82. }
  83. delete [] fileNameBuf;
  84. }
  85. list<CUIApp::CTFStatsExec>* CLogSelectProps::getList()
  86. {
  87. list<CUIApp::CTFStatsExec>* pRetList=new list<CUIApp::CTFStatsExec>;
  88. int numItems=m_Logs2Do.GetCount();
  89. for (int i=0;i<numItems;i++)
  90. {
  91. CUIApp::CTFStatsExec * pExec=(CUIApp::CTFStatsExec *)m_Logs2Do.GetItemDataPtr(i);
  92. pRetList->push_back(*pExec);
  93. }
  94. return pRetList;
  95. }
  96. void CLogSelectProps::OnSelchangeLogs2do()
  97. {
  98. if (m_Logs2Do.GetSelCount() > 0)
  99. m_RemoveButton.EnableWindow(TRUE);
  100. else
  101. m_RemoveButton.EnableWindow(FALSE);
  102. }
  103. void CLogSelectProps::OnRemovelog()
  104. {
  105. int* selitems=new int[500];
  106. int numselected=m_Logs2Do.GetSelItems(500,selitems);
  107. //have to do it backwards to account for indices being changed by the actual deletions
  108. for (int i=numselected-1;i>=0;i--)
  109. {
  110. //delete m_Logs2Do.GetItemDataPtr(selitems[i]);
  111. //m_Logs2Do.SetItemData(selitems[i],0);
  112. CString wow;
  113. m_Logs2Do.GetText(selitems[i],wow);
  114. m_Logs2Do.DeleteString(selitems[i]);
  115. }
  116. delete [] selitems;
  117. m_Logs2Do.SetSel(-1,FALSE);
  118. }
  119. #include "propsht.h"
  120. BOOL CLogSelectProps::OnSetActive()
  121. {
  122. //call superclass
  123. BOOL bRes=this->CPropertyPage::OnSetActive();
  124. if (theApp.FirstEverTimeRun && !alreadyAcknowledged)
  125. {
  126. alreadyAcknowledged=true;
  127. CPersistentString cps("InstallPath","Software\\Valve\\Half-Life");
  128. string basedir=addSlash(cps.toString());
  129. basedir+="tfc\\logs";
  130. m_persistLastDirectory=basedir;
  131. }
  132. return bRes;
  133. }
  134. BOOL CLogSelectProps::OnKillActive()
  135. {
  136. //call superclass
  137. BOOL bRes=this->CPropertyPage::OnKillActive();
  138. UpdateAppList();
  139. return bRes;
  140. }
  141. void CLogSelectProps::UpdateAppList()
  142. {
  143. if (theApp.m_pLogs != NULL)
  144. delete(theApp.m_pLogs);
  145. theApp.m_pLogs=getList();
  146. }