ReactOS 0.4.16-dev-597-gdbf7844
recyclebin_v5.cpp File Reference
#include "recyclebin_private.h"
#include <atlstr.h>
#include <shlwapi.h>
#include "sddl.h"
Include dependency graph for recyclebin_v5.cpp:

Go to the source code of this file.

Classes

class  CZZWStr
 
class  RecycleBin5
 

Functions

EXTERN_C HRESULT WINAPI SHUpdateRecycleBinIcon (void)
 
static int SHELL_SingleFileOperation (HWND hWnd, UINT Op, LPCWSTR pszFrom, LPCWSTR pszTo, FILEOP_FLAGS Flags)
 
static BOOL IntDeleteRecursive (IN LPCWSTR FullName)
 
 STDMETHODIMP_ (ULONG) RecycleBin5
 
static HRESULT RecycleBin5_Create (_In_ LPCWSTR Folder, _In_ PSID OwnerSid OPTIONAL)
 
EXTERN_C HRESULT RecycleBin5_Constructor (_In_ LPCWSTR VolumePath, _Out_ IUnknown **ppUnknown)
 

Function Documentation

◆ IntDeleteRecursive()

static BOOL IntDeleteRecursive ( IN LPCWSTR  FullName)
static

Definition at line 49 of file recyclebin_v5.cpp.

51{
52 DWORD RemovableAttributes = FILE_ATTRIBUTE_READONLY;
53 WIN32_FIND_DATAW FindData;
55 LPWSTR FullPath = NULL, pFilePart;
58 BOOL ret = FALSE;
59
62 {
64 ret = TRUE;
65 goto cleanup;
66 }
67 if (FileAttributes & RemovableAttributes)
68 {
69 if (!SetFileAttributesW(FullName, FileAttributes & ~RemovableAttributes))
70 goto cleanup;
71 }
73 {
74 /* Prepare file specification */
76 FullPath = (LPWSTR)HeapAlloc(GetProcessHeap(), 0, (dwLength + 1 + MAX_PATH + 1) * sizeof(WCHAR));
77 if (!FullPath)
78 {
80 goto cleanup;
81 }
82 wcscpy(FullPath, FullName);
83 if (FullPath[dwLength - 1] != '\\')
84 {
85 FullPath[dwLength] = '\\';
86 dwLength++;
87 }
88 pFilePart = &FullPath[dwLength];
89 wcscpy(pFilePart, L"*");
90
91 /* Enumerate contents, and delete it */
92 hSearch = FindFirstFileW(FullPath, &FindData);
93 if (hSearch == INVALID_HANDLE_VALUE)
94 goto cleanup;
95 do
96 {
97 if (!(FindData.cFileName[0] == '.' &&
98 (FindData.cFileName[1] == '\0' || (FindData.cFileName[1] == '.' && FindData.cFileName[2] == '\0'))))
99 {
100 wcscpy(pFilePart, FindData.cFileName);
101 if (!IntDeleteRecursive(FullPath))
102 {
103 FindClose(hSearch);
104 goto cleanup;
105 }
106 }
107 }
108 while (FindNextFileW(hSearch, &FindData));
109 FindClose(hSearch);
111 goto cleanup;
112
113 /* Remove (now empty) directory */
115 goto cleanup;
116 }
117 else
118 {
119 if (!DeleteFileW(FullName))
120 goto cleanup;
121 }
122 ret = TRUE;
123
124cleanup:
125 HeapFree(GetProcessHeap(), 0, FullPath);
126 return ret;
127}
wcscpy
#define ERROR_NOT_ENOUGH_MEMORY
Definition: dderror.h:7
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define GetProcessHeap()
Definition: compat.h:736
#define SetLastError(x)
Definition: compat.h:752
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
#define HeapAlloc
Definition: compat.h:733
#define MAX_PATH
Definition: compat.h:34
#define HeapFree(x, y, z)
Definition: compat.h:735
static DWORD DWORD * dwLength
Definition: fusion.c:86
static void cleanup(void)
Definition: main.c:1335
BOOL WINAPI DeleteFileW(IN LPCWSTR lpFileName)
Definition: delete.c:39
BOOL WINAPI RemoveDirectoryW(IN LPCWSTR lpPathName)
Definition: dir.c:732
DWORD WINAPI GetFileAttributesW(LPCWSTR lpFileName)
Definition: fileinfo.c:652
BOOL WINAPI SetFileAttributesW(LPCWSTR lpFileName, DWORD dwFileAttributes)
Definition: fileinfo.c:794
HANDLE WINAPI FindFirstFileW(IN LPCWSTR lpFileName, OUT LPWIN32_FIND_DATAW lpFindFileData)
Definition: find.c:320
BOOL WINAPI FindClose(HANDLE hFindFile)
Definition: find.c:502
BOOL WINAPI FindNextFileW(IN HANDLE hFindFile, OUT LPWIN32_FIND_DATAW lpFindFileData)
Definition: find.c:382
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
_Must_inspect_result_ _In_opt_ PFLT_INSTANCE _Out_ PHANDLE _In_ ACCESS_MASK _In_ POBJECT_ATTRIBUTES _Out_ PIO_STATUS_BLOCK _In_opt_ PLARGE_INTEGER _In_ ULONG FileAttributes
Definition: fltkernel.h:1236
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define ERROR_FILE_NOT_FOUND
Definition: disk.h:79
#define FILE_ATTRIBUTE_READONLY
Definition: nt_native.h:702
#define FILE_ATTRIBUTE_DIRECTORY
Definition: nt_native.h:705
#define L(x)
Definition: ntvdm.h:50
static BOOL IntDeleteRecursive(IN LPCWSTR FullName)
ULONG_PTR SIZE_T
Definition: typedefs.h:80
#define INVALID_FILE_ATTRIBUTES
Definition: vfdcmd.c:23
int ret
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define ERROR_NO_MORE_FILES
Definition: winerror.h:121
_In_ PSTRING FullName
Definition: rtlfuncs.h:1665
__wchar_t WCHAR
Definition: xmlstorage.h:180
WCHAR * LPWSTR
Definition: xmlstorage.h:184

