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.

457 lines
12 KiB

  1. // Copyright (c) 1997-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 "InstallationUnitProvider.h"
  12. #include "CustomServerPage.h"
  13. #include "state.h"
  14. typedef struct _CustomInstallationTypes
  15. {
  16. InstallationUnitType installationType;
  17. DWORD productSKUs;
  18. } CustomInstallationType;
  19. // table of items that are available in the server type list box
  20. CustomInstallationType serverTypeTable[] =
  21. {
  22. { DNS_INSTALL, CYS_ALL_SERVER_SKUS },
  23. { DHCP_INSTALL, CYS_ALL_SERVER_SKUS },
  24. { WINS_INSTALL, CYS_ALL_SERVER_SKUS },
  25. { RRAS_INSTALL, CYS_ALL_SERVER_SKUS },
  26. { APPLICATIONSERVER_INSTALL, CYS_ALL_SERVER_SKUS },
  27. { FILESERVER_INSTALL, CYS_ALL_SERVER_SKUS },
  28. { PRINTSERVER_INSTALL, CYS_ALL_SERVER_SKUS },
  29. { SHAREPOINT_INSTALL, CYS_SERVER | CYS_ADVANCED_SERVER | CYS_32BIT }, // notice: this excludes 64bit
  30. { MEDIASERVER_INSTALL, CYS_ALL_SKUS_NO_64BIT },
  31. { WEBSERVER_INSTALL, CYS_ALL_SERVER_SKUS },
  32. { DC_INSTALL, CYS_ALL_SERVER_SKUS },
  33. { CLUSTERSERVER_INSTALL, CYS_ADVANCED_SERVER | CYS_DATACENTER_SERVER | CYS_32BIT }
  34. };
  35. static PCWSTR CUSTOM_PAGE_HELP = L"cys.chm::/cys_configuring_networking_infrastructure.htm";
  36. CustomServerPage::CustomServerPage()
  37. :
  38. CYSWizardPage(
  39. IDD_CUSTOM_SERVER_PAGE,
  40. IDS_CUSTOM_SERVER_TITLE,
  41. IDS_CUSTOM_SERVER_SUBTITLE,
  42. CUSTOM_PAGE_HELP)
  43. {
  44. LOG_CTOR(CustomServerPage);
  45. }
  46. CustomServerPage::~CustomServerPage()
  47. {
  48. LOG_DTOR(CustomServerPage);
  49. }
  50. void
  51. CustomServerPage::OnInit()
  52. {
  53. LOG_FUNCTION(CustomServerPage::OnInit);
  54. InitializeServerListView();
  55. FillServerTypeList();
  56. }
  57. void
  58. CustomServerPage::InitializeServerListView()
  59. {
  60. LOG_FUNCTION(CustomServerPage::InitializeServerListView);
  61. // Prepare a column
  62. HWND hwndBox = Win::GetDlgItem(hwnd, IDC_SERVER_TYPE_LIST);
  63. RECT rect;
  64. Win::GetClientRect(hwndBox, rect);
  65. // Get the width of a scroll bar
  66. int scrollThumbWidth = ::GetSystemMetrics(SM_CXHTHUMB);
  67. // net width of listview
  68. int netWidth = rect.right - scrollThumbWidth - ::GetSystemMetrics(SM_CXBORDER);
  69. // Set full row select
  70. ListView_SetExtendedListViewStyle(
  71. hwndBox,
  72. LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES);
  73. // Get the size of the listview
  74. LVCOLUMN column;
  75. ZeroMemory(&column, sizeof(LVCOLUMN));
  76. column.mask = LVCF_WIDTH | LVCF_TEXT;
  77. // Use 80 percent of the width minus the scrollbar for the role and the rest for the status
  78. column.cx = static_cast<int>(netWidth * 0.8);
  79. String columnHeader = String::load(IDS_SERVER_ROLE_COLUMN_HEADER);
  80. column.pszText = const_cast<wchar_t*>(columnHeader.c_str());
  81. Win::ListView_InsertColumn(
  82. hwndBox,
  83. 0,
  84. column);
  85. // Add the status column
  86. columnHeader = String::load(IDS_STATUS_COLUMN_HEADER);
  87. column.pszText = const_cast<wchar_t*>(columnHeader.c_str());
  88. column.cx = netWidth - column.cx;
  89. Win::ListView_InsertColumn(
  90. hwndBox,
  91. 1,
  92. column);
  93. }
  94. void
  95. CustomServerPage::FillServerTypeList()
  96. {
  97. LOG_FUNCTION(CustomServerPage::FillServerTypeList);
  98. // Load the status strings
  99. String statusCompleted = String::load(IDS_STATUS_COMPLETED);
  100. // loop throught the table putting all the server
  101. // types in the listbox
  102. HWND hwndBox = Win::GetDlgItem(hwnd, IDC_SERVER_TYPE_LIST);
  103. int serverTableSize =
  104. sizeof(serverTypeTable) / sizeof(CustomInstallationType);
  105. for (int index = 0; index < serverTableSize; index++)
  106. {
  107. // Special case AD installation so that it is not available if
  108. // CertServer is installed
  109. if (serverTypeTable[index].installationType == DC_INSTALL)
  110. {
  111. if (NTService(L"CertSvc").IsInstalled())
  112. {
  113. continue;
  114. }
  115. }
  116. // Load the string for the type of server and add it to the list
  117. // Filter out roles by SKU and platform
  118. LOG(String::format(
  119. L"Current role SKUs: 0x%1!x!",
  120. serverTypeTable[index].productSKUs));
  121. DWORD sku = State::GetInstance().GetProductSKU();
  122. LOG(String::format(
  123. L"Verifying against computer sku: 0x%1!x!",
  124. sku));
  125. if (sku & serverTypeTable[index].productSKUs)
  126. {
  127. DWORD platform = State::GetInstance().GetPlatform();
  128. LOG(String::format(
  129. L"Verifying against computer platform: 0x%1!x!",
  130. platform));
  131. if (platform & serverTypeTable[index].productSKUs)
  132. {
  133. String serverTypeName =
  134. InstallationUnitProvider::GetInstance().GetInstallationUnitForType(
  135. serverTypeTable[index].installationType).GetServiceName();
  136. bool isInstalled =
  137. InstallationUnitProvider::GetInstance().GetInstallationUnitForType(
  138. serverTypeTable[index].installationType).IsServiceInstalled();
  139. LVITEM listItem;
  140. ZeroMemory(&listItem, sizeof(LVITEM));
  141. listItem.iItem = index;
  142. listItem.mask = LVIF_TEXT | LVIF_PARAM;
  143. listItem.pszText = const_cast<wchar_t*>(serverTypeName.c_str());
  144. listItem.lParam = serverTypeTable[index].installationType;
  145. int newItem = Win::ListView_InsertItem(
  146. hwndBox,
  147. listItem);
  148. ASSERT(newItem >= 0);
  149. LOG(String::format(
  150. L"New role inserted: %1 at index %2!d!",
  151. serverTypeName.c_str(),
  152. newItem));
  153. // if the service is installed fill the status column
  154. if (isInstalled)
  155. {
  156. Win::ListView_SetItemText(
  157. hwndBox,
  158. newItem,
  159. 1,
  160. statusCompleted);
  161. }
  162. }
  163. else
  164. {
  165. LOG(String::format(
  166. L"Role not supported for this platform: 0x%1!x! role: 0x%2!x!",
  167. platform,
  168. serverTypeTable[index].productSKUs));
  169. }
  170. }
  171. else
  172. {
  173. LOG(String::format(
  174. L"Role does not for this SKU: 0x%1!x! role: 0x%2!x!",
  175. State::GetInstance().GetProductSKU(),
  176. serverTypeTable[index].productSKUs));
  177. }
  178. }
  179. }
  180. bool
  181. CustomServerPage::OnSetActive()
  182. {
  183. LOG_FUNCTION(CustomServerPage::OnSetActive);
  184. // make sure something is selected in the list box
  185. HWND hwndBox = Win::GetDlgItem(hwnd, IDC_SERVER_TYPE_LIST);
  186. int currentSelection = ListView_GetNextItem(hwndBox, -1, LVNI_SELECTED);
  187. if (currentSelection <= 0)
  188. {
  189. // Select the first item
  190. ListView_SetItemState(hwndBox, 0, LVIS_SELECTED, LVIS_SELECTED);
  191. }
  192. SetDescriptionForSelection();
  193. return true;
  194. }
  195. void
  196. CustomServerPage::SetDescriptionForSelection()
  197. {
  198. LOG_FUNCTION(CustomServerPage::SetDescriptionForSelection);
  199. HWND hwndBox = Win::GetDlgItem(hwnd, IDC_SERVER_TYPE_LIST);
  200. int currentSelection = ListView_GetNextItem(hwndBox, -1, LVNI_SELECTED);
  201. ASSERT(currentSelection >= 0);
  202. // Now that we know the selection, find the installation type
  203. LVITEM item;
  204. ZeroMemory(&item, sizeof(item));
  205. item.iItem = currentSelection;
  206. item.mask = LVIF_PARAM;
  207. bool result = Win::ListView_GetItem(hwndBox, item);
  208. ASSERT(result);
  209. LPARAM value = item.lParam;
  210. LOG(String::format(
  211. L"Selection = %1!d!, type = %2!d!",
  212. currentSelection,
  213. value));
  214. // fill in the description text for the selected item
  215. HWND hwndDescription = Win::GetDlgItem(hwnd, IDC_TYPE_DESCRIPTION_STATIC);
  216. int serverTableSize =
  217. sizeof(serverTypeTable) / sizeof(CustomInstallationType);
  218. for (int index = 0; index < serverTableSize; index++)
  219. {
  220. if (serverTypeTable[index].installationType == value)
  221. {
  222. // Load the description for the type of server and put it in the
  223. // static control
  224. String serverTypeDescription =
  225. InstallationUnitProvider::GetInstance().GetInstallationUnitForType(
  226. serverTypeTable[index].installationType).GetServiceDescription();
  227. Win::SetWindowText(hwndDescription, serverTypeDescription);
  228. bool isServiceInstalled =
  229. InstallationUnitProvider::GetInstance().GetInstallationUnitForType(
  230. serverTypeTable[index].installationType).IsServiceInstalled();
  231. // Set the wizard buttons
  232. Win::PropSheet_SetWizButtons(
  233. Win::GetParent(hwnd),
  234. isServiceInstalled ? PSWIZB_BACK : PSWIZB_NEXT | PSWIZB_BACK);
  235. break;
  236. }
  237. }
  238. }
  239. bool
  240. CustomServerPage::OnNotify(
  241. HWND /*windowFrom*/,
  242. UINT_PTR controlIDFrom,
  243. UINT code,
  244. LPARAM lParam)
  245. {
  246. // LOG_FUNCTION(CustomServerPage::OnCommand);
  247. bool result = false;
  248. if (IDC_SERVER_TYPE_LIST == controlIDFrom &&
  249. code == LVN_ITEMCHANGED)
  250. {
  251. LPNMLISTVIEW pnmv = reinterpret_cast<LPNMLISTVIEW>(lParam);
  252. if (pnmv && pnmv->uNewState & LVNI_SELECTED)
  253. {
  254. SetDescriptionForSelection();
  255. result = true;
  256. }
  257. }
  258. return result;
  259. }
  260. int
  261. CustomServerPage::Validate()
  262. {
  263. LOG_FUNCTION(CustomServerPage::Validate);
  264. HWND hwndBox = Win::GetDlgItem(hwnd, IDC_SERVER_TYPE_LIST);
  265. int currentSelection = ListView_GetNextItem(hwndBox, -1, LVNI_SELECTED);
  266. ASSERT(currentSelection >= 0);
  267. // Now that we know the selection, find the installation type
  268. LVITEM item;
  269. ZeroMemory(&item, sizeof(item));
  270. item.iItem = currentSelection;
  271. item.mask = LVIF_PARAM;
  272. bool result = Win::ListView_GetItem(hwndBox, item);
  273. ASSERT(result);
  274. // set the current install to the selected installation unit
  275. InstallationUnitProvider::GetInstance().SetCurrentInstallationUnit(
  276. static_cast<InstallationUnitType>(item.lParam));
  277. int nextPage = -1;
  278. switch (item.lParam)
  279. {
  280. case CLUSTERSERVER_INSTALL:
  281. nextPage = IDD_CLUSTER_SERVER_PAGE;
  282. break;
  283. case PRINTSERVER_INSTALL:
  284. nextPage = IDD_PRINT_SERVER_PAGE;
  285. break;
  286. case SHAREPOINT_INSTALL:
  287. if (!InstallationUnitProvider::GetInstance().GetWebInstallationUnit().IsServiceInstalled())
  288. {
  289. nextPage = IDD_FINISH_PAGE;
  290. }
  291. else
  292. {
  293. if (InstallationUnitProvider::GetInstance().GetSharePointInstallationUnit().IsThereAPageToReplace())
  294. {
  295. LOG(L"There is a page to replace");
  296. nextPage = IDD_SHARE_POINT_PAGE;
  297. }
  298. else
  299. {
  300. LOG(L"There is no page to replace");
  301. nextPage = IDD_FINISH_PAGE;
  302. }
  303. }
  304. break;
  305. case APPLICATIONSERVER_INSTALL:
  306. if (State::GetInstance().GetProductSKU() == CYS_SERVER)
  307. {
  308. nextPage = IDD_FINISH_PAGE;
  309. }
  310. else
  311. {
  312. if (InstallationUnitProvider::GetInstance().GetApplicationInstallationUnit().GetApplicationMode() == 1)
  313. {
  314. nextPage = IDD_FINISH_PAGE;
  315. }
  316. else
  317. {
  318. nextPage = IDD_TERMINAL_SERVER_PAGE;
  319. }
  320. }
  321. break;
  322. case FILESERVER_INSTALL:
  323. if (State::GetInstance().HasNTFSDrive())
  324. {
  325. nextPage = IDD_FILE_SERVER_PAGE;
  326. }
  327. else
  328. {
  329. if (!InstallationUnitProvider::GetInstance().GetSharePointInstallationUnit().IsServiceInstalled())
  330. {
  331. nextPage = IDD_INDEXING_PAGE;
  332. }
  333. else
  334. {
  335. ASSERT(false && L"Next button should have been disabled!");
  336. }
  337. }
  338. break;
  339. default:
  340. nextPage = IDD_FINISH_PAGE;
  341. break;
  342. }
  343. LOG(String::format(
  344. L"nextPage = %1!d!",
  345. nextPage));
  346. return nextPage;
  347. }