ReactOS 0.4.15-dev-8614-gbc76250
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  RecycleBin5
 

Functions

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 15 of file recyclebin_v5.cpp.

17{
18 DWORD RemovableAttributes = FILE_ATTRIBUTE_READONLY;
19 WIN32_FIND_DATAW FindData;
21 LPWSTR FullPath = NULL, pFilePart;
24 BOOL ret = FALSE;
25
28 {
30 ret = TRUE;
31 goto cleanup;
32 }
33 if (FileAttributes & RemovableAttributes)
34 {
35 if (!SetFileAttributesW(FullName, FileAttributes & ~RemovableAttributes))
36 goto cleanup;
37 }
39 {
40 /* Prepare file specification */
42 FullPath = (LPWSTR)HeapAlloc(GetProcessHeap(), 0, (dwLength + 1 + MAX_PATH + 1) * sizeof(WCHAR));
43 if (!FullPath)
44 {
46 goto cleanup;
47 }
48 wcscpy(FullPath, FullName);
49 if (FullPath[dwLength - 1] != '\\')
50 {
51 FullPath[dwLength] = '\\';
52 dwLength++;
53 }
54 pFilePart = &FullPath[dwLength];
55 wcscpy(pFilePart, L"*");
56
57 /* Enumerate contents, and delete it */
58 hSearch = FindFirstFileW(FullPath, &FindData);
59 if (hSearch == INVALID_HANDLE_VALUE)
60 goto cleanup;
61 do
62 {
63 if (!(FindData.cFileName[0] == '.' &&
64 (FindData.cFileName[1] == '\0' || (FindData.cFileName[1] == '.' && FindData.cFileName[2] == '\0'))))
65 {
66 wcscpy(pFilePart, FindData.cFileName);
67 if (!IntDeleteRecursive(FullPath))
68 {
69 FindClose(hSearch);
70 goto cleanup;
71 }
72 }
73 }
74 while (FindNextFileW(hSearch, &FindData));
75 FindClose(hSearch);
77 goto cleanup;
78
79 /* Remove (now empty) directory */
81 goto cleanup;
82 }
83 else
84 {
86 goto cleanup;
87 }
88 ret = TRUE;
89
91 HeapFree(GetProcessHeap(), 0, FullPath);
92 return ret;
93}
#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)
_CRTIMP wchar_t *__cdecl wcscpy(_Out_writes_z_(_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
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:1648
__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 768 of file recyclebin_v5.cpp.

769{
770 if (!ppUnknown)
771 return E_POINTER;
772
773 *ppUnknown = NULL;
774
775 RecycleBin5 *pThis = new RecycleBin5();
776 if (!pThis)
777 return E_OUTOFMEMORY;
778
779 HRESULT hr = pThis->Init(VolumePath);
780 if (FAILED(hr))
781 {
782 delete pThis;
783 return hr;
784 }
785
786 *ppUnknown = static_cast<IRecycleBin5 *>(pThis);
787 return S_OK;
788}
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 537 of file recyclebin_v5.cpp.

540{
541 LPWSTR BufferName = NULL;
542 LPWSTR Separator; /* Pointer into BufferName buffer */
543 LPWSTR FileName; /* Pointer into BufferName buffer */
544 LPCSTR DesktopIniContents = "[.ShellClassInfo]\r\nCLSID={645FF040-5081-101B-9F08-00AA002F954E}\r\n";
545 INFO2_HEADER Info2Contents[] = { { 5, 0, 0, 0x320, 0 } };
546 DWORD BytesToWrite, BytesWritten, Needed;
548 HRESULT hr;
549
550 Needed = (wcslen(Folder) + 1 + max(wcslen(RECYCLE_BIN_FILE_NAME), wcslen(L"desktop.ini")) + 1) * sizeof(WCHAR);
551 BufferName = (LPWSTR)HeapAlloc(GetProcessHeap(), 0, Needed);
552 if (!BufferName)
553 {
555 goto cleanup;
556 }
557
558 wcscpy(BufferName, Folder);
559 Separator = wcsstr(&BufferName[3], L"\\");
560 if (Separator)
561 *Separator = UNICODE_NULL;
562 if (!CreateDirectoryW(BufferName, NULL) && GetLastError() != ERROR_ALREADY_EXISTS)
563 {
565 goto cleanup;
566 }
568 if (Separator)
569 {
570 *Separator = L'\\';
571 if (!CreateDirectoryW(BufferName, NULL) && GetLastError() != ERROR_ALREADY_EXISTS)
572 {
574 goto cleanup;
575 }
576 }
577
578 if (OwnerSid)
579 {
580 //DWORD rc;
581
582 /* Add ACL to allow only user/SYSTEM to open it */
583 /* FIXME: rc = SetNamedSecurityInfo(
584 BufferName,
585 SE_FILE_OBJECT,
586 ???,
587 OwnerSid,
588 NULL,
589 ???,
590 ???);
591 if (rc != ERROR_SUCCESS)
592 {
593 hr = HRESULT_FROM_WIN32(rc);
594 goto cleanup;
595 }
596 */
597 }
598
599 wcscat(BufferName, L"\\");
600 FileName = &BufferName[wcslen(BufferName)];
601
602 /* Create desktop.ini */
603 wcscpy(FileName, L"desktop.ini");
606 {
608 goto cleanup;
609 }
610 BytesToWrite = strlen(DesktopIniContents);
611 if (!WriteFile(hFile, DesktopIniContents, (DWORD)BytesToWrite, &BytesWritten, NULL))
612 {
614 goto cleanup;
615 }
616 if (BytesWritten != BytesToWrite)
617 {
618 hr = E_FAIL;
619 goto cleanup;
620 }
623
624 /* Create empty INFO2 file */
628 {
630 goto cleanup;
631 }
632 BytesToWrite = sizeof(Info2Contents);
633 if (!WriteFile(hFile, Info2Contents, (DWORD)BytesToWrite, &BytesWritten, NULL))
634 {
636 goto cleanup;
637 }
638 if (BytesWritten == BytesToWrite)
639 hr = S_OK;
640 else
641 hr = E_FAIL;
642
643cleanup:
644 HeapFree(GetProcessHeap(), 0, BufferName);
647 return hr;
648}
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
#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:896
_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
_CRTIMP wchar_t *__cdecl wcscat(_Inout_updates_z_(_String_length_(_Dest)+_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
#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().

◆ STDMETHODIMP_()

STDMETHODIMP_ ( ULONG  )

Definition at line 152 of file recyclebin_v5.cpp.

153{
154 TRACE("(%p)\n", this);
155 return InterlockedIncrement(&m_ref);
156}
#define InterlockedIncrement
Definition: armddk.h:53
#define TRACE(s)
Definition: solgame.cpp:4