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.

312 lines
8.1 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //
  7. //=============================================================================//
  8. // FolderSelectProps.cpp : implementation file
  9. //
  10. #include "stdafx.h"
  11. #include "UI.h"
  12. #include "FolderSelectProps.h"
  13. #ifdef _DEBUG
  14. #define new DEBUG_NEW
  15. #undef THIS_FILE
  16. static char THIS_FILE[] = __FILE__;
  17. #endif
  18. /////////////////////////////////////////////////////////////////////////////
  19. // CFolderSelectProps dialog
  20. CFolderSelectProps::CFolderSelectProps(CWnd* pParent /*=NULL*/)
  21. : CPropertyPage(CFolderSelectProps::IDD),
  22. m_StrSupportHTTPPath("SupportHTTPPath"),
  23. m_StrPlayerHTTPPath("PlayerHTTPPath"),
  24. m_StrPlayerDir("PlayerDir"),
  25. m_StrTFStatsDir("TFStatsDir"),
  26. m_StrSupportDir("SupportDir"),
  27. m_StrRuleDir("RuleDir"),
  28. m_StrOutDir("OutputDir"),
  29. m_BoolSupportDefault("DefaultSupportDir"),
  30. m_BoolTFStatsDefault("DefaultTFStatsDir"),
  31. m_BoolOutputDefault("DefaultOutputDir"),
  32. m_BoolRuleDefault("DefaultRuleDir"),
  33. m_BoolPlayerDefault("DefaultPlayerDir")
  34. {
  35. //{{AFX_DATA_INIT(CFolderSelectProps)
  36. //}}AFX_DATA_INIT
  37. m_psp.dwFlags &= ~PSP_HASHELP;
  38. theApp.m_OutDir=m_StrOutDir.toString();
  39. theApp.m_TFStatsDir=m_StrTFStatsDir.toString();
  40. theApp.m_RuleDir=m_StrRuleDir.toString();
  41. theApp.m_SupportDir=m_StrSupportDir.toString();
  42. theApp.m_SupportHTTPPath=m_StrSupportHTTPPath.toString();
  43. theApp.m_PlayerDir=m_StrPlayerDir.toString();
  44. theApp.m_PlayerHTTPPath=m_StrPlayerHTTPPath.toString();
  45. alreadyAcknowledged=false;
  46. lockOutDir=lockTFSDir=false;
  47. windowInitted=false;
  48. }
  49. void CFolderSelectProps::DoDataExchange(CDataExchange* pDX)
  50. {
  51. CDialog::DoDataExchange(pDX);
  52. //{{AFX_DATA_MAP(CFolderSelectProps)
  53. DDX_Control(pDX, IDC_DEFTFSTATS, m_DefTFStats);
  54. DDX_Control(pDX, IDC_DEFSUPPORT, m_DefSupport);
  55. DDX_Control(pDX, IDC_DEFRULE, m_DefRule);
  56. DDX_Control(pDX, IDC_DEFPLAYER, m_DefPlayer);
  57. DDX_Control(pDX, IDC_DEFOUTPUT, m_DefOutput);
  58. DDX_Control(pDX, IDC_SUPPORTHTTPPATH, m_SupportHTTPPath);
  59. DDX_Control(pDX, IDC_PLAYERHTTPPATH, m_PlayerHTTPPath);
  60. DDX_Control(pDX, IDC_PLAYERDIR, m_PlayerDir);
  61. DDX_Control(pDX, IDC_TFSTATSDIR, m_TFStatsDir);
  62. DDX_Control(pDX, IDC_SUPPORTDIR, m_SupportDir);
  63. DDX_Control(pDX, IDC_RULEDIR, m_RuleDir);
  64. DDX_Control(pDX, IDC_OUTPUTDIR, m_OutDir);
  65. //}}AFX_DATA_MAP
  66. }
  67. BEGIN_MESSAGE_MAP(CFolderSelectProps, CDialog)
  68. //{{AFX_MSG_MAP(CFolderSelectProps)
  69. ON_BN_CLICKED(IDC_DEFOUTPUT, OnDefaultCheckBoxClick)
  70. ON_EN_CHANGE(IDC_TFSTATSDIR, OnChangeTfstatsdir)
  71. ON_BN_CLICKED(IDC_DEFPLAYER, OnDefaultCheckBoxClick)
  72. ON_BN_CLICKED(IDC_DEFRULE, OnDefaultCheckBoxClick)
  73. ON_BN_CLICKED(IDC_DEFSUPPORT, OnDefaultCheckBoxClick)
  74. ON_BN_CLICKED(IDC_DEFTFSTATS, OnDefaultCheckBoxClick)
  75. ON_EN_CHANGE(IDC_OUTPUTDIR, OnChangeOutputdir)
  76. //}}AFX_MSG_MAP
  77. END_MESSAGE_MAP()
  78. /////////////////////////////////////////////////////////////////////////////
  79. // CFolderSelectProps message handlers
  80. #include "propsht.h"
  81. #include <winerror.h>
  82. BOOL CFolderSelectProps::OnSetActive()
  83. {
  84. //call superclass
  85. BOOL bRes=this->CPropertyPage::OnSetActive();
  86. if (theApp.FirstEverTimeRun && !alreadyAcknowledged)
  87. {
  88. alreadyAcknowledged=true;
  89. m_DefSupport.SetCheck(1);
  90. m_DefPlayer.SetCheck(1);
  91. m_DefOutput.SetCheck(1);
  92. m_DefTFStats.SetCheck(1);
  93. m_DefRule.SetCheck(1);
  94. m_BoolSupportDefault=1;
  95. m_BoolTFStatsDefault=1;
  96. m_BoolOutputDefault=1;
  97. m_BoolRuleDefault=1;
  98. m_BoolPlayerDefault=1;
  99. }
  100. m_TFStatsDir.EnableWindow(!m_DefTFStats.GetCheck());
  101. m_SupportHTTPPath.EnableWindow(!m_DefSupport.GetCheck());
  102. m_SupportDir.EnableWindow(!m_DefSupport.GetCheck());
  103. m_RuleDir.EnableWindow(!m_DefRule.GetCheck());
  104. m_PlayerHTTPPath.EnableWindow(!m_DefPlayer.GetCheck());
  105. m_PlayerDir.EnableWindow(!m_DefPlayer.GetCheck());
  106. m_OutDir.EnableWindow(!m_DefOutput.GetCheck());
  107. m_DefSupport.SetCheck(m_BoolSupportDefault.toBool());
  108. m_DefTFStats.SetCheck(m_BoolTFStatsDefault.toBool());
  109. m_DefOutput.SetCheck(m_BoolOutputDefault.toBool());
  110. m_DefRule.SetCheck(m_BoolRuleDefault.toBool());
  111. m_DefPlayer.SetCheck(m_BoolPlayerDefault.toBool());
  112. m_SupportHTTPPath.SetWindowText(m_StrSupportHTTPPath.toChars());
  113. m_PlayerHTTPPath.SetWindowText(m_StrPlayerHTTPPath.toChars());
  114. m_PlayerDir.SetWindowText(m_StrPlayerDir.toChars());
  115. m_TFStatsDir.SetWindowText(m_StrTFStatsDir.toChars());
  116. m_SupportDir.SetWindowText(m_StrSupportDir.toChars());
  117. m_RuleDir.SetWindowText(m_StrRuleDir.toChars());
  118. m_OutDir.SetWindowText(m_StrOutDir.toChars());
  119. char buf[500];
  120. string sbuf;
  121. m_TFStatsDir.GetWindowText(buf,500);
  122. sbuf=buf;
  123. addSlash(sbuf);
  124. m_TFStatsDir.SetWindowText(sbuf.c_str());
  125. OnDefaultCheckBoxClick() ;
  126. windowInitted=true;
  127. UpdateFolders();
  128. return bRes;
  129. }
  130. BOOL CFolderSelectProps::OnKillActive()
  131. {
  132. //call superclass
  133. BOOL bRes=this->CPropertyPage::OnKillActive();
  134. m_BoolSupportDefault=m_DefSupport.GetCheck();
  135. m_BoolTFStatsDefault=m_DefTFStats.GetCheck();
  136. m_BoolOutputDefault=m_DefOutput.GetCheck();
  137. m_BoolRuleDefault=m_DefRule.GetCheck();
  138. m_BoolPlayerDefault=m_DefPlayer.GetCheck();
  139. DWORD numbytes;
  140. char tempbuf[1000];
  141. numbytes=m_OutDir.GetWindowText(tempbuf,1000);
  142. m_StrOutDir=theApp.m_OutDir=tempbuf;
  143. numbytes=m_TFStatsDir.GetWindowText(tempbuf,1000);
  144. m_StrTFStatsDir=theApp.m_TFStatsDir=(tempbuf);
  145. numbytes=m_SupportDir.GetWindowText(tempbuf,1000);
  146. m_StrSupportDir=theApp.m_SupportDir=(tempbuf);
  147. numbytes=m_SupportHTTPPath.GetWindowText(tempbuf,1000);
  148. m_StrSupportHTTPPath=theApp.m_SupportHTTPPath=(tempbuf);
  149. numbytes=m_RuleDir.GetWindowText(tempbuf,1000);
  150. m_StrRuleDir=theApp.m_RuleDir=(tempbuf);
  151. numbytes=m_PlayerDir.GetWindowText(tempbuf,1000);
  152. m_StrPlayerDir=theApp.m_PlayerDir=(tempbuf);
  153. numbytes=m_PlayerHTTPPath.GetWindowText(tempbuf,1000);
  154. m_StrPlayerHTTPPath=theApp.m_PlayerHTTPPath=(tempbuf);
  155. windowInitted=false;
  156. return bRes;
  157. }
  158. void CFolderSelectProps::OnDefaultCheckBoxClick()
  159. {
  160. UpdateFolders();
  161. }
  162. void CFolderSelectProps::UpdateFolders(bool safe)
  163. {
  164. if (!windowInitted)
  165. return;
  166. char buf[1000];
  167. m_TFStatsDir.EnableWindow(!m_DefTFStats.GetCheck());
  168. //m_SupportHTTPPath.EnableWindow(!m_DefSupport.GetCheck());
  169. //m_SupportDir.EnableWindow(!m_DefSupport.GetCheck());
  170. m_RuleDir.EnableWindow(!m_DefRule.GetCheck());
  171. //m_PlayerHTTPPath.EnableWindow(!m_DefPlayer.GetCheck());
  172. //m_PlayerDir.EnableWindow(!m_DefPlayer.GetCheck());
  173. m_OutDir.EnableWindow(!m_DefOutput.GetCheck());
  174. this->m_PlayerDir.EnableWindow(theApp.persistPlayerStats && !m_DefPlayer.GetCheck());
  175. this->m_PlayerHTTPPath.EnableWindow(theApp.persistPlayerStats && !m_DefPlayer.GetCheck());
  176. this->m_SupportDir.EnableWindow(theApp.useSupportDir && !m_DefSupport.GetCheck());
  177. this->m_SupportHTTPPath.EnableWindow(theApp.useSupportDir && !m_DefSupport.GetCheck());
  178. string basedir;
  179. if (m_DefTFStats.GetCheck())
  180. {
  181. //find in registry
  182. CPersistentString cps("InstallPath","Software\\Valve\\Half-Life");
  183. basedir=addSlash(cps.toString());
  184. basedir+="tfc\\TFStats\\";
  185. if (!lockTFSDir)
  186. m_TFStatsDir.SetWindowText(basedir.c_str());
  187. }
  188. else
  189. {
  190. m_TFStatsDir.GetWindowText(buf,1000);
  191. basedir=buf;
  192. addSlash(basedir);
  193. }
  194. string outputdir;
  195. if (m_DefOutput.GetCheck())
  196. {
  197. outputdir=basedir+"output\\";
  198. if (!lockOutDir)
  199. m_OutDir.SetWindowText(outputdir.c_str());
  200. }
  201. else
  202. {
  203. m_OutDir.GetWindowText(buf,1000);
  204. outputdir=buf;
  205. addSlash(outputdir);
  206. }
  207. string supportdir=outputdir+"support\\";
  208. string playerdir=outputdir+"players\\";
  209. if (m_DefSupport.GetCheck())
  210. {
  211. m_SupportDir.SetWindowText(supportdir.c_str());
  212. //if (m_DefSupportHTTP.GetCheck())
  213. m_SupportHTTPPath.SetWindowText("../support");
  214. }
  215. if (m_DefRule.GetCheck())
  216. m_RuleDir.SetWindowText(basedir.c_str());
  217. if (m_DefPlayer.GetCheck())
  218. {
  219. m_PlayerDir.SetWindowText(playerdir.c_str());
  220. //if (m_DefPlayerHTTP.GetCheck())
  221. m_PlayerHTTPPath.SetWindowText("../players");
  222. }
  223. }
  224. void CFolderSelectProps::OnChangeTfstatsdir()
  225. {
  226. // TODO: Add your control notification handler code here
  227. if (!lockTFSDir)
  228. {
  229. lockTFSDir=true;
  230. UpdateFolders();
  231. lockTFSDir=false;
  232. }
  233. }
  234. void CFolderSelectProps::OnChangeOutputdir()
  235. {
  236. // TODO: Add your control notification handler code here
  237. if (!lockOutDir)
  238. {
  239. lockOutDir=true;
  240. UpdateFolders();
  241. lockOutDir=false;
  242. }
  243. }