Mikołaj Zalewski : shell32: Add a Trash virtual folder .

Alexandre Julliard julliard at wine.codeweavers.com
Wed Aug 9 06:03:32 CDT 2006


Module: wine
Branch: refs/heads/master
Commit: 289e469e7c7e624bc70f0b43e8b971743926d90c
URL:    http://source.winehq.org/git/?p=wine.git;a=commit;h=289e469e7c7e624bc70f0b43e8b971743926d90c

Author: Mikołaj Zalewski <mikolaj at zalewski.pl>
Date:   Thu Aug  3 19:04:11 2006 +0200

shell32: Add a Trash virtual folder.

---

 dlls/shell32/Makefile.in    |    1 +
 dlls/shell32/regsvr.c       |   16 +++++++++
 dlls/shell32/shell32_En.rc  |    3 ++
 dlls/shell32/shell32_main.h |    1 +
 dlls/shell32/shellole.c     |    1 +
 dlls/shell32/shresdef.h     |    5 +++
 dlls/shell32/trash.c        |   77 +++++++++++++++++++++++++++++++++++++++++++
 dlls/shell32/xdg.h          |    6 +++
 8 files changed, 110 insertions(+), 0 deletions(-)

diff --git a/dlls/shell32/Makefile.in b/dlls/shell32/Makefile.in
index 58376e9..54b2936 100644
--- a/dlls/shell32/Makefile.in
+++ b/dlls/shell32/Makefile.in
@@ -27,6 +27,7 @@ C_SRCS = \
 	folders.c \
 	iconcache.c \
 	pidl.c \
+	recyclebin.c \
 	regsvr.c \
 	shell32_main.c \
 	shelllink.c \
diff --git a/dlls/shell32/regsvr.c b/dlls/shell32/regsvr.c
index 6efb192..cb8f69b 100644
--- a/dlls/shell32/regsvr.c
+++ b/dlls/shell32/regsvr.c
@@ -660,6 +660,16 @@ static struct regsvr_coclass const cocla
 	SFGAO_FILESYSANCESTOR|SFGAO_FOLDER|SFGAO_HASSUBFOLDER,
 	SFGAO_FILESYSTEM
     },
+    {	&CLSID_RecycleBin,
+	"Trash",
+	IDS_RECYCLEBIN_FOLDER_NAME,
+	NULL,
+	"shell32.dll",
+	"Apartment",
+	SHELLFOLDER_ATTRIBUTES,
+	SFGAO_FOLDER|SFGAO_DROPTARGET|SFGAO_HASPROPSHEET,
+	0
+    },
     { NULL }			/* list terminator */
 };
 
@@ -677,6 +687,7 @@ static struct regsvr_interface const int
 static const WCHAR wszDesktop[] = { 'D','e','s','k','t','o','p',0 };
 static const WCHAR wszSlash[] = { '/', 0 };
 static const WCHAR wszMyDocuments[] = { 'M','y',' ','D','o','c','u','m','e','n','t','s', 0 };
+static const WCHAR wszRecycleBin[] = { 'T','r','a','s','h', 0 };
 
 static struct regsvr_namespace const namespace_extensions_list[] = {
     {   
@@ -689,6 +700,11 @@ static struct regsvr_namespace const nam
         wszDesktop,
         wszMyDocuments
     },
+    {   
+        &CLSID_RecycleBin,
+        wszDesktop,
+        wszRecycleBin
+    },
     { NULL }
 };
 
diff --git a/dlls/shell32/shell32_En.rc b/dlls/shell32/shell32_En.rc
index 03b31f6..7c7caaa 100644
--- a/dlls/shell32/shell32_En.rc
+++ b/dlls/shell32/shell32_En.rc
@@ -145,10 +145,13 @@ STRINGTABLE DISCARDABLE
 	IDS_SHV_COLUMN9		"Comments"
 	IDS_SHV_COLUMN10	"Owner"
 	IDS_SHV_COLUMN11	"Group"
+	IDS_SHV_COLUMN_DELFROM	"Original location"
+	IDS_SHV_COLUMN_DELDATE	"Date deleted"
 
         /* special folders */
 	IDS_DESKTOP		"Desktop"
 	IDS_MYCOMPUTER		"My Computer"
+	IDS_RECYCLEBIN_FOLDER_NAME      "Trash"
 
         /* context menus */
 	IDS_VIEW_LARGE		"Lar&ge Icons"