Referenced by RecycleBin5::Delete(), and IntDeleteRecursive().

◆ RecycleBin5_Constructor()

EXTERN_C HRESULT RecycleBin5_Constructor ( _In_ LPCWSTR  VolumePath,
_Out_ IUnknown **  ppUnknown 
)

Definition at line 815 of file recyclebin_v5.cpp.

816{
817 if (!ppUnknown)
818 return E_POINTER;
819
820 *ppUnknown = NULL;
821
822 RecycleBin5 *pThis = new RecycleBin5();
823 if (!pThis)
824 return E_OUTOFMEMORY;
825
826 HRESULT hr = pThis->Init(VolumePath);
827 if (FAILED(hr))
828 {
829 delete pThis;
830 return hr;
831 }
832
833 *ppUnknown = static_cast<IRecycleBin5 *>(pThis);
834 return S_OK;
835}
HRESULT Init(_In_ LPCWSTR VolumePath)
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
#define S_OK
Definition: intsafe.h:52
#define FAILED(hr)
Definition: intsafe.h:51
interface IRecycleBin5 IRecycleBin5
Definition: recyclebin_v5.h:27
HRESULT hr
Definition: shlfolder.c:183
#define E_POINTER
Definition: winerror.h:2365

Referenced by GetDefaultRecycleBin().

◆ RecycleBin5_Create()

static HRESULT RecycleBin5_Create ( _In_ LPCWSTR  Folder,
_In_ PSID OwnerSid  OPTIONAL 
)
static

Definition at line 584 of file recyclebin_v5.cpp.

