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.

836 lines
25 KiB

  1. #include <urlmon.h>
  2. #include "item.h"
  3. #include <webcheck.h>
  4. #include "utils.h"
  5. #include "parseinf.h"
  6. #include <mluisupp.h>
  7. extern "C" HRESULT GetControlFolderPath(LPTSTR lpszDir, ULONG ulSizeBuf);
  8. typedef HRESULT (STDAPICALLTYPE *PFNASYNCINSTALLDU)(LPCWSTR,LPCWSTR, LPCWSTR, DWORD,
  9. DWORD,LPCWSTR, IBindCtx *, LPVOID, DWORD );
  10. // registered clipboard formats
  11. //UINT g_cfFileDescriptor = 0;
  12. //UINT g_cfFileContents = 0;
  13. //UINT g_cfURL = 0;
  14. UINT g_cfPrefDropEffect = 0;
  15. ///////////////////////////////////////////////////////////////////////////////
  16. // CControlItem methods.
  17. CControlItem::CControlItem()
  18. {
  19. DebugMsg(DM_TRACE, TEXT("ci - CControlItem() called."));
  20. DllAddRef();
  21. m_cRef = 1;
  22. m_piciUpdate = NULL;
  23. m_pcpidlUpdate = NULL;
  24. m_pcdlbsc = NULL;
  25. }
  26. CControlItem::~CControlItem()
  27. {
  28. Assert(m_cRef == 0); // we should have zero ref count here
  29. DebugMsg(DM_TRACE, TEXT("ci - ~CControlItem() called."));
  30. LocalFree((HLOCAL)m_ppcei);
  31. if (m_pCFolder != NULL)
  32. m_pCFolder->Release(); // release the pointer to the sf
  33. DllRelease();
  34. }
  35. HRESULT CControlItem::Initialize(CControlFolder *pCFolder, UINT cidl, LPCITEMIDLIST *ppidl)
  36. {
  37. m_ppcei = (LPCONTROLPIDL*)LocalAlloc(LPTR, cidl * sizeof(LPCONTROLPIDL));
  38. if (m_ppcei == NULL)
  39. return E_OUTOFMEMORY;
  40. m_cItems = cidl;
  41. m_pCFolder = pCFolder;
  42. for (UINT i = 0; i < cidl; i++)
  43. m_ppcei[i] = (LPCONTROLPIDL)(ppidl[i]);
  44. m_pCFolder->AddRef(); // we're going to hold onto this pointer, so
  45. // we need to AddRef it.
  46. return NOERROR;
  47. }
  48. HRESULT CControlItem_CreateInstance(
  49. CControlFolder *pCFolder,
  50. UINT cidl,
  51. LPCITEMIDLIST *ppidl,
  52. REFIID riid,
  53. void **ppvOut)
  54. {
  55. *ppvOut = NULL; // null the out param
  56. // if (!_ValidateIDListArray(cidl, ppidl))
  57. // return E_FAIL;
  58. CControlItem *pCItem = new CControlItem;
  59. if (pCItem == NULL)
  60. return E_OUTOFMEMORY;
  61. HRESULT hr = pCItem->Initialize(pCFolder, cidl, ppidl);
  62. if (SUCCEEDED(hr))
  63. {
  64. hr = pCItem->QueryInterface(riid, ppvOut);
  65. }
  66. pCItem->Release();
  67. if (g_cfPrefDropEffect == 0)
  68. {
  69. // g_cfFileDescriptor = RegisterClipboardFormat(CFSTR_FILEDESCRIPTOR); // "FileContents"
  70. // g_cfFileContents = RegisterClipboardFormat(CFSTR_FILECONTENTS); // "FileDescriptor"
  71. // g_cfURL = RegisterClipboardFormat(TEXT("UniformResourceLocator")); // "UniformResourceLocator"
  72. g_cfPrefDropEffect = RegisterClipboardFormat(TEXT("Preferred DropEffect"));// "Preferred DropEffect"
  73. }
  74. return hr;
  75. }
  76. HRESULT CControlItem::QueryInterface(REFIID iid, void **ppv)
  77. {
  78. DebugMsg(DM_TRACE, TEXT("ci - QueryInterface() called."));
  79. if ((iid == IID_IUnknown) || (iid == IID_IContextMenu))
  80. {
  81. *ppv = (LPVOID)(IContextMenu*)this;
  82. }
  83. else if (iid == IID_IDataObject)
  84. {
  85. *ppv = (LPVOID)(IDataObject*)this;
  86. }
  87. else if (iid == IID_IExtractIcon)
  88. {
  89. *ppv = (LPVOID)(IExtractIcon*)this;
  90. }
  91. else if (iid == CLSID_ControlFolder) // really should be CLSID_ControlFolderItem
  92. {
  93. *ppv = (void *)this; // for our friends
  94. }
  95. else
  96. {
  97. *ppv = NULL; // null the out param
  98. return E_NOINTERFACE;
  99. }
  100. AddRef();
  101. return S_OK;
  102. }
  103. ULONG CControlItem::AddRef()
  104. {
  105. return ++m_cRef;
  106. }
  107. ULONG CControlItem::Release()
  108. {
  109. if (--m_cRef)
  110. return m_cRef;
  111. delete this;
  112. return 0;
  113. }
  114. HRESULT CControlItem::GetData(LPFORMATETC pFEIn, LPSTGMEDIUM pSTM)
  115. {
  116. HRESULT hres;
  117. #ifdef _DEBUG_
  118. TCHAR szName[64];
  119. if (!GetClipboardFormatName(pFEIn->cfFormat, szName, sizeof(szName)))
  120. wsprintf(szName, "#%d", pFEIn->cfFormat);
  121. DebugMsg(DM_TRACE, TEXT("ci - do - GetData(%s)"), szName);
  122. #endif
  123. pSTM->hGlobal = NULL;
  124. pSTM->pUnkForRelease = NULL;
  125. if ((pFEIn->cfFormat == g_cfPrefDropEffect) && (pFEIn->tymed & TYMED_HGLOBAL))
  126. hres = CreatePrefDropEffect(pSTM);
  127. else
  128. hres = E_FAIL; // FAIL WHEN YOU DON'T SUPPORT IT!!!
  129. return hres;
  130. }
  131. HRESULT CControlItem::GetDataHere(LPFORMATETC pFE, LPSTGMEDIUM pSTM)
  132. {
  133. DebugMsg(DM_TRACE, TEXT("ci - do - GetDataHere() called."));
  134. return E_NOTIMPL;
  135. }
  136. HRESULT CControlItem::QueryGetData(LPFORMATETC pFEIn)
  137. {
  138. #ifdef _DEBUG_
  139. TCHAR szName[64];
  140. if (!GetClipboardFormatName(pFEIn->cfFormat, szName, sizeof(szName)))
  141. wsprintf(szName, "#%d", pFEIn->cfFormat);
  142. DebugMsg(DM_TRACE, TEXT("ci - do - QueryGetData(%s)"), szName);
  143. #endif
  144. if (pFEIn->cfFormat == g_cfPrefDropEffect)
  145. {
  146. DebugMsg(DM_TRACE, TEXT(" format supported."));
  147. return NOERROR;
  148. }
  149. return S_FALSE;
  150. }
  151. HRESULT CControlItem::GetCanonicalFormatEtc(LPFORMATETC pFEIn, LPFORMATETC pFEOut)
  152. {
  153. DebugMsg(DM_TRACE, TEXT("ci - do - GetCanonicalFormatEtc() called."));
  154. return DATA_S_SAMEFORMATETC;
  155. }
  156. HRESULT CControlItem::SetData(LPFORMATETC pFE, LPSTGMEDIUM pSTM, BOOL fRelease)
  157. {
  158. DebugMsg(DM_TRACE,TEXT("ci - do - SetData() called."));
  159. return E_NOTIMPL;
  160. }
  161. HRESULT CControlItem::EnumFormatEtc(DWORD dwDirection, LPENUMFORMATETC *ppEnum)
  162. {
  163. FORMATETC ControlFmte[1] = {
  164. {(CLIPFORMAT)g_cfPrefDropEffect, NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL}
  165. };
  166. DebugMsg(DM_TRACE, TEXT("ci - do - EnumFormatEtc() called."));
  167. return SHCreateStdEnumFmtEtc(ARRAYSIZE(ControlFmte), ControlFmte, ppEnum);
  168. }
  169. HRESULT CControlItem::DAdvise(LPFORMATETC pFE, DWORD grfAdv, LPADVISESINK pAdvSink,
  170. LPDWORD pdwConnection)
  171. {
  172. DebugMsg(DM_TRACE, TEXT("ci - do - DAdvise() called."));
  173. return OLE_E_ADVISENOTSUPPORTED;
  174. }
  175. HRESULT CControlItem::DUnadvise(DWORD dwConnection)
  176. {
  177. DebugMsg(DM_TRACE, TEXT("ci - do - DUnAdvise() called."));
  178. return OLE_E_ADVISENOTSUPPORTED;
  179. }
  180. HRESULT CControlItem::EnumDAdvise(LPENUMSTATDATA *ppEnum)
  181. {
  182. DebugMsg(DM_TRACE, TEXT("ci - do - EnumAdvise() called."));
  183. return OLE_E_ADVISENOTSUPPORTED;
  184. }
  185. HRESULT CControlItem::CreatePrefDropEffect(LPSTGMEDIUM pSTM)
  186. {
  187. pSTM->tymed = TYMED_HGLOBAL;
  188. pSTM->pUnkForRelease = NULL;
  189. pSTM->hGlobal = GlobalAlloc(GPTR, sizeof(DWORD));
  190. if (pSTM->hGlobal)
  191. {
  192. *((LPDWORD)pSTM->hGlobal) = DROPEFFECT_COPY;
  193. return S_OK;
  194. }
  195. return E_OUTOFMEMORY;
  196. }
  197. HRESULT CControlItem::Remove(HWND hwnd)
  198. {
  199. TCHAR szMsg[MESSAGE_MAXSIZE];
  200. TCHAR szBuf[MESSAGE_MAXSIZE];
  201. if ( !g_fAllAccess )
  202. {
  203. // The current user does not have the access privileges to modify the
  204. // keys we need to tweak to remove a control, so let 'em know and bail
  205. // out quickly.
  206. MLLoadString(IDS_WARNING_USERNOACCESS, szMsg, ARRAYSIZE(szMsg));
  207. MLLoadString(IDS_MBTITLE_REMOVECONTROL, szBuf, ARRAYSIZE(szBuf));
  208. MessageBox(hwnd, szMsg, szBuf, MB_OK|MB_ICONWARNING);
  209. return S_FALSE;
  210. }
  211. szMsg[0] = '\0';
  212. if (m_cItems == 1)
  213. {
  214. // if(!PathFileExists(GetStringInfo(m_ppcei[0], SI_LOCATION)) ||
  215. // IsModuleRemovable(GetStringInfo(m_ppcei[0], SI_LOCATION)))
  216. {
  217. MLLoadString(IDS_WARNING_SINGLEREMOVAL, szBuf, ARRAYSIZE(szBuf));
  218. wsprintf(szMsg, szBuf, GetStringInfo(m_ppcei[0], SI_CONTROL));
  219. }
  220. }
  221. else
  222. {
  223. MLLoadString(IDS_WARNING_MULTIPLEREMOVAL, szMsg, ARRAYSIZE(szMsg));
  224. }
  225. if (szMsg[0] != '\0')
  226. {
  227. MLLoadString(IDS_MBTITLE_REMOVECONTROL, szBuf, ARRAYSIZE(szBuf));
  228. if (MessageBox(hwnd, szMsg, szBuf, MB_YESNO | MB_ICONWARNING) != IDYES)
  229. {
  230. return S_FALSE;
  231. }
  232. }
  233. // set wait cursor
  234. HRESULT hr = S_OK;
  235. HCURSOR hCurOld = StartWaitCur();
  236. LPCTSTR pszTypeLibId = NULL;
  237. for (UINT i = 0; i < m_cItems; i++)
  238. {
  239. Assert(m_ppcei[i] != NULL);
  240. if (m_ppcei[i] == NULL)
  241. {
  242. hr = E_FAIL;
  243. break;
  244. }
  245. pszTypeLibId = GetStringInfo(m_ppcei[i], SI_TYPELIBID);
  246. if (SUCCEEDED(hr = RemoveControlByName2(
  247. GetStringInfo(m_ppcei[i], SI_LOCATION),
  248. GetStringInfo(m_ppcei[i], SI_CLSID),
  249. (pszTypeLibId[0] == '\0' ? NULL : pszTypeLibId),
  250. TRUE, (m_ppcei[i])->ci.dwIsDistUnit, FALSE)))
  251. {
  252. if ( hr == S_FALSE )
  253. {
  254. MLLoadString(
  255. IDS_ERROR_NOUNINSTALLACTION,
  256. szBuf,
  257. ARRAYSIZE(szBuf));
  258. wsprintf(szMsg, szBuf, GetStringInfo(m_ppcei[i], SI_CONTROL));
  259. MLLoadString(
  260. IDS_MBTITLE_NOUNINSTALLACTION,
  261. szBuf,
  262. ARRAYSIZE(szBuf));
  263. MessageBox(hwnd, szMsg, szBuf, MB_OK|MB_ICONWARNING);
  264. }
  265. GenerateEvent(
  266. SHCNE_DELETE,
  267. m_pCFolder->m_pidl,
  268. (LPITEMIDLIST)(m_ppcei[i]),
  269. NULL);
  270. }
  271. else if (hr == STG_E_SHAREVIOLATION)
  272. {
  273. MLLoadString(
  274. IDS_CONTROL_INUSE,
  275. szBuf,
  276. ARRAYSIZE(szBuf));
  277. wsprintf(szMsg, szBuf, GetStringInfo(m_ppcei[i], SI_CONTROL));
  278. MLLoadString(
  279. IDS_MBTITLE_SHAREVIOLATION,
  280. szBuf,
  281. ARRAYSIZE(szBuf));
  282. MessageBox(hwnd, szMsg, szBuf, MB_OK|MB_ICONSTOP);
  283. }
  284. else
  285. {
  286. MLLoadString(
  287. IDS_ERROR_REMOVEFAIL,
  288. szBuf,
  289. ARRAYSIZE(szBuf));
  290. wsprintf(szMsg, szBuf, GetStringInfo(m_ppcei[i], SI_CONTROL));
  291. MLLoadString(
  292. IDS_MBTITLE_REMOVEFAIL,
  293. szBuf,
  294. ARRAYSIZE(szBuf));
  295. MessageBox(hwnd, szMsg, szBuf, MB_OK|MB_ICONSTOP);
  296. break;
  297. }
  298. }
  299. EndWaitCur(hCurOld);
  300. return hr;
  301. }
  302. ///////////////////////////////////////////////////////////////////////////////
  303. // IExtractIcon Methods
  304. STDMETHODIMP CControlItem::GetIconLocation(
  305. UINT uFlags,
  306. LPSTR szIconFile,
  307. UINT cchMax,
  308. int *piIndex,
  309. UINT *pwFlags)
  310. {
  311. Assert(szIconFile != NULL);
  312. Assert(m_cItems == 1);
  313. if (szIconFile == NULL)
  314. return S_FALSE;
  315. *piIndex = 0;
  316. *pwFlags = 0;
  317. if (uFlags != GIL_FORSHELL)
  318. return S_FALSE;
  319. *pwFlags = GIL_NOTFILENAME|GIL_PERINSTANCE;
  320. if (cchMax > (UINT)lstrlen(GetStringInfo(m_ppcei[0], SI_LOCATION)))
  321. {
  322. lstrcpy(szIconFile, GetStringInfo(m_ppcei[0], SI_LOCATION));
  323. return NOERROR;
  324. }
  325. szIconFile[0] = '\0';
  326. return S_FALSE;
  327. }
  328. STDMETHODIMP CControlItem::Extract(
  329. LPCSTR pszFile,
  330. UINT nIconIndex,
  331. HICON *phiconLarge,
  332. HICON *phiconSmall,
  333. UINT nIconSize)
  334. {
  335. *phiconLarge = ExtractIcon(g_hInst, pszFile, nIconIndex);
  336. if (*phiconLarge == NULL)
  337. {
  338. *phiconLarge = GetDefaultOCIcon( m_ppcei[0] );
  339. Assert(*phiconLarge != NULL);
  340. }
  341. *phiconSmall = *phiconLarge;
  342. return NOERROR;
  343. }
  344. ///////////////////////////////////////////////////////////////////////////////
  345. // IContextMenu Methods
  346. const struct {
  347. LPCTSTR pszVerb;
  348. UINT idCmd;
  349. } rgcmds[] = {
  350. {TEXT("Remove"), IDM_CTRL_REMOVECONTROL},
  351. {TEXT("Properties"), IDM_CTRL_PROPERTIES},
  352. {TEXT("Update"), IDM_CTRL_UPDATE},
  353. {TEXT("Delete"), IDM_CTRL_REMOVECONTROL},
  354. {NULL, 0} // terminator
  355. };
  356. int GetCmdID(LPCTSTR pszCmd)
  357. {
  358. if ((DWORD_PTR)pszCmd <= 0xFFFF)
  359. return (int)LOWORD(pszCmd);
  360. for (int i = 0; rgcmds[i].pszVerb != NULL; i++)
  361. if (lstrcmpi(pszCmd, rgcmds[i].pszVerb) == 0)
  362. return rgcmds[i].idCmd;
  363. return -1;
  364. }
  365. HMENU LoadPopupMenu(UINT id, UINT uSubOffset)
  366. {
  367. HMENU hmParent, hmPopup;
  368. hmParent = LoadMenu(MLGetHinst(), MAKEINTRESOURCE(id));
  369. if (!hmParent)
  370. return NULL;
  371. hmPopup = GetSubMenu(hmParent, uSubOffset);
  372. RemoveMenu(hmParent, uSubOffset, MF_BYPOSITION);
  373. DestroyMenu(hmParent);
  374. return hmPopup;
  375. }
  376. UINT MergePopupMenu(
  377. HMENU *phMenu,
  378. UINT idResource,
  379. UINT uSubOffset,
  380. UINT indexMenu,
  381. UINT idCmdFirst,
  382. UINT idCmdLast)
  383. {
  384. HMENU hmMerge;
  385. if (*phMenu == NULL)
  386. {
  387. *phMenu = CreatePopupMenu();
  388. if (*phMenu == NULL)
  389. return 0;
  390. indexMenu = 0; // at the bottom
  391. }
  392. hmMerge = LoadPopupMenu(idResource, uSubOffset);
  393. if (!hmMerge)
  394. return 0;
  395. idCmdLast = Shell_MergeMenus(*phMenu, hmMerge, indexMenu, idCmdFirst, idCmdLast, MM_ADDSEPARATOR);
  396. DestroyMenu(hmMerge);
  397. return idCmdLast;
  398. }
  399. HRESULT CControlItem::QueryContextMenu(
  400. HMENU hmenu,
  401. UINT indexMenu,
  402. UINT idCmdFirst,
  403. UINT idCmdLast,
  404. UINT uFlags)
  405. {
  406. UINT idLastMerged = 0;
  407. DebugMsg(DM_TRACE, TEXT("ci - cm - QueryContextMenu() called."));
  408. if (uFlags & CMF_DVFILE)
  409. {
  410. idLastMerged = MergePopupMenu(
  411. &hmenu,
  412. IDR_FILE_MERGE,
  413. 0,
  414. indexMenu,
  415. idCmdFirst,
  416. idCmdLast);
  417. if (IsShowAllFilesEnabled()) {
  418. CheckMenuItem(hmenu, 1, MF_BYPOSITION | MF_CHECKED);
  419. }
  420. else {
  421. CheckMenuItem(hmenu, 1, MF_BYPOSITION | MF_UNCHECKED);
  422. }
  423. }
  424. else if (!(uFlags & CMF_VERBSONLY))
  425. {
  426. DWORD dwState = 0;
  427. // Must have a connection and not be working offline to be able
  428. // to update.
  429. if (InternetGetConnectedState(&dwState, 0) && !IsGlobalOffline()) {
  430. idLastMerged = MergePopupMenu(
  431. &hmenu,
  432. IDR_POPUP_CONTROLCONTEXT,
  433. 0,
  434. indexMenu,
  435. idCmdFirst,
  436. idCmdLast);
  437. }
  438. else {
  439. idLastMerged = MergePopupMenu(
  440. &hmenu,
  441. IDR_POPUP_CONTROLCONTEXT_NO_UPDATE,
  442. 0,
  443. indexMenu,
  444. idCmdFirst,
  445. idCmdLast);
  446. }
  447. SetMenuDefaultItem(hmenu, idLastMerged - idCmdFirst, MF_BYPOSITION); // make the last menu, Properties, the default
  448. }
  449. return ResultFromShort(idLastMerged - idCmdFirst); // number of menu items
  450. }
  451. HRESULT CControlItem::InvokeCommand(LPCMINVOKECOMMANDINFO pici)
  452. {
  453. UINT i;
  454. int idCmd = GetCmdID((LPCTSTR)(pici->lpVerb));
  455. HRESULT hres = S_OK;
  456. // LPOLESTR szMimeType = NULL;
  457. // LPOLESTR szExtension = NULL;
  458. // LPOLESTR szCodeBase = NULL;
  459. // IBindCtx *pbc = NULL;
  460. // CodeDownloadBSC *pCDLBSC = NULL;
  461. DebugMsg(DM_TRACE, TEXT("ci - cm - InvokeCommand() called."));
  462. if (idCmd == IDM_CTRL_REMOVECONTROL)
  463. {
  464. hres = Remove(pici->hwnd);
  465. }
  466. else if (idCmd == IDM_CTRL_SHOWALL) {
  467. ToggleShowAllFiles();
  468. GenerateEvent(SHCNE_UPDATEITEM, m_pCFolder->m_pidl, 0, NULL);
  469. }
  470. else
  471. {
  472. for (i = 0; i < m_cItems && SUCCEEDED(hres); i++)
  473. if (m_ppcei[i])
  474. {
  475. switch (idCmd)
  476. {
  477. case IDM_CTRL_PROPERTIES:
  478. hres = CreatePropDialog(pici->hwnd, m_ppcei[i]);
  479. break;;
  480. case IDM_CTRL_UPDATE:
  481. hres = Update( pici, m_ppcei[i] );
  482. /*
  483. hres = CreateBindCtx(0, &pbc);
  484. if (SUCCEEDED(hres)) {
  485. LPITEMIDLIST pidlUpdate = ILCombine(m_pCFolder->m_pidl,(LPITEMIDLIST)(m_ppcei[i]));
  486. // destructor of CodeDownloadBSC will free pidlUpdate
  487. if ( pidlUpdate != NULL &&
  488. (pCDLBSC = new CodeDownloadBSC( pici->hwnd, pidlUpdate )) != NULL &&
  489. SUCCEEDED(hres = RegisterBindStatusCallback(pbc, pCDLBSC, NULL, 0)))
  490. {
  491. PFNASYNCINSTALLDU pfnAsyncInstallDU;
  492. HINSTANCE hModule;
  493. pCDLBSC->Release();
  494. hModule = LoadLibrary("URLMON.DLL");
  495. #ifdef UNICODE
  496. WCHAR swzCodeBase = (m_ppcei[i])->ci.szCodeBase;
  497. WCHAR swzDUName = (m_ppcei[i])->ci.szCLSID;
  498. #else
  499. MAKE_WIDEPTR_FROMANSI(swzCodeBase, (m_ppcei[i])->ci.szCodeBase);
  500. MAKE_WIDEPTR_FROMANSI(swzDUName, (m_ppcei[i])->ci.szCLSID);
  501. #endif
  502. pfnAsyncInstallDU = (PFNASYNCINSTALLDU)GetProcAddress((HMODULE)hModule, "AsyncInstallDistributionUnit");
  503. pfnAsyncInstallDU( swzDUName, szMimeType, szExtension,
  504. 0xFFFFFFFF, 0xFFFFFFFF,
  505. swzCodeBase,
  506. pbc,
  507. NULL, 0);
  508. FreeLibrary(hModule);
  509. }
  510. else
  511. {
  512. if ( pCDLBSC != NULL )
  513. delete pCDLBSC;
  514. else if ( pidlUpdate != NULL )
  515. ILFree( pidlUpdate );
  516. }
  517. if (pbc != NULL) {
  518. pbc->Release();
  519. }
  520. }
  521. */
  522. break;
  523. default:
  524. hres = E_FAIL;
  525. break;
  526. }
  527. }
  528. }
  529. return hres;
  530. }
  531. HRESULT CControlItem::GetCommandString(
  532. UINT_PTR idCmd,
  533. UINT uFlags,
  534. UINT *pwReserved,
  535. LPTSTR pszName,
  536. UINT cchMax)
  537. {
  538. HRESULT hres = E_FAIL;
  539. DebugMsg(DM_TRACE, TEXT("ci - cm - GetCommandString() called."));
  540. pszName[0] = '\0';
  541. if (uFlags == GCS_VERB)
  542. {
  543. for (int i = 0; rgcmds[i].pszVerb != NULL; i++)
  544. if (idCmd == rgcmds[i].idCmd)
  545. {
  546. lstrcpyn(pszName, rgcmds[i].pszVerb, cchMax);
  547. hres = NOERROR;
  548. }
  549. }
  550. else if (uFlags == GCS_HELPTEXT)
  551. {
  552. hres = NOERROR;
  553. switch (idCmd)
  554. {
  555. case IDM_CTRL_REMOVECONTROL:
  556. MLLoadString(IDS_HELP_REMOVECONTROL, pszName, cchMax);
  557. break;
  558. case IDM_CTRL_PROPERTIES:
  559. MLLoadString(IDS_HELP_PROPERTIES, pszName, cchMax);
  560. break;
  561. case IDM_CTRL_UPDATE:
  562. MLLoadString(IDS_HELP_UPDATE, pszName, cchMax);
  563. break;
  564. default:
  565. hres = E_FAIL;
  566. }
  567. }
  568. return hres;
  569. }
  570. HRESULT
  571. CControlItem::Update(LPCMINVOKECOMMANDINFO pici, LPCONTROLPIDL pcpidl )
  572. {
  573. HRESULT hres = NOERROR;
  574. m_piciUpdate = pici;
  575. m_pcpidlUpdate = pcpidl;
  576. if (pici->hwnd)
  577. {
  578. INT_PTR nRes = DialogBoxParam(MLGetHinst(), MAKEINTRESOURCE(IDD_OCUPDATE),
  579. pici->hwnd, CControlItem::DlgProc, (LPARAM)this);
  580. }
  581. return hres;
  582. }
  583. INT_PTR CControlItem::DlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
  584. {
  585. BOOL fRet = TRUE;
  586. CControlItem* pctlitem = (CControlItem*)GetWindowLongPtr(hDlg, DWLP_USER);
  587. HRESULT hr = S_OK;
  588. IBindCtx *pbc = NULL;
  589. LPOLESTR szMimeType = NULL;
  590. LPOLESTR szExtension = NULL;
  591. TCHAR szBuf[MESSAGE_MAXSIZE];
  592. switch (msg)
  593. {
  594. case WM_INITDIALOG:
  595. SetWindowLongPtr(hDlg, DWLP_USER, lParam);
  596. pctlitem = (CControlItem*)lParam;
  597. MLLoadString(IDS_UPDATE_CAPTION, szBuf, ARRAYSIZE(szBuf));
  598. lstrcatn( szBuf, pctlitem->m_pcpidlUpdate->ci.szName, ARRAYSIZE(szBuf));
  599. SetWindowText( hDlg, szBuf );
  600. hr = CreateBindCtx(0, &pbc);
  601. if (SUCCEEDED(hr))
  602. {
  603. LPITEMIDLIST pidlUpdate = ILCombine(pctlitem->m_pCFolder->m_pidl,(LPITEMIDLIST)(pctlitem->m_pcpidlUpdate));
  604. // destructor of CodeDownloadBSC will free pidlUpdate
  605. // if new succeeds but register fails, we'll deallocate pidlUpdate twice.
  606. if ( pidlUpdate != NULL &&
  607. (pctlitem->m_pcdlbsc = new CodeDownloadBSC( pctlitem->m_piciUpdate->hwnd, hDlg, pidlUpdate )) != NULL &&
  608. SUCCEEDED(hr = RegisterBindStatusCallback(pbc, pctlitem->m_pcdlbsc, NULL, 0)))
  609. {
  610. PFNASYNCINSTALLDU pfnAsyncInstallDU;
  611. HINSTANCE hModule;
  612. hModule = LoadLibrary("URLMON.DLL");
  613. #ifdef UNICODE
  614. WCHAR swzCodeBase = pctlitem->m_pcpidlUpdate->ci.szCodeBase;
  615. WCHAR swzDUName = pctlitem->m_pcpidlUpdate->ci.szCLSID;
  616. #else
  617. MAKE_WIDEPTR_FROMANSI(swzCodeBase, pctlitem->m_pcpidlUpdate->ci.szCodeBase);
  618. MAKE_WIDEPTR_FROMANSI(swzDUName, pctlitem->m_pcpidlUpdate->ci.szCLSID);
  619. #endif
  620. pfnAsyncInstallDU = (PFNASYNCINSTALLDU)GetProcAddress((HMODULE)hModule, "AsyncInstallDistributionUnit");
  621. if ( pfnAsyncInstallDU != NULL )
  622. hr = pfnAsyncInstallDU( swzDUName, szMimeType, szExtension,
  623. 0xFFFFFFFF, 0xFFFFFFFF,
  624. swzCodeBase,
  625. pbc,
  626. NULL, 0);
  627. else
  628. hr = E_FAIL;
  629. FreeLibrary(hModule);
  630. }
  631. else
  632. {
  633. if ( pctlitem->m_pcdlbsc != NULL )
  634. {
  635. delete pctlitem->m_pcdlbsc;
  636. pctlitem->m_pcdlbsc = NULL;
  637. }
  638. else if ( pidlUpdate != NULL )
  639. ILFree( pidlUpdate );
  640. }
  641. if (pbc != NULL) {
  642. pbc->Release();
  643. }
  644. }
  645. if ( SUCCEEDED(hr) )
  646. {
  647. Animate_Open(GetDlgItem(hDlg, IDC_DOWNLOADANIMATE), IDA_DOWNLOAD);
  648. Animate_Play(GetDlgItem(hDlg, IDC_DOWNLOADANIMATE), 0, -1, -1);
  649. }
  650. else
  651. EndDialog(hDlg, FALSE);
  652. fRet = 0;
  653. break;
  654. case WM_COMMAND:
  655. switch (LOWORD(wParam))
  656. {
  657. case IDCANCEL:
  658. Assert( pctlitem->m_pcdlbsc != NULL );
  659. hr = pctlitem->m_pcdlbsc->Abort();
  660. Assert( SUCCEEDED( hr ) );
  661. EndDialog(hDlg, FALSE);
  662. break;
  663. case DOWNLOAD_PROGRESS:
  664. SendMessage(GetDlgItem(hDlg, IDC_DOWNLOADPROGRESS), PBM_SETPOS,
  665. lParam, 0);
  666. break;
  667. case DOWNLOAD_COMPLETE:
  668. if (lParam)
  669. SendMessage(GetDlgItem(hDlg, IDC_DOWNLOADPROGRESS), PBM_SETPOS,
  670. 100, 0);
  671. EndDialog(hDlg, lParam);
  672. break;
  673. }
  674. break;
  675. case WM_CLOSE:
  676. EndDialog(hDlg, FALSE);
  677. break;
  678. case WM_DESTROY:
  679. Assert( pctlitem->m_pcdlbsc != NULL );
  680. pctlitem->m_pcdlbsc->_hdlg = NULL;
  681. pctlitem->m_pcdlbsc->Release();
  682. break;
  683. default:
  684. fRet = FALSE;
  685. }
  686. return fRet;
  687. }
  688. BOOL CControlItem::IsGlobalOffline()
  689. {
  690. DWORD dwState = 0, dwSize = sizeof(DWORD);
  691. BOOL fRet = FALSE;
  692. if(InternetQueryOption(NULL, INTERNET_OPTION_CONNECTED_STATE, &dwState,
  693. &dwSize))
  694. {
  695. if(dwState & INTERNET_STATE_DISCONNECTED_BY_USER)
  696. fRet = TRUE;
  697. }
  698. return fRet;
  699. }