Leaked source code of windows server 2003
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.

514 lines
13 KiB

  1. // Copyright (c) 2001 Microsoft Corporation
  2. //
  3. // File: CustomServerPage.cpp
  4. //
  5. // Synopsis: Defines Custom Server Page for the CYS
  6. // Wizard
  7. //
  8. // History: 02/06/2001 JeffJon Created
  9. #include "pch.h"
  10. #include "resource.h"
  11. #include "cys.h"
  12. #include "InstallationUnitProvider.h"
  13. #include "CustomServerPage.h"
  14. #include "uiutil.h"
  15. static PCWSTR CUSTOM_PAGE_HELP = L"cys.chm::/cys_topnode.htm";
  16. CustomServerPage::CustomServerPage()
  17. :
  18. CYSWizardPage(
  19. IDD_CUSTOM_SERVER_PAGE,
  20. IDS_CUSTOM_SERVER_TITLE,
  21. IDS_CUSTOM_SERVER_SUBTITLE,
  22. CUSTOM_PAGE_HELP)
  23. {
  24. LOG_CTOR(CustomServerPage);
  25. }
  26. CustomServerPage::~CustomServerPage()
  27. {
  28. LOG_DTOR(CustomServerPage);
  29. }
  30. void
  31. CustomServerPage::OnInit()
  32. {
  33. LOG_FUNCTION(CustomServerPage::OnInit);
  34. CYSWizardPage::OnInit();
  35. SetBoldFont(
  36. hwnd,
  37. IDC_ROLE_STATIC);
  38. InitializeServerListView();
  39. FillServerTypeList();
  40. }
  41. void
  42. CustomServerPage::InitializeServerListView()
  43. {
  44. LOG_FUNCTION(CustomServerPage::InitializeServerListView);
  45. // Prepare a column
  46. HWND hwndBox = Win::GetDlgItem(hwnd, IDC_SERVER_TYPE_LIST);
  47. RECT rect;
  48. Win::GetClientRect(hwndBox, rect);
  49. // Get the width of a scroll bar
  50. // int scrollThumbWidth = ::GetSystemMetrics(SM_CXHTHUMB);
  51. // net width of listview
  52. int netWidth = rect.right /*- scrollThumbWidth*/ - ::GetSystemMetrics(SM_CXBORDER);
  53. // Set full row select
  54. Win::ListView_SetExtendedListViewStyle(
  55. hwndBox,
  56. LVS_EX_FULLROWSELECT | LVS_EX_INFOTIP/* | LVS_EX_GRIDLINES*/);
  57. // Get the size of the listview
  58. LVCOLUMN column;
  59. ZeroMemory(&column, sizeof(LVCOLUMN));
  60. column.mask = LVCF_WIDTH | LVCF_TEXT;
  61. // Use 80 percent of the width minus the scrollbar for the role and the rest for the status
  62. column.cx = static_cast<int>(netWidth * 0.75);
  63. String columnHeader = String::load(IDS_SERVER_ROLE_COLUMN_HEADER);
  64. column.pszText = const_cast<wchar_t*>(columnHeader.c_str());
  65. Win::ListView_InsertColumn(
  66. hwndBox,
  67. 0,
  68. column);
  69. // Add the status column
  70. columnHeader = String::load(IDS_STATUS_COLUMN_HEADER);
  71. column.pszText = const_cast<wchar_t*>(columnHeader.c_str());
  72. column.cx = netWidth - column.cx;
  73. Win::ListView_InsertColumn(
  74. hwndBox,
  75. 1,
  76. column);
  77. }
  78. void
  79. CustomServerPage::FillServerTypeList()
  80. {
  81. LOG_FUNCTION(CustomServerPage::FillServerTypeList);
  82. // Load the status strings
  83. String statusCompleted = String::load(IDS_STATUS_COMPLETED);
  84. String statusNo = String::load(IDS_STATUS_NO);
  85. // loop throught the table putting all the server
  86. // types in the listbox
  87. HWND hwndBox = Win::GetDlgItem(hwnd, IDC_SERVER_TYPE_LIST);
  88. for (
  89. size_t index = 0;
  90. index < GetServerRoleStatusTableElementCount();
  91. ++index)
  92. {
  93. InstallationUnit& installationUnit =
  94. InstallationUnitProvider::GetInstance().
  95. GetInstallationUnitForType(serverRoleStatusTable[index].role);
  96. InstallationStatus status =
  97. serverRoleStatusTable[index].Status();
  98. if (status != STATUS_NOT_AVAILABLE)
  99. {
  100. String serverTypeName = installationUnit.GetServiceName();
  101. LVITEM listItem;
  102. ZeroMemory(&listItem, sizeof(LVITEM));
  103. listItem.iItem = (int) index;
  104. listItem.mask = LVIF_TEXT | LVIF_PARAM;
  105. listItem.pszText = const_cast<wchar_t*>(serverTypeName.c_str());
  106. listItem.lParam = serverRoleStatusTable[index].role;
  107. int newItem = Win::ListView_InsertItem(
  108. hwndBox,
  109. listItem);
  110. ASSERT(newItem >= 0);
  111. LOG(String::format(
  112. L"New role inserted: %1 at index %2!d!",
  113. serverTypeName.c_str(),
  114. newItem));
  115. // if the service is installed fill the status column
  116. if (status == STATUS_COMPLETED ||
  117. status == STATUS_CONFIGURED)
  118. {
  119. Win::ListView_SetItemText(
  120. hwndBox,
  121. newItem,
  122. 1,
  123. statusCompleted);
  124. }
  125. else
  126. {
  127. Win::ListView_SetItemText(
  128. hwndBox,
  129. newItem,
  130. 1,
  131. statusNo);
  132. }
  133. }
  134. }
  135. // Set the focus of the first item so that the user can see
  136. // the focus but don't select it
  137. Win::ListView_SetItemState(
  138. hwndBox,
  139. 0,
  140. LVIS_FOCUSED,
  141. LVIS_FOCUSED);
  142. }
  143. bool
  144. CustomServerPage::OnSetActive()
  145. {
  146. LOG_FUNCTION(CustomServerPage::OnSetActive);
  147. SetDescriptionForSelection();
  148. // If log file is available then
  149. // enable the link
  150. if (IsLogFilePresent())
  151. {
  152. Win::ShowWindow(
  153. Win::GetDlgItem(
  154. hwnd,
  155. IDC_LOG_STATIC),
  156. SW_SHOW);
  157. }
  158. else
  159. {
  160. Win::ShowWindow(
  161. Win::GetDlgItem(
  162. hwnd,
  163. IDC_LOG_STATIC),
  164. SW_HIDE);
  165. }
  166. // If there is a selection set the Next button as
  167. // the default with focus. If not, then give the
  168. // list view the focus
  169. HWND hwndBox = Win::GetDlgItem(hwnd, IDC_SERVER_TYPE_LIST);
  170. int currentSelection = ListView_GetNextItem(hwndBox, -1, LVNI_SELECTED);
  171. if (currentSelection >= 0)
  172. {
  173. Win::PostMessage(
  174. Win::GetParent(hwnd),
  175. WM_NEXTDLGCTL,
  176. (WPARAM) Win::GetDlgItem(Win::GetParent(hwnd), Wizard::NEXT_BTN_ID),
  177. TRUE);
  178. }
  179. else
  180. {
  181. Win::PostMessage(
  182. Win::GetParent(hwnd),
  183. WM_NEXTDLGCTL,
  184. (WPARAM) hwndBox,
  185. TRUE);
  186. }
  187. return true;
  188. }
  189. InstallationUnit&
  190. CustomServerPage::GetInstallationUnitFromSelection(int currentSelection)
  191. {
  192. LOG_FUNCTION(CustomServerPage::GetInstallationUnitFromSelection);
  193. ASSERT(currentSelection >= 0);
  194. HWND hwndBox = Win::GetDlgItem(hwnd, IDC_SERVER_TYPE_LIST);
  195. // Now that we know the selection, find the installation type
  196. LVITEM item;
  197. ZeroMemory(&item, sizeof(item));
  198. item.iItem = currentSelection;
  199. item.mask = LVIF_PARAM;
  200. bool result = Win::ListView_GetItem(hwndBox, item);
  201. ASSERT(result);
  202. LPARAM value = item.lParam;
  203. LOG(String::format(
  204. L"Selection = %1!d!, type = %2!d!",
  205. currentSelection,
  206. value));
  207. return InstallationUnitProvider::GetInstance().GetInstallationUnitForType(
  208. (ServerRole)value);
  209. }
  210. void
  211. CustomServerPage::SetDescriptionForSelection()
  212. {
  213. LOG_FUNCTION(CustomServerPage::SetDescriptionForSelection);
  214. HWND hwndDescription = Win::GetDlgItem(hwnd, IDC_TYPE_DESCRIPTION_STATIC);
  215. HWND hwndBox = Win::GetDlgItem(hwnd, IDC_SERVER_TYPE_LIST);
  216. int currentSelection = ListView_GetNextItem(hwndBox, -1, LVNI_SELECTED);
  217. if (currentSelection >= 0)
  218. {
  219. InstallationUnit& installationUnit = GetInstallationUnitFromSelection(currentSelection);
  220. String serverTypeName = installationUnit.GetServiceName();
  221. Win::SetDlgItemText(hwnd, IDC_ROLE_STATIC, serverTypeName);
  222. String serverTypeDescription = installationUnit.GetServiceDescription();
  223. Win::SetWindowText(hwndDescription, serverTypeDescription);
  224. Win::ShowWindow(hwndDescription, SW_SHOW);
  225. Win::EnableWindow(hwndDescription, true);
  226. InstallationStatus status =
  227. installationUnit.GetStatus();
  228. // Set the status column
  229. if (status == STATUS_COMPLETED ||
  230. status == STATUS_CONFIGURED)
  231. {
  232. String statusCompleted = String::load(IDS_STATUS_COMPLETED);
  233. Win::ListView_SetItemText(
  234. hwndBox,
  235. currentSelection,
  236. 1,
  237. statusCompleted);
  238. }
  239. else
  240. {
  241. String statusNo = String::load(IDS_STATUS_NO);
  242. Win::ListView_SetItemText(
  243. hwndBox,
  244. currentSelection,
  245. 1,
  246. statusNo);
  247. }
  248. Win::PropSheet_SetWizButtons(
  249. Win::GetParent(hwnd),
  250. PSWIZB_NEXT | PSWIZB_BACK);
  251. }
  252. else
  253. {
  254. // If no selection set the description text to blank
  255. // For some reason the SysLink control doesn't like
  256. // to be blank so I have to disable and hide the control
  257. // instead of just setting a blank string
  258. Win::EnableWindow(hwndDescription, false);
  259. Win::ShowWindow(hwndDescription, SW_HIDE);
  260. Win::SetDlgItemText(hwnd, IDC_ROLE_STATIC, L"");
  261. // Set the wizard buttons
  262. Win::PropSheet_SetWizButtons(
  263. Win::GetParent(hwnd),
  264. PSWIZB_BACK);
  265. }
  266. }
  267. bool
  268. CustomServerPage::OnNotify(
  269. HWND /*windowFrom*/,
  270. UINT_PTR controlIDFrom,
  271. UINT code,
  272. LPARAM lParam)
  273. {
  274. // LOG_FUNCTION(CustomServerPage::OnCommand);
  275. bool result = false;
  276. if (IDC_SERVER_TYPE_LIST == controlIDFrom &&
  277. code == LVN_ITEMCHANGED)
  278. {
  279. LPNMLISTVIEW pnmv = reinterpret_cast<LPNMLISTVIEW>(lParam);
  280. if (pnmv && pnmv->uNewState & LVNI_SELECTED)
  281. {
  282. SetDescriptionForSelection();
  283. result = true;
  284. }
  285. else
  286. {
  287. // Check to see if we have something selected
  288. // and set the state of the Next button accordingly
  289. SetDescriptionForSelection();
  290. SetNextButtonState();
  291. }
  292. }
  293. else if (controlIDFrom == IDC_TYPE_DESCRIPTION_STATIC ||
  294. controlIDFrom == IDC_ADD_REMOVE_STATIC)
  295. {
  296. switch (code)
  297. {
  298. case NM_CLICK:
  299. case NM_RETURN:
  300. {
  301. if (controlIDFrom == IDC_TYPE_DESCRIPTION_STATIC)
  302. {
  303. HWND hwndBox = Win::GetDlgItem(hwnd, IDC_SERVER_TYPE_LIST);
  304. int currentSelection = ListView_GetNextItem(hwndBox, -1, LVNI_SELECTED);
  305. if (currentSelection >= 0)
  306. {
  307. InstallationUnit& installationUnit =
  308. GetInstallationUnitFromSelection(currentSelection);
  309. int linkIndex = LinkIndexFromNotifyLPARAM(lParam);
  310. installationUnit.ServerRoleLinkSelected(linkIndex, hwnd);
  311. }
  312. }
  313. else
  314. {
  315. // launch the sysocmgr
  316. String fullPath =
  317. String::format(
  318. IDS_SYSOC_FULL_PATH,
  319. Win::GetSystemDirectory().c_str());
  320. String infPath =
  321. Win::GetSystemWindowsDirectory() + L"\\inf\\sysoc.inf";
  322. String commandLine =
  323. String::format(
  324. L"/i:%1",
  325. infPath.c_str());
  326. MyCreateProcess(fullPath, commandLine);
  327. }
  328. result = true;
  329. }
  330. default:
  331. {
  332. // do nothing
  333. break;
  334. }
  335. }
  336. }
  337. else if (controlIDFrom == IDC_LOG_STATIC)
  338. {
  339. switch (code)
  340. {
  341. case NM_CLICK:
  342. case NM_RETURN:
  343. {
  344. OpenLogFile();
  345. }
  346. break;
  347. default:
  348. break;
  349. }
  350. }
  351. return result;
  352. }
  353. void
  354. CustomServerPage::SetNextButtonState()
  355. {
  356. HWND hwndBox = Win::GetDlgItem(hwnd, IDC_SERVER_TYPE_LIST);
  357. int currentSelection = ListView_GetNextItem(hwndBox, -1, LVNI_SELECTED);
  358. // Set the wizard buttons
  359. Win::PropSheet_SetWizButtons(
  360. Win::GetParent(hwnd),
  361. (currentSelection < 0) ? PSWIZB_BACK : PSWIZB_NEXT | PSWIZB_BACK);
  362. }
  363. int
  364. CustomServerPage::Validate()
  365. {
  366. LOG_FUNCTION(CustomServerPage::Validate);
  367. HWND hwndBox = Win::GetDlgItem(hwnd, IDC_SERVER_TYPE_LIST);
  368. int currentSelection = ListView_GetNextItem(hwndBox, -1, LVNI_SELECTED);
  369. ASSERT(currentSelection >= 0);
  370. // Now that we know the selection, find the installation type
  371. LVITEM item;
  372. ZeroMemory(&item, sizeof(item));
  373. item.iItem = currentSelection;
  374. item.mask = LVIF_PARAM;
  375. bool result = Win::ListView_GetItem(hwndBox, item);
  376. ASSERT(result);
  377. // set the current install to the selected installation unit
  378. InstallationUnit& currentInstallationUnit =
  379. InstallationUnitProvider::GetInstance().SetCurrentInstallationUnit(
  380. static_cast<ServerRole>(item.lParam));
  381. // NTRAID#NTBUG-604592-2002/04/23-JeffJon-Key the action of the wizard
  382. // off the installation status at this point. The InstallationProgressPage
  383. // will call either CompletePath or UninstallService based on the value
  384. // that is set here.
  385. currentInstallationUnit.SetInstalling(
  386. currentInstallationUnit.IsServiceInstalled());
  387. int nextPage = currentInstallationUnit.GetWizardStart();
  388. LOG(String::format(
  389. L"nextPage = %1!d!",
  390. nextPage));
  391. return nextPage;
  392. }