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.

266 lines
6.1 KiB

  1. // Copyright (c) 1997-2001 Microsoft Corporation
  2. //
  3. // File: FinishPage.cpp
  4. //
  5. // Synopsis: Defines the Finish 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 "FinishPage.h"
  13. #include "state.h"
  14. #include "Dialogs.h"
  15. FinishPage::FinishPage()
  16. :
  17. WizardPage(IDD_FINISH_PAGE, IDS_FINISH_TITLE, IDS_FINISH_SUBTITLE, false, true)
  18. {
  19. LOG_CTOR(FinishPage);
  20. }
  21. FinishPage::~FinishPage()
  22. {
  23. LOG_DTOR(FinishPage);
  24. }
  25. void
  26. FinishPage::OnInit()
  27. {
  28. LOG_FUNCTION(FinishPage::OnInit);
  29. SetLargeFont(hwnd, IDC_BIG_BOLD_TITLE);
  30. }
  31. bool
  32. FinishPage::OnSetActive()
  33. {
  34. LOG_FUNCTION(FinishPage::OnSetActive);
  35. Win::PropSheet_SetWizButtons(
  36. Win::GetParent(hwnd),
  37. PSWIZB_FINISH | PSWIZB_BACK);
  38. // Get the finish text from the installation unit and put it in the finish box
  39. String message;
  40. bool changes =
  41. InstallationUnitProvider::GetInstance().GetCurrentInstallationUnit().GetFinishText(message);
  42. Win::SetDlgItemText(hwnd, IDC_FINISH_MESSAGE, message);
  43. // set the rerun check box state
  44. if (InstallationUnitProvider::GetInstance().GetCurrentInstallationUnit().GetInstallationUnitType()
  45. == DC_INSTALL ||
  46. InstallationUnitProvider::GetInstance().GetCurrentInstallationUnit().GetInstallationUnitType()
  47. == EXPRESS_INSTALL)
  48. {
  49. // the wizard must be rerun when we are installing a DC
  50. Win::ShowWindow(
  51. Win::GetDlgItem(hwnd, IDC_RERUN_CHECK),
  52. SW_HIDE);
  53. Win::Button_SetCheck(
  54. Win::GetDlgItem(hwnd, IDC_RERUN_CHECK),
  55. BST_CHECKED);
  56. Win::EnableWindow(
  57. Win::GetDlgItem(hwnd, IDC_RERUN_CHECK),
  58. false);
  59. }
  60. else
  61. {
  62. Win::ShowWindow(
  63. Win::GetDlgItem(hwnd, IDC_RERUN_CHECK),
  64. SW_SHOW);
  65. Win::Button_SetCheck(
  66. Win::GetDlgItem(hwnd, IDC_RERUN_CHECK),
  67. State::GetInstance().RerunWizard() ? BST_CHECKED : BST_UNCHECKED);
  68. Win::EnableWindow(
  69. Win::GetDlgItem(hwnd, IDC_RERUN_CHECK),
  70. true);
  71. }
  72. if (!changes)
  73. {
  74. popup.MessageBox(
  75. hwnd,
  76. IDS_NO_CHANGES_MESSAGEBOX_TEXT,
  77. MB_OK | MB_ICONWARNING);
  78. }
  79. return true;
  80. }
  81. bool
  82. FinishPage::OnHelp()
  83. {
  84. LOG_FUNCTION(FinishPage::OnHelp);
  85. // NOTE: I am not using Win::HtmlHelp here so that the help
  86. // is actually running in a different process. This
  87. // allows us to close down CYS without closing the help
  88. // window.
  89. String commandline =
  90. L"hh.exe \"" +
  91. InstallationUnitProvider::GetInstance().GetCurrentInstallationUnit().GetFinishHelp() +
  92. L"\"";
  93. HRESULT hr = MyCreateProcess(commandline);
  94. if (FAILED(hr))
  95. {
  96. LOG(String::format(
  97. L"Failed to open help: hr = 0x%1!x!",
  98. hr));
  99. }
  100. return true;
  101. }
  102. bool
  103. FinishPage::OnWizFinish()
  104. {
  105. LOG_FUNCTION(FinishPage::OnWizFinish);
  106. Win::WaitCursor wait;
  107. bool result = false;
  108. // Get the rerun state
  109. bool rerunWizard = Win::Button_GetCheck(Win::GetDlgItem(hwnd, IDC_RERUN_CHECK));
  110. State::GetInstance().SetRerunWizard(rerunWizard);
  111. // Open the log file and pass the handle to the installation unit
  112. // Create the log file
  113. String logName;
  114. HANDLE logfileHandle = AppendLogFile(
  115. CYS_LOGFILE_NAME,
  116. logName);
  117. if (logfileHandle)
  118. {
  119. LOG(String::format(L"New log file was created: %1", logName.c_str()));
  120. }
  121. else
  122. {
  123. LOG(L"Unable to create the log file!!!");
  124. }
  125. // Install the current Installation Unit. This may be one or more services depending on the
  126. // path that was taken through the wizard
  127. InstallationUnit& installationUnit =
  128. InstallationUnitProvider::GetInstance().GetCurrentInstallationUnit();
  129. InstallationReturnType installResult =
  130. installationUnit.InstallService(logfileHandle, hwnd);
  131. FinishDialog dialog(logName, installationUnit.GetFinishHelp());
  132. if (INSTALL_SUCCESS == installResult)
  133. {
  134. LOG(L"Service installed successfully");
  135. // Bring up finish dialog that allows the user to select to
  136. // show help and/or the log file
  137. dialog.ModalExecute(hwnd);
  138. }
  139. else if (INSTALL_NO_CHANGES == installResult ||
  140. INSTALL_SUCCESS_REBOOT == installResult)
  141. {
  142. LOG(L"Service installed successfully");
  143. LOG(L"Not logging results because reboot was initiated");
  144. }
  145. else if (INSTALL_SUCCESS_PROMPT_REBOOT == installResult)
  146. {
  147. LOG(L"Service installed successfully");
  148. LOG(L"Prompting user to reboot");
  149. if (-1 == SetupPromptReboot(
  150. 0,
  151. hwnd,
  152. FALSE))
  153. {
  154. LOG(String::format(
  155. L"Failed to reboot: hr = %1!x!",
  156. GetLastError()));
  157. }
  158. // At this point the system should be shutting down
  159. // so don't do anything else
  160. }
  161. else
  162. {
  163. LOG(L"Service failed to install");
  164. if (IDYES == popup.MessageBox(
  165. hwnd,
  166. String::load(IDS_FAILED_INSTALL),
  167. MB_YESNO | MB_ICONWARNING))
  168. {
  169. dialog.OpenLogFile();
  170. Win::SetForegroundWindow(hwnd);
  171. }
  172. result = true;
  173. }
  174. // Add an additional line at the end of the log file
  175. // only if we are not rebooting. All the reboot
  176. // scenarios require additional logging to the same
  177. // entry.
  178. if (installResult != INSTALL_SUCCESS_REBOOT)
  179. {
  180. CYS_APPEND_LOG(L"\r\n");
  181. }
  182. LOG_BOOL(result);
  183. Win::SetWindowLongPtr(hwnd, DWLP_MSGRESULT, result ? TRUE : FALSE);
  184. if (!result)
  185. {
  186. // clean up the InstallationUnits so that all the data must be re-read if
  187. // if CYS automatically restarts
  188. InstallationUnitProvider::GetInstance().Destroy();
  189. }
  190. return true;
  191. }
  192. bool
  193. FinishPage::OnQueryCancel()
  194. {
  195. LOG_FUNCTION(FinishPage::OnQueryCancel);
  196. bool result = false;
  197. // set the rerun state to false so the wizard doesn't
  198. // just restart itself
  199. State::GetInstance().SetRerunWizard(false);
  200. Win::SetWindowLongPtr(
  201. hwnd,
  202. DWLP_MSGRESULT,
  203. result ? TRUE : FALSE);
  204. return true;
  205. }