ReactOS 0.4.15-dev-8417-gb6b82fe
recyclebin_generic.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.c
5 * PURPOSE: Deals with a system-wide recycle bin
6 * PROGRAMMERS: Copyright 2007 Hervé Poussineau (hpoussin@reactos.org)
7 */
8
10
12{
14 IRecycleBin recycleBinImpl;
15};
16
19 IRecycleBin *This,
21 void **ppvObject)
22{
24
25 TRACE("(%p, %s, %p)\n", This, debugstr_guid(riid), ppvObject);
26
27 if (!ppvObject)
28 return E_POINTER;
29
31 *ppvObject = &s->recycleBinImpl;
33 *ppvObject = &s->recycleBinImpl;
34 else
35 {
36 *ppvObject = NULL;
37 return E_NOINTERFACE;
38 }
39
40 IUnknown_AddRef(This);
41 return S_OK;
42}
43
46 IRecycleBin *This)
47{
49 ULONG refCount = InterlockedIncrement((PLONG)&s->ref);
50 TRACE("(%p)\n", This);
51 return refCount;
52}
53
54static VOID
56 struct RecycleBinGeneric *s)
57{
58 TRACE("(%p)\n", s);
59
61}
62
65 IRecycleBin *This)
66{
68 ULONG refCount;
69
70 TRACE("(%p)\n", This);
71
72 refCount = InterlockedDecrement((PLONG)&s->ref);
73
74 if (refCount == 0)
76
77 return refCount;
78}
79
82 IN IRecycleBin *This,
83 IN LPCWSTR szFileName)
84{
85 IRecycleBin *prb;
86 LPWSTR szFullName = NULL;
87 DWORD dwBufferLength = 0;
88 DWORD len;
89 WCHAR szVolume[MAX_PATH];
90 HRESULT hr;
91
92 TRACE("(%p, %s)\n", This, debugstr_w(szFileName));
93
94 /* Get full file name */
95 while (TRUE)
96 {
97 len = GetFullPathNameW(szFileName, dwBufferLength, szFullName, NULL);
98 if (len == 0)
99 {
100 if (szFullName)
101 CoTaskMemFree(szFullName);
103 }
104 else if (len < dwBufferLength)
105 break;
106 if (szFullName)
107 CoTaskMemFree(szFullName);
108 dwBufferLength = len;
109 szFullName = CoTaskMemAlloc(dwBufferLength * sizeof(WCHAR));
110 if (!szFullName)
112 }
113
114 /* Get associated volume path */
115#ifndef __REACTOS__
116 if (!GetVolumePathNameW(szFullName, szVolume, MAX_PATH))
117 {
118 CoTaskMemFree(szFullName);
120 }
121#else
122 swprintf(szVolume, L"%c:\\", szFullName[0]);
123#endif
124
125 /* Skip namespace (if any) */
126 if (szVolume[0] == '\\'
127 && szVolume[1] == '\\'
128 && (szVolume[2] == '.' || szVolume[2] == '?')
129 && szVolume[3] == '\\')
130 {
131 MoveMemory(szVolume, &szVolume[4], (MAX_PATH - 4) * sizeof(WCHAR));
132 }
133
134 hr = GetDefaultRecycleBin(szVolume, &prb);
135 if (!SUCCEEDED(hr))
136 {
137 CoTaskMemFree(szFullName);
138 return hr;
139 }
140
141 hr = IRecycleBin_DeleteFile(prb, szFullName);
142 CoTaskMemFree(szFullName);
143 IRecycleBin_Release(prb);
144 return hr;
145}
146
149 IN IRecycleBin *This)
150{
151 WCHAR szVolumeName[MAX_PATH];
152 DWORD dwLogicalDrives, i;
153 IRecycleBin *prb;
154 HRESULT hr;
155
156 TRACE("(%p)\n", This);
157
158 dwLogicalDrives = GetLogicalDrives();
159 if (dwLogicalDrives == 0)
161
162 for (i = 0; i < 26; i++)
163 {
164 if (!(dwLogicalDrives & (1 << i)))
165 continue;
166 swprintf(szVolumeName, L"%c:\\", 'A' + i);
167 if (GetDriveTypeW(szVolumeName) != DRIVE_FIXED)
168 continue;
169
170 hr = GetDefaultRecycleBin(szVolumeName, &prb);
171 if (!SUCCEEDED(hr))
172 return hr;
173
174 hr = IRecycleBin_EmptyRecycleBin(prb);
175 IRecycleBin_Release(prb);
176 }
177
178 return S_OK;
179}
180
183 IN IRecycleBin *This,
184 OUT IRecycleBinEnumList **ppEnumList)
185{
186 TRACE("(%p, %p)\n", This, ppEnumList);
187 return RecycleBinGenericEnum_Constructor(ppEnumList);
188}
189
190CONST_VTBL struct IRecycleBinVtbl RecycleBinGenericVtbl =
191{
198};
199
201{
202 /* This RecycleBin implementation was introduced to be able to manage all
203 * drives at once, and instanciate the 'real' implementations when needed */
204 struct RecycleBinGeneric *s;
205
206 s = CoTaskMemAlloc(sizeof(struct RecycleBinGeneric));
207 if (!s)
208 return E_OUTOFMEMORY;
209 s->ref = 1;
210 s->recycleBinImpl.lpVtbl = &RecycleBinGenericVtbl;
211
212 *ppUnknown = (IUnknown *)&s->recycleBinImpl;
213 return S_OK;
214}
#define InterlockedIncrement
Definition: armddk.h:53
#define InterlockedDecrement
Definition: armddk.h:52
const GUID IID_IUnknown
#define STDMETHODCALLTYPE
Definition: bdasup.h:9
#define ERROR_NOT_ENOUGH_MEMORY
Definition: dderror.h:7
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define MAX_PATH
Definition: compat.h:34
UINT WINAPI GetDriveTypeW(IN LPCWSTR lpRootPathName)
Definition: disk.c:497
BOOL WINAPI GetVolumePathNameW(IN LPCWSTR lpszFileName, IN LPWSTR lpszVolumePathName, IN DWORD cchBufferLength)
Definition: volume.c:815
DWORD WINAPI GetFullPathNameW(IN LPCWSTR lpFileName, IN DWORD nBufferLength, OUT LPWSTR lpBuffer, OUT LPWSTR *lpFilePart)
Definition: path.c:1106
HRESULT WINAPI GetDefaultRecycleBin(IN LPCWSTR pszVolume OPTIONAL, OUT IRecycleBin **pprb)
Definition: recyclebin.c:399
#define swprintf
Definition: precomp.h:40
unsigned long DWORD
Definition: ntddk_ex.h:95
GLdouble s
Definition: gl.h:2039
GLenum GLsizei len
Definition: glext.h:6722
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 debugstr_w
Definition: kernel32.h:32
#define L(x)
Definition: ntvdm.h:50
#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_IRecycleBin
Definition: recyclebin.h:246
static HRESULT STDMETHODCALLTYPE RecycleBinGeneric_RecycleBin_EnumObjects(IN IRecycleBin *This, OUT IRecycleBinEnumList **ppEnumList)
static VOID RecycleBinGeneric_Destructor(struct RecycleBinGeneric *s)
static HRESULT STDMETHODCALLTYPE RecycleBinGeneric_RecycleBin_EmptyRecycleBin(IN IRecycleBin *This)
static ULONG STDMETHODCALLTYPE RecycleBinGeneric_RecycleBin_AddRef(IRecycleBin *This)
HRESULT RecycleBinGeneric_Constructor(OUT IUnknown **ppUnknown)
static HRESULT STDMETHODCALLTYPE RecycleBinGeneric_RecycleBin_DeleteFile(IN IRecycleBin *This, IN LPCWSTR szFileName)
CONST_VTBL struct IRecycleBinVtbl RecycleBinGenericVtbl
static HRESULT STDMETHODCALLTYPE RecycleBinGeneric_RecycleBin_QueryInterface(IRecycleBin *This, REFIID riid, void **ppvObject)
static ULONG STDMETHODCALLTYPE RecycleBinGeneric_RecycleBin_Release(IRecycleBin *This)
HRESULT RecycleBinGenericEnum_Constructor(OUT IRecycleBinEnumList **pprbel)
HRESULT hr
Definition: shlfolder.c:183
#define TRACE(s)
Definition: solgame.cpp:4
IRecycleBin recycleBinImpl
#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
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
DWORD WINAPI GetLogicalDrives(void)
Definition: disk.c:110
#define MoveMemory
Definition: winbase.h:1709
#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 E_NOINTERFACE
Definition: winerror.h:2364
#define HRESULT_FROM_WIN32(x)
Definition: winerror.h:92
#define E_POINTER
Definition: winerror.h:2365
__wchar_t WCHAR
Definition: xmlstorage.h:180
WCHAR * LPWSTR
Definition: xmlstorage.h:184
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185