ReactOS 0.4.15-dev-7934-g1dc8d80
recyclebin_generic_enumerator.c
Go to the documentation of this file.
1/*
2 * PROJECT: Recycle bin management
3 * LICENSE: GPL v2 - See COPYING in the top level directory
4 * FILE: lib/recyclebin/recyclebin_generic_enumerator.c
5 * PURPOSE: Enumerates contents of all recycle bins
6 * PROGRAMMERS: Copyright 2007 Hervé Poussineau (hpoussin@reactos.org)
7 */
8
10
12{
14 IRecycleBinEnumList recycleBinEnumImpl;
15 IRecycleBinEnumList *current;
18};
19
22 IN IRecycleBinEnumList *This,
24 OUT void **ppvObject)
25{
27
28 TRACE("(%p, %s, %p)\n", This, debugstr_guid(riid), ppvObject);
29
30 if (!ppvObject)
31 return E_POINTER;
32
34 *ppvObject = &s->recycleBinEnumImpl;
36 *ppvObject = &s->recycleBinEnumImpl;
37 else
38 {
39 *ppvObject = NULL;
40 return E_NOINTERFACE;
41 }
42
43 IUnknown_AddRef(This);
44 return S_OK;
45}
46
49 IN IRecycleBinEnumList *This)
50{
52 ULONG refCount = InterlockedIncrement((PLONG)&s->ref);
53 TRACE("(%p)\n", This);
54 return refCount;
55}
56
57static VOID
60{
61 TRACE("(%p)\n", s);
62
63 if (s->current)
64 IRecycleBinEnumList_Release(s->current);
66}
67
70 IN IRecycleBinEnumList *This)
71{
73 ULONG refCount;
74
75 TRACE("(%p)\n", This);
76
77 refCount = InterlockedDecrement((PLONG)&s->ref);
78
79 if (refCount == 0)
81
82 return refCount;
83}
84
87 IN IRecycleBinEnumList *This,
88 IN DWORD celt,
89 IN OUT IRecycleBinFile **rgelt,
90 OUT DWORD *pceltFetched)
91{
93 IRecycleBin *prb;
94 DWORD i;
95 DWORD fetched = 0, newFetched;
96 HRESULT hr;
97
98 TRACE("(%p, %u, %p, %p)\n", This, celt, rgelt, pceltFetched);
99
100 if (!rgelt)
101 return E_POINTER;
102 if (!pceltFetched && celt > 1)
103 return E_INVALIDARG;
104
105 while (TRUE)
106 {
107 /* Get enumerator implementation */
108 if (!s->current && s->dwLogicalDrives)
109 {
110 for (i = 0; i < 26; i++)
111 if (s->dwLogicalDrives & (1 << i))
112 {
113 WCHAR szVolumeName[4];
114 szVolumeName[0] = (WCHAR)('A' + i);
115 szVolumeName[1] = ':';
116 szVolumeName[2] = '\\';
117 szVolumeName[3] = UNICODE_NULL;
118 if (GetDriveTypeW(szVolumeName) != DRIVE_FIXED)
119 {
120 s->dwLogicalDrives &= ~(1 << i);
121 continue;
122 }
123 hr = GetDefaultRecycleBin(szVolumeName, &prb);
124 if (!SUCCEEDED(hr))
125 return hr;
126 hr = IRecycleBin_EnumObjects(prb, &s->current);
127 IRecycleBin_Release(prb);
128 if (!SUCCEEDED(hr))
129 return hr;
130 s->dwLogicalDrives &= ~(1 << i);
131 break;
132 }
133 }
134 if (!s->current)
135 {
136 /* Nothing more to enumerate */
137 if (pceltFetched)
138 *pceltFetched = fetched;
139 return S_FALSE;
140 }
141
142 /* Skip some elements */
143 while (s->skip > 0)
144 {
145 IRecycleBinFile *rbf;
146 hr = IRecycleBinEnumList_Next(s->current, 1, &rbf, NULL);
147 if (hr == S_OK)
148 hr = IRecycleBinFile_Release(rbf);
149 else if (hr == S_FALSE)
150 break;
151 else if (!SUCCEEDED(hr))
152 return hr;
153 }
154 if (s->skip > 0)
155 continue;
156
157 /* Fill area */
158 hr = IRecycleBinEnumList_Next(s->current, celt - fetched, &rgelt[fetched], &newFetched);
159 if (SUCCEEDED(hr))
160 fetched += newFetched;
161 if (hr == S_FALSE || newFetched == 0)
162 {
163 hr = IRecycleBinEnumList_Release(s->current);
164 s->current = NULL;
165 }
166 else if (!SUCCEEDED(hr))
167 return hr;
168 if (fetched == celt)
169 {
170 if (pceltFetched)
171 *pceltFetched = fetched;
172 return S_OK;
173 }
174 }
175
176 /* Never go here */
177}
178
181 IN IRecycleBinEnumList *This,
182 IN DWORD celt)
183{
185 TRACE("(%p, %u)\n", This, celt);
186 s->skip += celt;
187 return S_OK;
188}
189
192 IN IRecycleBinEnumList *This)
193{
195
196 TRACE("(%p)\n", This);
197
198 if (s->current)
199 {
200 IRecycleBinEnumList_Release(s->current);
201 s->current = NULL;
202 s->skip = 0;
203 }
204 s->dwLogicalDrives = GetLogicalDrives();
205 return S_OK;
206}
207
208CONST_VTBL struct IRecycleBinEnumListVtbl RecycleBinGenericEnumVtbl =
209{
216};
217
220 OUT IRecycleBinEnumList **pprbel)
221{
222 struct RecycleBinGenericEnum *s;
223
224 s = CoTaskMemAlloc(sizeof(struct RecycleBinGenericEnum));
225 if (!s)
226 return E_OUTOFMEMORY;
227 ZeroMemory(s, sizeof(struct RecycleBinGenericEnum));
228 s->ref = 1;
229 s->recycleBinEnumImpl.lpVtbl = &RecycleBinGenericEnumVtbl;
230
231 *pprbel = &s->recycleBinEnumImpl;
232 return IRecycleBinEnumList_Reset(*pprbel);
233}
#define InterlockedIncrement
Definition: armddk.h:53
#define InterlockedDecrement
Definition: armddk.h:52
const GUID IID_IUnknown
#define STDMETHODCALLTYPE
Definition: bdasup.h:9
#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
GLdouble s
Definition: gl.h:2039
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
VOID WINAPI CoTaskMemFree(LPVOID ptr)
Definition: ifs.c:442
LPVOID WINAPI CoTaskMemAlloc(SIZE_T size)
Definition: ifs.c:426
REFIID riid
Definition: atlbase.h:39
#define S_OK
Definition: intsafe.h:52
#define SUCCEEDED(hr)
Definition: intsafe.h:50
#define debugstr_guid
Definition: kernel32.h:35
#define UNICODE_NULL
#define CONST_VTBL
Definition: objbase.h:222
#define IsEqualIID(riid1, riid2)
Definition: guiddef.h:95
#define REFIID
Definition: guiddef.h:118
EXTERN_C const IID IID_IRecycleBinEnumList
Definition: recyclebin.h:242
static VOID RecycleBinGenericEnum_Destructor(struct RecycleBinGenericEnum *s)
static HRESULT STDMETHODCALLTYPE RecycleBinGenericEnum_RecycleBinEnumList_QueryInterface(IN IRecycleBinEnumList *This, IN REFIID riid, OUT void **ppvObject)
static HRESULT STDMETHODCALLTYPE RecycleBinGenericEnum_RecycleBinEnumList_Reset(IN IRecycleBinEnumList *This)
static HRESULT STDMETHODCALLTYPE RecycleBinGenericEnum_RecycleBinEnumList_Skip(IN IRecycleBinEnumList *This, IN DWORD celt)
static ULONG STDMETHODCALLTYPE RecycleBinGenericEnum_RecycleBinEnumList_Release(IN IRecycleBinEnumList *This)
static ULONG STDMETHODCALLTYPE RecycleBinGenericEnum_RecycleBinEnumList_AddRef(IN IRecycleBinEnumList *This)
CONST_VTBL struct IRecycleBinEnumListVtbl RecycleBinGenericEnumVtbl
static HRESULT STDMETHODCALLTYPE RecycleBinGenericEnum_RecycleBinEnumList_Next(IN IRecycleBinEnumList *This, IN DWORD celt, IN OUT IRecycleBinFile **rgelt, OUT DWORD *pceltFetched)
HRESULT RecycleBinGenericEnum_Constructor(OUT IRecycleBinEnumList **pprbel)
HRESULT hr
Definition: shlfolder.c:183
#define TRACE(s)
Definition: solgame.cpp:4
IRecycleBinEnumList recycleBinEnumImpl
ULONG_PTR SIZE_T
Definition: typedefs.h:80
#define IN
Definition: typedefs.h:39
int32_t * PLONG
Definition: typedefs.h:58
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
uint32_t ULONG
Definition: typedefs.h:59
#define OUT
Definition: typedefs.h:40
#define ZeroMemory
Definition: winbase.h:1712
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