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.

396 lines
9.4 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //
  7. //=============================================================================//
  8. // cstm1dlg.cpp : implementation file
  9. //
  10. #include "stdafx.h"
  11. #include "valvelib.h"
  12. #include "cstm1dlg.h"
  13. #include "valvelibaw.h"
  14. #ifdef _PSEUDO_DEBUG
  15. #undef THIS_FILE
  16. static char THIS_FILE[] = __FILE__;
  17. #endif
  18. /////////////////////////////////////////////////////////////////////////////
  19. // CCustom1Dlg dialog
  20. CCustom1Dlg::CCustom1Dlg()
  21. : CAppWizStepDlg(CCustom1Dlg::IDD)
  22. {
  23. //{{AFX_DATA_INIT(CCustom1Dlg)
  24. m_RootPath = _T("");
  25. m_TargetPath = _T("");
  26. m_ProjectType = -1;
  27. m_ToolProject = FALSE;
  28. m_ImplibPath = _T("");
  29. m_PublicProject = FALSE;
  30. m_ConsoleApp = FALSE;
  31. m_PublishImportLib = FALSE;
  32. m_SrcPath = _T("");
  33. //}}AFX_DATA_INIT
  34. m_ProjectType = 0;
  35. m_PublicProject = TRUE;
  36. m_SrcPath = "src";
  37. }
  38. void CCustom1Dlg::DoDataExchange(CDataExchange* pDX)
  39. {
  40. if (pDX->m_bSaveAndValidate == 0)
  41. {
  42. // Refresh the paths based on project information...
  43. if (m_RootPath.GetLength() == 0)
  44. {
  45. if (!Valvelibaw.m_Dictionary.Lookup("FULL_DIR_PATH", m_RootPath))
  46. m_RootPath = "u:\\hl2\\";
  47. m_RootPath.MakeLower();
  48. m_ToolProject = (m_RootPath.Find( "util" ) >= 0);
  49. int idx = m_RootPath.Find( m_SrcPath ); // look for src tree
  50. if (idx >= 0)
  51. {
  52. m_RootPath = m_RootPath.Left( idx );
  53. }
  54. m_TargetPath = m_RootPath;
  55. m_TargetPath += m_SrcPath;
  56. m_TargetPath += "\\lib\\public\\";
  57. m_ImplibPath = "unused";
  58. EnableCheckboxes();
  59. }
  60. }
  61. CAppWizStepDlg::DoDataExchange(pDX);
  62. //{{AFX_DATA_MAP(CCustom1Dlg)
  63. DDX_Text(pDX, IDC_EDIT_ROOT_PATH, m_RootPath);
  64. DDX_Text(pDX, IDC_EDIT_TARGET_PATH, m_TargetPath);
  65. DDX_CBIndex(pDX, IDC_SELECT_PROJECT_TYPE, m_ProjectType);
  66. DDX_Check(pDX, IDC_CHECK_TOOL, m_ToolProject);
  67. DDX_Text(pDX, IDC_EDIT_IMPLIB_PATH, m_ImplibPath);
  68. DDX_Check(pDX, IDC_CHECK_PUBLIC, m_PublicProject);
  69. DDX_Check(pDX, IDC_CHECK_CONSOLE_APP, m_ConsoleApp);
  70. DDX_Check(pDX, IDC_CHECK_PUBLISH_IMPORT, m_PublishImportLib);
  71. DDX_Text(pDX, IDC_EDIT_SRC_PATH, m_SrcPath);
  72. //}}AFX_DATA_MAP
  73. }
  74. static void FixupPath( CString& path )
  75. {
  76. int idx;
  77. idx = path.Find("/");
  78. while (idx >= 0)
  79. {
  80. path.SetAt(idx, '\\' );
  81. idx = path.Find("/");
  82. }
  83. bool hasTerminatingSlash = ( path.Right(1).Find("\\") >= 0 );
  84. if (!hasTerminatingSlash)
  85. path += '\\';
  86. path.MakeLower();
  87. }
  88. static int CountSlashes( CString& path )
  89. {
  90. int count = 0;
  91. int idx = path.Find("\\", 0);
  92. while (idx >= 0)
  93. {
  94. ++count;
  95. idx = path.Find("\\", idx+1 );
  96. }
  97. return count;
  98. }
  99. bool CCustom1Dlg::ComputeRelativePath( )
  100. {
  101. if ( m_RootPath.GetAt(1) != ':' )
  102. {
  103. MessageBox( "Error! The root path must specify a drive!", "Bogus Root Path!", MB_ICONERROR | MB_OK );
  104. return false;
  105. }
  106. if ( m_TargetPath.GetAt(1) != ':' )
  107. {
  108. MessageBox( "Error! The target path must specify a drive!", "Bogus Target Path!", MB_ICONERROR | MB_OK );
  109. return false;
  110. }
  111. CString sourcePath;
  112. if (!Valvelibaw.m_Dictionary.Lookup("FULL_DIR_PATH", sourcePath ))
  113. {
  114. MessageBox( "I can't seem to find the source path!??!", "Umm... Get Brian", MB_ICONERROR | MB_OK );
  115. return false;
  116. }
  117. FixupPath( m_RootPath );
  118. FixupPath( m_TargetPath );
  119. FixupPath( sourcePath );
  120. CString srcRootPath = m_RootPath;
  121. srcRootPath += m_SrcPath;
  122. srcRootPath += "\\";
  123. FixupPath( srcRootPath );
  124. if (sourcePath.Find( srcRootPath ) != 0)
  125. {
  126. MessageBox( "Error! The source path must lie under the root source path!", "Bogus Root Path!", MB_ICONERROR | MB_OK );
  127. return false;
  128. }
  129. if (m_TargetPath.Find( m_RootPath ) != 0)
  130. {
  131. MessageBox( "Error! The target path must lie under the root path!", "Bogus Target Path!", MB_ICONERROR | MB_OK );
  132. return false;
  133. }
  134. int rootLen = m_RootPath.GetLength();
  135. int rootSrcLen = srcRootPath.GetLength();
  136. int sourceLen = sourcePath.GetLength();
  137. int targetLen = m_TargetPath.GetLength();
  138. CString relativePath = m_TargetPath.Right( targetLen - rootLen );
  139. // Now that we've got the relative source path,
  140. // find out how many slashes are in it;
  141. // that'll tell us how many paths to back up....
  142. int i;
  143. CString relativeSourcePath = sourcePath.Right( sourceLen - rootLen );
  144. int numSlashes = CountSlashes(relativeSourcePath);
  145. CString targetRelativePath;
  146. for ( i = 0; i < numSlashes; ++i )
  147. {
  148. targetRelativePath += "..\\";
  149. }
  150. // Now that we've got the relative source path,
  151. // find out how many slashes are in it;
  152. // that'll tell us how many paths to back up....
  153. CString rootSrcToProj = sourcePath.Right( sourceLen - rootSrcLen );
  154. numSlashes = CountSlashes(rootSrcToProj);
  155. CString projToRootSrc;
  156. for ( i = 0; i < numSlashes; ++i )
  157. {
  158. projToRootSrc += "..\\";
  159. }
  160. Valvelibaw.m_Dictionary["VALVE_ROOT_RELATIVE_PATH"] = targetRelativePath;
  161. Valvelibaw.m_Dictionary["VALVE_SRC_RELATIVE_PATH"] = projToRootSrc;
  162. targetRelativePath += relativePath;
  163. Valvelibaw.m_Dictionary["VALVE_ROOT_PATH"] = m_RootPath;
  164. Valvelibaw.m_Dictionary["VALVE_ROOT_SRC_PATH"] = srcRootPath;
  165. Valvelibaw.m_Dictionary["VALVE_TARGET_PATH"] = m_TargetPath;
  166. Valvelibaw.m_Dictionary["VALVE_RELATIVE_PATH"] = targetRelativePath;
  167. if (m_ToolProject)
  168. Valvelibaw.m_Dictionary["VALVE_TOOL"] = "1";
  169. if (m_PublicProject && (m_ProjectType != 2))
  170. Valvelibaw.m_Dictionary["VALVE_PUBLIC_PROJECT"] = "1";
  171. if (m_PublishImportLib && (m_ProjectType == 1))
  172. Valvelibaw.m_Dictionary["VALVE_PUBLISH_IMPORT_LIB"] = "1";
  173. // Import libraries
  174. if (m_ProjectType == 1)
  175. {
  176. if ( m_ImplibPath.GetAt(1) != ':' )
  177. {
  178. MessageBox( "Error! The import library path must specify a drive!", "Bogus Import Library Path!", MB_ICONERROR | MB_OK );
  179. return false;
  180. }
  181. if (m_ImplibPath.Find( srcRootPath ) != 0)
  182. {
  183. MessageBox( "Error! The import library path must lie under the root src path!", "Bogus Target Path!", MB_ICONERROR | MB_OK );
  184. return false;
  185. }
  186. int implibLen = m_ImplibPath.GetLength();
  187. relativePath = m_ImplibPath.Right( implibLen - rootSrcLen );
  188. int numSlashes = CountSlashes(rootSrcToProj);
  189. CString implibRelativePath;
  190. for (int i = 0; i < numSlashes; ++i )
  191. {
  192. implibRelativePath += "..\\";
  193. }
  194. implibRelativePath += relativePath;
  195. Valvelibaw.m_Dictionary["VALVE_IMPLIB_PATH"] = m_ImplibPath;
  196. Valvelibaw.m_Dictionary["VALVE_IMPLIB_RELATIVE_PATH"] = implibRelativePath;
  197. }
  198. return true;
  199. }
  200. // This is called whenever the user presses Next, Back, or Finish with this step
  201. // present. Do all validation & data exchange from the dialog in this function.
  202. BOOL CCustom1Dlg::OnDismiss()
  203. {
  204. if (!UpdateData(TRUE))
  205. return FALSE;
  206. if (!ComputeRelativePath())
  207. return FALSE;
  208. switch( m_ProjectType )
  209. {
  210. case 0:
  211. Valvelibaw.m_Dictionary["VALVE_TARGET_TYPE"] = "lib";
  212. Valvelibaw.m_Dictionary["PROJTYPE_LIB"] = "1";
  213. break;
  214. case 1:
  215. Valvelibaw.m_Dictionary["VALVE_TARGET_TYPE"] = "dll";
  216. Valvelibaw.m_Dictionary["PROJTYPE_DLL"] = "1";
  217. break;
  218. case 2:
  219. Valvelibaw.m_Dictionary["VALVE_TARGET_TYPE"] = "exe";
  220. if (m_ConsoleApp)
  221. {
  222. Valvelibaw.m_Dictionary["PROJTYPE_CON"] = "1";
  223. }
  224. break;
  225. }
  226. return TRUE; // return FALSE if the dialog shouldn't be dismissed
  227. }
  228. BEGIN_MESSAGE_MAP(CCustom1Dlg, CAppWizStepDlg)
  229. //{{AFX_MSG_MAP(CCustom1Dlg)
  230. ON_CBN_SELCHANGE(IDC_SELECT_PROJECT_TYPE, OnSelchangeSelectProjectType)
  231. ON_EN_CHANGE(IDC_EDIT_ROOT_PATH, OnChangeEditRootPath)
  232. ON_BN_CLICKED(IDC_CHECK_PUBLIC, OnCheckPublic)
  233. ON_BN_CLICKED(IDC_CHECK_TOOL, OnCheckTool)
  234. ON_BN_CLICKED(IDC_CHECK_PUBLISH_IMPORT, OnCheckPublishImport)
  235. ON_EN_CHANGE(IDC_EDIT_SRC_PATH, OnChangeEditSrcPath)
  236. //}}AFX_MSG_MAP
  237. END_MESSAGE_MAP()
  238. /////////////////////////////////////////////////////////////////////////////
  239. // CCustom1Dlg message handlers
  240. void CCustom1Dlg::RecomputeTargetPath()
  241. {
  242. bool hasTerminatingSlash = ( m_RootPath.Right(1).FindOneOf("\\/") >= 0 );
  243. m_TargetPath = m_RootPath;
  244. if (!hasTerminatingSlash)
  245. m_TargetPath += '\\';
  246. m_ImplibPath = m_TargetPath;
  247. switch( m_ProjectType )
  248. {
  249. case 0:
  250. // static library
  251. m_TargetPath += m_SrcPath;
  252. m_TargetPath += m_PublicProject ? "\\lib\\public\\" : "\\lib\\common\\";
  253. m_ImplibPath = "unused";
  254. break;
  255. case 1:
  256. m_TargetPath += "bin\\";
  257. m_ImplibPath += m_SrcPath;
  258. m_ImplibPath += m_PublicProject ? "\\lib\\public\\" : "\\lib\\common\\";
  259. break;
  260. case 2:
  261. m_TargetPath += "bin\\";
  262. m_ImplibPath = "unused";
  263. break;
  264. }
  265. UpdateData(FALSE);
  266. }
  267. void CCustom1Dlg::EnableCheckboxes()
  268. {
  269. CWnd* pConsoleApp = GetDlgItem(IDC_CHECK_CONSOLE_APP);
  270. CWnd* pPublishImport = GetDlgItem(IDC_CHECK_PUBLISH_IMPORT);
  271. CWnd* pImportLib = GetDlgItem(IDC_EDIT_IMPLIB_PATH);
  272. switch (m_ProjectType)
  273. {
  274. case 0:
  275. pConsoleApp->EnableWindow( false );
  276. pPublishImport->EnableWindow( false );
  277. pImportLib->EnableWindow( false );
  278. break;
  279. case 1:
  280. pConsoleApp->EnableWindow( false );
  281. pPublishImport->EnableWindow( true );
  282. pImportLib->EnableWindow( m_PublishImportLib );
  283. break;
  284. case 2:
  285. pConsoleApp->EnableWindow( true );
  286. pPublishImport->EnableWindow( false );
  287. pImportLib->EnableWindow( false );
  288. break;
  289. }
  290. }
  291. void CCustom1Dlg::OnSelchangeSelectProjectType()
  292. {
  293. if (!UpdateData(TRUE))
  294. return;
  295. RecomputeTargetPath();
  296. EnableCheckboxes();
  297. }
  298. void CCustom1Dlg::OnChangeEditRootPath()
  299. {
  300. if (!UpdateData(TRUE))
  301. return;
  302. RecomputeTargetPath();
  303. }
  304. void CCustom1Dlg::OnCheckPublic()
  305. {
  306. if (!UpdateData(TRUE))
  307. return;
  308. RecomputeTargetPath();
  309. }
  310. void CCustom1Dlg::OnCheckTool()
  311. {
  312. if (!UpdateData(TRUE))
  313. return;
  314. RecomputeTargetPath();
  315. }
  316. void CCustom1Dlg::OnCheckPublishImport()
  317. {
  318. if (!UpdateData(TRUE))
  319. return;
  320. EnableCheckboxes();
  321. }
  322. void CCustom1Dlg::OnChangeEditSrcPath()
  323. {
  324. if (!UpdateData(TRUE))
  325. return;
  326. RecomputeTargetPath();
  327. }