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.

332 lines
7.0 KiB

  1. #include "pch.h"
  2. #pragma hdrstop
  3. #include "wuauengi_i.c"
  4. CAUInternals::~CAUInternals()
  5. {
  6. if (m_pUpdates != NULL)
  7. {
  8. m_pUpdates->Release();
  9. }
  10. }
  11. HRESULT CAUInternals::m_setReminderState(DWORD dwState)
  12. {
  13. HRESULT hr = S_OK;
  14. // save selections so we have them after the reminder
  15. if ( AUSTATE_NOT_CONFIGURED == dwState || (SUCCEEDED(hr = m_saveSelectionsToServer(m_pUpdates))))
  16. {
  17. hr = SetRegDWordValue(TIMEOUTSTATE, dwState);
  18. }
  19. return hr;
  20. }
  21. /*****
  22. Takes the number of seconds we want to wait before reminding the user
  23. and records it in the current user's registry along with a timestamp.
  24. *****/
  25. HRESULT CAUInternals::m_setReminderTimeout(UINT iTimeout)
  26. {
  27. //const int NanoSec100PerSec = 10000000;
  28. DEBUGMSG("WUAUCLT Setting timeout = %lu", ReminderTimes[iTimeout].timeout);
  29. DWORD timeout;
  30. if ( TIMEOUT_INX_TOMORROW == iTimeout )
  31. {
  32. // time to wait is midnight - current time.
  33. SYSTEMTIME tmCurrent;
  34. SYSTEMTIME tmMidnight;
  35. FILETIME ftCurrent;
  36. FILETIME ftMidnight;
  37. GetLocalTime(&tmCurrent);
  38. tmMidnight = tmCurrent;
  39. tmMidnight.wHour = 23;
  40. tmMidnight.wMinute = 59;
  41. tmMidnight.wSecond = 59;
  42. tmMidnight.wMilliseconds = 999;
  43. SystemTimeToFileTime(&tmCurrent, &ftCurrent);
  44. SystemTimeToFileTime(&tmMidnight, &ftMidnight);
  45. ULONGLONG diff = *((ULONGLONG *)&ftMidnight) - *((ULONGLONG *)&ftCurrent);
  46. timeout = DWORD(diff / NanoSec100PerSec);
  47. DEBUGMSG("WUAUCLT: tomorrow is %lu secs away", timeout);
  48. }
  49. else
  50. {
  51. timeout = ReminderTimes[iTimeout].timeout;
  52. }
  53. return setAddedTimeout(timeout, TIMEOUTVALUE);
  54. }
  55. HRESULT CAUInternals::m_getServiceState(AUSTATE *pAuState)
  56. {
  57. #ifdef TESTUI
  58. return S_OK;
  59. #else
  60. if (NULL == m_pUpdates)
  61. {
  62. return E_FAIL;
  63. }
  64. HRESULT hr = m_pUpdates->get_State(pAuState);
  65. if (FAILED(hr))
  66. {
  67. DEBUGMSG("WUAUCLT m_getServiceState failed, hr=%#lx", hr);
  68. }
  69. return hr;
  70. #endif
  71. }
  72. HRESULT TransformSafeArrayToItemList(VARIANT & var, AUCatalogItemList & ItemList)
  73. {
  74. HRESULT hr; //= S_OK;
  75. // determine how many elements there are.
  76. if (FAILED(hr = ItemList.Allocate(var)))
  77. {
  78. DEBUGMSG("WUAUCLT fail to allocate item list with error %#lx", hr);
  79. goto done;
  80. }
  81. DEBUGMSG("ItemList had %d elements", ItemList.Count());
  82. #if 0
  83. if ( !m_bValid )
  84. {
  85. DEBUGMSG("Catalog::getUpdateList fails because catalog is not valid");
  86. goto done;
  87. }
  88. #endif
  89. for ( UINT index = 0; index < ItemList.Count(); index++ )
  90. {
  91. VARIANT varg;
  92. VariantInit(&varg);
  93. struct
  94. {
  95. VARTYPE vt;
  96. void * pv;
  97. } grMembers[] = { { VT_I4, &ItemList[index].m_dwStatus },
  98. { VT_BSTR, &ItemList[index].m_bstrID },
  99. { VT_BSTR, &ItemList[index].m_bstrProviderName },
  100. { VT_BSTR, &ItemList[index].m_bstrTitle },
  101. { VT_BSTR, &ItemList[index].m_bstrDescription },
  102. { VT_BSTR, &ItemList[index].m_bstrRTFPath },
  103. { VT_BSTR, &ItemList[index].m_bstrEULAPath } };
  104. for ( int index2 = 0; index2 < ARRAYSIZE(grMembers); index2++ )
  105. {
  106. long dex = (index * 7) + index2;
  107. if ( FAILED(hr = SafeArrayGetElement(var.parray, &dex, &varg)) )
  108. {
  109. DEBUGMSG("Failed to get element %ld", dex);
  110. goto done;
  111. }
  112. switch (grMembers[index2].vt)
  113. {
  114. case VT_I4:
  115. *((long *)grMembers[index2].pv) = varg.lVal;
  116. break;
  117. case VT_BSTR:
  118. *((BSTR *)grMembers[index2].pv) = varg.bstrVal;
  119. break;
  120. }
  121. }
  122. }
  123. done:
  124. return hr;
  125. }
  126. HRESULT CAUInternals::m_getServiceUpdatesList(void)
  127. {
  128. #ifdef TESTUI
  129. return S_OK;
  130. #else
  131. VARIANT var;
  132. HRESULT hr;
  133. if ( SUCCEEDED(hr = m_pUpdates->GetUpdatesList(&var)) &&
  134. SUCCEEDED(hr = TransformSafeArrayToItemList(var, m_ItemList)) )
  135. {
  136. // gItemList.DbgDump();
  137. }
  138. else
  139. {
  140. DEBUGMSG("WUAUCLT m_getUpdatesList failed, hr=%#lx", hr);
  141. }
  142. VariantClear(&var);
  143. return hr;
  144. #endif
  145. }
  146. HRESULT CAUInternals::m_saveSelectionsToServer(IUpdates *pUpdates)
  147. {
  148. HRESULT hr = E_FAIL;
  149. SAFEARRAYBOUND bound[1] = { m_ItemList.Count() * 2, 0};
  150. if ( 0 == m_ItemList.Count() )
  151. {
  152. DEBUGMSG("Catalog::m_saveSelectionsToServer fails because getNumItems is 0");
  153. hr = E_UNEXPECTED;
  154. goto Done;
  155. }
  156. VARIANT varSelections;
  157. varSelections.vt = VT_ARRAY | VT_VARIANT;
  158. if (NULL == (varSelections.parray = SafeArrayCreate(VT_VARIANT, 1, bound)))
  159. {
  160. hr = E_OUTOFMEMORY;
  161. goto Done;
  162. }
  163. VARIANT *grVariant = NULL;
  164. if (FAILED(hr = SafeArrayAccessData(varSelections.parray, (void **)&grVariant)))
  165. {
  166. goto CleanUp;
  167. }
  168. for ( UINT n = 0; n < m_ItemList.Count(); n++ )
  169. {
  170. if (NULL == (grVariant[n*2+0].bstrVal = SysAllocString(m_ItemList[n].bstrID())))
  171. {
  172. hr = E_OUTOFMEMORY;
  173. break;
  174. }
  175. grVariant[n*2+0].vt = VT_BSTR;
  176. grVariant[n*2+1].vt = VT_I4;
  177. grVariant[n*2+1].lVal = m_ItemList[n].dwStatus();
  178. }
  179. HRESULT hr2 = SafeArrayUnaccessData(varSelections.parray);
  180. if (SUCCEEDED(hr) && FAILED(hr2))
  181. {
  182. hr = hr2;
  183. goto CleanUp;
  184. }
  185. if (SUCCEEDED(hr))
  186. {
  187. hr = pUpdates->SaveSelections(varSelections);
  188. }
  189. CleanUp:
  190. VariantClear(&varSelections);
  191. Done:
  192. return hr;
  193. }
  194. HRESULT CAUInternals::m_startDownload(void)
  195. {
  196. //fixcode this call is probably unneccesary
  197. HRESULT hr = m_saveSelectionsToServer(m_pUpdates);
  198. DEBUGMSG("WUAUCLT %s download", FAILED(hr) ? "skip" : "start");
  199. if ( SUCCEEDED(hr) )
  200. {
  201. hr = m_pUpdates->StartDownload();
  202. if (FAILED(hr))
  203. {
  204. DEBUGMSG("WUAUCLT m_startDownload failed, hr=%#lx", hr);
  205. }
  206. }
  207. return hr;
  208. }
  209. HRESULT CAUInternals::m_getDownloadStatus(UINT *percent, DWORD *status)
  210. {
  211. HRESULT hr = m_pUpdates->GetDownloadStatus(percent, status);
  212. if (FAILED(hr))
  213. {
  214. DEBUGMSG("WUAUCLT m_getDownloadStatus failed, hr=%#lx", hr);
  215. }
  216. return hr;
  217. }
  218. HRESULT CAUInternals::m_setDownloadPaused(BOOL bPaused)
  219. {
  220. HRESULT hr = m_pUpdates->SetDownloadPaused(bPaused);
  221. if (FAILED(hr))
  222. {
  223. DEBUGMSG("WUAUCLT m_setDownloadPaused failed, hr=%#lx", hr);
  224. }
  225. return hr;
  226. }
  227. //fAutoInstall TRUE if client doing install via local system
  228. // FALSE if installing via local admin
  229. HRESULT CAUInternals::m_startInstall(BOOL fAutoInstall)
  230. {
  231. HRESULT hr = m_pUpdates->ClientMessage(AUMSG_PRE_INSTALL);
  232. if (FAILED(hr))
  233. {
  234. DEBUGMSG("WUAUCLT m_startInstall failed, hr=%#lx", hr);
  235. }
  236. else
  237. {
  238. gpClientCatalog->m_WrkThread.m_DoDirective(fAutoInstall ? enWrkThreadAutoInstall : enWrkThreadInstall);
  239. }
  240. return hr;
  241. }
  242. //fixcode: should change name to complete wizard
  243. HRESULT CAUInternals::m_configureAU()
  244. {
  245. HRESULT hr = m_pUpdates->ConfigureAU();
  246. if (FAILED(hr))
  247. {
  248. DEBUGMSG("WUAUCLT m_ConfigureAU failed, hr=%#lx", hr);
  249. }
  250. return hr;
  251. }
  252. #if 0
  253. long CAUInternals::m_getNum(DWORD dwSelectionStatus)
  254. {
  255. long total = 0;
  256. for (UINT index = 0; index < gItemList.Count(); index++ )
  257. {
  258. if ( dwSelectionStatus == gItemList[index].dwStatus() )
  259. {
  260. total++;
  261. }
  262. }
  263. return total;
  264. }
  265. #endif
  266. HRESULT CAUInternals::m_AvailableSessions(LPUINT pcSess)
  267. {
  268. if (NULL == pcSess)
  269. {
  270. return E_INVALIDARG;
  271. }
  272. return m_pUpdates->AvailableSessions(pcSess);
  273. }
  274. HRESULT CAUInternals::m_getEvtHandles(DWORD dwProcId, AUEVTHANDLES *pAuEvtHandles)
  275. {
  276. HRESULT hr = m_pUpdates->get_EvtHandles(dwProcId, pAuEvtHandles);
  277. if (FAILED(hr))
  278. {
  279. DEBUGMSG("WUAUCLT get_EvtHandles failed hr=%#lx", hr);
  280. }
  281. return hr;
  282. }