Source code of Windows XP (NT5)
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.

277 lines
6.2 KiB

  1. /*
  2. * Copyright (c) 1998 Microsoft Corporation
  3. *
  4. * Module Name:
  5. *
  6. * pages.cpp
  7. *
  8. * Abstract:
  9. *
  10. * This file defines the License Server Setup Wizard Page class.
  11. *
  12. * Author:
  13. *
  14. * Breen Hagan (BreenH) Oct-02-98
  15. *
  16. * Environment:
  17. *
  18. * User Mode
  19. */
  20. #include "stdafx.h"
  21. #include "pages.h"
  22. #include "logfile.h"
  23. extern BOOL gStandAlone;
  24. extern BOOL gUnAttended;
  25. TCHAR gszInitialDir[MAX_PATH + 1];
  26. BOOL GetCurrentSelectionState(VOID);
  27. BOOL InWin2000Domain(VOID);
  28. EInstall GetInstallSection(VOID);
  29. HINSTANCE GetInstance(VOID);
  30. EServerType GetServerRole(VOID);
  31. DWORD SetServerRole(UINT);
  32. /*
  33. * EnablePage::CanShow()
  34. *
  35. * The page will only be displayed during standalone installations.
  36. */
  37. BOOL
  38. EnablePage::CanShow(
  39. )
  40. {
  41. return((GetInstallSection() == kInstall) && gStandAlone && !gUnAttended);
  42. }
  43. /*
  44. * EnablePage::OnInitDialog()
  45. *
  46. * Initializes the wizard page controls. If the machine is not a domain
  47. * controller, the server type is reduced to plain server only.
  48. */
  49. BOOL
  50. EnablePage::OnInitDialog(
  51. HWND hWndDlg,
  52. WPARAM wParam,
  53. LPARAM lParam
  54. )
  55. {
  56. BOOL fInDomain = InWin2000Domain();
  57. TCHAR pszExpDir[MAX_PATH + 1];
  58. if (!fInDomain) {
  59. EnableWindow(
  60. GetDlgItem(GetDlgWnd(), IDC_RADIO_ENTERPRISE_SERVER),
  61. FALSE
  62. );
  63. }
  64. CheckRadioButton(
  65. GetDlgWnd(),
  66. IDC_RADIO_ENTERPRISE_SERVER,
  67. IDC_RADIO_PLAIN_SERVER,
  68. fInDomain ?
  69. (GetServerRole() == eEnterpriseServer ?
  70. IDC_RADIO_ENTERPRISE_SERVER :
  71. IDC_RADIO_PLAIN_SERVER
  72. ) :
  73. IDC_RADIO_PLAIN_SERVER
  74. );
  75. _tcscpy(gszInitialDir, GetDatabaseDirectory());
  76. ExpandEnvironmentStrings(gszInitialDir, pszExpDir, MAX_PATH);
  77. SetDlgItemText(GetDlgWnd(), IDC_EDIT_INSTALL_DIR, pszExpDir);
  78. UNREFERENCED_PARAMETER(lParam);
  79. UNREFERENCED_PARAMETER(wParam);
  80. UNREFERENCED_PARAMETER(hWndDlg);
  81. return(TRUE);
  82. }
  83. BOOL
  84. EnablePage::OnCommand(
  85. HWND hWndDlg,
  86. WPARAM wParam,
  87. LPARAM lParam
  88. )
  89. {
  90. int iRet;
  91. if ((LOWORD(wParam) == IDC_BUTTON_BROWSE_DIR) &&
  92. (HIWORD(wParam) == BN_CLICKED))
  93. {
  94. BROWSEINFO brInfo;
  95. ZeroMemory(&brInfo, sizeof(brInfo));
  96. brInfo.hwndOwner = hWndDlg;
  97. TCHAR strText[1024];
  98. iRet = LoadString(
  99. GetInstance(),
  100. IDS_STRING_DIRECTORY_SELECT,
  101. strText,
  102. 1024
  103. );
  104. brInfo.lpszTitle = strText;
  105. LPITEMIDLIST pidl = SHBrowseForFolder(&brInfo);
  106. if (pidl) {
  107. TCHAR szDir[MAX_PATH + 1];
  108. SHGetPathFromIDList (pidl, szDir);
  109. SetDlgItemText(hWndDlg, IDC_EDIT_INSTALL_DIR, szDir);
  110. }
  111. }
  112. UNREFERENCED_PARAMETER(lParam);
  113. return(TRUE);
  114. }
  115. BOOL
  116. EnablePage::ApplyChanges(
  117. )
  118. {
  119. BOOL fDirExists = FALSE;
  120. DWORD dwErr;
  121. int iRet;
  122. TCHAR szTxt[MAX_PATH + 1] = _T("");
  123. TCHAR szSubDir[] = _T("\\LServer");
  124. TCHAR szExpDir[MAX_PATH + 1];
  125. TCHAR szExpInitDir[MAX_PATH + 1];
  126. if (GetDlgItemText(GetDlgWnd(), IDC_EDIT_INSTALL_DIR, szTxt,
  127. MAX_PATH) == 0) {
  128. //
  129. // Complain about blank entries.
  130. //
  131. DisplayMessageBox(
  132. IDS_STRING_INVLID_INSTALLATION_DIRECTORY,
  133. IDS_MAIN_TITLE,
  134. MB_OK,
  135. &iRet
  136. );
  137. return(FALSE);
  138. }
  139. //
  140. // Verify the string is not too long, expanding environment strings
  141. // in the process.
  142. //
  143. if (ExpandEnvironmentStrings(szTxt, szExpDir, MAX_PATH) > MAX_PATH) {
  144. DisplayMessageBox(
  145. IDS_STRING_INVLID_INSTALLATION_DIRECTORY,
  146. IDS_MAIN_TITLE,
  147. MB_OK,
  148. &iRet
  149. );
  150. return(FALSE);
  151. }
  152. //
  153. // If the entry is still the original default directory, no more
  154. // verification is necessary.
  155. //
  156. ExpandEnvironmentStrings(gszInitialDir, szExpInitDir, MAX_PATH);
  157. if (_tcsicmp(szExpDir, szExpInitDir) == 0) {
  158. goto DirCreation;
  159. }
  160. //
  161. // Check for directory existance before appending a subdirectory.
  162. // This will prevent the user chosen directory of "C:\", for
  163. // example, from prompting the user to create the directory.
  164. //
  165. fDirExists = SetCurrentDirectory(szExpDir);
  166. //
  167. // The user has chosen a different directory. To protect its
  168. // contents during uninstall, the TLServer subdirectory will be
  169. // used.
  170. //
  171. if ((_tcslen(szExpDir) + _tcslen(szSubDir) + 1) > MAX_PATH) {
  172. DisplayMessageBox(
  173. IDS_STRING_INVLID_INSTALLATION_DIRECTORY,
  174. IDS_MAIN_TITLE,
  175. MB_OK,
  176. &iRet
  177. );
  178. return(FALSE);
  179. }
  180. _tcscat(szExpDir, szSubDir);
  181. _tcscat(szTxt, szSubDir);
  182. //
  183. // Verify the user's directory choice is valid, e.g. no floppy
  184. // drives, CD-ROMs, network paths, etc.
  185. //
  186. if (CheckDatabaseDirectory(szExpDir) != ERROR_SUCCESS) {
  187. DisplayMessageBox(
  188. IDS_STRING_INVLID_INSTALLATION_DIRECTORY,
  189. IDS_MAIN_TITLE,
  190. MB_OK,
  191. &iRet
  192. );
  193. return(FALSE);
  194. }
  195. //
  196. // Prompt to create the directory if necessary.
  197. //
  198. if (!fDirExists) {
  199. DisplayMessageBox(
  200. IDS_STRING_CREATE_INSTALLATION_DIRECTORY,
  201. IDS_MAIN_TITLE,
  202. MB_OKCANCEL,
  203. &iRet
  204. );
  205. if (iRet != IDOK) {
  206. return(FALSE);
  207. }
  208. }
  209. //
  210. // The selected directory has passed all the tests, but it may
  211. // still not be created. If creation fails, let the user know,
  212. // and let s/he choose another directory.
  213. //
  214. DirCreation:
  215. SetDatabaseDirectory(szTxt);
  216. dwErr = CreateDatabaseDirectory();
  217. if (dwErr != ERROR_SUCCESS) {
  218. DisplayMessageBox(
  219. IDS_STRING_CANT_CREATE_INSTALLATION_DIRECTORY,
  220. IDS_MAIN_TITLE,
  221. MB_OK,
  222. &iRet
  223. );
  224. return(FALSE);
  225. }
  226. SetServerRole(IsDlgButtonChecked (
  227. GetDlgWnd(), IDC_RADIO_ENTERPRISE_SERVER) == BST_CHECKED ?
  228. eEnterpriseServer : ePlainServer);
  229. return(TRUE);
  230. }