ReactOS 0.4.16-dev-819-g75c0dc0
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 784 of file recyclebin_v5.cpp.

785{
786 if (!ppUnknown)
787 return E_POINTER;
788
789 *ppUnknown = NULL;
790
791 RecycleBin5 *pThis = new RecycleBin5();
792 if (!pThis)
793 return E_OUTOFMEMORY;
794
795 HRESULT hr = pThis->Init(VolumePath);
796 if (FAILED(hr))
797 {
798 delete pThis;
799 return hr;
800 }
801
802 *ppUnknown = static_cast<IRecycleBin5 *>(pThis);
803 return S_OK;
804}
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 553 of file recyclebin_v5.cpp.

556{
557 LPWSTR BufferName = NULL;
558 LPWSTR Separator; /* Pointer into BufferName buffer */
559 LPWSTR FileName; /* Pointer into BufferName buffer */
560 LPCSTR DesktopIniContents = "[.ShellClassInfo]\r\nCLSID={645FF040-5081-101B-9F08-00AA002F954E}\r\n";
561 INFO2_HEADER Info2Contents[] = { { 5, 0, 0, 0x320, 0 } };
562 DWORD BytesToWrite, BytesWritten, Needed;
564 HRESULT hr;
565
566 Needed = (wcslen(Folder) + 1 + max(wcslen(RECYCLE_BIN_FILE_NAME), wcslen(L"desktop.ini")) + 1) * sizeof(WCHAR);
567 BufferName = (LPWSTR)HeapAlloc(GetProcessHeap(), 0, Needed);
568 if (!BufferName)
569 {
571 goto cleanup;
572 }
573
574 wcscpy(BufferName, Folder);
575 Separator = wcsstr(&BufferName[3], L"\\");
576 if (Separator)
577 *Separator = UNICODE_NULL;
578 if (!CreateDirectoryW(BufferName, NULL) && GetLastError() != ERROR_ALREADY_EXISTS)
579 {
581 goto cleanup;
582 }
584 if (Separator)
585 {
586 *Separator = L'\\';
587 if (!CreateDirectoryW(BufferName, NULL) && GetLastError() != ERROR_ALREADY_EXISTS)
588 {
590 goto cleanup;
591 }
592 }
593
594 if (OwnerSid)
595 {
596 //DWORD rc;
597
598 /* Add ACL to allow only user/SYSTEM to open it */
599 /* FIXME: rc = SetNamedSecurityInfo(
600 BufferName,
601 SE_FILE_OBJECT,
602 ???,
603 OwnerSid,
604 NULL,
605 ???,
606 ???);
607 if (rc != ERROR_SUCCESS)
608 {
609 hr = HRESULT_FROM_WIN32(rc);
610 goto cleanup;
611 }
612 */
613 }
614
615 wcscat(BufferName, L"\\");
616 FileName = &BufferName[wcslen(BufferName)];
617
618 /* Create desktop.ini */
619 wcscpy(FileName, L"desktop.ini");
622 {
624 goto cleanup;
625 }
626 BytesToWrite = strlen(DesktopIniContents);
627 if (!WriteFile(hFile, DesktopIniContents, (DWORD)BytesToWrite, &BytesWritten, NULL))
628 {
630 goto cleanup;
631 }
632 if (BytesWritten != BytesToWrite)
633 {
634 hr = E_FAIL;
635 goto cleanup;
636 }
639
640 /* Create empty INFO2 file */
644 {
646 goto cleanup;
647 }
648 BytesToWrite = sizeof(Info2Contents);
649 if (!WriteFile(hFile, Info2Contents, (DWORD)BytesToWrite, &BytesWritten, NULL))
650 {
652 goto cleanup;
653 }
654 if (BytesWritten == BytesToWrite)
655 hr = S_OK;
656 else
657 hr = E_FAIL;
658
659cleanup:
660 HeapFree(GetProcessHeap(), 0, BufferName);
663 return hr;
664}
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:2119
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170

Referenced by RecycleBin5::Restore().

◆ SHUpdateRecycleBinIcon()

EXTERN_C HRESULT WINAPI SHUpdateRecycleBinIcon ( void  )

Definition at line 1294 of file CRecycleBin.cpp.

1295{
1296 FIXME("stub\n");
1297
1298 // HACK! This dwItem2 should be the icon index in the system image list that has changed.
1299 // FIXME: Call SHMapPIDLToSystemImageListIndex
1300 DWORD dwItem2 = -1;
1301
1303 return S_OK;
1304}
#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::Delete(), and RecycleBin5::Restore().

◆ STDMETHODIMP_()

STDMETHODIMP_ ( ULONG  )

Definition at line 196 of file recyclebin_v5.cpp.

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