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.

123 lines
3.9 KiB

  1. #include "priv.h"
  2. #include "icotask.h"
  3. // {EB30900C-1AC4-11d2-8383-00C04FD918D0}
  4. static const GUID TASKID_IconExtraction =
  5. { 0xeb30900c, 0x1ac4, 0x11d2, { 0x83, 0x83, 0x0, 0xc0, 0x4f, 0xd9, 0x18, 0xd0 } };
  6. CIconTask::CIconTask(LPITEMIDLIST pidl, PFNICONTASKBALLBACK pfn, LPVOID pvData, UINT uId):
  7. _pidl(pidl), _pfn(pfn), _pvData(pvData), _uId(uId), CRunnableTask(RTF_DEFAULT)
  8. {
  9. }
  10. CIconTask::~CIconTask()
  11. {
  12. if (_pidl)
  13. ILFree(_pidl);
  14. }
  15. // IRunnableTask methods (override)
  16. STDMETHODIMP CIconTask::RunInitRT(void)
  17. {
  18. int iIndex = -1;
  19. IShellFolder* psf;
  20. LPCITEMIDLIST pidlItem;
  21. // We need to rebind because shell folders may not be thread safe.
  22. HRESULT hres = IEBindToParentFolder(_pidl, &psf, &pidlItem);
  23. if (SUCCEEDED(hres))
  24. {
  25. iIndex = SHMapPIDLToSystemImageListIndex(psf, pidlItem, NULL);
  26. psf->Release();
  27. }
  28. _pfn(_pvData, _uId, iIndex);
  29. return S_OK; // return S_OK even if we don't get an icon.
  30. }
  31. // NOTE: If you pass NULL for psf and pidlFolder, you must pass a full pidl which
  32. // the API takes ownership of. (This is an optimization) lamadio - 7.28.98
  33. HRESULT AddIconTask(IShellTaskScheduler* pts, IShellFolder* psf, LPCITEMIDLIST pidlFolder,
  34. LPCITEMIDLIST pidl, PFNICONTASKBALLBACK pfn, LPVOID pvData,
  35. UINT uId, int* piTempIcon)
  36. {
  37. if (!pts)
  38. return E_INVALIDARG;
  39. HRESULT hres = E_PENDING;
  40. TCHAR szIconFile[MAX_PATH];
  41. // The shell has a concept of GIL_ASYNC which means that an extension called with this flag
  42. // should not really load the target file, it should "Fake" it, returning an icon for the type.
  43. // Later, on a background thread, we're going to call it again without the GIL_ASYNC, and at
  44. // that time, it should really extract the icon.
  45. // This is an optimiation for slow icon extraction, such as network shares
  46. // NOTE: There is significant overhead to actually loading the shell extension. If you know the
  47. // type of the item, pass NULL to piTempIcopn
  48. if (piTempIcon)
  49. {
  50. *piTempIcon = -1;
  51. UINT uFlags;
  52. IExtractIconA* pixa;
  53. IExtractIconW* pix;
  54. if (SUCCEEDED(psf->GetUIObjectOf(NULL, 1, (LPCITEMIDLIST*)&pidl, IID_IExtractIconW, NULL, (LPVOID*)&pix)))
  55. {
  56. hres = pix->GetIconLocation(GIL_FORSHELL | GIL_ASYNC,
  57. szIconFile, ARRAYSIZE(szIconFile), piTempIcon, &uFlags);
  58. pix->Release();
  59. }
  60. else if (SUCCEEDED(psf->GetUIObjectOf(NULL, 1,(LPCITEMIDLIST*)&pidl, IID_IExtractIconA, NULL, (LPVOID*)&pixa)))
  61. {
  62. char szIconFileA[MAX_PATH];
  63. hres = pixa->GetIconLocation(GIL_FORSHELL | GIL_ASYNC,
  64. szIconFileA, ARRAYSIZE(szIconFileA), piTempIcon, &uFlags);
  65. SHAnsiToUnicode(szIconFileA, szIconFile, ARRAYSIZE(szIconFile));
  66. pixa->Release();
  67. }
  68. }
  69. if (hres == E_PENDING)
  70. {
  71. if (piTempIcon)
  72. *piTempIcon = Shell_GetCachedImageIndex(szIconFile, *piTempIcon, 0);
  73. LPITEMIDLIST pidlFull;
  74. if (psf)
  75. pidlFull = ILCombine(pidlFolder, pidl);
  76. else
  77. pidlFull = (LPITEMIDLIST)pidl;
  78. hres = E_OUTOFMEMORY;
  79. CIconTask* pit = new CIconTask(pidlFull, pfn, pvData, uId);
  80. // Don't ILFree(pidlFull) because CIconTask takes ownership.
  81. // BUGBUG (lamadio) Remove this from the memory list. Ask Saml how to do this
  82. // for the IMallocSpy stuff.
  83. if (pit)
  84. {
  85. hres = pts->AddTask(SAFECAST(pit, IRunnableTask*), TASKID_IconExtraction,
  86. ITSAT_DEFAULT_LPARAM, ITSAT_DEFAULT_PRIORITY);
  87. pit->Release();
  88. }
  89. }
  90. else
  91. {
  92. *piTempIcon = SHMapPIDLToSystemImageListIndex(psf, pidl, NULL);
  93. hres = S_OK;
  94. }
  95. return hres;
  96. }