ReactOS 0.4.15-dev-8614-gbc76250
recyclebin_generic_enumerator.cpp
Go to the documentation of this file.
1/*
2 * PROJECT: Recycle bin management
3 * LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
4 * PURPOSE: Enumerates contents of all recycle bins
5 * COPYRIGHT: Copyright 2007 Hervé Poussineau (hpoussin@reactos.org)
6 * Copyright 2024 Katayama Hirofumi MZ (katayama.hirofumi.mz@gmail.com)
7 */
8
10
11class RecycleBinGenericEnum : public IRecycleBinEnumList
12{
13public:
15 virtual ~RecycleBinGenericEnum();
16
17 /* IUnknown methods */
21
22 /* IRecycleBinEnumList methods */
23 STDMETHODIMP Next(DWORD celt, IRecycleBinFile **rgelt, DWORD *pceltFetched) override;
24 STDMETHODIMP Skip(DWORD celt) override;
25 STDMETHODIMP Reset() override;
26
27protected:
29 IRecycleBinEnumList *m_current;
32};
33
36{
37 TRACE("(%p, %s, %p)\n", this, debugstr_guid(&riid), ppvObject);
38
39 if (!ppvObject)
40 return E_POINTER;
41
43 *ppvObject = static_cast<IRecycleBinEnumList *>(this);
44 else
45 {
46 *ppvObject = NULL;
47 return E_NOINTERFACE;
48 }
49
50 AddRef();
51 return S_OK;
52}
53
55RecycleBinGenericEnum::AddRef()
56{
57 ULONG refCount = InterlockedIncrement(&m_ref);
58 TRACE("(%p)\n", this);
59 return refCount;
60}
61
63{
64 TRACE("(%p)\n", this);
65
66 if (m_current)
67 m_current->Release();
68}
69
71RecycleBinGenericEnum::Release()
72{
73 TRACE("(%p)\n", this);
74
75 ULONG refCount = InterlockedDecrement(&m_ref);
76 if (refCount == 0)
77 delete this;
78 return refCount;
79}
80
82RecycleBinGenericEnum::Next(DWORD celt, IRecycleBinFile **rgelt, DWORD *pceltFetched)
83{
84 TRACE("(%p, %u, %p, %p)\n", this, celt, rgelt, pceltFetched);
85
86 if (!rgelt)
87 return E_POINTER;
88 if (!pceltFetched && celt > 1)
89 return E_INVALIDARG;
90
91 HRESULT hr;
92 DWORD fetched = 0;
93 while (TRUE)
94 {
95 /* Get enumerator implementation */
97 {
98 for (DWORD i = 0; i < L'Z' - L'A' + 1; ++i)
99 {
100 if (m_dwLogicalDrives & (1 << i))
101 {
102 WCHAR szVolumeName[4];
103 szVolumeName[0] = (WCHAR)(L'A' + i);
104 szVolumeName[1] = L':';
105 szVolumeName[2] = L'\\';
106 szVolumeName[3] = UNICODE_NULL;
107 if (GetDriveTypeW(szVolumeName) != DRIVE_FIXED)
108 {
109 m_dwLogicalDrives &= ~(1 << i);
110 continue;
111 }
112
113 IRecycleBin *prb;
114 hr = GetDefaultRecycleBin(szVolumeName, &prb);
115 if (!SUCCEEDED(hr))
116 return hr;
117 hr = prb->EnumObjects(&m_current);
118 prb->Release();
119
120 if (!SUCCEEDED(hr))
121 return hr;
122
123 m_dwLogicalDrives &= ~(1 << i);
124 break;
125 }
126 }
127 }
128
129 if (!m_current)
130 {
131 /* Nothing more to enumerate */
132 if (pceltFetched)
133 *pceltFetched = fetched;
134 return S_FALSE;
135 }
136
137 /* Skip some elements */
138 while (m_skip > 0)
139 {
140 IRecycleBinFile *rbf;
141 hr = m_current->Next(1, &rbf, NULL);
142 if (hr == S_OK)
143 rbf->Release();
144 else if (hr == S_FALSE)
145 break;
146 else if (!SUCCEEDED(hr))
147 return hr;
148 }
149
150 if (m_skip > 0)
151 continue;
152
153 /* Fill area */
154 DWORD newFetched;
155 hr = m_current->Next(celt - fetched, &rgelt[fetched], &newFetched);
156 if (SUCCEEDED(hr))
157 fetched += newFetched;
158
159 if (hr == S_FALSE || newFetched == 0)
160 {
161 m_current->Release();
162 m_current = NULL;
163 }
164 else if (!SUCCEEDED(hr))
165 return hr;
166
167 if (fetched == celt)
168 {
169 if (pceltFetched)
170 *pceltFetched = fetched;
171 return S_OK;
172 }
173 }
174
175 /* Never go here */
177}
178
180{
181 TRACE("(%p, %u)\n", this, celt);
182 m_skip += celt;
183 return S_OK;
184}
185
187{
188 TRACE("(%p)\n", this);
189
190 if (m_current)
191 {
192 m_current->Release();
193 m_current = NULL;
194 }
195 m_skip = 0;
197 return S_OK;
198}
199
201 : m_ref(1)
202 , m_current(NULL)
203 , m_dwLogicalDrives(0)
204 , m_skip(0)
205{
206}
207
211 OUT IRecycleBinEnumList **pprbel)
212{
214 if (!pThis)
215 return E_OUTOFMEMORY;
216
217 *pprbel = static_cast<IRecycleBinEnumList *>(pThis);
218 return (*pprbel)->Reset();
219}
#define InterlockedIncrement
Definition: armddk.h:53
#define InterlockedDecrement
Definition: armddk.h:52
#define EXTERN_C
Definition: basetyps.h:12
#define STDMETHODIMP
Definition: basetyps.h:43
#define STDMETHODIMP_(t)
Definition: basetyps.h:44
const GUID IID_IUnknown
_In_ BOOLEAN Release
Definition: cdrom.h:920
STDMETHODIMP QueryInterface(REFIID riid, void **ppvObject) override
STDMETHODIMP_(ULONG) AddRef() override
STDMETHODIMP_(ULONG) Release() override
STDMETHODIMP Next(DWORD celt, IRecycleBinFile **rgelt, DWORD *pceltFetched) override
STDMETHODIMP Skip(DWORD celt) override
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
#define E_INVALIDARG
Definition: ddrawi.h:101
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
UINT WINAPI GetDriveTypeW(IN LPCWSTR lpRootPathName)
Definition: disk.c:497
HRESULT WINAPI GetDefaultRecycleBin(IN LPCWSTR pszVolume OPTIONAL, OUT IRecycleBin **pprb)
Definition: recyclebin.c:399
unsigned long DWORD
Definition: ntddk_ex.h:95
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
REFIID riid
Definition: atlbase.h:39
ULONG Release()
#define S_OK
Definition: intsafe.h:52
#define SUCCEEDED(hr)
Definition: intsafe.h:50
#define debugstr_guid
Definition: kernel32.h:35
static ULONG WINAPI AddRef(IStream *iface)
Definition: clist.c:90
#define UNREACHABLE
#define UNICODE_NULL
#define L(x)
Definition: ntvdm.h:50
long LONG
Definition: pedump.c:60
#define IsEqualIID(riid1, riid2)
Definition: guiddef.h:95
#define REFIID
Definition: guiddef.h:118
EXTERN_C const IID IID_IRecycleBinEnumList
Definition: recyclebin.h:245
EXTERN_C HRESULT RecycleBinGenericEnum_Constructor(OUT IRecycleBinEnumList **pprbel)
HRESULT hr
Definition: shlfolder.c:183
#define TRACE(s)
Definition: solgame.cpp:4
ULONG_PTR SIZE_T
Definition: typedefs.h:80
uint32_t ULONG
Definition: typedefs.h:59
#define OUT
Definition: typedefs.h:40
DWORD WINAPI GetLogicalDrives(void)
Definition: disk.c:110
#define DRIVE_FIXED
Definition: winbase.h:252
_In_ void _In_ PCCERT_CONTEXT _In_opt_ LPFILETIME _In_ DWORD _In_ DWORD _Outptr_opt_ void ** ppvObject
Definition: wincrypt.h:6082
#define S_FALSE
Definition: winerror.h:2357
#define E_NOINTERFACE
Definition: winerror.h:2364
#define E_POINTER
Definition: winerror.h:2365
__wchar_t WCHAR
Definition: xmlstorage.h:180