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.

214 lines
4.7 KiB

  1. /******************************************************************
  2. Copyright (c) 2000 Microsoft Corporation
  3. diskcleanup.h -- disk cleanup COM object for SR
  4. Description:
  5. delete datastores from stale builds
  6. ******************************************************************/
  7. #include <emptyvc.h>
  8. extern long g_cLock;
  9. //+---------------------------------------------------------------------------
  10. //
  11. // Class: CSREmptyVolumeCache2
  12. //
  13. // Synopsis: implements IEmptyVolumeCache2
  14. //
  15. // Arguments:
  16. //
  17. // History: 20-Jul-2000 HenryLee Created
  18. //
  19. //----------------------------------------------------------------------------
  20. class CSREmptyVolumeCache2 : IEmptyVolumeCache2
  21. {
  22. public:
  23. STDMETHOD(QueryInterface) (REFIID riid, void ** ppObject)
  24. {
  25. if (riid == IID_IEmptyVolumeCache2)
  26. {
  27. *ppObject = (IEmptyVolumeCache2 *) this;
  28. AddRef();
  29. }
  30. else if (riid == IID_IEmptyVolumeCache)
  31. {
  32. *ppObject = (IEmptyVolumeCache *) this;
  33. AddRef();
  34. }
  35. else return E_NOINTERFACE;
  36. return S_OK;
  37. }
  38. STDMETHOD_(ULONG, AddRef) ()
  39. {
  40. return InterlockedIncrement (&_lRefs);
  41. }
  42. STDMETHOD_(ULONG, Release) ()
  43. {
  44. if (0 == InterlockedDecrement (&_lRefs))
  45. {
  46. delete this;
  47. return 0;
  48. }
  49. return _lRefs;
  50. }
  51. CSREmptyVolumeCache2 ()
  52. {
  53. _lRefs = 1;
  54. _fStop = FALSE;
  55. InterlockedIncrement (&g_cLock);
  56. _ulGuids = 0;
  57. for (int i=0; i < ARRAYSIZE; i++)
  58. _wszGuid[i][0] = L'\0';
  59. _wszVolume[0] = L'\0';
  60. }
  61. ~CSREmptyVolumeCache2 ()
  62. {
  63. InterlockedDecrement (&g_cLock);
  64. }
  65. STDMETHOD(Initialize) (
  66. HKEY hkRegKey,
  67. const WCHAR * pcwszVolume,
  68. WCHAR **ppwszDisplayName,
  69. WCHAR **ppwszDescription,
  70. DWORD *pdwFlags)
  71. {
  72. return InitializeEx (
  73. hkRegKey,
  74. pcwszVolume,
  75. NULL,
  76. ppwszDisplayName,
  77. ppwszDescription,
  78. NULL,
  79. pdwFlags);
  80. }
  81. STDMETHOD(InitializeEx) (
  82. HKEY hkRegKey,
  83. const WCHAR *pcwszVolume,
  84. const WCHAR *pcwszKeyName,
  85. WCHAR **ppwszDisplayName,
  86. WCHAR **ppwszDescription,
  87. WCHAR **ppwszBtnText,
  88. DWORD *pdwFlags);
  89. STDMETHOD(GetSpaceUsed) (
  90. DWORDLONG *pdwlSpaceUsed,
  91. IEmptyVolumeCacheCallBack *picb);
  92. STDMETHOD(Purge) (
  93. DWORDLONG dwlSpaceToFree,
  94. IEmptyVolumeCacheCallBack *picb);
  95. STDMETHOD(ShowProperties) (HWND hwnd)
  96. {
  97. return S_OK; // no special UI
  98. }
  99. STDMETHOD(Deactivate) (DWORD *pdwFlags);
  100. private:
  101. DWORD LoadBootIni ();
  102. DWORD EnumDataStores (DWORDLONG *pdwlSpaceUsed,
  103. IEmptyVolumeCacheCallBack *picb,
  104. BOOL fPurge,
  105. WCHAR *pwszVolume);
  106. HRESULT ForAllMountPoints (DWORDLONG *pdwlSpaceUsed,
  107. IEmptyVolumeCacheCallBack *picb,
  108. BOOL fPurge);
  109. static const enum { ARRAYSIZE = 16 };
  110. static const enum { RESTOREGUID_STRLEN = 64 };
  111. LONG _lRefs;
  112. BOOL _fStop;
  113. ULONG _ulGuids;
  114. WCHAR _wszGuid [ARRAYSIZE][RESTOREGUID_STRLEN];
  115. WCHAR _wszVolume [MAX_PATH]; // DOS drive letter
  116. };
  117. //+---------------------------------------------------------------------------
  118. //
  119. // Class: CSRClassFactory
  120. //
  121. // Synopsis: generic class factory
  122. //
  123. // Arguments:
  124. //
  125. // History: 20-Jul-2000 HenryLee Created
  126. //
  127. //----------------------------------------------------------------------------
  128. class CSRClassFactory : IClassFactory
  129. {
  130. public:
  131. STDMETHOD(QueryInterface) (REFIID riid, void ** ppObject)
  132. {
  133. if (riid == IID_IClassFactory)
  134. {
  135. *ppObject = (IClassFactory *) this;
  136. AddRef();
  137. }
  138. else
  139. {
  140. return E_NOINTERFACE;
  141. }
  142. return S_OK;
  143. }
  144. STDMETHOD_(ULONG, AddRef) ()
  145. {
  146. return InterlockedIncrement (&_lRefs);
  147. }
  148. STDMETHOD_(ULONG, Release) ()
  149. {
  150. if (0 == InterlockedDecrement (&_lRefs))
  151. {
  152. delete this;
  153. return 0;
  154. }
  155. return _lRefs;
  156. }
  157. CSRClassFactory ()
  158. {
  159. _lRefs = 1;
  160. InterlockedIncrement (&g_cLock);
  161. }
  162. ~CSRClassFactory ()
  163. {
  164. InterlockedDecrement (&g_cLock);
  165. }
  166. STDMETHOD(CreateInstance) (IUnknown *pUnkOuter,
  167. REFIID riid,
  168. void **ppvObject);
  169. STDMETHOD(LockServer) (BOOL fLock)
  170. {
  171. if (fLock) InterlockedIncrement(&g_cLock);
  172. else InterlockedDecrement(&g_cLock);
  173. return S_OK;
  174. }
  175. private:
  176. LONG _lRefs;
  177. };