diff --git a/dlls/shell32/shell32_main.h b/dlls/shell32/shell32_main.h
index 5bc8e64..4463da5 100644
--- a/dlls/shell32/shell32_main.h
+++ b/dlls/shell32/shell32_main.h
@@ -97,6 +97,7 @@ HRESULT WINAPI UnixFolder_Constructor(IU
 HRESULT WINAPI UnixDosFolder_Constructor(IUnknown * pUnkOuter, REFIID riid, LPVOID *ppv);
 HRESULT WINAPI FolderShortcut_Constructor(IUnknown * pUnkOuter, REFIID riid, LPVOID *ppv);
 HRESULT WINAPI MyDocuments_Constructor(IUnknown * pUnkOuter, REFIID riid, LPVOID *ppv);
+HRESULT WINAPI RecycleBin_Constructor(IUnknown * pUnkOuter, REFIID riif, LPVOID *ppv);
 HRESULT WINAPI ShellFSFolder_Constructor(IUnknown * pUnkOuter, REFIID riid, LPVOID *ppv);
 extern HRESULT CPanel_GetIconLocationW(LPITEMIDLIST, LPWSTR, UINT, int*);
 HRESULT WINAPI CPanel_ExtractIconA(LPITEMIDLIST pidl, LPCSTR pszFile, UINT nIconIndex, HICON *phiconLarge, HICON *phiconSmall, UINT nIconSize);
diff --git a/dlls/shell32/shellole.c b/dlls/shell32/shellole.c
index d154cbe..b16be1b 100644
--- a/dlls/shell32/shellole.c
+++ b/dlls/shell32/shellole.c
@@ -74,6 +74,7 @@ static const struct {
 	{&CLSID_UnixDosFolder,  &UnixDosFolder_Constructor},
 	{&CLSID_FolderShortcut, &FolderShortcut_Constructor},
 	{&CLSID_MyDocuments,    &MyDocuments_Constructor},
+	{&CLSID_RecycleBin,     &RecycleBin_Constructor},
 	{NULL,NULL}
 };
 
diff --git a/dlls/shell32/shresdef.h b/dlls/shell32/shresdef.h
index 3f0e1d7..ab475eb 100644
--- a/dlls/shell32/shresdef.h
+++ b/dlls/shell32/shresdef.h
@@ -33,6 +33,8 @@ #define IDS_SHV_COLUMN8		14
 #define IDS_SHV_COLUMN9		15
 #define IDS_SHV_COLUMN10	16
 #define IDS_SHV_COLUMN11	17
+#define IDS_SHV_COLUMN_DELFROM  18
+#define IDS_SHV_COLUMN_DELDATE  19
 
 #define IDS_DESKTOP		20
 #define IDS_MYCOMPUTER		21
@@ -91,6 +93,9 @@ #define IDS_TRASHITEM_TEXT          138
 #define IDS_TRASHMULTIPLE_TEXT      139
 #define IDS_CANTTRASH_TEXT          140
 
+/* Note: this string is referenced from the registry*/
+#define IDS_RECYCLEBIN_FOLDER_NAME   8964
+
 /* browse for folder dialog box */
 #define IDD_STATUS		0x3743
 #define IDD_TITLE		0x3742
diff --git a/dlls/shell32/trash.c b/dlls/shell32/trash.c
index 0432694..d5d7fc3 100644
--- a/dlls/shell32/trash.c
+++ b/dlls/shell32/trash.c
@@ -306,3 +306,80 @@ BOOL TRASH_TrashFile(LPCWSTR wszPath)
     HeapFree(GetProcessHeap(), 0, unix_path);
     return result;
 }
