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.

395 lines
9.5 KiB

  1. // Copyright (c) 2001 Microsoft Corporation
  2. //
  3. // File: InstallationUnit.cpp
  4. //
  5. // Synopsis: Defines an InstallationUnit
  6. // An InstallationUnit represents a single
  7. // entity that can be installed. (i.e. DHCP, IIS, etc.)
  8. //
  9. // History: 02/03/2001 JeffJon Created
  10. #include "pch.h"
  11. #include "InstallationUnit.h"
  12. // It should match the values in the InstallationReturnType
  13. // The values of the enum are used to index this array
  14. extern String installReturnTypeStrings[] =
  15. {
  16. String(L"INSTALL_SUCCESS"),
  17. String(L"INSTALL_FAILURE"),
  18. String(L"INSTALL_SUCCESS_REBOOT"),
  19. String(L"INSTALL_SUCCESS_PROMPT_REBOOT"),
  20. String(L"INSTALL_SUCCESS_NEEDS_REBOOT"),
  21. String(L"INSTALL_FAILURE_NEEDS_REBOOT"),
  22. String(L"INSTALL_NO_CHANGES"),
  23. String(L"INSTALL_CANCELLED")
  24. };
  25. // It should match the values in the UnInstallReturnType
  26. // The values of the enum are used to index this array
  27. extern String uninstallReturnTypeStrings[] =
  28. {
  29. String(L"UNINSTALL_SUCCESS"),
  30. String(L"UNINSTALL_FAILURE"),
  31. String(L"UNINSTALL_SUCCESS_REBOOT"),
  32. String(L"UNINSTALL_SUCCESS_PROMPT_REBOOT"),
  33. String(L"UNINSTALL_SUCCESS_NEEDS_REBOOT"),
  34. String(L"UNINSTALL_FAILURE_NEEDS_REBOOT"),
  35. String(L"UNINSTALL_CANCELLED"),
  36. String(L"UNINSTALL_NO_CHANGES")
  37. };
  38. // Finish page help string
  39. static PCWSTR FINISH_PAGE_HELP = L"cys.chm::/cys_topnode.htm";
  40. InstallationUnit::InstallationUnit(unsigned int serviceNameID,
  41. unsigned int serviceDescriptionID,
  42. unsigned int finishPageTitleID,
  43. unsigned int finishPageUninstallTitleID,
  44. unsigned int finishPageMessageID,
  45. unsigned int finishPageInstallFailedMessageID,
  46. unsigned int finishPageUninstallMessageID,
  47. unsigned int finishPageUninstallFailedMessageID,
  48. unsigned int uninstallMilestonePageWarningID,
  49. unsigned int uninstallMilestonePageCheckboxID,
  50. const String finishPageHelpString,
  51. const String installMilestoneHelpString,
  52. const String afterFinishHelpString,
  53. ServerRole newInstallType) :
  54. nameID(serviceNameID),
  55. descriptionID(serviceDescriptionID),
  56. finishTitleID(finishPageTitleID),
  57. finishUninstallTitleID(finishPageUninstallTitleID),
  58. finishMessageID(finishPageMessageID),
  59. finishInstallFailedMessageID(finishPageInstallFailedMessageID),
  60. finishUninstallMessageID(finishPageUninstallMessageID),
  61. finishUninstallFailedMessageID(finishPageUninstallFailedMessageID),
  62. uninstallMilestoneWarningID(uninstallMilestonePageWarningID),
  63. uninstallMilestoneCheckboxID(uninstallMilestonePageCheckboxID),
  64. finishHelp(finishPageHelpString),
  65. milestoneHelp(installMilestoneHelpString),
  66. afterFinishHelp(afterFinishHelpString),
  67. role(newInstallType),
  68. name(),
  69. description(),
  70. installationResult(INSTALL_SUCCESS),
  71. uninstallResult(UNINSTALL_SUCCESS),
  72. installing(true)
  73. {
  74. }
  75. String
  76. InstallationUnit::GetServiceName()
  77. {
  78. LOG_FUNCTION(InstallationUnit::GetServiceName);
  79. if (name.empty())
  80. {
  81. name = String::load(nameID);
  82. }
  83. return name;
  84. }
  85. String
  86. InstallationUnit::GetServiceDescription()
  87. {
  88. LOG_FUNCTION(InstallationUnit::GetServiceDescription);
  89. if (description.empty())
  90. {
  91. description = String::load(descriptionID);
  92. }
  93. return description;
  94. }
  95. String
  96. InstallationUnit::GetFinishHelp()
  97. {
  98. LOG_FUNCTION(InstallationUnit::GetFinishHelp);
  99. String result = finishHelp;
  100. LOG(result);
  101. return result;
  102. }
  103. String
  104. InstallationUnit::GetMilestonePageHelp()
  105. {
  106. LOG_FUNCTION(InstallationUnit::GetMilestonePageHelp);
  107. String result = milestoneHelp;
  108. LOG(result);
  109. return result;
  110. }
  111. String
  112. InstallationUnit::GetAfterFinishHelp()
  113. {
  114. LOG_FUNCTION(InstallationUnit::GetAfterFinishHelp);
  115. String result = afterFinishHelp;
  116. LOG(result);
  117. return result;
  118. }
  119. InstallationStatus
  120. InstallationUnit::GetStatus()
  121. {
  122. LOG_FUNCTION(InstallationUnit::GetStatus);
  123. InstallationStatus result =
  124. GetInstallationStatusForServerRole(GetServerRole());
  125. LOG(statusStrings[result]);
  126. return result;
  127. }
  128. bool
  129. InstallationUnit::IsServiceInstalled()
  130. {
  131. LOG_FUNCTION(InstallationUnit::IsServiceInstalled);
  132. bool result = false;
  133. InstallationStatus status = GetInstallationStatusForServerRole(GetServerRole());
  134. if (status == STATUS_COMPLETED ||
  135. status == STATUS_CONFIGURED)
  136. {
  137. result = true;
  138. }
  139. LOG_BOOL(result);
  140. return result;
  141. }
  142. InstallationReturnType
  143. InstallationUnit::CompletePath(
  144. HANDLE logfileHandle,
  145. HWND hwnd)
  146. {
  147. LOG_FUNCTION(InstallationUnit::CompletePath);
  148. return InstallService(logfileHandle, hwnd);
  149. }
  150. void
  151. InstallationUnit::SetInstallResult(InstallationReturnType result)
  152. {
  153. LOG_FUNCTION(InstallationUnit::SetInstallResult);
  154. LOG_INSTALL_RETURN(result);
  155. installationResult = result;
  156. }
  157. void
  158. InstallationUnit::SetUninstallResult(UnInstallReturnType result)
  159. {
  160. LOG_FUNCTION(InstallationUnit::SetUninstallResult);
  161. LOG_UNINSTALL_RETURN(result);
  162. uninstallResult = result;
  163. }
  164. InstallationReturnType
  165. InstallationUnit::GetInstallResult() const
  166. {
  167. LOG_FUNCTION(InstallationUnit::GetInstallResult);
  168. LOG_INSTALL_RETURN(installationResult);
  169. return installationResult;
  170. }
  171. UnInstallReturnType
  172. InstallationUnit::GetUnInstallResult() const
  173. {
  174. LOG_FUNCTION(InstallationUnit::GetUnInstallResult);
  175. LOG_UNINSTALL_RETURN(uninstallResult);
  176. return uninstallResult;
  177. }
  178. int
  179. InstallationUnit::GetWizardStart()
  180. {
  181. LOG_FUNCTION(InstallationUnit::GetWizardStart);
  182. int result = IDD_MILESTONE_PAGE;
  183. bool installingRole = true;
  184. if (IsServiceInstalled())
  185. {
  186. installingRole = false;
  187. result = IDD_UNINSTALL_MILESTONE_PAGE;
  188. }
  189. SetInstalling(installingRole);
  190. LOG(String::format(
  191. L"wizard start = %1!d!",
  192. result));
  193. return result;
  194. }
  195. void
  196. InstallationUnit::UpdateInstallationProgressText(
  197. HWND hwnd,
  198. unsigned int messageID)
  199. {
  200. LOG_FUNCTION(InstallationUnit::UpdateInstallationProgressText);
  201. SendMessage(
  202. hwnd,
  203. InstallationProgressPage::CYS_PROGRESS_UPDATE,
  204. (WPARAM)String::load(messageID).c_str(),
  205. 0);
  206. }
  207. String
  208. InstallationUnit::GetFinishTitle()
  209. {
  210. LOG_FUNCTION(InstallationUnit::GetFinishTitle);
  211. unsigned int titleID = finishTitleID;
  212. if (installing)
  213. {
  214. InstallationReturnType result = GetInstallResult();
  215. if (result != INSTALL_SUCCESS &&
  216. result != INSTALL_SUCCESS_REBOOT &&
  217. result != INSTALL_SUCCESS_PROMPT_REBOOT &&
  218. result != INSTALL_SUCCESS_NEEDS_REBOOT)
  219. {
  220. titleID = IDS_CANNOT_COMPLETE;
  221. }
  222. }
  223. else
  224. {
  225. titleID = finishUninstallTitleID;
  226. UnInstallReturnType result = GetUnInstallResult();
  227. if (result != UNINSTALL_SUCCESS &&
  228. result != UNINSTALL_SUCCESS_REBOOT &&
  229. result != UNINSTALL_SUCCESS_PROMPT_REBOOT &&
  230. result != UNINSTALL_SUCCESS_NEEDS_REBOOT)
  231. {
  232. titleID = IDS_CANNOT_COMPLETE;
  233. }
  234. }
  235. return String::load(titleID);
  236. }
  237. void
  238. InstallationUnit::SetInstalling(bool installRole)
  239. {
  240. LOG_FUNCTION(InstallationUnit::SetInstalling);
  241. LOG_BOOL(installRole);
  242. installing = installRole;
  243. }
  244. String
  245. InstallationUnit::GetFinishText()
  246. {
  247. LOG_FUNCTION(InstallationUnit::GetFinishText);
  248. unsigned int messageID = finishMessageID;
  249. if (installing)
  250. {
  251. InstallationReturnType result = GetInstallResult();
  252. if (result != INSTALL_SUCCESS &&
  253. result != INSTALL_SUCCESS_REBOOT &&
  254. result != INSTALL_SUCCESS_PROMPT_REBOOT)
  255. {
  256. messageID = finishInstallFailedMessageID;
  257. }
  258. }
  259. else
  260. {
  261. messageID = finishUninstallMessageID;
  262. UnInstallReturnType result = GetUnInstallResult();
  263. if (result != UNINSTALL_SUCCESS &&
  264. result != UNINSTALL_SUCCESS_REBOOT &&
  265. result != UNINSTALL_SUCCESS_PROMPT_REBOOT)
  266. {
  267. messageID = finishUninstallFailedMessageID;
  268. }
  269. }
  270. return String::load(messageID);
  271. }
  272. String
  273. InstallationUnit::GetUninstallWarningText()
  274. {
  275. LOG_FUNCTION(InstallationUnit::GetUninstallWarningText);
  276. return String::load(uninstallMilestoneWarningID);
  277. }
  278. String
  279. InstallationUnit::GetUninstallCheckboxText()
  280. {
  281. LOG_FUNCTION(InstallationUnit::GetUninstallCheckboxText);
  282. return String::load(uninstallMilestoneCheckboxID);
  283. }
  284. void
  285. InstallationUnit::DoPostInstallAction(HWND)
  286. {
  287. LOG_FUNCTION(InstallationUnit::DoPostInstallAction);
  288. if ((Installing() &&
  289. GetInstallResult() == INSTALL_SUCCESS) ||
  290. State::GetInstance().IsRebootScenario())
  291. {
  292. LaunchMYS();
  293. }
  294. }
  295. bool
  296. InstallationUnit::DoInstallerCheck(HWND hwnd) const
  297. {
  298. LOG_FUNCTION(InstallationUnit::DoInstallerCheck);
  299. bool result = State::GetInstance().IsWindowsSetupRunning();
  300. if (result)
  301. {
  302. LOG(L"Windows setup is running");
  303. popup.MessageBox(
  304. Win::GetParent(hwnd),
  305. IDS_WINDOWS_SETUP_RUNNING,
  306. MB_OK);
  307. }
  308. LOG_BOOL(result);
  309. return result;
  310. }