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.

193 lines
4.8 KiB

  1. #include "shellprv.h"
  2. #include "emptyvc.h"
  3. #include "recclean.h"
  4. #include "ids.h"
  5. STDAPI CRecycleBinCleaner_CreateInstance(LPUNKNOWN punkOuter, REFIID riid, void **ppvOut)
  6. {
  7. *ppvOut = NULL;
  8. CRecycleBinCleaner *p = new CRecycleBinCleaner();
  9. if (!p)
  10. return E_OUTOFMEMORY;
  11. HRESULT hres = p->QueryInterface(riid, ppvOut);
  12. p->Release();
  13. return hres;
  14. }
  15. CRecycleBinCleaner::CRecycleBinCleaner() : m_cRef(1)
  16. {
  17. // start ref at one
  18. }
  19. CRecycleBinCleaner::~CRecycleBinCleaner()
  20. {
  21. // cleanup - nothing yet
  22. }
  23. /*----------------------------------------------------------
  24. QueryInterface handler for CRecycleBinCleaner
  25. */
  26. STDMETHODIMP CRecycleBinCleaner::QueryInterface(REFIID riid, PVOID *ppvObj)
  27. {
  28. if (IsEqualIID(riid, IID_IUnknown) ||
  29. IsEqualIID(riid, IID_IEmptyVolumeCache2))
  30. {
  31. *ppvObj = SAFECAST(this, IEmptyVolumeCache2 *);
  32. }
  33. else if (IsEqualIID(riid, IID_IEmptyVolumeCache))
  34. {
  35. *ppvObj = SAFECAST(this, IEmptyVolumeCache *);
  36. }
  37. else
  38. {
  39. *ppvObj = NULL;
  40. return E_NOINTERFACE;
  41. }
  42. AddRef();
  43. return NOERROR;
  44. }
  45. STDMETHODIMP_(ULONG) CRecycleBinCleaner::AddRef()
  46. {
  47. return ++m_cRef;
  48. }
  49. STDMETHODIMP_(ULONG) CRecycleBinCleaner::Release()
  50. {
  51. m_cRef--;
  52. if (m_cRef > 0)
  53. return m_cRef;
  54. delete this;
  55. return 0;
  56. }
  57. STDMETHODIMP CRecycleBinCleaner::InitializeEx(
  58. HKEY hkRegKey,
  59. LPCWSTR pcwszVolume,
  60. LPCWSTR pcwszKeyName,
  61. LPWSTR *ppwszDisplayName,
  62. LPWSTR *ppwszDescription,
  63. LPWSTR *ppwszBtnText,
  64. DWORD *pdwFlags
  65. )
  66. {
  67. TCHAR szTmp[128];
  68. int iLen;
  69. iLen = 1 + LoadString( g_hinst, IDS_RECCLEAN_BTNTEXT, szTmp, ARRAYSIZE(szTmp));
  70. if (iLen == 1) // and hence LoadString returned 0 (error)
  71. return E_FAIL;
  72. *ppwszBtnText = (LPWSTR)CoTaskMemAlloc( iLen * sizeof(WCHAR) );
  73. if ( !*ppwszBtnText )
  74. return E_OUTOFMEMORY;
  75. SHTCharToUnicode(szTmp, *ppwszBtnText, iLen);
  76. return Initialize(hkRegKey, pcwszVolume, ppwszDisplayName, ppwszDescription, pdwFlags);
  77. }
  78. STDMETHODIMP CRecycleBinCleaner::Initialize(HKEY hRegKey, LPCWSTR pszVolume,
  79. LPWSTR *ppwszName, LPWSTR *ppwszDesc, DWORD *pdwFlags)
  80. {
  81. TCHAR szTmpName[256], szTmpDesc[512];
  82. int iNameLen, iDescLen;
  83. if(!pdwFlags)
  84. return E_INVALIDARG;
  85. *pdwFlags = EVCF_HASSETTINGS;
  86. iNameLen = 1 + LoadString( g_hinst, IDS_RECCLEAN_NAMETEXT, szTmpName, ARRAYSIZE(szTmpName));
  87. iDescLen = 1 + LoadString( g_hinst, IDS_RECCLEAN_DESCTEXT, szTmpDesc, ARRAYSIZE(szTmpDesc));
  88. if ( (iNameLen == 1) || (iDescLen == 1) ) // meaning LoadString returned 0 (error)
  89. return E_FAIL;
  90. *ppwszName = (LPWSTR)CoTaskMemAlloc( iNameLen*sizeof(WCHAR) );
  91. *ppwszDesc = (LPWSTR)CoTaskMemAlloc( iDescLen*sizeof(WCHAR) );
  92. if ( !*ppwszName || !*ppwszDesc )
  93. return E_OUTOFMEMORY;
  94. SHTCharToUnicode(szTmpName, *ppwszName, iNameLen);
  95. SHTCharToUnicode(szTmpDesc, *ppwszDesc, iDescLen);
  96. StringCchCopy(m_szVolume, ARRAYSIZE(m_szVolume), pszVolume);
  97. return S_OK;
  98. }
  99. STDMETHODIMP CRecycleBinCleaner::GetSpaceUsed(DWORDLONG *pdwSpaceUsed, IEmptyVolumeCacheCallBack *picb)
  100. {
  101. SHQUERYRBINFO qinfo;
  102. if(!pdwSpaceUsed)
  103. return E_INVALIDARG;
  104. qinfo.cbSize = sizeof(SHQUERYRBINFO);
  105. if(SUCCEEDED(SHQueryRecycleBinW(m_szVolume, &qinfo)))
  106. {
  107. *pdwSpaceUsed = qinfo.i64Size;
  108. }
  109. else
  110. {
  111. *pdwSpaceUsed = 0;
  112. }
  113. // call back to be nice
  114. if(picb)
  115. picb->ScanProgress(*pdwSpaceUsed, EVCCBF_LASTNOTIFICATION, NULL);
  116. return S_OK;
  117. }
  118. STDMETHODIMP CRecycleBinCleaner::Purge(DWORDLONG dwSpaceToFree, IEmptyVolumeCacheCallBack *picb)
  119. {
  120. SHQUERYRBINFO qinfo;
  121. if (picb)
  122. {
  123. qinfo.cbSize = sizeof(SHQUERYRBINFO);
  124. SHQueryRecycleBinW(m_szVolume, &qinfo);
  125. }
  126. // we ignore dwSpaceToFree and clean everything
  127. SHEmptyRecycleBin(NULL, m_szVolume, SHERB_NOCONFIRMATION | SHERB_NOPROGRESSUI | SHERB_NOSOUND);
  128. // call back to be nice
  129. if (picb)
  130. {
  131. picb->PurgeProgress(qinfo.i64Size, qinfo.i64Size, EVCCBF_LASTNOTIFICATION, NULL);
  132. }
  133. return S_OK;
  134. }
  135. STDMETHODIMP CRecycleBinCleaner::ShowProperties(HWND hwnd)
  136. {
  137. LPITEMIDLIST pidlBitBuck = SHCloneSpecialIDList(hwnd, CSIDL_BITBUCKET, TRUE);
  138. if (pidlBitBuck)
  139. {
  140. SHELLEXECUTEINFO ei;
  141. FillExecInfo(ei, hwnd, c_szOpen, szNULL, NULL, szNULL, SW_NORMAL);
  142. ei.fMask |= SEE_MASK_IDLIST;
  143. ei.lpIDList = pidlBitBuck;
  144. ShellExecuteEx(&ei);
  145. ILFree(pidlBitBuck);
  146. }
  147. return S_OK;
  148. }
  149. STDMETHODIMP CRecycleBinCleaner::Deactivate(LPDWORD pdwFlags)
  150. {
  151. // whatever, nothing to deactivate
  152. return S_OK;
  153. }