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.

380 lines
8.7 KiB

  1. // Copyright (c) 1997-2001 Microsoft Corporation
  2. //
  3. // File: WelcomePage.cpp
  4. //
  5. // Synopsis: Defines Welcome Page for the CYS
  6. // Wizard
  7. //
  8. // History: 02/03/2001 JeffJon Created
  9. #include "pch.h"
  10. #include "resource.h"
  11. #include "InstallationUnitProvider.h"
  12. #include "WelcomePage.h"
  13. #include "state.h"
  14. #include "Dialogs.h"
  15. static PCWSTR WELCOME_PAGE_HELP = L"cys.chm::/cys_topnode.htm";
  16. WelcomePage::WelcomePage()
  17. :
  18. CYSWizardPage(
  19. IDD_WELCOME_PAGE,
  20. IDS_WELCOME_TITLE,
  21. IDS_WELCOME_SUBTITLE,
  22. WELCOME_PAGE_HELP,
  23. true,
  24. false)
  25. {
  26. LOG_CTOR(WelcomePage);
  27. }
  28. WelcomePage::~WelcomePage()
  29. {
  30. LOG_DTOR(WelcomePage);
  31. }
  32. void
  33. WelcomePage::OnInit()
  34. {
  35. LOG_FUNCTION(WelcomePage::OnInit);
  36. SetLargeFont(hwnd, IDC_BIG_BOLD_TITLE);
  37. Win::PropSheet_SetTitle(
  38. Win::GetParent(hwnd),
  39. 0,
  40. String::load(IDS_WIZARD_TITLE));
  41. // Check to see if we are in a reboot scenario
  42. String homeKeyValue;
  43. if (State::GetInstance().GetHomeRegkey(homeKeyValue))
  44. {
  45. if (homeKeyValue.icompare(CYS_HOME_REGKEY_TERMINAL_SERVER_VALUE) == 0)
  46. {
  47. TerminalServerPostBoot();
  48. }
  49. else if (homeKeyValue.icompare(CYS_HOME_REGKEY_TERMINAL_SERVER_OPTIMIZED) == 0)
  50. {
  51. TerminalServerPostBoot(false);
  52. }
  53. else if (homeKeyValue.icompare(CYS_HOME_REGKEY_FIRST_SERVER_VALUE) == 0)
  54. {
  55. FirstServerPostBoot();
  56. }
  57. else if (homeKeyValue.icompare(CYS_HOME_REGKEY_DCPROMO_VALUE) == 0)
  58. {
  59. DCPromoPostBoot();
  60. }
  61. // Now set the home regkey back to "home" so that we won't run
  62. // through these again
  63. if (homeKeyValue.icompare(CYS_HOME_REGKEY_DEFAULT_VALUE) != 0)
  64. {
  65. bool result =
  66. State::GetInstance().SetHomeRegkey(CYS_HOME_REGKEY_DEFAULT_VALUE);
  67. ASSERT(result);
  68. }
  69. // Reset the must run key now that we have done the reboot stuff
  70. bool regkeyResult = SetRegKeyValue(
  71. CYS_HOME_REGKEY,
  72. CYS_HOME_REGKEY_MUST_RUN,
  73. CYS_HOME_RUN_KEY_DONT_RUN,
  74. HKEY_LOCAL_MACHINE,
  75. true);
  76. ASSERT(regkeyResult);
  77. }
  78. }
  79. void
  80. WelcomePage::TerminalServerPostBoot(bool installed)
  81. {
  82. LOG_FUNCTION(WelcomePage::TerminalServerPostBoot);
  83. // Create the log file
  84. String logName;
  85. HANDLE logfileHandle = AppendLogFile(
  86. CYS_LOGFILE_NAME,
  87. logName);
  88. if (logfileHandle)
  89. {
  90. LOG(String::format(L"New log file was created: %1", logName.c_str()));
  91. }
  92. else
  93. {
  94. LOG(L"Unable to create the log file!!!");
  95. }
  96. // Prepare the finish dialog
  97. FinishDialog dialog(
  98. logName,
  99. InstallationUnitProvider::GetInstance().GetApplicationInstallationUnit().GetFinishHelp());
  100. if (installed)
  101. {
  102. if (InstallationUnitProvider::GetInstance().GetApplicationInstallationUnit().GetApplicationMode() == 1)
  103. {
  104. CYS_APPEND_LOG(String::load(IDS_LOG_APP_REBOOT_SUCCESS));
  105. // Prompt the user to show help or log file
  106. dialog.ModalExecute(hwnd);
  107. }
  108. else
  109. {
  110. // Failed to install TS
  111. CYS_APPEND_LOG(String::load(IDS_LOG_APP_REBOOT_FAILED));
  112. dialog.OpenLogFile();
  113. }
  114. }
  115. else
  116. {
  117. // Since all we did is optimize we should always be successful on reboot
  118. dialog.ModalExecute(hwnd);
  119. }
  120. }
  121. void
  122. WelcomePage::FirstServerPostBoot()
  123. {
  124. LOG_FUNCTION(WelcomePage::FirstServerPostBoot);
  125. // Create the log file
  126. String logName;
  127. HANDLE logfileHandle = AppendLogFile(
  128. CYS_LOGFILE_NAME,
  129. logName);
  130. if (logfileHandle)
  131. {
  132. LOG(String::format(L"New log file was created: %1", logName.c_str()));
  133. }
  134. else
  135. {
  136. LOG(L"Unable to create the log file!!!");
  137. }
  138. // Verify the machine is a DC
  139. do
  140. {
  141. if (State::GetInstance().IsDC())
  142. {
  143. // Authorize the new DHCP scope
  144. String dnsName = Win::GetComputerNameEx(ComputerNameDnsFullyQualified);
  145. if (InstallationUnitProvider::GetInstance().GetDHCPInstallationUnit().AuthorizeDHCPScope(dnsName))
  146. {
  147. LOG(L"DHCP scope successfully authorized");
  148. CYS_APPEND_LOG(String::load(IDS_LOG_DHCP_AUTHORIZATION_SUCCEEDED));
  149. }
  150. else
  151. {
  152. LOG(L"DHCP scope authorization failed");
  153. String failureMessage = String::load(IDS_LOG_DHCP_AUTHORIZATION_FAILED);
  154. CYS_APPEND_LOG(failureMessage);
  155. Win::MessageBox(
  156. hwnd,
  157. failureMessage,
  158. String::load(IDS_WIZARD_TITLE),
  159. MB_OK);
  160. }
  161. // Do TAPI config
  162. if (State::GetInstance().IsFirstDC())
  163. {
  164. HRESULT hr =
  165. InstallationUnitProvider::GetInstance().GetExpressInstallationUnit().DoTapiConfig(dnsName);
  166. if (SUCCEEDED(hr))
  167. {
  168. LOG(L"TAPI config succeeded");
  169. CYS_APPEND_LOG(String::load(IDS_LOG_TAPI_CONFIG_SUCCEEDED));
  170. CYS_APPEND_LOG(
  171. String::format(
  172. String::load(IDS_LOG_TAPI_CONFIG_SUCCEEDED_FORMAT),
  173. dnsName.c_str()));
  174. }
  175. else
  176. {
  177. LOG(L"TAPI config failed");
  178. CYS_APPEND_LOG(
  179. String::format(
  180. String::load(IDS_LOG_TAPI_CONFIG_FAILED_FORMAT),
  181. hr));
  182. }
  183. }
  184. // Show dialog that lets the user open help or the log file
  185. }
  186. else
  187. {
  188. LOG(L"DCPromo failed on reboot");
  189. CYS_APPEND_LOG(String::load(IDS_LOG_DCPROMO_REBOOT_FAILED));
  190. break;
  191. }
  192. } while (false);
  193. }
  194. void
  195. WelcomePage::DCPromoPostBoot()
  196. {
  197. LOG_FUNCTION(WelcomePage::DCPromoPostBoot);
  198. // Create the log file
  199. String logName;
  200. HANDLE logfileHandle = AppendLogFile(
  201. CYS_LOGFILE_NAME,
  202. logName);
  203. if (logfileHandle)
  204. {
  205. LOG(String::format(L"New log file was created: %1", logName.c_str()));
  206. }
  207. else
  208. {
  209. LOG(L"Unable to create the log file!!!");
  210. ASSERT(false);
  211. }
  212. // Prepare the finish dialog
  213. FinishDialog dialog(
  214. logName,
  215. InstallationUnitProvider::GetInstance().GetADInstallationUnit().GetFinishHelp());
  216. CYS_APPEND_LOG(String::load(IDS_LOG_DOMAIN_CONTROLLER_HEADING));
  217. CYS_APPEND_LOG(String::load(IDS_LOG_DOMAIN_CONTROLLER_INSTALL));
  218. if (State::GetInstance().IsDC())
  219. {
  220. CYS_APPEND_LOG(String::load(IDS_LOG_DOMAIN_CONTROLLER_SUCCESS));
  221. // Show the log/help dialog
  222. dialog.ModalExecute(hwnd);
  223. }
  224. else
  225. {
  226. CYS_APPEND_LOG(String::load(IDS_LOG_DOMAIN_CONTROLLER_FAILED));
  227. // just open the log
  228. dialog.OpenLogFile();
  229. }
  230. }
  231. bool
  232. WelcomePage::OnSetActive()
  233. {
  234. LOG_FUNCTION(WelcomePage::OnSetActive);
  235. // Only Next and Cancel are available from the Welcome page
  236. Win::PropSheet_SetWizButtons(Win::GetParent(hwnd), PSWIZB_NEXT);
  237. return true;
  238. }
  239. int
  240. WelcomePage::Validate()
  241. {
  242. LOG_FUNCTION(WelcomePage::Validate);
  243. // For now, just initialize the state object and then
  244. // go directly to the custom server page. Eventually
  245. // we will figure out what we want express path to do
  246. // and then we will have to delay retrieving machine
  247. // info and go to the BeforeBeginPage.
  248. // Gather the machine network and role information
  249. State& state = State::GetInstance();
  250. if (!state.HasStateBeenRetrieved())
  251. {
  252. if (!state.RetrieveMachineConfigurationInformation(hwnd))
  253. {
  254. ASSERT(false);
  255. LOG(L"The machine configuration could not be retrieved.");
  256. return -1;
  257. }
  258. }
  259. int nextPage = IDD_CUSTOM_SERVER_PAGE;
  260. do
  261. {
  262. if (state.GetNICCount() != 1)
  263. {
  264. LOG(String::format(
  265. L"GetNICCount() = %1!d!",
  266. state.GetNICCount()));
  267. break;
  268. }
  269. if (state.IsDC())
  270. {
  271. LOG(L"Computer is DC");
  272. break;
  273. }
  274. if (InstallationUnitProvider::GetInstance().GetDNSInstallationUnit().IsServiceInstalled())
  275. {
  276. LOG(L"Computer is DNS server");
  277. break;
  278. }
  279. if (InstallationUnitProvider::GetInstance().GetDHCPInstallationUnit().IsServiceInstalled())
  280. {
  281. LOG(L"Computer is DHCP server");
  282. break;
  283. }
  284. if (state.IsDHCPServerAvailable())
  285. {
  286. LOG(L"DHCP server found on the network");
  287. break;
  288. }
  289. nextPage = IDD_DECISION_PAGE;
  290. } while (false);
  291. LOG(String::format(
  292. L"nextPage = %1!d!",
  293. nextPage));
  294. return nextPage;
  295. }