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.

256 lines
6.1 KiB

  1. // Copyright (c) 2001 Microsoft Corporation
  2. //
  3. // File: WINSInstallationUnit.cpp
  4. //
  5. // Synopsis: Defines a WINSInstallationUnit
  6. // This object has the knowledge for installing the
  7. // WINS service
  8. //
  9. // History: 02/06/2001 JeffJon Created
  10. #include "pch.h"
  11. #include "resource.h"
  12. #include "WINSInstallationUnit.h"
  13. // Finish page help
  14. static PCWSTR CYS_WINS_FINISH_PAGE_HELP = L"cys.chm::/wins_server_role.htm";
  15. static PCWSTR CYS_WINS_MILESTONE_HELP = L"cys.chm::/wins_server_role.htm#winssrvsummary";
  16. static PCWSTR CYS_WINS_AFTER_FINISH_HELP = L"cys.chm::/wins_server_role.htm#winssrvcompletion";
  17. WINSInstallationUnit::WINSInstallationUnit() :
  18. installedDescriptionID(IDS_WINS_SERVER_DESCRIPTION_INSTALLED),
  19. InstallationUnit(
  20. IDS_WINS_SERVER_TYPE,
  21. IDS_WINS_SERVER_DESCRIPTION,
  22. IDS_WINS_FINISH_TITLE,
  23. IDS_WINS_FINISH_UNINSTALL_TITLE,
  24. IDS_WINS_FINISH_MESSAGE,
  25. IDS_WINS_INSTALL_FAILED,
  26. IDS_WINS_UNINSTALL_MESSAGE,
  27. IDS_WINS_UNINSTALL_FAILED,
  28. IDS_WINS_UNINSTALL_WARNING,
  29. IDS_WINS_UNINSTALL_CHECKBOX,
  30. CYS_WINS_FINISH_PAGE_HELP,
  31. CYS_WINS_MILESTONE_HELP,
  32. CYS_WINS_AFTER_FINISH_HELP,
  33. WINS_SERVER)
  34. {
  35. LOG_CTOR(WINSInstallationUnit);
  36. }
  37. WINSInstallationUnit::~WINSInstallationUnit()
  38. {
  39. LOG_DTOR(WINSInstallationUnit);
  40. }
  41. InstallationReturnType
  42. WINSInstallationUnit::InstallService(HANDLE logfileHandle, HWND hwnd)
  43. {
  44. LOG_FUNCTION(WINSInstallationUnit::InstallService);
  45. InstallationReturnType result = INSTALL_SUCCESS;
  46. // Log the WINS header
  47. CYS_APPEND_LOG(String::load(IDS_LOG_WINS_HEADING));
  48. UpdateInstallationProgressText(hwnd, IDS_WINS_PROGRESS);
  49. // Create the inf and unattend files that are used by the
  50. // Optional Component Manager
  51. String infFileText;
  52. String unattendFileText;
  53. CreateInfFileText(infFileText, IDS_WINS_INF_WINDOW_TITLE);
  54. CreateUnattendFileText(unattendFileText, CYS_WINS_SERVICE_NAME);
  55. // Install the service through the Optional Component Manager
  56. bool ocmResult = InstallServiceWithOcManager(infFileText, unattendFileText);
  57. if (ocmResult &&
  58. IsServiceInstalled())
  59. {
  60. // Log the successful installation
  61. LOG(L"WINS was installed successfully");
  62. CYS_APPEND_LOG(String::load(IDS_LOG_SERVER_WINS_SUCCESS));
  63. }
  64. else
  65. {
  66. // Log the failure
  67. LOG(L"WINS failed to install");
  68. CYS_APPEND_LOG(String::load(IDS_LOG_WINS_SERVER_FAILED));
  69. result = INSTALL_FAILURE;
  70. }
  71. LOG_INSTALL_RETURN(result);
  72. return result;
  73. }
  74. UnInstallReturnType
  75. WINSInstallationUnit::UnInstallService(HANDLE logfileHandle, HWND hwnd)
  76. {
  77. LOG_FUNCTION(WINSInstallationUnit::UnInstallService);
  78. UnInstallReturnType result = UNINSTALL_SUCCESS;
  79. // Log the WINS header
  80. CYS_APPEND_LOG(String::load(IDS_LOG_UNINSTALL_WINS_HEADING));
  81. UpdateInstallationProgressText(hwnd, IDS_WINS_UNINSTALL_PROGRESS);
  82. // Create the inf and unattend files that are used by the
  83. // Optional Component Manager
  84. String infFileText;
  85. String unattendFileText;
  86. CreateInfFileText(infFileText, IDS_WINS_INF_WINDOW_TITLE);
  87. CreateUnattendFileText(unattendFileText, CYS_WINS_SERVICE_NAME, false);
  88. // NTRAID#NTBUG9-736557-2002/11/13-JeffJon
  89. // Pass the /w switch to sysocmgr when uninstalling
  90. // so that if a situation occurs in which a reboot
  91. // is required, the user will be prompted.
  92. String additionalArgs = L"/w";
  93. // Install the service through the Optional Component Manager
  94. bool ocmResult =
  95. InstallServiceWithOcManager(
  96. infFileText,
  97. unattendFileText,
  98. additionalArgs);
  99. if (ocmResult &&
  100. !IsServiceInstalled())
  101. {
  102. // Log the successful uninstall
  103. LOG(L"WINS was uninstalled successfully");
  104. CYS_APPEND_LOG(String::load(IDS_LOG_SERVER_UNINSTALL_WINS_SUCCESS));
  105. }
  106. else
  107. {
  108. // Log the failure
  109. LOG(L"WINS failed to uninstall");
  110. CYS_APPEND_LOG(String::load(IDS_LOG_UNINSTALL_WINS_SERVER_FAILED));
  111. result = UNINSTALL_FAILURE;
  112. }
  113. LOG_UNINSTALL_RETURN(result);
  114. return result;
  115. }
  116. bool
  117. WINSInstallationUnit::GetMilestoneText(String& message)
  118. {
  119. LOG_FUNCTION(WINSInstallationUnit::GetMilestoneText);
  120. message = String::load(IDS_WINS_FINISH_TEXT);
  121. LOG_BOOL(true);
  122. return true;
  123. }
  124. bool
  125. WINSInstallationUnit::GetUninstallMilestoneText(String& message)
  126. {
  127. LOG_FUNCTION(WINSInstallationUnit::GetUninstallMilestoneText);
  128. message = String::load(IDS_WINS_UNINSTALL_TEXT);
  129. LOG_BOOL(true);
  130. return true;
  131. }
  132. String
  133. WINSInstallationUnit::GetServiceDescription()
  134. {
  135. LOG_FUNCTION(WINSInstallationUnit::GetServiceDescription);
  136. String result;
  137. unsigned int resultID = descriptionID;
  138. if (IsServiceInstalled())
  139. {
  140. resultID = installedDescriptionID;
  141. }
  142. result = String::load(resultID);
  143. ASSERT(!result.empty());
  144. return result;
  145. }
  146. void
  147. WINSInstallationUnit::ServerRoleLinkSelected(int linkIndex, HWND /*hwnd*/)
  148. {
  149. LOG_FUNCTION2(
  150. WINSInstallationUnit::ServerRoleLinkSelected,
  151. String::format(
  152. L"linkIndex = %1!d!",
  153. linkIndex));
  154. if (IsServiceInstalled())
  155. {
  156. ASSERT(linkIndex == 0);
  157. LaunchMYS();
  158. }
  159. else
  160. {
  161. ASSERT(linkIndex == 0);
  162. LOG(L"Showing configuration help");
  163. ShowHelp(CYS_WINS_FINISH_PAGE_HELP);
  164. }
  165. }
  166. void
  167. WINSInstallationUnit::FinishLinkSelected(int linkIndex, HWND /*hwnd*/)
  168. {
  169. LOG_FUNCTION2(
  170. WINSInstallationUnit::FinishLinkSelected,
  171. String::format(
  172. L"linkIndex = %1!d!",
  173. linkIndex));
  174. if (installing)
  175. {
  176. if (linkIndex == 0 &&
  177. IsServiceInstalled())
  178. {
  179. LOG("Showing after checklist");
  180. ShowHelp(CYS_WINS_AFTER_FINISH_HELP);
  181. }
  182. else if (linkIndex == 0)
  183. {
  184. LOG(L"Showing configuration help");
  185. ShowHelp(CYS_WINS_FINISH_PAGE_HELP);
  186. }
  187. }
  188. else
  189. {
  190. }
  191. }