587{
588 LPWSTR BufferName = NULL;
589 LPWSTR Separator; /* Pointer into BufferName buffer */
590 LPWSTR FileName; /* Pointer into BufferName buffer */
591 LPCSTR DesktopIniContents = "[.ShellClassInfo]\r\nCLSID={645FF040-5081-101B-9F08-00AA002F954E}\r\n";
592 INFO2_HEADER Info2Contents[] = { { 5, 0, 0, 0x320, 0 } };
593 DWORD BytesToWrite, BytesWritten, Needed;
595 HRESULT hr;
596
597 Needed = (wcslen(Folder) + 1 + max(wcslen(RECYCLE_BIN_FILE_NAME), wcslen(L"desktop.ini")) + 1) * sizeof(WCHAR);
598 BufferName = (LPWSTR)HeapAlloc(GetProcessHeap(), 0, Needed);
599 if (!BufferName)
600 {
602 goto cleanup;
603 }
604
605 wcscpy(BufferName, Folder);
606 Separator = wcsstr(&BufferName[3], L"\\");
607 if (Separator)
608 *Separator = UNICODE_NULL;
609 if (!CreateDirectoryW(BufferName, NULL) && GetLastError() != ERROR_ALREADY_EXISTS)
610 {
612 goto cleanup;
613 }
615 if (Separator)
616 {
617 *Separator = L'\\';
618 if (!CreateDirectoryW(BufferName, NULL) && GetLastError() != ERROR_ALREADY_EXISTS)
619 {
621 goto cleanup;
622 }
623 }
624
625 if (OwnerSid)
626 {
627 //DWORD rc;
628
629 /* Add ACL to allow only user/SYSTEM to open it */
630 /* FIXME: rc = SetNamedSecurityInfo(
631 BufferName,
632 SE_FILE_OBJECT,
633 ???,
634 OwnerSid,
635 NULL,
636 ???,
637 ???);
638 if (rc != ERROR_SUCCESS)
639 {
640 hr = HRESULT_FROM_WIN32(rc);
641 goto cleanup;
642 }
643 */
644 }
645
646 wcscat(BufferName, L"\\");
647 FileName = &BufferName[wcslen(BufferName)];
648
649 /* Create desktop.ini */
650 wcscpy(FileName, L"desktop.ini");
653 {
655 goto cleanup;
656 }
657 BytesToWrite = strlen(DesktopIniContents);
658 if (!WriteFile(hFile, DesktopIniContents, (DWORD)BytesToWrite, &BytesWritten, NULL))
659 {
661 goto cleanup;
662 }
663 if (BytesWritten != BytesToWrite)
664 {
665 hr = E_FAIL;
666 goto cleanup;
667 }
670
671 /* Create empty INFO2 file */
675 {
677 goto cleanup;
678 }
679 BytesToWrite = sizeof(Info2Contents);
680 if (!WriteFile(hFile, Info2Contents, (DWORD)BytesToWrite, &BytesWritten, NULL))
681 {
683 goto cleanup;
684 }
685 if (BytesWritten == BytesToWrite)
686 hr = S_OK;
687 else
688 hr = E_FAIL;
689
690cleanup:
691 HeapFree(GetProcessHeap(), 0, BufferName);
694 return hr;
695}
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
wcscat
#define E_FAIL
Definition: ddrawi.h:102
#define CloseHandle
Definition: compat.h:739
#define GENERIC_READ
Definition: compat.h:135
#define CreateFileW
Definition: compat.h:741
BOOL WINAPI CreateDirectoryW(IN LPCWSTR lpPathName, IN LPSECURITY_ATTRIBUTES lpSecurityAttributes)
Definition: dir.c:90
BOOL WINAPI WriteFile(IN HANDLE hFile, IN LPCVOID lpBuffer, IN DWORD nNumberOfBytesToWrite OPTIONAL, OUT LPDWORD lpNumberOfBytesWritten, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: rw.c:24
struct _FileName FileName
Definition: fatprocs.h:897
_CONST_RETURN wchar_t *__cdecl wcsstr(_In_z_ const wchar_t *_Str, _In_z_ const wchar_t *_SubStr)
#define CREATE_ALWAYS
Definition: disk.h:72
#define ERROR_ALREADY_EXISTS
Definition: disk.h:80
_In_ HANDLE hFile
Definition: mswsock.h:90
#define FILE_ATTRIBUTE_HIDDEN
Definition: nt_native.h:703
#define FILE_ATTRIBUTE_SYSTEM
Definition: nt_native.h:704
#define GENERIC_WRITE
Definition: nt_native.h:90
#define UNICODE_NULL
#define RECYCLE_BIN_FILE_NAME
#define max(a, b)
Definition: svc.c:63
_Must_inspect_result_ _In_ WDFIOTARGET _In_opt_ WDFREQUEST _In_opt_ PWDF_MEMORY_DESCRIPTOR _In_opt_ PLONGLONG _In_opt_ PWDF_REQUEST_SEND_OPTIONS _Out_opt_ PULONG_PTR BytesWritten
Definition: wdfiotarget.h:960
#define HRESULT_FROM_WIN32(x)
Definition: winerror.h:92
const char * LPCSTR
Definition: xmlstorage.h:183

Referenced by RecycleBin5::Init().

◆ SHELL_SingleFileOperation()

static int SHELL_SingleFileOperation ( HWND  hWnd,
UINT  Op,
LPCWSTR  pszFrom,
LPCWSTR  pszTo,
FILEOP_FLAGS  Flags 
)
static

Definition at line 39 of file recyclebin_v5.cpp.

40{
41 CZZWStr szzFrom, szzTo;
42 if (!szzFrom.Initialize(pszFrom) || !szzTo.Initialize(pszTo))
43 return ERROR_OUTOFMEMORY; // Note: Not one of the DE errors but also not in the DE range
44 SHFILEOPSTRUCTW fos = { hWnd, Op, szzFrom.c_str(), szzTo.c_str(), Flags };
45 return SHFileOperationW(&fos);
46}
HWND hWnd
Definition: settings.c:17
bool Initialize(LPCWSTR Str)
LPWSTR c_str()
#define ERROR_OUTOFMEMORY
Definition: deptool.c:13
int WINAPI SHFileOperationW(LPSHFILEOPSTRUCTW lpFileOp)
Definition: shlfileop.cpp:1990
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170

Referenced by RecycleBin5::Restore().

◆ SHUpdateRecycleBinIcon()

EXTERN_C HRESULT WINAPI SHUpdateRecycleBinIcon ( void  )

Definition at line 1219 of file CRecycleBin.cpp.

1220{
1221 FIXME("stub\n");
1222
1223 // HACK! This dwItem2 should be the icon index in the system image list that has changed.
1224 // FIXME: Call SHMapPIDLToSystemImageListIndex
1225 DWORD dwItem2 = -1;
1226
1228 return S_OK;
1229}
#define FIXME(fmt,...)
Definition: precomp.h:53
EXTERN_C void WINAPI SHChangeNotify(LONG wEventId, UINT uFlags, LPCVOID dwItem1, LPCVOID dwItem2)
#define SHCNE_UPDATEIMAGE
Definition: shlobj.h:1905
#define SHCNF_DWORD
Definition: shlobj.h:1924

Referenced by RecycleBin5::Restore().

◆ STDMETHODIMP_()

STDMETHODIMP_ ( ULONG  )

Definition at line 193 of file recyclebin_v5.cpp.

194{
195 TRACE("(%p)\n", this);
196 return InterlockedIncrement(&m_ref);
197}
#define InterlockedIncrement
Definition: armddk.h:53
#define TRACE(s)
Definition: solgame.cpp:4