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.

464 lines
12 KiB

  1. // Copyright (c) 1997-2001 Microsoft Corporation
  2. //
  3. // File: SharePointInstallationUnit.cpp
  4. //
  5. // Synopsis: Defines a SharePointInstallationUnit
  6. // This object has the knowledge for installing the
  7. // SharePoint server
  8. //
  9. // History: 02/06/2001 JeffJon Created
  10. #include "pch.h"
  11. #include "resource.h"
  12. #include "SharePointInstallationUnit.h"
  13. #include "InstallationUnitProvider.h"
  14. #include "state.h"
  15. // Define the GUIDs used by the SharePoint COM object
  16. #include <initguid.h>
  17. DEFINE_GUID(CLSID_SpCys,0x252EF1C7,0x6625,0x4D44,0xAB,0x9D,0x1D,0x80,0xE6,0x13,0x84,0xF9);
  18. DEFINE_GUID(IID_ISpCys,0x389C9713,0x9775,0x4206,0xA0,0x47,0xA2,0xF7,0x49,0xF8,0x03,0x9D);
  19. // Finish page help
  20. static PCWSTR CYS_SHAREPOINT_FINISH_PAGE_HELP = L"cys.chm::/cys_configuring_sharepoint_server.htm";
  21. SharePointInstallationUnit::SharePointInstallationUnit() :
  22. replaceHomepage(false),
  23. InstallationUnit(
  24. IDS_SHARE_POINT_TYPE,
  25. IDS_SHARE_POINT_DESCRIPTION,
  26. CYS_SHAREPOINT_FINISH_PAGE_HELP,
  27. SHAREPOINT_INSTALL)
  28. {
  29. LOG_CTOR(SharePointInstallationUnit);
  30. }
  31. SharePointInstallationUnit::~SharePointInstallationUnit()
  32. {
  33. LOG_DTOR(SharePointInstallationUnit);
  34. }
  35. InstallationReturnType
  36. SharePointInstallationUnit::InstallService(HANDLE logfileHandle, HWND hwnd)
  37. {
  38. LOG_FUNCTION(SharePointInstallationUnit::InstallService);
  39. InstallationReturnType result = INSTALL_SUCCESS;
  40. ASSERT(!IsServiceInstalled());
  41. CYS_APPEND_LOG(String::load(IDS_LOG_SHAREPOINT));
  42. do
  43. {
  44. // We should never get here on 64bit
  45. if (State::GetInstance().GetPlatform() & CYS_64BIT)
  46. {
  47. ASSERT(!(State::GetInstance().GetPlatform() & CYS_64BIT));
  48. LOG(L"SharePoint cannot be installed on 64bit!!!");
  49. result = INSTALL_FAILURE;
  50. break;
  51. }
  52. bool wasIndexingOn = IsIndexingServiceOn();
  53. if (!InstallationUnitProvider::GetInstance().GetWebInstallationUnit().IsServiceInstalled())
  54. {
  55. result =
  56. InstallationUnitProvider::GetInstance().GetWebInstallationUnit().InstallService(logfileHandle, hwnd);
  57. if (INSTALL_FAILURE == result)
  58. {
  59. break;
  60. }
  61. }
  62. if (InstallationUnitProvider::GetInstance().GetWebInstallationUnit().IsServiceInstalled())
  63. {
  64. // Get the name of the source location of the install files
  65. String installLocation;
  66. DWORD productSKU = State::GetInstance().GetProductSKU();
  67. if (productSKU & CYS_SERVER)
  68. {
  69. installLocation = String::load(IDS_SERVER_CD);
  70. }
  71. else if (productSKU & CYS_ADVANCED_SERVER)
  72. {
  73. installLocation = String::load(IDS_ADVANCED_SERVER_CD);
  74. }
  75. else if (productSKU & CYS_DATACENTER_SERVER)
  76. {
  77. installLocation = String::load(IDS_DATACENTER_SERVER_CD);
  78. }
  79. else
  80. {
  81. installLocation = String::load(IDS_WINDOWS_CD);
  82. }
  83. // Comments from the old HTA CYS
  84. // The SPInstall method of spcyscom starts the installation of OWS.
  85. // This method it will look in
  86. // "HKLM\Software\Microsoft\Windows\CurrentVersion\Setup\" for
  87. // SourcePath key and it will add
  88. // "valueadd\ms\sharepoint\setupse.exe" to it;
  89. // the method will call the command "setupse.exe /q /wait".
  90. // If errors are returned, is returning any error strings that
  91. // resulted from the install of SharePoint.
  92. BSTR errorMessage;
  93. HRESULT hr = GetSharePointObject()->SPInstall(
  94. ReplaceHomePage(),
  95. const_cast<WCHAR*>(installLocation.c_str()),
  96. &errorMessage);
  97. String message;
  98. if (errorMessage)
  99. {
  100. message = errorMessage;
  101. ::SysFreeString(errorMessage);
  102. }
  103. if (SUCCEEDED(hr) && message.empty())
  104. {
  105. // Log the successful install
  106. CYS_APPEND_LOG(String::load(IDS_LOG_SHAREPOINT_INSTALL_SUCCESS));
  107. BSTR nonDefaultHomePage;
  108. hr = GetSharePointObject()->SPNonDefaultHomePage(&nonDefaultHomePage);
  109. // ignore the return value and continue with a blank nonDefaultHomePage
  110. if (nonDefaultHomePage)
  111. {
  112. nonDefaultHP = nonDefaultHomePage;
  113. ::SysFreeString(nonDefaultHomePage);
  114. }
  115. // Log that the admin tool was added to the start menu
  116. CYS_APPEND_LOG(String::load(IDS_LOG_SHAREPOINT_STARTMENU));
  117. if (nonDefaultHP.empty())
  118. {
  119. // Created as the default
  120. CYS_APPEND_LOG(
  121. String::format(
  122. IDS_LOG_SHAREPOINT_DEFAULT_URL,
  123. State::GetInstance().GetComputerName()));
  124. }
  125. else
  126. {
  127. if (ReplaceHomePage())
  128. {
  129. // log the replacement URL
  130. CYS_APPEND_LOG(
  131. String::format(
  132. String::load(IDS_LOG_SHAREPOINT_REPLACEMENT_URL),
  133. nonDefaultHP.c_str()));
  134. }
  135. else
  136. {
  137. // log the URL
  138. CYS_APPEND_LOG(
  139. String::format(
  140. String::load(IDS_LOG_SHAREPOINT_NEW_URL),
  141. nonDefaultHP.c_str()));
  142. }
  143. }
  144. // Check to see if there has been a change in the indexing services
  145. bool isIndexingOn = IsIndexingServiceOn();
  146. if (isIndexingOn && !wasIndexingOn)
  147. {
  148. // log that the indexing service was turned on
  149. CYS_APPEND_LOG(String::load(IDS_LOG_SHAREPOINT_INDEXING_ON));
  150. }
  151. }
  152. else if (HRESULT_CODE(hr) == ERROR_FILE_NOT_FOUND ||
  153. HRESULT_CODE(hr) == ERROR_INSTALL_USEREXIT)
  154. {
  155. // Operation was cancelled by the user
  156. // We get ERROR_FILE_NOT_FOUND when the installation
  157. // source dialog is cancelled by the user
  158. LOG(String::format(
  159. L"The install was cancelled: hr = 0x%1!x!",
  160. hr));
  161. CYS_APPEND_LOG(String::load(IDS_LOG_WIZARD_CANCELLED));
  162. result = INSTALL_FAILURE;
  163. }
  164. else
  165. {
  166. // Log the failure
  167. static const maxMessageIDCount = 5;
  168. DWORD count = maxMessageIDCount;
  169. DWORD ids[maxMessageIDCount];
  170. ZeroMemory(ids, maxMessageIDCount * sizeof(ids));
  171. // Try to get the message IDs from the SharePoint COM object
  172. hr = GetSharePointObject()->SPGetMessageIDs(
  173. &count,
  174. ids);
  175. if (SUCCEEDED(hr))
  176. {
  177. // Write out a message for each of the IDs returned
  178. for (DWORD idx = 0; idx < count; ++idx)
  179. {
  180. if (ids[idx] != 0)
  181. {
  182. CYS_APPEND_LOG(String::load(static_cast<unsigned>(ids[idx])));
  183. }
  184. }
  185. }
  186. else
  187. {
  188. // Since we couldn't get a message from the COM object
  189. // write out a generic message
  190. CYS_APPEND_LOG(String::load(IDS_LOG_SHAREPOINT_INSTALL_FAILED));
  191. CYS_APPEND_LOG(
  192. String::format(
  193. String::load(IDS_LOG_SHAREPOINT_INSTALL_ERROR),
  194. message.c_str()));
  195. }
  196. result = INSTALL_FAILURE;
  197. }
  198. }
  199. else
  200. {
  201. LOG(L"IIS is not installed! Aborting SharePoint installation.");
  202. CYS_APPEND_LOG(String::load(IDS_LOG_SHAREPOINT_NO_IIS));
  203. result = INSTALL_FAILURE;
  204. break;
  205. }
  206. } while (false);
  207. LOG_INSTALL_RETURN(result);
  208. return result;
  209. }
  210. bool
  211. SharePointInstallationUnit::IsServiceInstalled()
  212. {
  213. LOG_FUNCTION(SharePointInstallationUnit::IsServiceInstalled);
  214. bool result = false;
  215. do
  216. {
  217. // We should never get here on 64bit
  218. if (State::GetInstance().GetPlatform() & CYS_64BIT)
  219. {
  220. LOG(L"SharePoint cannot be installed on 64bit");
  221. result = false;
  222. break;
  223. }
  224. VARIANT_BOOL spInstalled;
  225. HRESULT hr = GetSharePointObject()->SPAlreadyInstalled(&spInstalled);
  226. if (SUCCEEDED(hr) && spInstalled)
  227. {
  228. result = true;
  229. }
  230. else if (FAILED(hr))
  231. {
  232. LOG(String::format(
  233. L"Failed to retrieve SPAlreadyInstalled: hr = %1!x!",
  234. hr));
  235. }
  236. } while (false);
  237. LOG_BOOL(result);
  238. return result;
  239. }
  240. bool
  241. SharePointInstallationUnit::GetFinishText(String& message)
  242. {
  243. LOG_FUNCTION(SharePointInstallationUnit::GetFinishText);
  244. bool installIIS = !InstallationUnitProvider::GetInstance().GetWebInstallationUnit().IsServiceInstalled();
  245. bool installSP = true;
  246. String installIISText = String::load(IDS_WEB_FINISH_TEXT);
  247. String installSPText = String::load(IDS_SHAREPOINT_FINISH_TEXT);
  248. String installSPAdminText = String::load(IDS_SHAREPOINT_FINISH_ADD_ADMIN);
  249. if (installIIS && installSP)
  250. {
  251. message += installIISText;
  252. message += installSPText;
  253. message += installSPAdminText;
  254. }
  255. else if (installSP && !installIIS)
  256. {
  257. message += installSPText;
  258. if (!ReplaceHomePage())
  259. {
  260. message += String::format(
  261. String::load(IDS_SHAREPOINT_FINISH_WEBPAGE_FORMAT),
  262. GetReplacementHomePage().c_str());
  263. }
  264. else
  265. {
  266. message += String::format(
  267. String::load(IDS_SHAREPOINT_FINISH_CREATE_FORMAT),
  268. GetReplacementHomePage().c_str());
  269. }
  270. message += installSPAdminText;
  271. }
  272. if (!IsIndexingServiceOn())
  273. {
  274. message += String::load(IDS_SHAREPOINT_FINISH_INDEXING);
  275. }
  276. LOG_BOOL(installSP);
  277. return installSP;
  278. }
  279. String
  280. SharePointInstallationUnit::GetServiceDescription()
  281. {
  282. LOG_FUNCTION(SharePointInstallationUnit::GetServiceDescription);
  283. String result;
  284. result = String::load(IDS_SHAREPOINT_DESCRIPTION_BASE);
  285. if (IsServiceInstalled())
  286. {
  287. result += String::load(IDS_SHAREPOINT_DESCRIPTION_INSTALLED);
  288. }
  289. else
  290. {
  291. if (InstallationUnitProvider::GetInstance().GetWebInstallationUnit().IsServiceInstalled())
  292. {
  293. if (IsIndexingServiceOn())
  294. {
  295. result += String::load(IDS_SHAREPOINT_DESCRIPTION_SPONLY);
  296. }
  297. else
  298. {
  299. result += String::load(IDS_SHAREPOINT_DESCRIPTION_SP_AND_INDEXING);
  300. }
  301. }
  302. else
  303. {
  304. if (IsIndexingServiceOn())
  305. {
  306. result += String::load(IDS_SHAREPOINT_DESCRIPTION_SP_AND_IIS);
  307. }
  308. else
  309. {
  310. result += String::load(IDS_SHAREPOINT_DESCRIPTION_SP_INDEXING_IIS);
  311. }
  312. }
  313. }
  314. ASSERT(!result.empty());
  315. return result;
  316. }
  317. SmartInterface<ISpCys>&
  318. SharePointInstallationUnit::GetSharePointObject()
  319. {
  320. LOG_FUNCTION(SharePointInstallationUnit::GetSharePointObject);
  321. if (!sharePointObject)
  322. {
  323. HRESULT hr = sharePointObject.AcquireViaCreateInstance(
  324. CLSID_SpCys,
  325. 0,
  326. CLSCTX_INPROC_SERVER);
  327. ASSERT(SUCCEEDED(hr));
  328. }
  329. ASSERT(sharePointObject);
  330. return sharePointObject;
  331. }
  332. void
  333. SharePointInstallationUnit::SetReplaceHomePage(bool replace)
  334. {
  335. LOG_FUNCTION2(
  336. SharePointInstallationUnit::SetReplaceHomePage,
  337. replace ? L"true" : L"false");
  338. replaceHomepage = replace;
  339. }
  340. bool
  341. SharePointInstallationUnit::IsThereAPageToReplace()
  342. {
  343. LOG_FUNCTION(SharePointInstallationUnit::IsThereAPageToReplace);
  344. bool result = false;
  345. VARIANT_BOOL replace;
  346. HRESULT hr = GetSharePointObject()->SPAskReplace(&replace);
  347. if (SUCCEEDED(hr) && replace)
  348. {
  349. result = true;
  350. }
  351. LOG_BOOL(result);
  352. return result;
  353. }
  354. String
  355. SharePointInstallationUnit::GetReplacementHomePage()
  356. {
  357. LOG_FUNCTION(SharePointInstallationUnit::GetReplacementHomePage);
  358. if (nonDefaultHP.empty())
  359. {
  360. BSTR nonDefaultHomePage;
  361. HRESULT hr = GetSharePointObject()->SPNonDefaultHomePage(&nonDefaultHomePage);
  362. LOG(String::format(L"hr = %1!x!", hr));
  363. // ignore the return value and continue with a blank nonDefaultHomePage
  364. nonDefaultHP = nonDefaultHomePage;
  365. if (nonDefaultHomePage)
  366. {
  367. ::SysFreeString(nonDefaultHomePage);
  368. }
  369. }
  370. return nonDefaultHP;
  371. }