+
+/*
+ * The item ID of a trashed element is built as follows:
+ *  NUL byte                    - in most PIDLs the first byte is the type so we keep it constant
+ *  WIN32_FIND_DATAW structure  - with data about original file attributes
+ *  bucket name                 - currently only an empty string meaning the home bucket is supported
+ *  trash file name             - a NUL-terminated string
+ */
+struct tagTRASH_ELEMENT
+{
+    TRASH_BUCKET *bucket;
+    LPSTR filename;
+};
+
+static HRESULT TRASH_CreateSimplePIDL(const TRASH_ELEMENT *element, const WIN32_FIND_DATAW *data, LPITEMIDLIST *pidlOut)
+{
+    LPITEMIDLIST pidl = SHAlloc(2+1+sizeof(WIN32_FIND_DATAW)+1+lstrlenA(element->filename)+1+2);
+    *pidlOut = NULL;
+    if (pidl == NULL)
+        return E_OUTOFMEMORY;
+    pidl->mkid.cb = (USHORT)(2+1+sizeof(WIN32_FIND_DATAW)+1+lstrlenA(element->filename)+1);
+    pidl->mkid.abID[0] = 0;
+    memcpy(pidl->mkid.abID+1, data, sizeof(WIN32_FIND_DATAW));
+    pidl->mkid.abID[1+sizeof(WIN32_FIND_DATAW)] = 0;
+    lstrcpyA((LPSTR)(pidl->mkid.abID+1+sizeof(WIN32_FIND_DATAW)+1), element->filename);
+    *(USHORT *)(pidl->mkid.abID+1+sizeof(WIN32_FIND_DATAW)+1+lstrlenA(element->filename)+1) = 0;
+    *pidlOut = pidl;
+    return S_OK;
+}
+
+/***********************************************************************
+ *      TRASH_UnpackItemID [Internal]
+ *
+ * DESCRITION:
+ * Extract the information stored in an Item ID. The TRASH_ELEMENT
+ * identifies the element in the Trash. The WIN32_FIND_DATA contains the
+ * information about the original file. The data->ftLastAccessTime contains
+ * the deletion time
+ *
+ * PARAMETER(S):
+ * [I] id : the ID of the item
+ * [O] element : the trash element this item id contains. Can be NULL if not needed
+ * [O] data : the WIN32_FIND_DATA of the original file. Can be NULL is not needed
+ */                 
+HRESULT TRASH_UnpackItemID(LPCSHITEMID id, TRASH_ELEMENT *element, WIN32_FIND_DATAW *data)
+{
+    if (id->cb < 2+1+sizeof(WIN32_FIND_DATAW)+2)
+        return E_INVALIDARG;
+    if (id->abID[0] != 0 || id->abID[1+sizeof(WIN32_FIND_DATAW)] != 0)
+        return E_INVALIDARG;
+    if (memchr(id->abID+1+sizeof(WIN32_FIND_DATAW)+1, 0, id->cb-(2+1+sizeof(WIN32_FIND_DATAW)+1)) == NULL)
+        return E_INVALIDARG;
+
+    if (data != NULL)
+        *data = *(WIN32_FIND_DATAW *)(id->abID+1);
+    if (element != NULL)
+    {
+        element->bucket = home_trash;
+        element->filename = StrDupA((LPCSTR)(id->abID+1+sizeof(WIN32_FIND_DATAW)+1));
+        if (element->filename == NULL)
+            return E_OUTOFMEMORY;
+    }
+    return S_OK;
+}
+
+void TRASH_DisposeElement(TRASH_ELEMENT *element)
+{
+    if (element)
+        SHFree(element->filename);
+}
+
+HRESULT TRASH_EnumItems(LPITEMIDLIST **pidls, int *count)
+{
+    *count = 0;
+    *pidls = SHAlloc(0);
+    return S_OK;
+}
diff --git a/dlls/shell32/xdg.h b/dlls/shell32/xdg.h
index 46a8618..90f10f7 100644
--- a/dlls/shell32/xdg.h
+++ b/dlls/shell32/xdg.h
@@ -33,7 +33,13 @@ #define XDG_URLENCODE 0x1
 BOOL XDG_WriteDesktopStringEntry(int fd, const char *keyName, DWORD dwFlags, const char *value);
 
 /* implemented in trash.c */
+typedef struct tagTRASH_ELEMENT TRASH_ELEMENT;
+
 BOOL TRASH_CanTrashFile(LPCWSTR wszPath);
 BOOL TRASH_TrashFile(LPCWSTR wszPath);
+HRESULT TRASH_UnpackItemID(LPCSHITEMID id, TRASH_ELEMENT *element, WIN32_FIND_DATAW *data);
+HRESULT TRASH_EnumItems(LPITEMIDLIST **pidls, int *count);
+void TRASH_DisposeElement(TRASH_ELEMENT *element);
+
 
 #endif /* ndef __XDG_H__ */




More information about the wine-cvs mailing list