ReactOS  0.4.14-dev-384-g5b37caa
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 
9 #include "recyclebin_private.h"
10 
12 {
14  IRecycleBin recycleBinImpl;
15 };
16 
19  IRecycleBin *This,
20  REFIID riid,
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;
32  else if (IsEqualIID(riid, &IID_IRecycleBin))
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 
54 static 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 
190 CONST_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 }
static HRESULT STDMETHODCALLTYPE RecycleBinGeneric_RecycleBin_DeleteFile(IN IRecycleBin *This, IN LPCWSTR szFileName)
#define IN
Definition: typedefs.h:38
EXTERN_C const IID IID_IRecycleBin
Definition: recyclebin.h:249
#define REFIID
Definition: guiddef.h:118
#define TRUE
Definition: types.h:120
#define E_NOINTERFACE
Definition: winerror.h:2364
#define HRESULT_FROM_WIN32(x)
Definition: winerror.h:92
VOID WINAPI CoTaskMemFree(LPVOID ptr)
Definition: ifs.c:420
static ULONG STDMETHODCALLTYPE RecycleBinGeneric_RecycleBin_AddRef(IRecycleBin *This)
HRESULT hr
Definition: shlfolder.c:183
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
REFIID riid
Definition: precomp.h:44
HRESULT WINAPI GetDefaultRecycleBin(IN LPCWSTR pszVolume OPTIONAL, OUT IRecycleBin **pprb)
Definition: recyclebin.c:385
HRESULT RecycleBinGeneric_Constructor(OUT IUnknown **ppUnknown)
#define ERROR_NOT_ENOUGH_MEMORY
Definition: dderror.h:7
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
DWORD WINAPI GetFullPathNameW(IN LPCWSTR lpFileName, IN DWORD nBufferLength, OUT LPWSTR lpBuffer, OUT LPWSTR *lpFilePart)
Definition: path.c:1105
BOOL WINAPI GetVolumePathNameW(IN LPCWSTR lpszFileName, IN LPWSTR lpszVolumePathName, IN DWORD cchBufferLength)
Definition: volume.c:815
#define MoveMemory
Definition: winbase.h:1639
static HRESULT STDMETHODCALLTYPE RecycleBinGeneric_RecycleBin_EmptyRecycleBin(IN IRecycleBin *This)
static HRESULT STDMETHODCALLTYPE RecycleBinGeneric_RecycleBin_EnumObjects(IN IRecycleBin *This, OUT IRecycleBinEnumList **ppEnumList)
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
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
#define CONST_VTBL
Definition: objbase.h:222
#define debugstr_w
Definition: kernel32.h:32
smooth NULL
Definition: ftsmooth.c:416
HRESULT RecycleBinGenericEnum_Constructor(OUT IRecycleBinEnumList **pprbel)
#define debugstr_guid
Definition: kernel32.h:35
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
#define TRACE(s)
Definition: solgame.cpp:4
static VOID RecycleBinGeneric_Destructor(struct RecycleBinGeneric *s)
__wchar_t WCHAR
Definition: xmlstorage.h:180
LONG HRESULT
Definition: typedefs.h:77
const GUID IID_IUnknown
#define MAX_PATH
Definition: compat.h:26
#define swprintf(buf, format,...)
Definition: sprintf.c:56
#define STDMETHODCALLTYPE
Definition: bdasup.h:9
unsigned long DWORD
Definition: ntddk_ex.h:95
static ULONG STDMETHODCALLTYPE RecycleBinGeneric_RecycleBin_Release(IRecycleBin *This)
static const WCHAR L[]
Definition: oid.c:1250
#define InterlockedDecrement
Definition: armddk.h:52
CONST_VTBL struct IRecycleBinVtbl RecycleBinGenericVtbl
GLenum GLsizei len
Definition: glext.h:6722
GLdouble s
Definition: gl.h:2039
REFIID LPVOID * ppvObject
Definition: precomp.h:44
UINT WINAPI GetDriveTypeW(IN LPCWSTR lpRootPathName)
Definition: disk.c:497
#define DRIVE_FIXED
Definition: winbase.h:249
static HRESULT STDMETHODCALLTYPE RecycleBinGeneric_RecycleBin_QueryInterface(IRecycleBin *This, REFIID riid, void **ppvObject)
DWORD WINAPI GetLogicalDrives(VOID)
Definition: disk.c:110
#define S_OK
Definition: intsafe.h:59
#define InterlockedIncrement
Definition: armddk.h:53
#define OUT
Definition: typedefs.h:39
unsigned int ULONG
Definition: retypes.h:1
WCHAR * LPWSTR
Definition: xmlstorage.h:184
#define E_POINTER
Definition: winerror.h:2365
signed int * PLONG
Definition: retypes.h:5
LPVOID WINAPI CoTaskMemAlloc(SIZE_T size)
Definition: ifs.c:404
#define IsEqualIID(riid1, riid2)
Definition: guiddef.h:95
#define SUCCEEDED(hr)
Definition: intsafe.h:57
IRecycleBin recycleBinImpl