Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenrecyclebin_generic.c
Go to the documentation of this file.
00001 /* 00002 * PROJECT: Recycle bin management 00003 * LICENSE: GPL v2 - See COPYING in the top level directory 00004 * FILE: lib/recyclebin/recyclebin_generic.c 00005 * PURPOSE: Deals with a system-wide recycle bin 00006 * PROGRAMMERS: Copyright 2007 Hervé Poussineau (hpoussin@reactos.org) 00007 */ 00008 00009 #define COBJMACROS 00010 #include "recyclebin_private.h" 00011 #include <stdio.h> 00012 00013 WINE_DEFAULT_DEBUG_CHANNEL(recyclebin); 00014 00015 struct RecycleBinGeneric 00016 { 00017 ULONG ref; 00018 IRecycleBin recycleBinImpl; 00019 }; 00020 00021 static HRESULT STDMETHODCALLTYPE 00022 RecycleBinGeneric_RecycleBin_QueryInterface( 00023 IRecycleBin *This, 00024 REFIID riid, 00025 void **ppvObject) 00026 { 00027 struct RecycleBinGeneric *s = CONTAINING_RECORD(This, struct RecycleBinGeneric, recycleBinImpl); 00028 00029 TRACE("(%p, %s, %p)\n", This, debugstr_guid(riid), ppvObject); 00030 00031 if (!ppvObject) 00032 return E_POINTER; 00033 00034 if (IsEqualIID(riid, &IID_IUnknown)) 00035 *ppvObject = &s->recycleBinImpl; 00036 else if (IsEqualIID(riid, &IID_IRecycleBin)) 00037 *ppvObject = &s->recycleBinImpl; 00038 else 00039 { 00040 *ppvObject = NULL; 00041 return E_NOINTERFACE; 00042 } 00043 00044 IUnknown_AddRef(This); 00045 return S_OK; 00046 } 00047 00048 static ULONG STDMETHODCALLTYPE 00049 RecycleBinGeneric_RecycleBin_AddRef( 00050 IRecycleBin *This) 00051 { 00052 struct RecycleBinGeneric *s = CONTAINING_RECORD(This, struct RecycleBinGeneric, recycleBinImpl); 00053 ULONG refCount = InterlockedIncrement((PLONG)&s->ref); 00054 TRACE("(%p)\n", This); 00055 return refCount; 00056 } 00057 00058 static VOID 00059 RecycleBinGeneric_Destructor( 00060 struct RecycleBinGeneric *s) 00061 { 00062 TRACE("(%p)\n", s); 00063 00064 CoTaskMemFree(s); 00065 } 00066 00067 static ULONG STDMETHODCALLTYPE 00068 RecycleBinGeneric_RecycleBin_Release( 00069 IRecycleBin *This) 00070 { 00071 struct RecycleBinGeneric *s = CONTAINING_RECORD(This, struct RecycleBinGeneric, recycleBinImpl); 00072 ULONG refCount; 00073 00074 TRACE("(%p)\n", This); 00075 00076 refCount = InterlockedDecrement((PLONG)&s->ref); 00077 00078 if (refCount == 0) 00079 RecycleBinGeneric_Destructor(s); 00080 00081 return refCount; 00082 } 00083 00084 static HRESULT STDMETHODCALLTYPE 00085 RecycleBinGeneric_RecycleBin_DeleteFile( 00086 IN IRecycleBin *This, 00087 IN LPCWSTR szFileName) 00088 { 00089 IRecycleBin *prb; 00090 LPWSTR szFullName = NULL; 00091 DWORD dwBufferLength = 0; 00092 DWORD len; 00093 WCHAR szVolume[MAX_PATH]; 00094 HRESULT hr; 00095 00096 TRACE("(%p, %s)\n", This, debugstr_w(szFileName)); 00097 00098 /* Get full file name */ 00099 while (TRUE) 00100 { 00101 len = GetFullPathNameW(szFileName, dwBufferLength, szFullName, NULL); 00102 if (len == 0) 00103 { 00104 if (szFullName) 00105 CoTaskMemFree(szFullName); 00106 return HRESULT_FROM_WIN32(GetLastError()); 00107 } 00108 else if (len < dwBufferLength) 00109 break; 00110 if (szFullName) 00111 CoTaskMemFree(szFullName); 00112 dwBufferLength = len; 00113 szFullName = CoTaskMemAlloc(dwBufferLength * sizeof(WCHAR)); 00114 if (!szFullName) 00115 return HRESULT_FROM_WIN32(ERROR_NOT_ENOUGH_MEMORY); 00116 } 00117 00118 /* Get associated volume path */ 00119 #ifndef __REACTOS__ 00120 if (!GetVolumePathNameW(szFullName, szVolume, MAX_PATH)) 00121 { 00122 CoTaskMemFree(szFullName); 00123 return HRESULT_FROM_WIN32(GetLastError()); 00124 } 00125 #else 00126 swprintf(szVolume, L"%c:\\", szFullName[0]); 00127 #endif 00128 00129 /* Skip namespace (if any) */ 00130 if (szVolume[0] == '\\' 00131 && szVolume[1] == '\\' 00132 && (szVolume[2] == '.' || szVolume[2] == '?') 00133 && szVolume[3] == '\\') 00134 { 00135 MoveMemory(szVolume, &szVolume[4], (MAX_PATH - 4) * sizeof(WCHAR)); 00136 } 00137 00138 hr = GetDefaultRecycleBin(szVolume, &prb); 00139 if (!SUCCEEDED(hr)) 00140 { 00141 CoTaskMemFree(szFullName); 00142 return hr; 00143 } 00144 00145 hr = IRecycleBin_DeleteFile(prb, szFullName); 00146 CoTaskMemFree(szFullName); 00147 IRecycleBin_Release(prb); 00148 return hr; 00149 } 00150 00151 static HRESULT STDMETHODCALLTYPE 00152 RecycleBinGeneric_RecycleBin_EmptyRecycleBin( 00153 IN IRecycleBin *This) 00154 { 00155 WCHAR szVolumeName[MAX_PATH]; 00156 DWORD dwLogicalDrives, i; 00157 IRecycleBin *prb; 00158 HRESULT hr; 00159 00160 TRACE("(%p)\n", This); 00161 00162 dwLogicalDrives = GetLogicalDrives(); 00163 if (dwLogicalDrives == 0) 00164 return HRESULT_FROM_WIN32(GetLastError()); 00165 00166 for (i = 0; i < 26; i++) 00167 { 00168 if (!(dwLogicalDrives & (1 << i))) 00169 continue; 00170 swprintf(szVolumeName, L"%c:\\", 'A' + i); 00171 if (GetDriveTypeW(szVolumeName) != DRIVE_FIXED) 00172 continue; 00173 00174 hr = GetDefaultRecycleBin(szVolumeName, &prb); 00175 if (!SUCCEEDED(hr)) 00176 return hr; 00177 00178 hr = IRecycleBin_EmptyRecycleBin(prb); 00179 IRecycleBin_Release(prb); 00180 } 00181 00182 return S_OK; 00183 } 00184 00185 static HRESULT STDMETHODCALLTYPE 00186 RecycleBinGeneric_RecycleBin_EnumObjects( 00187 IN IRecycleBin *This, 00188 OUT IRecycleBinEnumList **ppEnumList) 00189 { 00190 TRACE("(%p, %p)\n", This, ppEnumList); 00191 return RecycleBinGenericEnum_Constructor(ppEnumList); 00192 } 00193 00194 CONST_VTBL struct IRecycleBinVtbl RecycleBinGenericVtbl = 00195 { 00196 RecycleBinGeneric_RecycleBin_QueryInterface, 00197 RecycleBinGeneric_RecycleBin_AddRef, 00198 RecycleBinGeneric_RecycleBin_Release, 00199 RecycleBinGeneric_RecycleBin_DeleteFile, 00200 RecycleBinGeneric_RecycleBin_EmptyRecycleBin, 00201 RecycleBinGeneric_RecycleBin_EnumObjects, 00202 }; 00203 00204 HRESULT RecycleBinGeneric_Constructor(OUT IUnknown **ppUnknown) 00205 { 00206 /* This RecycleBin implementation was introduced to be able to manage all 00207 * drives at once, and instanciate the 'real' implementations when needed */ 00208 struct RecycleBinGeneric *s; 00209 00210 s = CoTaskMemAlloc(sizeof(struct RecycleBinGeneric)); 00211 if (!s) 00212 return E_OUTOFMEMORY; 00213 s->ref = 1; 00214 s->recycleBinImpl.lpVtbl = &RecycleBinGenericVtbl; 00215 00216 *ppUnknown = (IUnknown *)&s->recycleBinImpl; 00217 return S_OK; 00218 } Generated on Sun May 27 2012 04:36:16 for ReactOS by
1.7.6.1
|