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.

1655 lines
59 KiB

  1. //=======================================================================
  2. //
  3. // Copyright (c) 1998-2000 Microsoft Corporation. All Rights Reserved.
  4. //
  5. // File: install.cpp
  6. //
  7. // Description:
  8. //
  9. // Implementation for the Install() function
  10. //
  11. //=======================================================================
  12. #include "iuengine.h" // PCH - must include first
  13. #include <iu.h>
  14. #include <iucommon.h>
  15. #include <trust.h>
  16. #include <install.h>
  17. #include <fileutil.h>
  18. #include <shlwapi.h>
  19. #include <srrestoreptapi.h>
  20. #include <iuprogress.h>
  21. #include "history.h"
  22. #include "iuxml.h"
  23. //#include <serverPing.h>
  24. #include <logging.h>
  25. #include <UrlLogging.h>
  26. #define AVERAGE_IDENTITY_SIZE_PER_ITEM 200
  27. #define SafeFreeLibrary(x) if (NULL != x) { FreeLibrary(x); x = NULL; }
  28. const TCHAR SFCDLL[] = _T("sfc.dll");
  29. const TCHAR SYSTEMRESTOREDESCRIPTION[] = _T("Windows Update V4");
  30. const CHAR SZ_INSTALL_FINISHED[] = "Install finished";
  31. const CHAR SZ_INSTALLASYNC_FAILED[] = "Asynchronous Install failed during startup";
  32. typedef BOOL (WINAPI * PFN_SRSetRestorePoint)(PRESTOREPOINTINFO pRestorePtSpec, PSTATEMGRSTATUS pSMgrStatus);
  33. typedef struct IUINSTALLSTARTUPINFO
  34. {
  35. BSTR bstrXmlClientInfo;
  36. BSTR bstrXmlCatalog;
  37. BSTR bstrXmlDownloadedItems;
  38. BSTR bstrOperationUUID;
  39. LONG lMode;
  40. IUnknown *punkProgressListener;
  41. HWND hwnd;
  42. CEngUpdate* pEngUpdate;
  43. } IUINSTALLSTARTUPINFO, *PIUINSTALLSTARTUPINFO;
  44. DWORD WINAPI InstallThreadProc(LPVOID lpv);
  45. class CIUInstall
  46. {
  47. public:
  48. CIUInstall(BSTR bstrXmlClientInfo, BSTR bstrXmlCatalog, BSTR bstrXmlDownloadedItems, BSTR bstrOperationUUID, LONG lMode, IUnknown *punkProgressListener, HWND hWnd);
  49. ~CIUInstall();
  50. public:
  51. HRESULT ProcessInstallCatalog(CEngUpdate* pEngUpdate);
  52. HRESULT GetXmlItemsBSTR(BSTR *pbstrXmlItems);
  53. private:
  54. HRESULT RecursiveInstallDependencies(HANDLE_NODE hItem, CEngUpdate* pEngUpdate);
  55. HRESULT DoInstall(HANDLE_NODE hItem, CEngUpdate* pEngUpdate);
  56. void RemoveDownloadTemporaryFolders(LPCTSTR pszComponentPath);
  57. void PingServerForInstall(HRESULT hr, HANDLE_NODE hItem, PHANDLE phEvtNeedToQuit, LPCTSTR lpszDeviceId=NULL, BOOL fExclusive=FALSE);
  58. private:
  59. BSTR m_bstrXmlClientInfo;
  60. BSTR m_bstrClientName;
  61. BSTR m_bstrXmlCatalog;
  62. BSTR m_bstrOperationUUID;
  63. BSTR m_bstrXmlResult;
  64. LONG m_lMode;
  65. IProgressListener* m_pProgressListener;
  66. HWND m_hWnd;
  67. CXmlCatalog m_xmlCatalog;
  68. CXmlItems m_xmlItems;
  69. CXmlItems *m_pxmlDownloadedItems;
  70. CXmlClientInfo m_xmlClientInfo;
  71. CIUHistory m_history;
  72. CUrlLog m_pingSvr;
  73. DWORD m_dwStatus;
  74. LPTSTR m_pszInstalledItemsList;
  75. LPTSTR m_pszItemDownloadPathListForDelete;
  76. LONG m_lInstalledItemsListAllocatedLength;
  77. LONG m_lItemDownloadPathListForDeleteLength;
  78. LONG m_lItemCount;
  79. LONG m_lItemsCompleted;
  80. BOOL m_fAbort;
  81. BOOL m_fSomeItemsSuccessful;
  82. };
  83. CIUInstall::CIUInstall(BSTR bstrXmlClientInfo, BSTR bstrXmlCatalog, BSTR bstrXmlDownloadedItems, BSTR bstrOperationUUID, LONG lMode, IUnknown *punkProgressListener, HWND hWnd)
  84. : m_pProgressListener(NULL),
  85. m_bstrXmlClientInfo(NULL),
  86. m_bstrClientName(NULL),
  87. m_bstrXmlCatalog(NULL),
  88. m_bstrOperationUUID(NULL),
  89. m_bstrXmlResult(NULL),
  90. m_lMode(lMode),
  91. m_hWnd(hWnd),
  92. m_dwStatus(0),
  93. m_pszInstalledItemsList(NULL),
  94. m_pszItemDownloadPathListForDelete(NULL),
  95. m_lInstalledItemsListAllocatedLength(0),
  96. m_lItemDownloadPathListForDeleteLength(0),
  97. m_lItemCount(0),
  98. m_lItemsCompleted(0),
  99. m_fAbort(FALSE),
  100. m_fSomeItemsSuccessful(FALSE),
  101. m_pxmlDownloadedItems(NULL)
  102. {
  103. USES_IU_CONVERSION;
  104. m_bstrXmlClientInfo = SysAllocString(bstrXmlClientInfo);
  105. m_bstrXmlCatalog = SysAllocString(bstrXmlCatalog);
  106. m_bstrOperationUUID = SysAllocString(bstrOperationUUID);
  107. if (NULL != punkProgressListener)
  108. {
  109. punkProgressListener->QueryInterface(IID_IProgressListener, (void**)&m_pProgressListener);
  110. }
  111. m_pxmlDownloadedItems = new CXmlItems(TRUE);
  112. if (NULL != m_pxmlDownloadedItems)
  113. {
  114. m_pxmlDownloadedItems->LoadXMLDocument(bstrXmlDownloadedItems);
  115. }
  116. }
  117. CIUInstall::~CIUInstall()
  118. {
  119. SysFreeString(m_bstrXmlClientInfo);
  120. SysFreeString(m_bstrClientName);
  121. SysFreeString(m_bstrXmlCatalog);
  122. SysFreeString(m_bstrOperationUUID);
  123. SafeReleaseNULL(m_pProgressListener);
  124. SafeHeapFree(m_pszInstalledItemsList);
  125. SafeHeapFree(m_pszItemDownloadPathListForDelete);
  126. SysFreeString(m_bstrXmlResult);
  127. if (NULL != m_pxmlDownloadedItems)
  128. {
  129. delete m_pxmlDownloadedItems;
  130. }
  131. }
  132. HRESULT CIUInstall::GetXmlItemsBSTR(BSTR *pbstrXmlItems)
  133. {
  134. if (NULL != m_bstrXmlResult)
  135. *pbstrXmlItems = SysAllocString(m_bstrXmlResult);
  136. return S_OK;
  137. }
  138. /////////////////////////////////////////////////////////////////////////////
  139. // Install()
  140. //
  141. // Do synchronous installation.
  142. // Input:
  143. // bstrXmlCatalog - the xml catalog portion containing items to be installed
  144. // bstrXmlDownloadedItems - the xml of downloaded items and their respective download
  145. // result as described in the result schema. Install uses this
  146. // to know whether the items were downloaded and if so where they
  147. // were downloaded to so that it can install the items
  148. // punkProgressListener - the callback function pointer for reporting install progress
  149. // hWnd - the event msg window handler passed from the stub
  150. // Output:
  151. // pbstrXmlItems - the items with installation status in xml format
  152. // e.g.
  153. // <id guid="2560AD4D-3ED3-49C6-A937-4368C0B0E06D" installed="1"/>
  154. /////////////////////////////////////////////////////////////////////////////
  155. HRESULT WINAPI CEngUpdate::Install(BSTR bstrXmlClientInfo,
  156. BSTR bstrXmlCatalog,
  157. BSTR bstrXmlDownloadedItems,
  158. LONG lMode,
  159. IUnknown *punkProgressListener,
  160. HWND hWnd,
  161. BSTR *pbstrXmlItems)
  162. {
  163. HRESULT hr;
  164. if ((DWORD) lMode & (DWORD) UPDATE_OFFLINE_MODE)
  165. {
  166. m_fOfflineMode = TRUE;
  167. }
  168. else
  169. {
  170. m_fOfflineMode = FALSE;
  171. }
  172. LogMessage("Install started");
  173. CIUInstall iuInstall(bstrXmlClientInfo, bstrXmlCatalog, bstrXmlDownloadedItems, NULL, lMode, punkProgressListener, hWnd);
  174. hr = iuInstall.ProcessInstallCatalog(this);
  175. iuInstall.GetXmlItemsBSTR(pbstrXmlItems);
  176. return hr;
  177. }
  178. HRESULT CIUInstall::ProcessInstallCatalog(CEngUpdate* pEngUpdate)
  179. {
  180. LOG_Block("ProcessInstallCatalog()");
  181. // clear any previous cancel event
  182. ResetEvent(pEngUpdate->m_evtNeedToQuit);
  183. HRESULT hr = S_OK, hrString = S_OK;
  184. HANDLE_NODE hCatalogItemList = HANDLE_NODELIST_INVALID;
  185. HANDLE_NODE hProviderList = HANDLE_NODELIST_INVALID;
  186. HANDLE_NODE hDependentItemList = HANDLE_NODELIST_INVALID;
  187. HANDLE_NODE hItem = HANDLE_NODE_INVALID;
  188. HANDLE_NODE hDependentItem = HANDLE_NODE_INVALID;
  189. HANDLE_NODE hProvider = HANDLE_NODE_INVALID;
  190. BSTR bstrPlatform = NULL;
  191. BSTR bstrUniqueIdentity = NULL;
  192. BSTR bstrProviderName = NULL;
  193. BSTR bstrProviderPublisher = NULL;
  194. BSTR bstrProviderUUID = NULL;
  195. TCHAR szUniqueIdentitySearch[MAX_PATH];
  196. HINSTANCE hSystemRestoreDLL = NULL;
  197. PFN_SRSetRestorePoint fpnSRSetRestorePoint = NULL;
  198. RESTOREPOINTINFO restoreInfo;
  199. STATEMGRSTATUS restoreStatus;
  200. BOOL fContinue = TRUE;
  201. LPTSTR ptszLivePingServerUrl = NULL;
  202. LPTSTR ptszCorpPingServerUrl = NULL;
  203. BOOL fPostWaitSuccess = TRUE;
  204. DWORD dwStatus = 0;
  205. USES_IU_CONVERSION;
  206. EventData evtData;
  207. ZeroMemory((LPVOID) &evtData, sizeof(evtData));
  208. if (NULL == m_pxmlDownloadedItems)
  209. {
  210. // Error occured during object initialization, no Return Schema Available
  211. // Cannot continue
  212. hr = E_INVALIDARG;
  213. LOG_ErrorMsg(hr);
  214. goto CleanUp;
  215. }
  216. hr = m_xmlCatalog.LoadXMLDocument(m_bstrXmlCatalog, pEngUpdate->m_fOfflineMode);
  217. if (FAILED(hr))
  218. {
  219. LOG_ErrorMsg(hr);
  220. goto CleanUp;
  221. }
  222. hr = m_xmlClientInfo.LoadXMLDocument(m_bstrXmlClientInfo, pEngUpdate->m_fOfflineMode);
  223. if (FAILED(hr))
  224. {
  225. LOG_ErrorMsg(hr);
  226. goto CleanUp;
  227. }
  228. m_xmlClientInfo.GetClientName(&m_bstrClientName);
  229. if (NULL == m_bstrClientName)
  230. {
  231. hr = E_INVALIDARG;
  232. LOG_ErrorMsg(hr);
  233. goto CleanUp;
  234. }
  235. m_pingSvr.SetDefaultClientName(OLE2T(m_bstrClientName));
  236. if (NULL != (ptszLivePingServerUrl = (LPTSTR)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, INTERNET_MAX_URL_LENGTH * sizeof(TCHAR))))
  237. {
  238. if (SUCCEEDED(g_pUrlAgent->GetLivePingServer(ptszLivePingServerUrl, INTERNET_MAX_URL_LENGTH)))
  239. {
  240. m_pingSvr.SetLiveServerUrl(ptszLivePingServerUrl);
  241. }
  242. else
  243. {
  244. LOG_Out(_T("failed to get live ping server URL"));
  245. }
  246. SafeHeapFree(ptszLivePingServerUrl);
  247. }
  248. else
  249. {
  250. LOG_Out(_T("failed to allocate memory for ptszLivePingServerUrl"));
  251. }
  252. if (NULL != (ptszCorpPingServerUrl = (LPTSTR)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, INTERNET_MAX_URL_LENGTH * sizeof(TCHAR))))
  253. {
  254. if (SUCCEEDED(g_pUrlAgent->GetCorpPingServer(ptszCorpPingServerUrl, INTERNET_MAX_URL_LENGTH)))
  255. {
  256. m_pingSvr.SetCorpServerUrl(ptszCorpPingServerUrl);
  257. }
  258. else
  259. {
  260. LOG_Out(_T("failed to get corp WU ping server URL"));
  261. }
  262. SafeHeapFree(ptszCorpPingServerUrl);
  263. }
  264. else
  265. {
  266. LOG_Out(_T("failed to allocate memory for ptszCorpPingServerUrl"));
  267. }
  268. m_xmlCatalog.GetItemCount(&m_lItemCount);
  269. SafeHeapFree(m_pszInstalledItemsList);
  270. m_lInstalledItemsListAllocatedLength = m_lItemCount * (AVERAGE_IDENTITY_SIZE_PER_ITEM * sizeof(TCHAR));
  271. m_pszInstalledItemsList = (LPTSTR) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, m_lInstalledItemsListAllocatedLength);
  272. if (NULL == m_pszInstalledItemsList)
  273. {
  274. hr = HRESULT_FROM_WIN32(GetLastError());
  275. LOG_ErrorMsg(hr);
  276. goto CleanUp;
  277. }
  278. SafeHeapFree(m_pszItemDownloadPathListForDelete);
  279. m_lItemDownloadPathListForDeleteLength = m_lItemCount * (MAX_PATH * sizeof(TCHAR));
  280. m_pszItemDownloadPathListForDelete = (LPTSTR) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, m_lItemDownloadPathListForDeleteLength);
  281. if (NULL == m_pszItemDownloadPathListForDelete)
  282. {
  283. hr = HRESULT_FROM_WIN32(GetLastError());
  284. LOG_ErrorMsg(hr);
  285. goto CleanUp;
  286. }
  287. // try to load the System Restore DLL (sfc.dll).
  288. hSystemRestoreDLL = LoadLibraryFromSystemDir(SFCDLL);
  289. if (NULL != hSystemRestoreDLL)
  290. {
  291. #ifdef UNICODE
  292. fpnSRSetRestorePoint = (PFN_SRSetRestorePoint)GetProcAddress(hSystemRestoreDLL, "SRSetRestorePointW");
  293. #else
  294. fpnSRSetRestorePoint = (PFN_SRSetRestorePoint)GetProcAddress(hSystemRestoreDLL, "SRSetRestorePointA");
  295. #endif
  296. if (NULL != fpnSRSetRestorePoint)
  297. {
  298. // Set the Restore Point
  299. ZeroMemory(&restoreInfo, sizeof(restoreInfo));
  300. ZeroMemory(&restoreStatus, sizeof(restoreStatus));
  301. restoreInfo.dwEventType = BEGIN_SYSTEM_CHANGE;
  302. restoreInfo.dwRestorePtType = APPLICATION_INSTALL;
  303. restoreInfo.llSequenceNumber = 0;
  304. hr = StringCchCopyEx(restoreInfo.szDescription, ARRAYSIZE(restoreInfo.szDescription),
  305. SYSTEMRESTOREDESCRIPTION,
  306. NULL, NULL, MISTSAFE_STRING_FLAGS);
  307. if (FAILED(hr))
  308. {
  309. LOG_ErrorMsg(hr);
  310. goto CleanUp;
  311. }
  312. if (!fpnSRSetRestorePoint(&restoreInfo, &restoreStatus))
  313. {
  314. // this will return FALSE if there is an error 'or' if its called from an OS without SystemRestore
  315. // support. SR is only supported on Professional and Personal SKU's of Whistler.
  316. if (ERROR_SUCCESS != restoreStatus.nStatus)
  317. {
  318. LOG_Software(_T("Failed SRSetRestorePoint Call, Error was: 0x%x"), restoreStatus.nStatus);
  319. LogError(restoreStatus.nStatus, "Install Set Restore Point");
  320. }
  321. }
  322. }
  323. }
  324. //
  325. // added by JHou for bug#433 in IU db: send 0:N OnProgress event before the install begins
  326. //
  327. TCHAR szProgress[64];
  328. hr = StringCchPrintfEx(szProgress, ARRAYSIZE(szProgress), NULL, NULL, MISTSAFE_STRING_FLAGS,
  329. _T("%lu:0"), (ULONG)m_lItemCount);
  330. if (FAILED(hr))
  331. {
  332. LOG_ErrorMsg(hr);
  333. goto CleanUp;
  334. }
  335. evtData.bstrProgress = SysAllocString(T2OLE(szProgress));
  336. if (NULL != m_pProgressListener)
  337. {
  338. m_pProgressListener->OnProgress(m_bstrOperationUUID, VARIANT_FALSE, evtData.bstrProgress, &evtData.lCommandRequest);
  339. }
  340. else
  341. {
  342. if (NULL != m_hWnd)
  343. {
  344. evtData.fItemCompleted = FALSE;
  345. evtData.bstrUuidOperation = SysAllocString(m_bstrOperationUUID);
  346. SendMessage(m_hWnd, UM_EVENT_PROGRESS, 0, LPARAM(&evtData));
  347. }
  348. }
  349. //
  350. // Need to check for a cancel command returned from OnProgress
  351. //
  352. if (UPDATE_COMMAND_CANCEL == evtData.lCommandRequest)
  353. {
  354. LOG_Out(_T("OnProgress received UPDATE_COMMAND_CANCEL"));
  355. SetEvent(pEngUpdate->m_evtNeedToQuit); // asked to quit
  356. hr = E_ABORT;
  357. fContinue = FALSE;
  358. }
  359. // Install has a complexity in how we loop through to install each item. Basically
  360. // we have to handle any dependent Item installs before installing core Item
  361. // Since Detection will already have been done at this point we rely on the caller
  362. // to only give us the list of items that really need to be installed. What we'll do
  363. // is go through each item and before actually installing it we'll look for any
  364. // dependent items that are also in the catalog. If they are in the Catalog then it is
  365. // assumed it needs to be installed. This check is done recursively for each item.
  366. // start the base item loop.
  367. hProviderList = m_xmlCatalog.GetFirstProvider(&hProvider);
  368. while (HANDLE_NODE_INVALID != hProvider && fContinue)
  369. {
  370. m_xmlCatalog.GetIdentity(hProvider, &bstrProviderName, &bstrProviderPublisher, &bstrProviderUUID);
  371. SafeSysFreeString(bstrProviderName);
  372. SafeSysFreeString(bstrProviderPublisher);
  373. SafeSysFreeString(bstrProviderUUID);
  374. // Get the Enumerator List of Items in this Catalog, and get the first item
  375. hCatalogItemList = m_xmlCatalog.GetFirstItem(hProvider, &hItem);
  376. if ((HANDLE_NODELIST_INVALID == hCatalogItemList) || (HANDLE_NODE_INVALID == hItem))
  377. {
  378. hr = E_FAIL;
  379. LOG_ErrorMsg(hr);
  380. goto CleanUp;
  381. }
  382. //
  383. // loop through each item in the catalog, calling the installer for each one
  384. //
  385. while (HANDLE_NODE_INVALID != hItem && fContinue)
  386. {
  387. BSTR bstrXmlItemForCallback = NULL;
  388. if (SUCCEEDED(m_xmlCatalog.GetBSTRItemForCallback(hItem, &bstrXmlItemForCallback)))
  389. {
  390. if (NULL != m_pProgressListener)
  391. {
  392. m_pProgressListener->OnItemStart(m_bstrOperationUUID, bstrXmlItemForCallback, &evtData.lCommandRequest);
  393. }
  394. else
  395. {
  396. if (NULL != m_hWnd)
  397. {
  398. evtData.bstrXmlData = bstrXmlItemForCallback;
  399. SendMessage(m_hWnd, UM_EVENT_ITEMSTART, 0, LPARAM(&evtData));
  400. evtData.bstrXmlData = NULL;
  401. }
  402. }
  403. SysFreeString(bstrXmlItemForCallback);
  404. bstrXmlItemForCallback = NULL;
  405. if (UPDATE_COMMAND_CANCEL == evtData.lCommandRequest)
  406. {
  407. LOG_Out(_T("OnItemStart received UPDATE_COMMAND_CANCEL"));
  408. SetEvent(pEngUpdate->m_evtNeedToQuit); // asked to quit
  409. hr = E_ABORT;
  410. fContinue = FALSE;
  411. }
  412. else
  413. {
  414. //
  415. // check the global quit event. If quit, then server ping treat it as a cancel.
  416. //
  417. fContinue = (WaitForSingleObject(pEngUpdate->m_evtNeedToQuit, 0) != WAIT_OBJECT_0);
  418. }
  419. if (!fContinue)
  420. {
  421. continue; // or break, same effect.
  422. }
  423. }
  424. else
  425. {
  426. //
  427. // something wrong with this item, so we should skip it
  428. //
  429. // get the next item. hItem will be HANDLE_NODE_INVALID when there are no
  430. // remaining items.
  431. m_xmlCatalog.CloseItem(hItem);
  432. m_xmlCatalog.GetNextItem(hCatalogItemList, &hItem);
  433. continue;
  434. }
  435. // We have an Item in the Catalog to be Installed. First Look for any Top
  436. // level dependencies
  437. hDependentItemList = m_xmlCatalog.GetFirstItemDependency(hItem, &hDependentItem);
  438. if (HANDLE_NODELIST_INVALID != hDependentItemList)
  439. {
  440. hr = S_OK;
  441. while (S_OK == hr)
  442. {
  443. // walk each dependent Item and call the Recursive Installer
  444. if (HANDLE_NODE_INVALID != hDependentItem)
  445. {
  446. // Check if we have installed this item already in this session
  447. m_xmlCatalog.GetIdentityStr(hDependentItem, &bstrUniqueIdentity);
  448. hrString = StringCchPrintfEx(szUniqueIdentitySearch, ARRAYSIZE(szUniqueIdentitySearch),
  449. NULL, NULL, MISTSAFE_STRING_FLAGS,
  450. _T("%ls|"), bstrUniqueIdentity);
  451. SafeSysFreeString(bstrUniqueIdentity);
  452. if (FAILED(hrString))
  453. {
  454. // The string check for the unique identity is an optimization to prevent installing the same item more
  455. // than once in an install operation. If we cannot do this optimization, we will just go ahead and install
  456. // the item. There is no real problem with installing the same item more than once, its just ineffecient.
  457. LOG_ErrorMsg(hrString);
  458. }
  459. else
  460. {
  461. if (NULL != StrStrI(m_pszInstalledItemsList, szUniqueIdentitySearch))
  462. {
  463. // we have already installed this item, skip to the next one.
  464. m_xmlCatalog.CloseItem(hDependentItem);
  465. hr = m_xmlCatalog.GetNextItemDependency(hDependentItemList, &hDependentItem);
  466. continue;
  467. }
  468. }
  469. // There is a Item in the Catalog that is a dependency of the Item we
  470. // are installing and we haven't installed it yet, so Call the
  471. // RecursiveInstaller to handle this one first
  472. hr = RecursiveInstallDependencies(hDependentItem, pEngUpdate);
  473. }
  474. // Get the next Dependent Item - will Return S_FALSE when there are
  475. // no more items.
  476. m_xmlCatalog.CloseItem(hDependentItem);
  477. hr = m_xmlCatalog.GetNextItemDependency(hDependentItemList, &hDependentItem);
  478. }
  479. m_xmlCatalog.CloseItemList(hDependentItemList);
  480. }
  481. if (WaitForSingleObject(pEngUpdate->m_evtNeedToQuit, 0) == WAIT_OBJECT_0)
  482. {
  483. m_xmlCatalog.CloseItem(hItem);
  484. goto CleanUp;
  485. }
  486. // Check if we have installed this item already in this session
  487. m_xmlCatalog.GetIdentityStr(hItem, &bstrUniqueIdentity);
  488. hrString = StringCchPrintfEx(szUniqueIdentitySearch, ARRAYSIZE(szUniqueIdentitySearch),
  489. NULL, NULL, MISTSAFE_STRING_FLAGS,
  490. _T("%ls|"), bstrUniqueIdentity);
  491. SafeSysFreeString(bstrUniqueIdentity);
  492. if (FAILED(hrString))
  493. {
  494. // The string check for the unique identity is an optimization to prevent installing the same item more
  495. // than once in an install operation. If we cannot do this optimization, we will just go ahead and install
  496. // the item. There is no real problem with installing the same item more than once, its just ineffecient.
  497. LOG_ErrorMsg(hrString);
  498. }
  499. else
  500. {
  501. if (NULL == StrStrI(m_pszInstalledItemsList, szUniqueIdentitySearch))
  502. {
  503. // we have NOT installed this item in this session
  504. hr = DoInstall(hItem, pEngUpdate);
  505. }
  506. }
  507. if (WaitForSingleObject(pEngUpdate->m_evtNeedToQuit, 0) == WAIT_OBJECT_0)
  508. {
  509. m_xmlCatalog.CloseItem(hItem);
  510. goto CleanUp;
  511. }
  512. // get the next item. hItem will be HANDLE_NODE_INVALID when there are no
  513. // remaining items.
  514. m_xmlCatalog.CloseItem(hItem);
  515. m_xmlCatalog.GetNextItem(hCatalogItemList, &hItem);
  516. }
  517. m_xmlCatalog.CloseItem(hProvider);
  518. m_xmlCatalog.GetNextProvider(hProviderList, &hProvider);
  519. }
  520. CleanUp:
  521. // BUG: 441316: Earlier in the install process we left the downloaded files on the machine to
  522. // support this bug which involves installing Multi Function Device Drivers, Now we want to enumerate
  523. // the list of download source paths and all folders/files from them.
  524. if (NULL != m_pszItemDownloadPathListForDelete)
  525. {
  526. LPTSTR pszWalk = m_pszItemDownloadPathListForDelete;
  527. LPTSTR pszChr = NULL;
  528. while (_T('\0') != *pszWalk)
  529. {
  530. pszChr = StrChr(pszWalk, _T('|'));
  531. if (NULL != pszChr)
  532. {
  533. *pszChr = _T('\0');
  534. // Call RemoveDownloadTemporaryFolders to delete this folder path
  535. RemoveDownloadTemporaryFolders(pszWalk);
  536. *pszChr = _T('|');
  537. pszWalk = pszChr + 1; // skip to next character
  538. }
  539. }
  540. }
  541. //
  542. // add HRESULT in case the install failed before the install loop
  543. //
  544. if (S_OK != hr)
  545. {
  546. m_xmlItems.AddGlobalErrorCodeIfNoItems(hr);
  547. }
  548. m_xmlItems.GetItemsBSTR(&m_bstrXmlResult); // get result for Caller and to Send OnOperationComplete
  549. if (NULL != m_pProgressListener)
  550. {
  551. m_pProgressListener->OnOperationComplete(m_bstrOperationUUID, m_bstrXmlResult);
  552. }
  553. else
  554. {
  555. if (NULL != m_hWnd)
  556. {
  557. if (NULL == evtData.bstrUuidOperation)
  558. {
  559. evtData.bstrUuidOperation = SysAllocString(m_bstrOperationUUID);
  560. }
  561. evtData.bstrXmlData = SysAllocString(m_bstrXmlResult);
  562. evtData.fItemCompleted = TRUE;
  563. fPostWaitSuccess = WUPostEventAndBlock(m_hWnd,
  564. UM_EVENT_COMPLETE,
  565. &evtData);
  566. }
  567. }
  568. if ((NULL != fpnSRSetRestorePoint) && (ERROR_SUCCESS == restoreStatus.nStatus))
  569. {
  570. if (!m_fSomeItemsSuccessful)
  571. {
  572. // need to revert our systemrestore point, no successful installs were done.
  573. restoreInfo.dwEventType = END_SYSTEM_CHANGE;
  574. restoreInfo.dwRestorePtType = CANCELLED_OPERATION;
  575. restoreInfo.llSequenceNumber = restoreStatus.llSequenceNumber;
  576. fpnSRSetRestorePoint(&restoreInfo, &restoreStatus);
  577. }
  578. else
  579. {
  580. // signal the end of the restore point change.
  581. restoreInfo.dwEventType = END_SYSTEM_CHANGE;
  582. restoreInfo.llSequenceNumber = restoreStatus.llSequenceNumber;
  583. fpnSRSetRestorePoint(&restoreInfo, &restoreStatus);
  584. m_fSomeItemsSuccessful = FALSE;
  585. }
  586. }
  587. if (SUCCEEDED(hr))
  588. {
  589. LogMessage("%s %s", SZ_SEE_IUHIST, SZ_INSTALL_FINISHED);
  590. }
  591. else
  592. {
  593. LogError(hr, "%s %s", SZ_SEE_IUHIST, SZ_INSTALL_FINISHED);
  594. }
  595. fpnSRSetRestorePoint = NULL;
  596. SafeFreeLibrary(hSystemRestoreDLL);
  597. // don't free up the strings below unless the wait succeeded in
  598. // WUPostEventAndBlock. If we do free the strings up and the wait didn't
  599. // succeed, then we run the risk of AVing ourselves. Note that fPostWaitSuccess
  600. // is initialized to TRUE so if we will free these BSTRs if WUPostEventAndBlock
  601. // is not called.
  602. if (fPostWaitSuccess)
  603. {
  604. SafeSysFreeString(evtData.bstrProgress);
  605. SafeSysFreeString(evtData.bstrUuidOperation);
  606. SafeSysFreeString(evtData.bstrXmlData);
  607. }
  608. return hr;
  609. }
  610. /////////////////////////////////////////////////////////////////////////////
  611. // InstallAsync()
  612. //
  613. // Install Asynchronously.
  614. // Input:
  615. // bstrXmlCatalog - the xml catalog portion containing items to be installed
  616. // bstrXmlDownloadedItems - the xml of downloaded items and their respective download
  617. // result as described in the result schema. Install uses this
  618. // to know whether the items were downloaded and if so where they
  619. // were downloaded to so that it can install the items
  620. // punkProgressListener - the callback function pointer for reporting install progress
  621. // hWnd - the event msg window handler passed from the stub
  622. // bstrUuidOperation - an id provided by the client to provide further
  623. // identification to the operation as indexes may be reused.
  624. // Output:
  625. // pbstrUuidOperation - the operation ID. If it is not provided by the in bstrUuidOperation
  626. // parameter (an empty string is passed), it will generate a new UUID.
  627. // Otherwise, it allocates and copies the value passed by bstrUuidOperation.
  628. // The caller is responsible for freeing the memory returned in
  629. // pbstrUuidOperation using SysFreeString().
  630. /////////////////////////////////////////////////////////////////////////////
  631. HRESULT WINAPI CEngUpdate::InstallAsync(BSTR bstrXmlClientInfo,
  632. BSTR bstrXmlCatalog,
  633. BSTR bstrXmlDownloadedItems,
  634. LONG lMode,
  635. IUnknown *punkProgressListener,
  636. HWND hWnd,
  637. BSTR bstrUuidOperation,
  638. BSTR *pbstrUuidOperation)
  639. {
  640. HRESULT hr = S_OK;
  641. DWORD dwThreadId;
  642. DWORD dwErr;
  643. HANDLE hThread = NULL;
  644. GUID guid;
  645. LPOLESTR pwszUuidOperation = NULL;
  646. PIUINSTALLSTARTUPINFO pStartupInfo;
  647. LOG_Block("InstallAsync()");
  648. LogMessage("Asynchronous Install started");
  649. if ((NULL == bstrXmlCatalog) || (NULL == pbstrUuidOperation))
  650. {
  651. hr = E_INVALIDARG;
  652. LOG_ErrorMsg(hr);
  653. LogError(hr, SZ_INSTALLASYNC_FAILED);
  654. return hr;
  655. }
  656. *pbstrUuidOperation = NULL;
  657. if (NULL == (pStartupInfo = (PIUINSTALLSTARTUPINFO) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IUINSTALLSTARTUPINFO))))
  658. {
  659. hr = E_OUTOFMEMORY;
  660. LOG_ErrorMsg(hr);
  661. LogError(hr, SZ_INSTALLASYNC_FAILED);
  662. return hr;
  663. }
  664. if ((DWORD) lMode & (DWORD) UPDATE_OFFLINE_MODE)
  665. {
  666. m_fOfflineMode = TRUE;
  667. }
  668. else
  669. {
  670. m_fOfflineMode = FALSE;
  671. }
  672. //
  673. // 481020 IU - Getting a blank for bstrUuidOperation in the
  674. // oIUControl_OnItemStart/OnProgress/OnOperationComplete events
  675. // when calling InstallAsync
  676. //
  677. // Also found that BSTRs were leaking (now freed), and that if bstrUuidOperation
  678. // was NULL or zero length, we need to generate a GUID, so this is done
  679. // prior to allocating (again) for pStartupInfo->bstrOperationUUID
  680. //
  681. if (NULL != bstrUuidOperation && SysStringLen(bstrUuidOperation) > 0)
  682. {
  683. *pbstrUuidOperation = SysAllocString(bstrUuidOperation);
  684. }
  685. else
  686. {
  687. hr = CoCreateGuid(&guid);
  688. if (FAILED(hr))
  689. {
  690. LOG_ErrorMsg(hr);
  691. LogError(hr, SZ_INSTALLASYNC_FAILED);
  692. return hr;
  693. }
  694. hr = StringFromCLSID(guid, &pwszUuidOperation);
  695. if (FAILED(hr))
  696. {
  697. LOG_ErrorMsg(hr);
  698. LogError(hr, SZ_INSTALLASYNC_FAILED);
  699. return hr;
  700. }
  701. *pbstrUuidOperation = SysAllocString(pwszUuidOperation);
  702. CoTaskMemFree(pwszUuidOperation);
  703. }
  704. pStartupInfo->lMode = lMode;
  705. pStartupInfo->hwnd = hWnd;
  706. pStartupInfo->punkProgressListener = punkProgressListener;
  707. pStartupInfo->pEngUpdate = this;
  708. pStartupInfo->bstrXmlClientInfo = SysAllocString(bstrXmlClientInfo);
  709. pStartupInfo->bstrXmlCatalog = SysAllocString(bstrXmlCatalog);
  710. pStartupInfo->bstrXmlDownloadedItems = SysAllocString(bstrXmlDownloadedItems);
  711. pStartupInfo->bstrOperationUUID = SysAllocString(*pbstrUuidOperation);
  712. LOG_XmlBSTR(pStartupInfo->bstrXmlClientInfo);
  713. LOG_XmlBSTR(pStartupInfo->bstrXmlCatalog);
  714. LOG_XmlBSTR(pStartupInfo->bstrXmlDownloadedItems);
  715. InterlockedIncrement(&m_lThreadCounter);
  716. if (NULL != pStartupInfo->punkProgressListener)
  717. {
  718. pStartupInfo->punkProgressListener->AddRef();
  719. }
  720. hThread = CreateThread(NULL, 0, InstallThreadProc, (LPVOID)pStartupInfo, 0, &dwThreadId);
  721. if (NULL == hThread)
  722. {
  723. dwErr = GetLastError();
  724. hr = HRESULT_FROM_WIN32(dwErr);
  725. LOG_ErrorMsg(hr);
  726. SysFreeString(pStartupInfo->bstrXmlClientInfo);
  727. SysFreeString(pStartupInfo->bstrXmlCatalog);
  728. SysFreeString(pStartupInfo->bstrXmlDownloadedItems);
  729. SysFreeString(pStartupInfo->bstrOperationUUID);
  730. SafeRelease(pStartupInfo->punkProgressListener);
  731. SafeHeapFree(pStartupInfo);
  732. SysFreeString(*pbstrUuidOperation);
  733. *pbstrUuidOperation = NULL;
  734. InterlockedDecrement(&m_lThreadCounter);
  735. LogError(hr, SZ_INSTALLASYNC_FAILED);
  736. return hr;
  737. }
  738. if (SUCCEEDED(hr))
  739. {
  740. LogMessage("Asynchronous Install completed startup");
  741. }
  742. else
  743. {
  744. LogError(hr, SZ_INSTALLASYNC_FAILED);
  745. }
  746. return hr;
  747. }
  748. DWORD WINAPI InstallThreadProc(LPVOID lpv)
  749. {
  750. USES_IU_CONVERSION;
  751. LOG_Block("InstallThreadProc");
  752. PIUINSTALLSTARTUPINFO pStartupInfo = (PIUINSTALLSTARTUPINFO)lpv;
  753. HRESULT hr = CoInitialize(NULL);
  754. if (SUCCEEDED(hr))
  755. {
  756. LOG_Out(_T("CoInitialize called successfully"));
  757. }
  758. {
  759. // we need to scope this object so it destructs before we decrement our thread counter
  760. // If we didn't do this and the control was unloading while the thread closed we would fault
  761. // when the engine unloaded and this class was destructing.
  762. CIUInstall iuInstall(pStartupInfo->bstrXmlClientInfo, pStartupInfo->bstrXmlCatalog, pStartupInfo->bstrXmlDownloadedItems, pStartupInfo->bstrOperationUUID, pStartupInfo->lMode, pStartupInfo->punkProgressListener, pStartupInfo->hwnd);
  763. iuInstall.ProcessInstallCatalog(pStartupInfo->pEngUpdate);
  764. }
  765. SysFreeString(pStartupInfo->bstrXmlClientInfo);
  766. SysFreeString(pStartupInfo->bstrXmlCatalog);
  767. SysFreeString(pStartupInfo->bstrXmlDownloadedItems);
  768. SysFreeString(pStartupInfo->bstrOperationUUID);
  769. SafeRelease(pStartupInfo->punkProgressListener);
  770. if (SUCCEEDED(hr))
  771. {
  772. CoUninitialize();
  773. LOG_Out(_T("CoUninitialize called"));
  774. }
  775. InterlockedDecrement(&pStartupInfo->pEngUpdate->m_lThreadCounter);
  776. SafeHeapFree(pStartupInfo);
  777. return 0;
  778. }
  779. HRESULT CIUInstall::RecursiveInstallDependencies(HANDLE_NODE hItem, CEngUpdate* pEngUpdate)
  780. {
  781. LOG_Block("RecursiveInstallDependencies()");
  782. BOOL fRet = FALSE;
  783. HRESULT hr = S_FALSE, hrString;
  784. HANDLE_NODE hDependentItemList = HANDLE_NODELIST_INVALID;
  785. HANDLE_NODE hDependentItem = HANDLE_NODE_INVALID;
  786. BSTR bstrUniqueIdentity = NULL;
  787. TCHAR szUniqueIdentitySearch[MAX_PATH];
  788. // Check to see if this item has dependencies
  789. hDependentItemList = m_xmlCatalog.GetFirstItemDependency(hItem, &hDependentItem);
  790. if (HANDLE_NODELIST_INVALID != hDependentItemList)
  791. {
  792. hr = S_OK;
  793. while (S_OK == hr)
  794. {
  795. // walk each dependent Item and call the Recursive Installer
  796. if (HANDLE_NODE_INVALID != hDependentItem)
  797. {
  798. // Check if we have installed this item already in this session
  799. m_xmlCatalog.GetIdentityStr(hDependentItem, &bstrUniqueIdentity);
  800. hrString = StringCchPrintfEx(szUniqueIdentitySearch, ARRAYSIZE(szUniqueIdentitySearch),
  801. NULL, NULL, MISTSAFE_STRING_FLAGS,
  802. _T("%ls|"), bstrUniqueIdentity);
  803. SafeSysFreeString(bstrUniqueIdentity);
  804. if (FAILED(hrString))
  805. {
  806. // The string check for the unique identity is an optimization to prevent installing the same item more
  807. // than once in an install operation. If we cannot do this optimization, we will just go ahead and install
  808. // the item. There is no real problem with installing the same item more than once, its just ineffecient.
  809. LOG_ErrorMsg(hrString);
  810. }
  811. else
  812. {
  813. if (NULL != StrStrI(m_pszInstalledItemsList, szUniqueIdentitySearch))
  814. {
  815. // we have already installed this item, skip to the next one.
  816. m_xmlCatalog.CloseItem(hDependentItem);
  817. hr = m_xmlCatalog.GetNextItemDependency(hDependentItemList, &hDependentItem);
  818. continue;
  819. }
  820. }
  821. // There is a Item in the Catalog that is a dependency of the Item we
  822. // are installing and we haven't installed it yet, so Call the
  823. // RecursiveInstaller to handle this one first
  824. hr = RecursiveInstallDependencies(hDependentItem, pEngUpdate);
  825. }
  826. // Get the next Dependent Item - will Return S_FALSE when there are
  827. // no more items.
  828. m_xmlCatalog.CloseItem(hDependentItem);
  829. hr = m_xmlCatalog.GetNextItemDependency(hDependentItemList, &hDependentItem);
  830. }
  831. m_xmlCatalog.CloseItemList(hDependentItemList);
  832. }
  833. // if all installs have succeeded up to this point (hr should be S_FALSE when all
  834. // nested installs have completed)
  835. if (SUCCEEDED(hr))
  836. {
  837. // No More Recursive Dependencies, Install This Item - Recursive Functions will unwind
  838. // Installing each nested item as it goes.
  839. // Check if we have installed this item already in this session
  840. m_xmlCatalog.GetIdentityStr(hItem, &bstrUniqueIdentity);
  841. hrString = StringCchPrintfEx(szUniqueIdentitySearch, ARRAYSIZE(szUniqueIdentitySearch),
  842. NULL, NULL, MISTSAFE_STRING_FLAGS,
  843. _T("%ls|"), bstrUniqueIdentity);
  844. SafeSysFreeString(bstrUniqueIdentity);
  845. if (FAILED(hrString))
  846. {
  847. LOG_ErrorMsg(hrString);
  848. // The string check for the unique identity is an optimization to prevent installing the same item more
  849. // than once in an install operation. If we cannot do this optimization, we will just go ahead and install
  850. // the item. There is no real problem with installing the same item more than once, its just ineffecient.
  851. hr = DoInstall(hItem, pEngUpdate);
  852. }
  853. else
  854. {
  855. if (NULL == StrStrI(m_pszInstalledItemsList, szUniqueIdentitySearch))
  856. {
  857. // we have NOT installed this item in this session
  858. hr = DoInstall(hItem, pEngUpdate);
  859. }
  860. }
  861. }
  862. return hr;
  863. }
  864. HRESULT CIUInstall::DoInstall(HANDLE_NODE hItem, CEngUpdate* pEngUpdate)
  865. {
  866. LOG_Block("DoInstall()");
  867. HRESULT hr, hrString;
  868. USES_IU_CONVERSION;
  869. BSTR bstrName = NULL;
  870. BSTR bstrPublisherName = NULL;
  871. BSTR bstrItemUUID = NULL;
  872. BSTR bstrInstallerType = NULL;
  873. BSTR bstrCommand = NULL;
  874. BSTR bstrSwitches = NULL;
  875. BSTR bstrCommandType = NULL;
  876. BSTR bstrInfSection = NULL;
  877. BSTR bstrItemDownloadPath = NULL;
  878. BSTR bstrDriverName = NULL;
  879. BSTR bstrArchitecture = NULL;
  880. BSTR bstrHWID = NULL;
  881. BSTR bstrDisplayName = NULL;
  882. BSTR bstrUniqueIdentity = NULL;
  883. BSTR bstrCodeBase = NULL;
  884. BSTR bstrCRC = NULL;
  885. BSTR bstrFileName = NULL;
  886. TCHAR szProgress[64];
  887. TCHAR szCommandType[64];
  888. TCHAR szInstallerType[256];
  889. TCHAR szItemSourcePath[MAX_PATH];
  890. TCHAR szCabFilePath[MAX_PATH];
  891. LPTSTR pszCabUrl = NULL;
  892. LPTSTR pszAllocatedFileName = NULL;
  893. LPTSTR pszLocalFileName = NULL;
  894. LONG lItemCommandCount = 0;
  895. LONG lListNeededLength = 0;
  896. LONG lSize;
  897. BOOL fInstallerNeedsReboot = FALSE;
  898. BOOL fExclusive = FALSE;
  899. BOOL fPatch;
  900. BOOL fContinue = TRUE;
  901. PINSTALLCOMMANDINFO pCommandInfoArray = NULL;
  902. DWORD dwStatus = ITEM_STATUS_FAILED;
  903. HANDLE_NODE hXmlItem = HANDLE_NODE_INVALID;
  904. HANDLE_NODELIST hItemCodeBaseList = HANDLE_NODELIST_INVALID;
  905. EventData evtData;
  906. ZeroMemory((LPVOID) &evtData, sizeof(evtData));
  907. LPTSTR pszClientName = OLE2T(m_bstrClientName);
  908. m_dwStatus = ITEM_STATUS_FAILED; // default install status to failure
  909. hr = m_xmlCatalog.GetIdentity(hItem, &bstrName, &bstrPublisherName, &bstrItemUUID);
  910. if (FAILED(hr))
  911. {
  912. LOG_Software(_T("Failed to get an Identity for an Item (invalid document??)"));
  913. LogError(hr, "Install failed to get an Item Identity");
  914. goto CleanUp;
  915. }
  916. hr = m_pxmlDownloadedItems->GetItemDownloadPath(&m_xmlCatalog, hItem, &bstrItemDownloadPath);
  917. if (NULL == bstrItemDownloadPath)
  918. {
  919. LOG_Software(_T("Failed to get Item Download Path"));
  920. if (SUCCEEDED(hr))
  921. hr = E_FAIL;
  922. LogError(hr, "Install couldn't get Item %ls Download Path", bstrName);
  923. goto CleanUp;
  924. }
  925. hr = StringCchCopyEx(szItemSourcePath, ARRAYSIZE(szItemSourcePath),
  926. OLE2T(bstrItemDownloadPath),
  927. NULL, NULL, MISTSAFE_STRING_FLAGS);
  928. SafeSysFreeString(bstrItemDownloadPath);
  929. if (FAILED(hr))
  930. {
  931. LOG_ErrorMsg(hr);
  932. goto CleanUp;
  933. }
  934. hr = m_xmlCatalog.GetItemInstallInfo(hItem, &bstrInstallerType, &fExclusive, &fInstallerNeedsReboot, &lItemCommandCount);
  935. if (FAILED(hr))
  936. {
  937. LOG_Software(_T("Failed to get ItemInstallInfo for Item %ls"), bstrName);
  938. LogError(hr, "Failed to get Item %ls Install Information", bstrName);
  939. goto CleanUp;
  940. }
  941. LogMessage("Installing %ls item from publisher %ls", bstrInstallerType, bstrPublisherName);
  942. if (lItemCommandCount > 0)
  943. {
  944. // Allocate INSTALLCOMMANDINFO array and fill out with command info
  945. pCommandInfoArray = (PINSTALLCOMMANDINFO) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
  946. sizeof(INSTALLCOMMANDINFO) * lItemCommandCount);
  947. if (NULL == pCommandInfoArray)
  948. {
  949. hr = HRESULT_FROM_WIN32(GetLastError());
  950. LOG_ErrorMsg(hr);
  951. LogError(hr, "Install Command processing");
  952. goto CleanUp;
  953. }
  954. }
  955. for (LONG lCnt = 0; lCnt < lItemCommandCount; lCnt++)
  956. {
  957. // Get Install Command Information for each Command
  958. m_xmlCatalog.GetItemInstallCommand(hItem, lCnt, &bstrCommandType, &bstrCommand, &bstrSwitches, &bstrInfSection);
  959. if (NULL == bstrCommandType || NULL == bstrCommand)
  960. {
  961. hr = E_INVALIDARG;
  962. LOG_ErrorMsg(hr);
  963. goto CleanUp;
  964. }
  965. LogMessage("Installer Command Type: %ls", bstrCommandType);
  966. // Copy the Command to Execute
  967. hr = StringCchCopyEx(pCommandInfoArray[lCnt].szCommandLine, ARRAYSIZE(pCommandInfoArray[lCnt].szCommandLine),
  968. OLE2T(bstrCommand),
  969. NULL, NULL, MISTSAFE_STRING_FLAGS);
  970. if (FAILED(hr))
  971. {
  972. LOG_ErrorMsg(hr);
  973. goto CleanUp;
  974. }
  975. hr = StringCchCopyEx(szCommandType, ARRAYSIZE(szCommandType), OLE2T(bstrCommandType),
  976. NULL, NULL, MISTSAFE_STRING_FLAGS);
  977. if (FAILED(hr))
  978. {
  979. LOG_ErrorMsg(hr);
  980. goto CleanUp;
  981. }
  982. if (CSTR_EQUAL == CompareString(MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT), NORM_IGNORECASE,
  983. szCommandType, -1, _T("INF"), -1))
  984. {
  985. pCommandInfoArray[lCnt].iCommandType = COMMANDTYPE_INF;
  986. }
  987. else if (CSTR_EQUAL == CompareString(MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT), NORM_IGNORECASE,
  988. szCommandType, -1, _T("ADVANCED_INF"), -1))
  989. {
  990. pCommandInfoArray[lCnt].iCommandType = COMMANDTYPE_ADVANCEDINF;
  991. }
  992. else if (CSTR_EQUAL == CompareString(MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT), NORM_IGNORECASE,
  993. szCommandType, -1, _T("EXE"), -1))
  994. {
  995. pCommandInfoArray[lCnt].iCommandType = COMMANDTYPE_EXE;
  996. }
  997. else if (CSTR_EQUAL == CompareString(MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT), NORM_IGNORECASE,
  998. szCommandType, -1, _T("WI"), -1))
  999. {
  1000. pCommandInfoArray[lCnt].iCommandType = COMMANDTYPE_MSI;
  1001. }
  1002. else if (CSTR_EQUAL == CompareString(MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT), NORM_IGNORECASE,
  1003. szCommandType, -1, _T("CUSTOM"), -1))
  1004. {
  1005. pCommandInfoArray[lCnt].iCommandType = COMMANDTYPE_CUSTOM;
  1006. }
  1007. else
  1008. {
  1009. LOG_Software(_T("Unable to determine Installer Type %s"), szCommandType);
  1010. pCommandInfoArray[lCnt].iCommandType = 0; // unknown
  1011. }
  1012. // Copy the Command Line Parameters (if any)
  1013. if (NULL != bstrSwitches)
  1014. {
  1015. hr = StringCchCopyEx(pCommandInfoArray[lCnt].szCommandParameters, ARRAYSIZE(pCommandInfoArray[lCnt].szCommandParameters),
  1016. OLE2T(bstrSwitches),
  1017. NULL, NULL, MISTSAFE_STRING_FLAGS);
  1018. if (FAILED(hr))
  1019. {
  1020. LOG_ErrorMsg(hr);
  1021. goto CleanUp;
  1022. }
  1023. }
  1024. if (NULL != bstrInfSection)
  1025. {
  1026. hr = StringCchCopyEx(pCommandInfoArray[lCnt].szInfSection, ARRAYSIZE(pCommandInfoArray[lCnt].szInfSection),
  1027. OLE2T(bstrInfSection),
  1028. NULL, NULL, MISTSAFE_STRING_FLAGS);
  1029. if (FAILED(hr))
  1030. {
  1031. LOG_ErrorMsg(hr);
  1032. goto CleanUp;
  1033. }
  1034. }
  1035. SafeSysFreeString(bstrCommandType);
  1036. SafeSysFreeString(bstrCommand);
  1037. SafeSysFreeString(bstrSwitches);
  1038. SafeSysFreeString(bstrInfSection);
  1039. }
  1040. // Before we start the install we need to verify the signature on all cabs of this item. This is to verify that they
  1041. // haven't been tampered with between download and install (especially during non-consumer scenarios)
  1042. hItemCodeBaseList = m_xmlCatalog.GetItemFirstCodeBase(hItem, &bstrCodeBase, &bstrFileName, &bstrCRC, &fPatch, &lSize);
  1043. if ((HANDLE_NODELIST_INVALID == hItemCodeBaseList) || (NULL == bstrCodeBase))
  1044. {
  1045. LOG_Software(_T("Item %s has no Cabs, cannot verify signature"), bstrName);
  1046. hr = E_INVALIDARG;
  1047. goto CleanUp;
  1048. }
  1049. while (fContinue && NULL != bstrCodeBase)
  1050. {
  1051. if (NULL != bstrFileName && SysStringLen(bstrFileName) > 0)
  1052. {
  1053. if (NULL != pszAllocatedFileName)
  1054. {
  1055. MemFree(pszAllocatedFileName);
  1056. }
  1057. pszAllocatedFileName = OLE2T(bstrFileName);
  1058. }
  1059. else // no special filename specified, use filename from URL
  1060. {
  1061. if (NULL != pszCabUrl)
  1062. {
  1063. MemFree(pszCabUrl);
  1064. }
  1065. pszCabUrl = OLE2T(bstrCodeBase);
  1066. // search for the last forward slash (will separate the URL from the filename)
  1067. LPTSTR pszLastSlash = StrRChr(pszCabUrl, NULL, _T('/'));
  1068. // if the last slash was found, skip to next character (will be the beginning of the filename)
  1069. if (NULL != pszLastSlash)
  1070. pszLastSlash++;
  1071. pszLocalFileName = pszLastSlash;
  1072. }
  1073. hr = PathCchCombine(szCabFilePath, ARRAYSIZE(szCabFilePath),
  1074. szItemSourcePath, (NULL != pszAllocatedFileName) ? pszAllocatedFileName : pszLocalFileName);
  1075. if (FAILED(hr))
  1076. {
  1077. LOG_ErrorMsg(hr);
  1078. m_xmlCatalog.CloseItemList(hItemCodeBaseList);
  1079. goto CleanUp;
  1080. }
  1081. hr = VerifyFileTrust(szCabFilePath,
  1082. NULL,
  1083. ReadWUPolicyShowTrustUI()
  1084. );
  1085. if (FAILED(hr))
  1086. {
  1087. // Cab File Failed Trust Validation
  1088. LOG_ErrorMsg(hr);
  1089. m_xmlCatalog.CloseItemList(hItemCodeBaseList);
  1090. goto CleanUp;
  1091. }
  1092. SafeSysFreeString(bstrCodeBase);
  1093. SafeSysFreeString(bstrFileName);
  1094. SafeSysFreeString(bstrCRC);
  1095. fContinue = SUCCEEDED(m_xmlCatalog.GetItemNextCodeBase(hItemCodeBaseList, &bstrCodeBase, &bstrFileName, &bstrCRC, &fPatch, &lSize)) &&
  1096. (WaitForSingleObject(pEngUpdate->m_evtNeedToQuit, 0) != WAIT_OBJECT_0);
  1097. }
  1098. // If this item is Exclusive we need to write something to the history to indicate that the install has started
  1099. // Normally an exclusive item won't return control back to the installer so no other history information will be
  1100. // available
  1101. if (fExclusive)
  1102. {
  1103. m_history.AddHistoryItemInstallStatus(&m_xmlCatalog, hItem, HISTORY_STATUS_IN_PROGRESS, pszClientName, fInstallerNeedsReboot, S_OK);
  1104. m_history.SaveHistoryToDisk();
  1105. PingServerForInstall(hr, hItem, &(pEngUpdate->m_evtNeedToQuit), NULL, TRUE); // ping exclusive item now
  1106. }
  1107. // Call Install Library with Item Information
  1108. hr = StringCchCopyEx(szInstallerType, ARRAYSIZE(szInstallerType), OLE2T(bstrInstallerType),
  1109. NULL, NULL, MISTSAFE_STRING_FLAGS);
  1110. if (FAILED(hr))
  1111. {
  1112. LOG_ErrorMsg(hr);
  1113. goto CleanUp;
  1114. }
  1115. if (CSTR_EQUAL == CompareString(MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT), NORM_IGNORECASE,
  1116. szInstallerType, -1, _T("SOFTWARE"), -1))
  1117. {
  1118. if (lItemCommandCount == 0)
  1119. {
  1120. LOG_Software(_T("Item %s has no Commands.. cannot install"), bstrName);
  1121. hr = E_INVALIDARG;
  1122. goto CleanUp;
  1123. }
  1124. hr = InstallSoftwareItem(szItemSourcePath, fInstallerNeedsReboot, lItemCommandCount, pCommandInfoArray, &dwStatus);
  1125. }
  1126. else if (CSTR_EQUAL == CompareString(MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT), NORM_IGNORECASE,
  1127. szInstallerType, -1, _T("CDM"), -1))
  1128. {
  1129. if (m_xmlCatalog.IsPrinterDriver(hItem))
  1130. {
  1131. // Printer Driver
  1132. m_xmlCatalog.GetPrinterDriverInfo(hItem, &bstrDriverName, &bstrArchitecture);
  1133. SafeSysFreeString(bstrArchitecture); // not used yet, should be NULL from xmlCatalog.GetPrinterDriverInfo()
  1134. hr = InstallPrinterDriver(OLE2T(bstrDriverName), szItemSourcePath, NULL, &dwStatus);
  1135. if (FAILED(hr))
  1136. {
  1137. LogError(hr, "Installing Printer Driver %ls", bstrDriverName);
  1138. }
  1139. }
  1140. else
  1141. {
  1142. // Normal Device Driver
  1143. m_xmlCatalog.GetDriverInfo(hItem, &bstrHWID, &bstrDisplayName);
  1144. hr = InstallDriver(szItemSourcePath, OLE2T(bstrDisplayName), OLE2T(bstrHWID), &dwStatus);
  1145. if (FAILED(hr))
  1146. {
  1147. LogError(hr, "Installing PnP Driver %ls, %ls", bstrHWID, bstrDisplayName);
  1148. }
  1149. SafeSysFreeString(bstrDisplayName);
  1150. }
  1151. }
  1152. // Bug 441336: Deleting all files on a successful install of an item causes some problems with
  1153. // Multi Function Device Drivers, these show up as multiple instances of the same 'item', share
  1154. // the same downloaded driver package, but have different HWID's. The Item's all have different
  1155. // identities because the calling application is making them unique when they recognize a MFD
  1156. // driver package. We need to purposely leave the downloaded files installed until the 'very' end
  1157. // of the installation process, so all items have a chance to be installed.
  1158. // So, we will no longer perform this deletion step here, but will instead enumerate the InstalledItemsList
  1159. // and remove the folders for each one.
  1160. // Regardless of Success or Failure, update the Count of Items Installed
  1161. m_lItemsCompleted++;
  1162. // Add this Item to the InstalledItemsList
  1163. m_xmlCatalog.GetIdentityStr(hItem, &bstrUniqueIdentity);
  1164. lListNeededLength = (lstrlen(m_pszInstalledItemsList) + lstrlen(OLE2T(bstrUniqueIdentity)) + 2) * sizeof(TCHAR);
  1165. if (lListNeededLength > m_lInstalledItemsListAllocatedLength)
  1166. {
  1167. // need to reallocate the installeditemlist
  1168. LPTSTR pszNew = (LPTSTR) HeapReAlloc(GetProcessHeap(),
  1169. 0,
  1170. m_pszInstalledItemsList,
  1171. m_lInstalledItemsListAllocatedLength * 2);
  1172. if (NULL != pszNew)
  1173. {
  1174. m_pszInstalledItemsList = pszNew;
  1175. m_lInstalledItemsListAllocatedLength *= 2;
  1176. // only do this if the realloc worked, if it didn't we won't be adding more items
  1177. hrString = StringCbCatEx(m_pszInstalledItemsList, m_lInstalledItemsListAllocatedLength,
  1178. OLE2T(bstrUniqueIdentity),
  1179. NULL, NULL, MISTSAFE_STRING_FLAGS);
  1180. if (FAILED(hrString))
  1181. {
  1182. LOG_ErrorMsg(hrString);
  1183. }
  1184. hrString = StringCbCatEx(m_pszInstalledItemsList, m_lInstalledItemsListAllocatedLength, _T("|"),
  1185. NULL, NULL, MISTSAFE_STRING_FLAGS);
  1186. if (FAILED(hrString))
  1187. {
  1188. LOG_ErrorMsg(hrString);
  1189. }
  1190. }
  1191. }
  1192. else
  1193. {
  1194. // only do this if the realloc worked, if it didn't we won't be adding more items
  1195. hrString = StringCbCatEx(m_pszInstalledItemsList, m_lInstalledItemsListAllocatedLength,
  1196. OLE2T(bstrUniqueIdentity),
  1197. NULL, NULL, MISTSAFE_STRING_FLAGS);
  1198. if (FAILED(hrString))
  1199. {
  1200. LOG_ErrorMsg(hrString);
  1201. }
  1202. hrString = StringCbCatEx(m_pszInstalledItemsList, m_lInstalledItemsListAllocatedLength, _T("|"),
  1203. NULL, NULL, MISTSAFE_STRING_FLAGS);
  1204. if (FAILED(hrString))
  1205. {
  1206. LOG_ErrorMsg(hrString);
  1207. }
  1208. }
  1209. if (SUCCEEDED(hr))
  1210. {
  1211. lListNeededLength = (lstrlen(m_pszItemDownloadPathListForDelete) + lstrlen(szItemSourcePath) + 2) * sizeof(TCHAR);
  1212. if (lListNeededLength > m_lItemDownloadPathListForDeleteLength)
  1213. {
  1214. // need to reallocate the downloadpathitemlist
  1215. LPTSTR pszNew = (LPTSTR) HeapReAlloc(GetProcessHeap(),
  1216. 0,
  1217. m_pszItemDownloadPathListForDelete,
  1218. m_lItemDownloadPathListForDeleteLength * 2);
  1219. if (NULL != pszNew)
  1220. {
  1221. m_pszItemDownloadPathListForDelete = pszNew;
  1222. m_lItemDownloadPathListForDeleteLength *= 2;
  1223. // only do this if the realloc worked, if it didn't we won't be adding more items
  1224. hrString = StringCbCatEx(m_pszItemDownloadPathListForDelete, m_lItemDownloadPathListForDeleteLength,
  1225. szItemSourcePath,
  1226. NULL, NULL, MISTSAFE_STRING_FLAGS);
  1227. if (FAILED(hrString))
  1228. {
  1229. LOG_ErrorMsg(hrString);
  1230. }
  1231. hrString = StringCbCatEx(m_pszItemDownloadPathListForDelete, m_lItemDownloadPathListForDeleteLength, _T("|"),
  1232. NULL, NULL, MISTSAFE_STRING_FLAGS);
  1233. if (FAILED(hrString))
  1234. {
  1235. LOG_ErrorMsg(hrString);
  1236. }
  1237. }
  1238. }
  1239. else
  1240. {
  1241. hrString = StringCbCatEx(m_pszItemDownloadPathListForDelete, m_lItemDownloadPathListForDeleteLength,
  1242. szItemSourcePath,
  1243. NULL, NULL, MISTSAFE_STRING_FLAGS);
  1244. if (FAILED(hrString))
  1245. {
  1246. LOG_ErrorMsg(hrString);
  1247. }
  1248. hr = StringCbCatEx(m_pszItemDownloadPathListForDelete, m_lItemDownloadPathListForDeleteLength, _T("|"),
  1249. NULL, NULL, MISTSAFE_STRING_FLAGS);
  1250. if (FAILED(hrString))
  1251. {
  1252. LOG_ErrorMsg(hrString);
  1253. }
  1254. }
  1255. }
  1256. CleanUp:
  1257. //
  1258. // Could have gotten here with stale hr if client called SetOperationMode
  1259. //
  1260. if (WaitForSingleObject(pEngUpdate->m_evtNeedToQuit, 0) == WAIT_OBJECT_0)
  1261. {
  1262. hr = E_ABORT;
  1263. }
  1264. m_xmlItems.AddItem(&m_xmlCatalog, hItem, &hXmlItem);
  1265. if (ITEM_STATUS_SUCCESS_REBOOT_REQUIRED == dwStatus)
  1266. {
  1267. fInstallerNeedsReboot = TRUE;
  1268. }
  1269. if (ITEM_STATUS_FAILED == dwStatus)
  1270. {
  1271. if (fExclusive)
  1272. {
  1273. m_history.UpdateHistoryItemInstallStatus(&m_xmlCatalog, hItem, HISTORY_STATUS_FAILED, fInstallerNeedsReboot, hr);
  1274. }
  1275. else
  1276. {
  1277. m_history.AddHistoryItemInstallStatus(&m_xmlCatalog, hItem, HISTORY_STATUS_FAILED, pszClientName, fInstallerNeedsReboot, hr);
  1278. }
  1279. m_xmlItems.AddInstallStatus(hXmlItem, KEY_STATUS_FAILED, 0, hr);
  1280. }
  1281. else
  1282. {
  1283. // install completed successfully
  1284. if (fExclusive)
  1285. {
  1286. m_history.UpdateHistoryItemInstallStatus(&m_xmlCatalog, hItem, HISTORY_STATUS_COMPLETE, fInstallerNeedsReboot, 0);
  1287. }
  1288. else
  1289. {
  1290. m_history.AddHistoryItemInstallStatus(&m_xmlCatalog, hItem, HISTORY_STATUS_COMPLETE, pszClientName, fInstallerNeedsReboot, 0);
  1291. }
  1292. if (ITEM_STATUS_INSTALLED_ERROR == dwStatus)
  1293. {
  1294. LOG_Software(_T("Item Installed However there were Minor Errors"));
  1295. }
  1296. m_xmlItems.AddInstallStatus(hXmlItem, KEY_STATUS_COMPLETE, fInstallerNeedsReboot, 0);
  1297. m_fSomeItemsSuccessful = TRUE; // any success in the install operation should set to true
  1298. }
  1299. //
  1300. // ping server to report the download status for this item
  1301. //
  1302. if (!fExclusive)
  1303. {
  1304. //
  1305. // if we haven't done so, ping server now
  1306. //
  1307. LPCTSTR pDeviceId = NULL;
  1308. if (NULL != bstrDriverName)
  1309. {
  1310. pDeviceId = OLE2T(bstrDriverName);
  1311. }
  1312. else if (NULL != bstrHWID)
  1313. {
  1314. pDeviceId = OLE2T(bstrHWID);
  1315. }
  1316. PingServerForInstall(hr, hItem, &(pEngUpdate->m_evtNeedToQuit), pDeviceId);
  1317. }
  1318. if ((DWORD) m_lMode & (DWORD) UPDATE_NOTIFICATION_COMPLETEONLY)
  1319. {
  1320. // Only Send OnOperationComplete, we won't send any progress messages.
  1321. }
  1322. else
  1323. {
  1324. // Send all Progress Messages
  1325. hrString = StringCchPrintfEx(szProgress, ARRAYSIZE(szProgress), NULL, NULL, MISTSAFE_STRING_FLAGS,
  1326. _T("%lu:%lu"), (ULONG)m_lItemCount, (ULONG)m_lItemsCompleted);
  1327. if (SUCCEEDED(hrString))
  1328. {
  1329. evtData.bstrProgress = SysAllocString(T2OLE(szProgress));
  1330. if (NULL != m_pProgressListener)
  1331. {
  1332. m_pProgressListener->OnProgress(m_bstrOperationUUID, VARIANT_TRUE, evtData.bstrProgress, &evtData.lCommandRequest);
  1333. }
  1334. else
  1335. {
  1336. if (NULL != m_hWnd)
  1337. {
  1338. evtData.fItemCompleted = TRUE;
  1339. evtData.bstrUuidOperation = SysAllocString(m_bstrOperationUUID);
  1340. SendMessage(m_hWnd, UM_EVENT_PROGRESS, 0, LPARAM(&evtData));
  1341. }
  1342. }
  1343. }
  1344. else
  1345. {
  1346. LOG_ErrorMsg(hrString);
  1347. }
  1348. //
  1349. // Need to check for a cancel command returned from OnProgress
  1350. //
  1351. if (UPDATE_COMMAND_CANCEL == evtData.lCommandRequest)
  1352. {
  1353. LOG_Out(_T("OnProgress received UPDATE_COMMAND_CANCEL"));
  1354. SetEvent(pEngUpdate->m_evtNeedToQuit); // asked to quit, we'll handle it in WaitForSingleObject
  1355. }
  1356. }
  1357. m_dwStatus = dwStatus; // return the status up the chain
  1358. SafeHeapFree(pCommandInfoArray);
  1359. SysFreeString(bstrName);
  1360. SysFreeString(bstrPublisherName);
  1361. SysFreeString(bstrItemUUID);
  1362. SysFreeString(bstrInstallerType);
  1363. SafeSysFreeString(bstrCommandType);
  1364. SafeSysFreeString(bstrCommand);
  1365. SafeSysFreeString(bstrSwitches);
  1366. SafeSysFreeString(bstrInfSection);
  1367. SafeSysFreeString(bstrHWID);
  1368. SafeSysFreeString(bstrDriverName);
  1369. SafeSysFreeString(evtData.bstrProgress);
  1370. SafeSysFreeString(evtData.bstrUuidOperation);
  1371. //
  1372. // Could have missed change during lengthy ping or OnProgress
  1373. //
  1374. if (WaitForSingleObject(pEngUpdate->m_evtNeedToQuit, 0) == WAIT_OBJECT_0)
  1375. {
  1376. hr = E_ABORT;
  1377. }
  1378. return hr;
  1379. }
  1380. //
  1381. // RemoveDownloadTemporaryFolders
  1382. //
  1383. // This helper function is called after the install is successfully finished
  1384. // in DoInstall() to delete the temporary component directory and all files underneath
  1385. //
  1386. void CIUInstall::RemoveDownloadTemporaryFolders(LPCTSTR pszComponentPath)
  1387. {
  1388. LOG_Block("CIUInstall::RemoveDownloadTemporaryFolders()");
  1389. HRESULT hr;
  1390. TCHAR szBuffer[MAX_PATH], szDeleteFile[MAX_PATH];
  1391. WIN32_FIND_DATA fd;
  1392. HANDLE hFind;
  1393. hr = PathCchCombine(szBuffer, ARRAYSIZE(szBuffer), pszComponentPath, _T("*.*"));
  1394. if (FAILED(hr))
  1395. {
  1396. LOG_ErrorMsg(hr);
  1397. return;
  1398. }
  1399. hFind = FindFirstFile(szBuffer, &fd);
  1400. BOOL fMore = (hFind != INVALID_HANDLE_VALUE);
  1401. while (fMore)
  1402. {
  1403. if ((fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0)
  1404. {
  1405. hr = PathCchCombine(szDeleteFile, ARRAYSIZE(szDeleteFile), pszComponentPath, fd.cFileName);
  1406. if (FAILED(hr))
  1407. {
  1408. LOG_ErrorMsg(hr);
  1409. goto doneCurrentEntry;
  1410. }
  1411. if (!DeleteFile(szDeleteFile))
  1412. {
  1413. // Try waiting a bit before trying one last time.
  1414. Sleep(1000);
  1415. DeleteFile(szDeleteFile);
  1416. }
  1417. }
  1418. else if (_T('.') != fd.cFileName[0] &&
  1419. (_T('\0') != fd.cFileName[1] ||
  1420. (_T('.') != fd.cFileName[1] && _T('\0') != fd.cFileName[2])))
  1421. {
  1422. hr = PathCchCombine(szBuffer, ARRAYSIZE(szDeleteFile), pszComponentPath, fd.cFileName);
  1423. if (FAILED(hr))
  1424. {
  1425. LOG_ErrorMsg(hr);
  1426. goto doneCurrentEntry;
  1427. }
  1428. RemoveDownloadTemporaryFolders(szBuffer);
  1429. }
  1430. doneCurrentEntry:
  1431. fMore = FindNextFile(hFind, &fd);
  1432. }
  1433. if (hFind != INVALID_HANDLE_VALUE)
  1434. FindClose(hFind);
  1435. BOOL fSuccess = RemoveDirectory(pszComponentPath);
  1436. if (!fSuccess)
  1437. {
  1438. // Try waiting a bit before trying one last time.
  1439. Sleep(1000);
  1440. fSuccess = RemoveDirectory(pszComponentPath);
  1441. }
  1442. }
  1443. //
  1444. // private utility function to ping server for installation activity.
  1445. // since there are two places we do this, so wrap this in a function to safe size
  1446. //
  1447. void CIUInstall::PingServerForInstall(HRESULT hr, HANDLE_NODE hItem, PHANDLE phEvtNeedToQuit, LPCTSTR lpszDeviceId /*=NULL*/, BOOL fExclusive /*=FALSE*/)
  1448. {
  1449. LOG_Block("CIUInstall::PingServerForInstall()");
  1450. BSTR bstrIdentity = NULL;
  1451. USES_IU_CONVERSION;
  1452. if (SUCCEEDED(m_xmlCatalog.GetIdentityStrForPing(hItem, &bstrIdentity)))
  1453. {
  1454. BOOL fOnLine = (0 == ((DWORD) m_lMode & (DWORD) UPDATE_OFFLINE_MODE));
  1455. URLLOGSTATUS status = SUCCEEDED(hr) ? URLLOGSTATUS_Success : URLLOGSTATUS_Failed;
  1456. if (fExclusive)
  1457. {
  1458. status = URLLOGSTATUS_Pending;
  1459. }
  1460. if (m_fAbort)
  1461. {
  1462. //
  1463. // user/system cancelled the current process
  1464. //
  1465. hr = E_ABORT;
  1466. status = URLLOGSTATUS_Cancelled;
  1467. }
  1468. m_pingSvr.Ping(
  1469. fOnLine, // on-line
  1470. URLLOGDESTINATION_DEFAULT, // going to live or corp WU server
  1471. phEvtNeedToQuit, // pt to cancel events
  1472. 1, // number of events
  1473. URLLOGACTIVITY_Installation, // activity
  1474. status, // status code
  1475. hr, // error code, can be 0 or 1
  1476. OLE2T(bstrIdentity), // itemID
  1477. lpszDeviceId // add'l device data for driver update
  1478. );
  1479. }
  1480. SafeSysFreeString(bstrIdentity);
  1481. }