2006-08-03 19:11:07 +02:00
|
|
|
/*
|
2021-09-16 17:16:57 +02:00
|
|
|
* Trash virtual folder support
|
2006-08-03 19:11:07 +02:00
|
|
|
*
|
|
|
|
* Copyright (C) 2006 Mikolaj Zalewski
|
2011-07-08 16:46:44 +02:00
|
|
|
* Copyright 2011 Jay Yang
|
2021-09-16 17:16:57 +02:00
|
|
|
* Copyright 2021 Alexandre Julliard
|
2006-08-03 19:11:07 +02:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define COBJMACROS
|
2006-10-18 21:24:50 +02:00
|
|
|
#define NONAMELESSUNION
|
2006-08-03 19:11:07 +02:00
|
|
|
|
|
|
|
#include <stdarg.h>
|
|
|
|
|
|
|
|
#include "winerror.h"
|
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
2021-09-17 17:16:11 +02:00
|
|
|
#include "winternl.h"
|
2006-08-03 19:11:07 +02:00
|
|
|
#include "winreg.h"
|
|
|
|
#include "winuser.h"
|
|
|
|
#include "shlwapi.h"
|
2011-08-19 13:16:33 +02:00
|
|
|
#include "ntquery.h"
|
2006-08-03 19:11:07 +02:00
|
|
|
#include "shlobj.h"
|
|
|
|
#include "shresdef.h"
|
2011-07-08 16:46:57 +02:00
|
|
|
#include "shellfolder.h"
|
2011-07-08 16:46:44 +02:00
|
|
|
#include "shellapi.h"
|
2011-07-08 16:46:49 +02:00
|
|
|
#include "knownfolders.h"
|
2006-08-03 19:11:07 +02:00
|
|
|
#include "wine/debug.h"
|
|
|
|
|
|
|
|
#include "shell32_main.h"
|
2011-07-08 16:47:03 +02:00
|
|
|
#include "pidl.h"
|
2021-09-10 18:50:19 +02:00
|
|
|
#include "shfldr.h"
|
2006-08-03 19:11:07 +02:00
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(recyclebin);
|
|
|
|
|
2021-09-10 18:50:19 +02:00
|
|
|
static const shvheader RecycleBinColumns[] =
|
|
|
|
{
|
|
|
|
{&FMTID_Storage, PID_STG_NAME, IDS_SHV_COLUMN1, SHCOLSTATE_TYPE_STR|SHCOLSTATE_ONBYDEFAULT, LVCFMT_LEFT, 30},
|
|
|
|
{&FMTID_Displaced, PID_DISPLACED_FROM, IDS_SHV_COLUMN_DELFROM, SHCOLSTATE_TYPE_STR|SHCOLSTATE_ONBYDEFAULT, LVCFMT_LEFT, 30},
|
|
|
|
{&FMTID_Displaced, PID_DISPLACED_DATE, IDS_SHV_COLUMN_DELDATE, SHCOLSTATE_TYPE_DATE|SHCOLSTATE_ONBYDEFAULT, LVCFMT_LEFT, 20},
|
|
|
|
{&FMTID_Storage, PID_STG_SIZE, IDS_SHV_COLUMN2, SHCOLSTATE_TYPE_INT|SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 20},
|
|
|
|
{&FMTID_Storage, PID_STG_STORAGETYPE,IDS_SHV_COLUMN3, SHCOLSTATE_TYPE_INT|SHCOLSTATE_ONBYDEFAULT, LVCFMT_LEFT, 20},
|
|
|
|
{&FMTID_Storage, PID_STG_WRITETIME, IDS_SHV_COLUMN4, SHCOLSTATE_TYPE_DATE|SHCOLSTATE_ONBYDEFAULT, LVCFMT_LEFT, 20},
|
|
|
|
/* {&FMTID_Storage, PID_STG_CREATETIME, "creation time", SHCOLSTATE_TYPE_DATE, LVCFMT_LEFT, 20}, */
|
|
|
|
/* {&FMTID_Storage, PID_STG_ATTRIBUTES, "attribs", SHCOLSTATE_TYPE_STR, LVCFMT_LEFT, 20}, */
|
2006-08-03 19:11:07 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#define COLUMN_NAME 0
|
|
|
|
#define COLUMN_DELFROM 1
|
|
|
|
#define COLUMN_DATEDEL 2
|
|
|
|
#define COLUMN_SIZE 3
|
|
|
|
#define COLUMN_TYPE 4
|
|
|
|
#define COLUMN_MTIME 5
|
|
|
|
|
|
|
|
#define COLUMNS_COUNT 6
|
|
|
|
|
2021-09-16 17:14:58 +02:00
|
|
|
static const WIN32_FIND_DATAW *get_trash_item_data( LPCITEMIDLIST id )
|
|
|
|
{
|
|
|
|
if (id->mkid.cb < 2 + 1 + sizeof(WIN32_FIND_DATAW) + 2) return NULL;
|
|
|
|
if (id->mkid.abID[0] != 0) return NULL;
|
|
|
|
return (const WIN32_FIND_DATAW *)(id->mkid.abID + 1);
|
|
|
|
}
|
|
|
|
|
2021-09-16 17:16:57 +02:00
|
|
|
static INIT_ONCE trash_dir_once;
|
|
|
|
static WCHAR *trash_dir;
|
|
|
|
static WCHAR *trash_info_dir;
|
|
|
|
static ULONG random_seed;
|
|
|
|
|
2021-09-17 17:47:07 +02:00
|
|
|
extern void CDECL wine_get_host_version( const char **sysname, const char **release );
|
|
|
|
|
|
|
|
static BOOL is_macos(void)
|
|
|
|
{
|
|
|
|
const char *sysname;
|
|
|
|
|
|
|
|
wine_get_host_version( &sysname, NULL );
|
|
|
|
return !strcmp( sysname, "Darwin" );
|
|
|
|
}
|
|
|
|
|
2021-09-16 17:16:57 +02:00
|
|
|
static BOOL WINAPI init_trash_dirs( INIT_ONCE *once, void *param, void **context )
|
|
|
|
{
|
2021-09-17 17:47:07 +02:00
|
|
|
const WCHAR *home = _wgetenv( L"WINEHOMEDIR" );
|
|
|
|
WCHAR *info = NULL, *files = NULL;
|
2021-09-17 17:16:11 +02:00
|
|
|
ULONG len;
|
2021-09-16 17:16:57 +02:00
|
|
|
|
2021-09-17 17:47:07 +02:00
|
|
|
if (!home) return TRUE;
|
|
|
|
if (is_macos())
|
|
|
|
{
|
2021-09-20 12:58:52 +02:00
|
|
|
files = heap_alloc( (lstrlenW(home) + lstrlenW(L"\\.Trash") + 1) * sizeof(WCHAR) );
|
2021-09-17 17:47:07 +02:00
|
|
|
lstrcpyW( files, home );
|
2021-09-20 12:58:52 +02:00
|
|
|
lstrcatW( files, L"\\.Trash" );
|
2021-09-17 17:47:07 +02:00
|
|
|
files[1] = '\\'; /* change \??\ to \\?\ */
|
|
|
|
}
|
|
|
|
else
|
2021-09-16 17:16:57 +02:00
|
|
|
{
|
2021-09-17 17:47:07 +02:00
|
|
|
const WCHAR *data_home = _wgetenv( L"XDG_DATA_HOME" );
|
|
|
|
const WCHAR *fmt = L"%s/.local/share/Trash";
|
|
|
|
WCHAR *p;
|
|
|
|
|
|
|
|
if (data_home && data_home[0] == '/')
|
|
|
|
{
|
|
|
|
home = data_home;
|
|
|
|
fmt = L"\\??\\unix%s/Trash";
|
|
|
|
}
|
|
|
|
len = lstrlenW(home) + lstrlenW(fmt) + 7;
|
|
|
|
files = heap_alloc( len * sizeof(WCHAR) );
|
|
|
|
swprintf( files, len, fmt, home );
|
|
|
|
files[1] = '\\'; /* change \??\ to \\?\ */
|
|
|
|
for (p = files; *p; p++) if (*p == '/') *p = '\\';
|
|
|
|
CreateDirectoryW( files, NULL );
|
|
|
|
info = heap_alloc( len * sizeof(WCHAR) );
|
|
|
|
lstrcpyW( info, files );
|
|
|
|
lstrcatW( files, L"\\files" );
|
|
|
|
lstrcatW( info, L"\\info" );
|
|
|
|
if (!CreateDirectoryW( info, NULL ) && GetLastError() != ERROR_ALREADY_EXISTS) goto done;
|
|
|
|
trash_info_dir = info;
|
2021-09-16 17:16:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!CreateDirectoryW( files, NULL ) && GetLastError() != ERROR_ALREADY_EXISTS) goto done;
|
|
|
|
trash_dir = files;
|
|
|
|
random_seed = GetTickCount();
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
done:
|
|
|
|
heap_free( files );
|
|
|
|
heap_free( info );
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL is_trash_available(void)
|
|
|
|
{
|
|
|
|
InitOnceExecuteOnce( &trash_dir_once, init_trash_dirs, NULL, NULL );
|
|
|
|
return trash_dir != NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void encode( const char *src, char *dst )
|
|
|
|
{
|
|
|
|
static const char escape_chars[] = "^&`{}|[]'<>\\#%\"+";
|
|
|
|
static const char hexchars[] = "0123456789ABCDEF";
|
|
|
|
|
|
|
|
for ( ; *src; src++)
|
|
|
|
{
|
|
|
|
if (*src <= 0x20 || *src >= 0x7f || strchr( escape_chars, *src ))
|
|
|
|
{
|
|
|
|
*dst++ = '%';
|
|
|
|
*dst++ = hexchars[(unsigned char)*src / 16];
|
|
|
|
*dst++ = hexchars[(unsigned char)*src % 16];
|
|
|
|
}
|
|
|
|
else *dst++ = *src;
|
|
|
|
}
|
|
|
|
*dst = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static char *decode( char *buf )
|
|
|
|
{
|
|
|
|
const char *src = buf;
|
|
|
|
char *dst = buf; /* decode in place */
|
|
|
|
|
|
|
|
while (*src)
|
|
|
|
{
|
|
|
|
if (*src == '%')
|
|
|
|
{
|
|
|
|
unsigned char v;
|
|
|
|
|
|
|
|
if (src[1] >= '0' && src[1] <= '9') v = src[1] - '0';
|
|
|
|
else if (src[1] >= 'A' && src[1] <= 'F') v = src[1] - 'A' + 10;
|
|
|
|
else if (src[1] >= 'a' && src[1] <= 'f') v = src[1] - 'a' + 10;
|
|
|
|
else goto next;
|
|
|
|
v <<= 4;
|
|
|
|
if (src[2] >= '0' && src[2] <= '9') v += src[2] - '0';
|
|
|
|
else if (src[2] >= 'A' && src[2] <= 'F') v += src[2] - 'A' + 10;
|
|
|
|
else if (src[2] >= 'a' && src[2] <= 'f') v += src[2] - 'a' + 10;
|
|
|
|
else goto next;
|
|
|
|
*dst++ = v;
|
|
|
|
next:
|
|
|
|
if (src[1] && src[2]) src += 3;
|
|
|
|
else break;
|
|
|
|
}
|
|
|
|
else *dst++ = *src++;
|
|
|
|
}
|
|
|
|
*dst = 0;
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL write_trashinfo_file( HANDLE handle, const WCHAR *orig_path )
|
|
|
|
{
|
|
|
|
char *path, *buffer;
|
|
|
|
SYSTEMTIME now;
|
|
|
|
|
|
|
|
if (!(path = wine_get_unix_file_name( orig_path ))) return FALSE;
|
|
|
|
GetLocalTime( &now );
|
|
|
|
|
|
|
|
buffer = heap_alloc( strlen(path) * 3 + 128 );
|
|
|
|
strcpy( buffer, "[Trash Info]\nPath=" );
|
|
|
|
encode( path, buffer + strlen(buffer) );
|
|
|
|
sprintf( buffer + strlen(buffer), "\nDeletionDate=%04u-%02u-%02uT%02u:%02u:%02u\n",
|
|
|
|
now.wYear, now.wMonth, now.wDay, now.wHour, now.wMinute, now.wSecond);
|
|
|
|
WriteFile( handle, buffer, strlen(buffer), NULL, NULL );
|
|
|
|
heap_free( path );
|
|
|
|
heap_free( buffer );
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void read_trashinfo_file( HANDLE handle, WIN32_FIND_DATAW *data )
|
|
|
|
{
|
|
|
|
ULONG size;
|
|
|
|
WCHAR *path;
|
|
|
|
char *buffer, *next, *p;
|
|
|
|
int header = 0;
|
|
|
|
|
|
|
|
size = GetFileSize( handle, NULL );
|
|
|
|
if (!(buffer = heap_alloc( size + 1 ))) return;
|
|
|
|
if (!ReadFile( handle, buffer, size, &size, NULL )) size = 0;
|
|
|
|
buffer[size] = 0;
|
|
|
|
next = buffer;
|
|
|
|
while (next)
|
|
|
|
{
|
|
|
|
p = next;
|
|
|
|
if ((next = strchr( next, '\n' ))) *next++ = 0;
|
|
|
|
while (*p == ' ' || *p == '\t') p++;
|
|
|
|
if (!strncmp( p, "[Trash Info]", 12 ))
|
|
|
|
{
|
|
|
|
header++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (header && !strncmp( p, "Path=", 5 ))
|
|
|
|
{
|
|
|
|
p += 5;
|
|
|
|
if ((path = wine_get_dos_file_name( decode( p ))))
|
|
|
|
{
|
|
|
|
lstrcpynW( data->cFileName, path, MAX_PATH );
|
|
|
|
heap_free( path );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* show only the file name */
|
|
|
|
char *file = strrchr( p, '/' );
|
|
|
|
if (!file) file = p;
|
|
|
|
else file++;
|
|
|
|
MultiByteToWideChar( CP_UNIXCP, 0, file, -1, data->cFileName, MAX_PATH );
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (header && !strncmp( p, "DeletionDate=", 13 ))
|
|
|
|
{
|
|
|
|
int year, mon, day, hour, min, sec;
|
|
|
|
if (sscanf( p + 13, "%d-%d-%dT%d:%d:%d", &year, &mon, &day, &hour, &min, &sec ) == 6)
|
|
|
|
{
|
|
|
|
SYSTEMTIME time = { year, mon, 0, day, hour, min, sec };
|
|
|
|
FILETIME ft;
|
|
|
|
if (SystemTimeToFileTime( &time, &ft ))
|
|
|
|
LocalFileTimeToFileTime( &ft, &data->ftLastAccessTime );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
heap_free( buffer );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
BOOL trash_file( const WCHAR *path )
|
|
|
|
{
|
|
|
|
WCHAR *dest = NULL, *file = PathFindFileNameW( path );
|
|
|
|
BOOL ret = TRUE;
|
2021-09-17 17:16:11 +02:00
|
|
|
ULONG i, len;
|
2021-09-16 17:16:57 +02:00
|
|
|
|
|
|
|
InitOnceExecuteOnce( &trash_dir_once, init_trash_dirs, NULL, NULL );
|
|
|
|
if (!trash_dir) return FALSE;
|
|
|
|
|
2021-09-17 17:16:11 +02:00
|
|
|
len = lstrlenW(trash_dir) + lstrlenW(file) + 11;
|
|
|
|
dest = heap_alloc( len * sizeof(WCHAR) );
|
2021-09-16 17:16:57 +02:00
|
|
|
|
|
|
|
if (trash_info_dir)
|
|
|
|
{
|
|
|
|
HANDLE handle;
|
2021-09-17 17:16:11 +02:00
|
|
|
ULONG infolen = lstrlenW(trash_info_dir) + lstrlenW(file) + 21;
|
|
|
|
WCHAR *info = heap_alloc( infolen * sizeof(WCHAR) );
|
2021-09-16 17:16:57 +02:00
|
|
|
|
2021-09-20 12:58:52 +02:00
|
|
|
swprintf( info, infolen, L"%s\\%s.trashinfo", trash_info_dir, file );
|
2021-09-16 17:16:57 +02:00
|
|
|
for (i = 0; i < 1000; i++)
|
|
|
|
{
|
|
|
|
handle = CreateFileW( info, GENERIC_WRITE, 0, NULL, CREATE_NEW, 0, 0 );
|
|
|
|
if (handle != INVALID_HANDLE_VALUE) break;
|
2021-09-20 12:58:52 +02:00
|
|
|
swprintf( info, infolen, L"%s\\%s-%08x.trashinfo", trash_info_dir, file, RtlRandom( &random_seed ));
|
2021-09-16 17:16:57 +02:00
|
|
|
}
|
|
|
|
if (handle != INVALID_HANDLE_VALUE)
|
|
|
|
{
|
|
|
|
if ((ret = write_trashinfo_file( handle, path )))
|
|
|
|
{
|
2021-09-17 17:16:11 +02:00
|
|
|
ULONG namelen = lstrlenW(info) - lstrlenW(trash_info_dir) - 10 /* .trashinfo */;
|
2021-09-20 12:58:52 +02:00
|
|
|
swprintf( dest, len, L"%s%.*s", trash_dir, namelen, info + lstrlenW(trash_info_dir) );
|
2021-09-16 17:16:57 +02:00
|
|
|
ret = MoveFileW( path, dest );
|
|
|
|
}
|
|
|
|
CloseHandle( handle );
|
|
|
|
if (!ret) DeleteFileW( info );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-09-20 12:58:52 +02:00
|
|
|
swprintf( dest, len, L"%s\\%s", trash_dir, file );
|
2021-09-16 17:16:57 +02:00
|
|
|
for (i = 0; i < 1000; i++)
|
|
|
|
{
|
|
|
|
ret = MoveFileW( path, dest );
|
|
|
|
if (ret || GetLastError() != ERROR_ALREADY_EXISTS) break;
|
2021-09-20 12:58:52 +02:00
|
|
|
swprintf( dest, len, L"%s\\%s-%08x", trash_dir, file, RtlRandom( &random_seed ));
|
2021-09-16 17:16:57 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (ret) TRACE( "%s -> %s\n", debugstr_w(path), debugstr_w(dest) );
|
|
|
|
heap_free( dest );
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL get_trash_item_info( const WCHAR *filename, WIN32_FIND_DATAW *data )
|
|
|
|
{
|
|
|
|
if (!trash_info_dir)
|
|
|
|
{
|
2021-09-20 12:58:52 +02:00
|
|
|
return !!wcscmp( filename, L".DS_Store" );
|
2021-09-16 17:16:57 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
HANDLE handle;
|
2021-09-17 17:16:11 +02:00
|
|
|
ULONG len = lstrlenW(trash_info_dir) + lstrlenW(filename) + 12;
|
|
|
|
WCHAR *info = heap_alloc( len * sizeof(WCHAR) );
|
2021-09-16 17:16:57 +02:00
|
|
|
|
2021-09-20 12:58:52 +02:00
|
|
|
swprintf( info, len, L"%s\\%s.trashinfo", trash_info_dir, filename );
|
2021-09-16 17:16:57 +02:00
|
|
|
handle = CreateFileW( info, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, 0 );
|
|
|
|
heap_free( info );
|
2021-09-17 17:16:11 +02:00
|
|
|
if (handle == INVALID_HANDLE_VALUE) return FALSE;
|
2021-09-16 17:16:57 +02:00
|
|
|
read_trashinfo_file( handle, data );
|
|
|
|
CloseHandle( handle );
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT add_trash_item( WIN32_FIND_DATAW *orig_data, LPITEMIDLIST **pidls,
|
|
|
|
ULONG *count, ULONG *size )
|
|
|
|
{
|
|
|
|
ITEMIDLIST *pidl;
|
|
|
|
WIN32_FIND_DATAW *data;
|
|
|
|
const WCHAR *filename = orig_data->cFileName;
|
2021-09-17 17:16:11 +02:00
|
|
|
ULONG len = offsetof( ITEMIDLIST, mkid.abID[1 + sizeof(*data) + (lstrlenW(filename)+1) * sizeof(WCHAR)]);
|
2021-09-16 17:16:57 +02:00
|
|
|
|
|
|
|
if (!(pidl = SHAlloc( len + 2 ))) return E_OUTOFMEMORY;
|
|
|
|
pidl->mkid.cb = len;
|
|
|
|
pidl->mkid.abID[0] = 0;
|
|
|
|
data = (WIN32_FIND_DATAW *)(pidl->mkid.abID + 1);
|
|
|
|
memcpy( data, orig_data, sizeof(*data) );
|
2021-09-17 17:16:11 +02:00
|
|
|
lstrcpyW( (WCHAR *)(data + 1), filename );
|
2021-09-16 17:16:57 +02:00
|
|
|
*(USHORT *)((char *)pidl + len) = 0;
|
|
|
|
|
|
|
|
if (get_trash_item_info( filename, data ))
|
|
|
|
{
|
|
|
|
if (*count == *size)
|
|
|
|
{
|
|
|
|
LPITEMIDLIST *new;
|
|
|
|
|
|
|
|
*size = max( *size * 2, 32 );
|
|
|
|
new = heap_realloc( *pidls, *size * sizeof(**pidls) );
|
|
|
|
if (!new)
|
|
|
|
{
|
|
|
|
SHFree( pidl );
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
*pidls = new;
|
|
|
|
}
|
|
|
|
(*pidls)[(*count)++] = pidl;
|
|
|
|
}
|
|
|
|
else SHFree( pidl ); /* ignore it */
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT enum_trash_items( LPITEMIDLIST **pidls, int *ret_count )
|
|
|
|
{
|
|
|
|
HANDLE handle;
|
|
|
|
WCHAR *file;
|
|
|
|
WIN32_FIND_DATAW data;
|
|
|
|
LPITEMIDLIST *ret = NULL;
|
|
|
|
ULONG count = 0, size = 0;
|
|
|
|
HRESULT hr = S_OK;
|
|
|
|
|
|
|
|
InitOnceExecuteOnce( &trash_dir_once, init_trash_dirs, NULL, NULL );
|
|
|
|
if (!trash_dir) return E_FAIL;
|
|
|
|
|
2021-09-20 12:58:52 +02:00
|
|
|
file = heap_alloc( (lstrlenW(trash_dir) + lstrlenW(L"\\*") + 1) * sizeof(WCHAR) );
|
2021-09-17 17:16:11 +02:00
|
|
|
lstrcpyW( file, trash_dir );
|
2021-09-20 12:58:52 +02:00
|
|
|
lstrcatW( file, L"\\*" );
|
2021-09-16 17:16:57 +02:00
|
|
|
handle = FindFirstFileW( file, &data );
|
|
|
|
if (handle != INVALID_HANDLE_VALUE)
|
|
|
|
{
|
|
|
|
do
|
|
|
|
{
|
2021-09-20 12:58:52 +02:00
|
|
|
if (!wcscmp( data.cFileName, L"." )) continue;
|
|
|
|
if (!wcscmp( data.cFileName, L".." )) continue;
|
2021-09-16 17:16:57 +02:00
|
|
|
hr = add_trash_item( &data, &ret, &count, &size );
|
|
|
|
} while (hr == S_OK && FindNextFileW( handle, &data ));
|
|
|
|
FindClose( handle );
|
|
|
|
}
|
|
|
|
|
|
|
|
if (FAILED(hr)) while (count) SHFree( &ret[--count] );
|
|
|
|
else if (count)
|
|
|
|
{
|
|
|
|
*pidls = SHAlloc( count * sizeof(**pidls) );
|
|
|
|
memcpy( *pidls, ret, count * sizeof(**pidls) );
|
|
|
|
}
|
|
|
|
heap_free( ret );
|
|
|
|
*ret_count = count;
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void remove_trashinfo( const WCHAR *filename )
|
|
|
|
{
|
|
|
|
WCHAR *info;
|
2021-09-17 17:16:11 +02:00
|
|
|
ULONG len;
|
2021-09-16 17:16:57 +02:00
|
|
|
|
|
|
|
if (!trash_info_dir) return;
|
2021-09-17 17:16:11 +02:00
|
|
|
len = lstrlenW(trash_info_dir) + lstrlenW(filename) + 12;
|
|
|
|
info = heap_alloc( len * sizeof(WCHAR) );
|
|
|
|
swprintf( info, len, L"%s\\%s.trashinfo", trash_info_dir, filename );
|
2021-09-16 17:16:57 +02:00
|
|
|
DeleteFileW( info );
|
|
|
|
heap_free( info );
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT restore_trash_item( LPCITEMIDLIST pidl )
|
|
|
|
{
|
|
|
|
const WIN32_FIND_DATAW *data = get_trash_item_data( pidl );
|
|
|
|
WCHAR *from, *filename = (WCHAR *)(data + 1);
|
2021-09-17 17:16:11 +02:00
|
|
|
ULONG len;
|
2021-09-16 17:16:57 +02:00
|
|
|
|
2021-09-17 17:16:11 +02:00
|
|
|
if (!wcschr( data->cFileName, '\\' ))
|
2021-09-16 17:16:57 +02:00
|
|
|
{
|
|
|
|
FIXME( "original name for %s not available\n", debugstr_w(data->cFileName) );
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
2021-09-17 17:16:11 +02:00
|
|
|
len = lstrlenW(trash_dir) + lstrlenW(filename) + 2;
|
|
|
|
from = heap_alloc( len * sizeof(WCHAR) );
|
|
|
|
swprintf( from, len, L"%s\\%s", trash_dir, filename );
|
2021-09-16 17:16:57 +02:00
|
|
|
if (MoveFileW( from, data->cFileName )) remove_trashinfo( filename );
|
|
|
|
else WARN( "failed to restore %s to %s\n", debugstr_w(from), debugstr_w(data->cFileName) );
|
|
|
|
heap_free( from );
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT erase_trash_item( LPCITEMIDLIST pidl )
|
|
|
|
{
|
|
|
|
const WIN32_FIND_DATAW *data = get_trash_item_data( pidl );
|
|
|
|
WCHAR *from, *filename = (WCHAR *)(data + 1);
|
2021-09-17 17:16:11 +02:00
|
|
|
ULONG len = lstrlenW(trash_dir) + lstrlenW(filename) + 2;
|
2021-09-16 17:16:57 +02:00
|
|
|
|
2021-09-17 17:16:11 +02:00
|
|
|
from = heap_alloc( len * sizeof(WCHAR) );
|
|
|
|
swprintf( from, len, L"%s\\%s", trash_dir, filename );
|
2021-09-16 17:16:57 +02:00
|
|
|
if (DeleteFileW( from )) remove_trashinfo( filename );
|
|
|
|
heap_free( from );
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-11-28 11:38:58 +01:00
|
|
|
static HRESULT FormatDateTime(LPWSTR buffer, int size, FILETIME ft)
|
2006-08-03 19:11:07 +02:00
|
|
|
{
|
|
|
|
FILETIME lft;
|
|
|
|
SYSTEMTIME time;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
FileTimeToLocalFileTime(&ft, &lft);
|
|
|
|
FileTimeToSystemTime(&lft, &time);
|
|
|
|
|
|
|
|
ret = GetDateFormatW(LOCALE_USER_DEFAULT, DATE_SHORTDATE, &time, NULL, buffer, size);
|
|
|
|
if (ret>0 && ret<size)
|
|
|
|
{
|
|
|
|
/* Append space + time without seconds */
|
|
|
|
buffer[ret-1] = ' ';
|
|
|
|
GetTimeFormatW(LOCALE_USER_DEFAULT, TIME_NOSECONDS, &time, NULL, &buffer[ret], size - ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (ret!=0 ? E_FAIL : S_OK);
|
|
|
|
}
|
|
|
|
|
2011-07-08 16:47:03 +02:00
|
|
|
typedef struct tagRecycleBinMenu
|
|
|
|
{
|
|
|
|
IContextMenu2 IContextMenu2_iface;
|
|
|
|
LONG refCount;
|
|
|
|
|
|
|
|
UINT cidl;
|
|
|
|
LPITEMIDLIST *apidl;
|
|
|
|
IShellFolder2 *folder;
|
|
|
|
} RecycleBinMenu;
|
|
|
|
|
|
|
|
static const IContextMenu2Vtbl recycleBinMenuVtbl;
|
|
|
|
|
|
|
|
static RecycleBinMenu *impl_from_IContextMenu2(IContextMenu2 *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, RecycleBinMenu, IContextMenu2_iface);
|
|
|
|
}
|
|
|
|
|
|
|
|
static IContextMenu2* RecycleBinMenu_Constructor(UINT cidl, LPCITEMIDLIST *apidl, IShellFolder2 *folder)
|
|
|
|
{
|
|
|
|
RecycleBinMenu *This = SHAlloc(sizeof(RecycleBinMenu));
|
|
|
|
TRACE("(%u,%p)\n",cidl,apidl);
|
|
|
|
This->IContextMenu2_iface.lpVtbl = &recycleBinMenuVtbl;
|
|
|
|
This->cidl = cidl;
|
|
|
|
This->apidl = _ILCopyaPidl(apidl,cidl);
|
|
|
|
IShellFolder2_AddRef(folder);
|
|
|
|
This->folder = folder;
|
|
|
|
This->refCount = 1;
|
|
|
|
return &This->IContextMenu2_iface;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI RecycleBinMenu_QueryInterface(IContextMenu2 *iface,
|
|
|
|
REFIID riid,
|
|
|
|
void **ppvObject)
|
|
|
|
{
|
|
|
|
RecycleBinMenu *This = impl_from_IContextMenu2(iface);
|
|
|
|
TRACE("(%p, %s, %p) - stub\n", This, debugstr_guid(riid), ppvObject);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI RecycleBinMenu_AddRef(IContextMenu2 *iface)
|
|
|
|
{
|
|
|
|
RecycleBinMenu *This = impl_from_IContextMenu2(iface);
|
|
|
|
TRACE("(%p)\n", This);
|
|
|
|
return InterlockedIncrement(&This->refCount);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI RecycleBinMenu_Release(IContextMenu2 *iface)
|
|
|
|
{
|
|
|
|
RecycleBinMenu *This = impl_from_IContextMenu2(iface);
|
|
|
|
UINT result;
|
|
|
|
TRACE("(%p)\n", This);
|
|
|
|
result = InterlockedDecrement(&This->refCount);
|
|
|
|
if (result == 0)
|
|
|
|
{
|
|
|
|
TRACE("Destroying object\n");
|
|
|
|
_ILFreeaPidl(This->apidl,This->cidl);
|
2012-07-29 10:51:05 +02:00
|
|
|
IShellFolder2_Release(This->folder);
|
2011-07-08 16:47:03 +02:00
|
|
|
SHFree(This);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI RecycleBinMenu_QueryContextMenu(IContextMenu2 *iface,
|
|
|
|
HMENU hmenu,
|
|
|
|
UINT indexMenu,
|
|
|
|
UINT idCmdFirst,
|
|
|
|
UINT idCmdLast,
|
|
|
|
UINT uFlags)
|
|
|
|
{
|
|
|
|
HMENU menures = LoadMenuW(shell32_hInstance,MAKEINTRESOURCEW(MENU_RECYCLEBIN));
|
|
|
|
if(uFlags & CMF_DEFAULTONLY)
|
|
|
|
return E_NOTIMPL;
|
|
|
|
else{
|
|
|
|
UINT idMax = Shell_MergeMenus(hmenu,GetSubMenu(menures,0),indexMenu,idCmdFirst,idCmdLast,MM_SUBMENUSHAVEIDS);
|
2011-07-14 13:14:13 +02:00
|
|
|
TRACE("Added %d id(s)\n",idMax-idCmdFirst);
|
2011-07-08 16:47:03 +02:00
|
|
|
return MAKE_HRESULT(SEVERITY_SUCCESS, FACILITY_NULL, idMax-idCmdFirst+1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void DoErase(RecycleBinMenu *This)
|
|
|
|
{
|
|
|
|
ISFHelper *helper;
|
|
|
|
IShellFolder2_QueryInterface(This->folder,&IID_ISFHelper,(void**)&helper);
|
|
|
|
if(helper)
|
|
|
|
ISFHelper_DeleteItems(helper,This->cidl,(LPCITEMIDLIST*)This->apidl);
|
|
|
|
}
|
|
|
|
|
2011-07-08 16:47:08 +02:00
|
|
|
static void DoRestore(RecycleBinMenu *This)
|
|
|
|
{
|
|
|
|
|
|
|
|
/*TODO add prompts*/
|
|
|
|
UINT i;
|
|
|
|
for(i=0;i<This->cidl;i++)
|
|
|
|
{
|
2021-09-16 17:14:58 +02:00
|
|
|
const WIN32_FIND_DATAW *data = get_trash_item_data( This->apidl[i] );
|
|
|
|
|
|
|
|
if(PathFileExistsW(data->cFileName))
|
2011-07-08 16:47:08 +02:00
|
|
|
{
|
2021-09-16 17:14:58 +02:00
|
|
|
PIDLIST_ABSOLUTE dest_pidl = ILCreateFromPathW(data->cFileName);
|
2011-07-08 16:47:08 +02:00
|
|
|
WCHAR message[100];
|
|
|
|
WCHAR caption[50];
|
|
|
|
if(_ILIsFolder(ILFindLastID(dest_pidl)))
|
2018-03-19 08:11:27 +01:00
|
|
|
LoadStringW(shell32_hInstance, IDS_RECYCLEBIN_OVERWRITEFOLDER, message, ARRAY_SIZE(message));
|
2011-07-08 16:47:08 +02:00
|
|
|
else
|
2018-03-19 08:11:27 +01:00
|
|
|
LoadStringW(shell32_hInstance, IDS_RECYCLEBIN_OVERWRITEFILE, message, ARRAY_SIZE(message));
|
|
|
|
LoadStringW(shell32_hInstance, IDS_RECYCLEBIN_OVERWRITE_CAPTION, caption, ARRAY_SIZE(caption));
|
2011-07-08 16:47:08 +02:00
|
|
|
|
|
|
|
if(ShellMessageBoxW(shell32_hInstance,GetActiveWindow(),message,
|
|
|
|
caption,MB_YESNO|MB_ICONEXCLAMATION,
|
2021-09-16 17:14:58 +02:00
|
|
|
data->cFileName)!=IDYES)
|
2011-07-08 16:47:08 +02:00
|
|
|
continue;
|
|
|
|
}
|
2021-09-16 17:16:57 +02:00
|
|
|
if(SUCCEEDED(restore_trash_item(This->apidl[i])))
|
2011-07-08 16:47:08 +02:00
|
|
|
{
|
|
|
|
IPersistFolder2 *persist;
|
|
|
|
LPITEMIDLIST root_pidl;
|
2021-09-16 17:14:58 +02:00
|
|
|
PIDLIST_ABSOLUTE dest_pidl = ILCreateFromPathW(data->cFileName);
|
2011-07-08 16:47:08 +02:00
|
|
|
BOOL is_folder = _ILIsFolder(ILFindLastID(dest_pidl));
|
|
|
|
IShellFolder2_QueryInterface(This->folder,&IID_IPersistFolder2,
|
|
|
|
(void**)&persist);
|
|
|
|
IPersistFolder2_GetCurFolder(persist,&root_pidl);
|
|
|
|
SHChangeNotify(is_folder ? SHCNE_RMDIR : SHCNE_DELETE,
|
|
|
|
SHCNF_IDLIST,ILCombine(root_pidl,This->apidl[i]),0);
|
|
|
|
SHChangeNotify(is_folder ? SHCNE_MKDIR : SHCNE_CREATE,
|
|
|
|
SHCNF_IDLIST,dest_pidl,0);
|
|
|
|
ILFree(dest_pidl);
|
|
|
|
ILFree(root_pidl);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-07-08 16:47:03 +02:00
|
|
|
|
|
|
|
static HRESULT WINAPI RecycleBinMenu_InvokeCommand(IContextMenu2 *iface,
|
|
|
|
LPCMINVOKECOMMANDINFO pici)
|
|
|
|
{
|
|
|
|
RecycleBinMenu *This = impl_from_IContextMenu2(iface);
|
|
|
|
LPCSTR verb = pici->lpVerb;
|
2011-09-01 17:10:05 +02:00
|
|
|
if(IS_INTRESOURCE(verb))
|
2011-07-08 16:47:03 +02:00
|
|
|
{
|
2011-09-01 17:10:05 +02:00
|
|
|
switch(LOWORD(verb))
|
2011-07-08 16:47:03 +02:00
|
|
|
{
|
|
|
|
case IDM_RECYCLEBIN_ERASE:
|
|
|
|
DoErase(This);
|
|
|
|
break;
|
2011-07-08 16:47:08 +02:00
|
|
|
case IDM_RECYCLEBIN_RESTORE:
|
|
|
|
DoRestore(This);
|
|
|
|
break;
|
2011-07-08 16:47:03 +02:00
|
|
|
default:
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI RecycleBinMenu_GetCommandString(IContextMenu2 *iface,
|
|
|
|
UINT_PTR idCmd,
|
|
|
|
UINT uType,
|
|
|
|
UINT *pwReserved,
|
|
|
|
LPSTR pszName,
|
|
|
|
UINT cchMax)
|
|
|
|
{
|
|
|
|
TRACE("(%p, %lu, %u, %p, %s, %u) - stub\n",iface,idCmd,uType,pwReserved,debugstr_a(pszName),cchMax);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI RecycleBinMenu_HandleMenuMsg(IContextMenu2 *iface,
|
|
|
|
UINT uMsg, WPARAM wParam,
|
|
|
|
LPARAM lParam)
|
|
|
|
{
|
|
|
|
TRACE("(%p, %u, 0x%lx, 0x%lx) - stub\n",iface,uMsg,wParam,lParam);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static const IContextMenu2Vtbl recycleBinMenuVtbl =
|
|
|
|
{
|
|
|
|
RecycleBinMenu_QueryInterface,
|
|
|
|
RecycleBinMenu_AddRef,
|
|
|
|
RecycleBinMenu_Release,
|
|
|
|
RecycleBinMenu_QueryContextMenu,
|
|
|
|
RecycleBinMenu_InvokeCommand,
|
|
|
|
RecycleBinMenu_GetCommandString,
|
|
|
|
RecycleBinMenu_HandleMenuMsg,
|
|
|
|
};
|
|
|
|
|
2006-08-03 19:11:07 +02:00
|
|
|
/*
|
|
|
|
* Recycle Bin folder
|
|
|
|
*/
|
|
|
|
|
|
|
|
typedef struct tagRecycleBin
|
|
|
|
{
|
2011-01-27 10:46:37 +01:00
|
|
|
IShellFolder2 IShellFolder2_iface;
|
|
|
|
IPersistFolder2 IPersistFolder2_iface;
|
2011-07-08 16:46:57 +02:00
|
|
|
ISFHelper ISFHelper_iface;
|
2006-08-03 19:11:07 +02:00
|
|
|
LONG refCount;
|
|
|
|
|
|
|
|
LPITEMIDLIST pidl;
|
|
|
|
} RecycleBin;
|
|
|
|
|
2006-11-28 11:38:58 +01:00
|
|
|
static const IShellFolder2Vtbl recycleBinVtbl;
|
|
|
|
static const IPersistFolder2Vtbl recycleBinPersistVtbl;
|
2011-07-08 16:46:57 +02:00
|
|
|
static const ISFHelperVtbl sfhelperVtbl;
|
2006-08-03 19:11:07 +02:00
|
|
|
|
2011-01-27 10:46:37 +01:00
|
|
|
static inline RecycleBin *impl_from_IShellFolder2(IShellFolder2 *iface)
|
2006-08-03 19:11:07 +02:00
|
|
|
{
|
2011-01-27 10:46:37 +01:00
|
|
|
return CONTAINING_RECORD(iface, RecycleBin, IShellFolder2_iface);
|
|
|
|
}
|
|
|
|
|
|
|
|
static RecycleBin *impl_from_IPersistFolder2(IPersistFolder2 *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, RecycleBin, IPersistFolder2_iface);
|
2006-08-03 19:11:07 +02:00
|
|
|
}
|
|
|
|
|
2011-07-08 16:46:57 +02:00
|
|
|
static RecycleBin *impl_from_ISFHelper(ISFHelper *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, RecycleBin, ISFHelper_iface);
|
|
|
|
}
|
|
|
|
|
2006-11-28 11:38:58 +01:00
|
|
|
static void RecycleBin_Destructor(RecycleBin *This);
|
2006-08-03 19:11:07 +02:00
|
|
|
|
|
|
|
HRESULT WINAPI RecycleBin_Constructor(IUnknown *pUnkOuter, REFIID riid, LPVOID *ppOutput)
|
|
|
|
{
|
|
|
|
RecycleBin *obj;
|
|
|
|
HRESULT ret;
|
|
|
|
if (pUnkOuter)
|
|
|
|
return CLASS_E_NOAGGREGATION;
|
|
|
|
|
|
|
|
obj = SHAlloc(sizeof(RecycleBin));
|
|
|
|
if (obj == NULL)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
ZeroMemory(obj, sizeof(RecycleBin));
|
2011-01-27 10:46:37 +01:00
|
|
|
obj->IShellFolder2_iface.lpVtbl = &recycleBinVtbl;
|
|
|
|
obj->IPersistFolder2_iface.lpVtbl = &recycleBinPersistVtbl;
|
2011-07-08 16:46:57 +02:00
|
|
|
obj->ISFHelper_iface.lpVtbl = &sfhelperVtbl;
|
2011-01-27 10:46:37 +01:00
|
|
|
if (FAILED(ret = IPersistFolder2_QueryInterface(&obj->IPersistFolder2_iface, riid, ppOutput)))
|
2006-08-03 19:11:07 +02:00
|
|
|
{
|
|
|
|
RecycleBin_Destructor(obj);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
/* InterlockedIncrement(&objCount);*/
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2006-11-28 11:38:58 +01:00
|
|
|
static void RecycleBin_Destructor(RecycleBin *This)
|
2006-08-03 19:11:07 +02:00
|
|
|
{
|
|
|
|
/* InterlockedDecrement(&objCount);*/
|
|
|
|
SHFree(This->pidl);
|
|
|
|
SHFree(This);
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI RecycleBin_QueryInterface(IShellFolder2 *iface, REFIID riid, void **ppvObject)
|
|
|
|
{
|
2011-01-27 10:46:37 +01:00
|
|
|
RecycleBin *This = impl_from_IShellFolder2(iface);
|
2006-08-03 19:11:07 +02:00
|
|
|
TRACE("(%p, %s, %p)\n", This, debugstr_guid(riid), ppvObject);
|
|
|
|
|
|
|
|
*ppvObject = NULL;
|
|
|
|
if (IsEqualGUID(riid, &IID_IUnknown) || IsEqualGUID(riid, &IID_IShellFolder)
|
|
|
|
|| IsEqualGUID(riid, &IID_IShellFolder2))
|
2013-09-03 15:09:07 +02:00
|
|
|
*ppvObject = &This->IShellFolder2_iface;
|
2006-08-03 19:11:07 +02:00
|
|
|
|
|
|
|
if (IsEqualGUID(riid, &IID_IPersist) || IsEqualGUID(riid, &IID_IPersistFolder)
|
|
|
|
|| IsEqualGUID(riid, &IID_IPersistFolder2))
|
2011-01-27 10:46:37 +01:00
|
|
|
*ppvObject = &This->IPersistFolder2_iface;
|
2011-07-08 16:46:57 +02:00
|
|
|
if (IsEqualGUID(riid, &IID_ISFHelper))
|
|
|
|
*ppvObject = &This->ISFHelper_iface;
|
2006-08-03 19:11:07 +02:00
|
|
|
|
|
|
|
if (*ppvObject != NULL)
|
|
|
|
{
|
|
|
|
IUnknown_AddRef((IUnknown *)*ppvObject);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
WARN("no interface %s\n", debugstr_guid(riid));
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI RecycleBin_AddRef(IShellFolder2 *iface)
|
|
|
|
{
|
2011-01-27 10:46:37 +01:00
|
|
|
RecycleBin *This = impl_from_IShellFolder2(iface);
|
2006-08-03 19:11:07 +02:00
|
|
|
TRACE("(%p)\n", This);
|
|
|
|
return InterlockedIncrement(&This->refCount);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI RecycleBin_Release(IShellFolder2 *iface)
|
|
|
|
{
|
2011-01-27 10:46:37 +01:00
|
|
|
RecycleBin *This = impl_from_IShellFolder2(iface);
|
2006-08-03 19:11:07 +02:00
|
|
|
LONG result;
|
|
|
|
|
|
|
|
TRACE("(%p)\n", This);
|
|
|
|
result = InterlockedDecrement(&This->refCount);
|
|
|
|
if (result == 0)
|
|
|
|
{
|
|
|
|
TRACE("Destroy object\n");
|
|
|
|
RecycleBin_Destructor(This);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI RecycleBin_ParseDisplayName(IShellFolder2 *This, HWND hwnd, LPBC pbc,
|
|
|
|
LPOLESTR pszDisplayName, ULONG *pchEaten, LPITEMIDLIST *ppidl,
|
|
|
|
ULONG *pdwAttributes)
|
|
|
|
{
|
|
|
|
FIXME("stub\n");
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI RecycleBin_EnumObjects(IShellFolder2 *iface, HWND hwnd, SHCONTF grfFlags, IEnumIDList **ppenumIDList)
|
|
|
|
{
|
2011-01-27 10:46:37 +01:00
|
|
|
RecycleBin *This = impl_from_IShellFolder2(iface);
|
2011-10-10 01:02:48 +02:00
|
|
|
IEnumIDListImpl *list;
|
2006-08-03 19:11:07 +02:00
|
|
|
LPITEMIDLIST *pidls;
|
2011-10-10 01:00:46 +02:00
|
|
|
HRESULT ret = E_OUTOFMEMORY;
|
2015-01-30 17:03:30 +01:00
|
|
|
int pidls_count = 0;
|
2006-08-03 19:11:07 +02:00
|
|
|
int i=0;
|
2008-01-19 17:54:28 +01:00
|
|
|
|
|
|
|
TRACE("(%p, %p, %x, %p)\n", This, hwnd, grfFlags, ppenumIDList);
|
|
|
|
|
2011-10-10 01:00:46 +02:00
|
|
|
*ppenumIDList = NULL;
|
|
|
|
list = IEnumIDList_Constructor();
|
|
|
|
if (!list)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
2006-08-03 19:11:07 +02:00
|
|
|
if (grfFlags & SHCONTF_NONFOLDERS)
|
|
|
|
{
|
2021-09-16 17:16:57 +02:00
|
|
|
if (FAILED(ret = enum_trash_items(&pidls, &pidls_count)))
|
2006-08-03 19:11:07 +02:00
|
|
|
goto failed;
|
|
|
|
for (i=0; i<pidls_count; i++)
|
2011-10-10 01:04:37 +02:00
|
|
|
if (!AddToEnumList(list, pidls[i]))
|
2006-08-03 19:11:07 +02:00
|
|
|
goto failed;
|
|
|
|
}
|
2011-10-10 01:00:46 +02:00
|
|
|
|
2011-10-10 01:02:48 +02:00
|
|
|
*ppenumIDList = &list->IEnumIDList_iface;
|
2006-08-03 19:11:07 +02:00
|
|
|
return S_OK;
|
|
|
|
|
|
|
|
failed:
|
2019-03-08 21:16:52 +01:00
|
|
|
IEnumIDList_Release(&list->IEnumIDList_iface);
|
2006-08-03 19:11:07 +02:00
|
|
|
for (; i<pidls_count; i++)
|
|
|
|
ILFree(pidls[i]);
|
|
|
|
SHFree(pidls);
|
2011-10-10 01:00:46 +02:00
|
|
|
return ret;
|
2006-08-03 19:11:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI RecycleBin_BindToObject(IShellFolder2 *This, LPCITEMIDLIST pidl, LPBC pbc, REFIID riid, void **ppv)
|
|
|
|
{
|
|
|
|
FIXME("(%p, %p, %p, %s, %p) - stub\n", This, pidl, pbc, debugstr_guid(riid), ppv);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI RecycleBin_BindToStorage(IShellFolder2 *This, LPCITEMIDLIST pidl, LPBC pbc, REFIID riid, void **ppv)
|
|
|
|
{
|
|
|
|
FIXME("(%p, %p, %p, %s, %p) - stub\n", This, pidl, pbc, debugstr_guid(riid), ppv);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI RecycleBin_CompareIDs(IShellFolder2 *iface, LPARAM lParam, LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2)
|
|
|
|
{
|
2011-01-27 10:46:37 +01:00
|
|
|
RecycleBin *This = impl_from_IShellFolder2(iface);
|
2012-07-07 11:52:23 +02:00
|
|
|
int ret;
|
2006-08-03 19:11:07 +02:00
|
|
|
|
|
|
|
/* TODO */
|
|
|
|
TRACE("(%p, %p, %p, %p)\n", This, (void *)lParam, pidl1, pidl2);
|
|
|
|
if (pidl1->mkid.cb != pidl2->mkid.cb)
|
|
|
|
return MAKE_HRESULT(SEVERITY_SUCCESS, 0, pidl1->mkid.cb - pidl2->mkid.cb);
|
2012-07-07 11:52:23 +02:00
|
|
|
/* Looks too complicated, but in optimized memcpy we might get
|
|
|
|
* a 32bit wide difference and would truncate it to 16 bit, so
|
|
|
|
* erroneously returning equality. */
|
|
|
|
ret = memcmp(pidl1->mkid.abID, pidl2->mkid.abID, pidl1->mkid.cb);
|
|
|
|
if (ret < 0) ret = -1;
|
|
|
|
if (ret > 0) ret = 1;
|
|
|
|
return MAKE_HRESULT(SEVERITY_SUCCESS, 0, (unsigned short)ret);
|
2006-08-03 19:11:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI RecycleBin_CreateViewObject(IShellFolder2 *iface, HWND hwndOwner, REFIID riid, void **ppv)
|
|
|
|
{
|
2011-01-27 10:46:37 +01:00
|
|
|
RecycleBin *This = impl_from_IShellFolder2(iface);
|
2006-08-03 19:11:07 +02:00
|
|
|
HRESULT ret;
|
|
|
|
TRACE("(%p, %p, %s, %p)\n", This, hwndOwner, debugstr_guid(riid), ppv);
|
|
|
|
|
|
|
|
*ppv = NULL;
|
|
|
|
if (IsEqualGUID(riid, &IID_IShellView))
|
|
|
|
{
|
|
|
|
IShellView *tmp;
|
|
|
|
CSFV sfv;
|
|
|
|
|
|
|
|
ZeroMemory(&sfv, sizeof(sfv));
|
|
|
|
sfv.cbSize = sizeof(sfv);
|
2016-08-25 22:30:16 +02:00
|
|
|
sfv.pshf = (IShellFolder *)&This->IShellFolder2_iface;
|
2006-08-03 19:11:07 +02:00
|
|
|
|
|
|
|
TRACE("Calling SHCreateShellFolderViewEx\n");
|
|
|
|
ret = SHCreateShellFolderViewEx(&sfv, &tmp);
|
|
|
|
TRACE("Result: %08x, output: %p\n", (unsigned int)ret, tmp);
|
|
|
|
*ppv = tmp;
|
|
|
|
return ret;
|
|
|
|
}
|
2021-05-03 03:12:07 +02:00
|
|
|
else
|
|
|
|
FIXME("invalid/unsupported interface %s\n", debugstr_guid(riid));
|
2006-08-03 19:11:07 +02:00
|
|
|
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI RecycleBin_GetAttributesOf(IShellFolder2 *This, UINT cidl, LPCITEMIDLIST *apidl,
|
|
|
|
SFGAOF *rgfInOut)
|
|
|
|
{
|
2008-01-19 17:54:28 +01:00
|
|
|
TRACE("(%p, %d, {%p, ...}, {%x})\n", This, cidl, apidl[0], *rgfInOut);
|
2006-08-03 19:11:07 +02:00
|
|
|
*rgfInOut &= SFGAO_CANMOVE|SFGAO_CANDELETE|SFGAO_HASPROPSHEET|SFGAO_FILESYSTEM;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2011-07-08 16:47:03 +02:00
|
|
|
static HRESULT WINAPI RecycleBin_GetUIObjectOf(IShellFolder2 *iface, HWND hwndOwner, UINT cidl, LPCITEMIDLIST *apidl,
|
2006-08-03 19:11:07 +02:00
|
|
|
REFIID riid, UINT *rgfReserved, void **ppv)
|
|
|
|
{
|
2011-07-08 16:47:03 +02:00
|
|
|
RecycleBin *This = impl_from_IShellFolder2(iface);
|
2006-08-03 19:11:07 +02:00
|
|
|
*ppv = NULL;
|
2011-07-08 16:47:03 +02:00
|
|
|
if(IsEqualGUID(riid, &IID_IContextMenu) || IsEqualGUID(riid, &IID_IContextMenu2))
|
|
|
|
{
|
|
|
|
TRACE("(%p, %p, %d, {%p, ...}, %s, %p, %p)\n", This, hwndOwner, cidl, apidl[0], debugstr_guid(riid), rgfReserved, ppv);
|
|
|
|
*ppv = RecycleBinMenu_Constructor(cidl,apidl,&(This->IShellFolder2_iface));
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
FIXME("(%p, %p, %d, {%p, ...}, %s, %p, %p): stub!\n", iface, hwndOwner, cidl, apidl[0], debugstr_guid(riid), rgfReserved, ppv);
|
|
|
|
|
2006-08-03 19:11:07 +02:00
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI RecycleBin_GetDisplayNameOf(IShellFolder2 *This, LPCITEMIDLIST pidl, SHGDNF uFlags, STRRET *pName)
|
|
|
|
{
|
2021-09-16 17:14:58 +02:00
|
|
|
const WIN32_FIND_DATAW *data = get_trash_item_data( pidl );
|
2006-08-03 19:11:07 +02:00
|
|
|
|
2008-01-19 17:54:28 +01:00
|
|
|
TRACE("(%p, %p, %x, %p)\n", This, pidl, uFlags, pName);
|
2006-08-03 19:11:07 +02:00
|
|
|
pName->uType = STRRET_WSTR;
|
2021-09-16 17:14:58 +02:00
|
|
|
return SHStrDupW(PathFindFileNameW(data->cFileName), &pName->u.pOleStr);
|
2006-08-03 19:11:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI RecycleBin_SetNameOf(IShellFolder2 *This, HWND hwnd, LPCITEMIDLIST pidl, LPCOLESTR pszName,
|
|
|
|
SHGDNF uFlags, LPITEMIDLIST *ppidlOut)
|
|
|
|
{
|
|
|
|
TRACE("\n");
|
|
|
|
return E_FAIL; /* not supported */
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI RecycleBin_GetClassID(IPersistFolder2 *This, CLSID *pClassID)
|
|
|
|
{
|
|
|
|
TRACE("(%p, %p)\n", This, pClassID);
|
|
|
|
if (This == NULL || pClassID == NULL)
|
|
|
|
return E_INVALIDARG;
|
2008-03-17 22:36:59 +01:00
|
|
|
*pClassID = CLSID_RecycleBin;
|
2006-08-03 19:11:07 +02:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI RecycleBin_Initialize(IPersistFolder2 *iface, LPCITEMIDLIST pidl)
|
|
|
|
{
|
2011-01-27 10:46:37 +01:00
|
|
|
RecycleBin *This = impl_from_IPersistFolder2(iface);
|
2006-08-03 19:11:07 +02:00
|
|
|
TRACE("(%p, %p)\n", This, pidl);
|
2011-01-27 10:46:37 +01:00
|
|
|
|
2006-08-03 19:11:07 +02:00
|
|
|
This->pidl = ILClone(pidl);
|
|
|
|
if (This->pidl == NULL)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI RecycleBin_GetCurFolder(IPersistFolder2 *iface, LPITEMIDLIST *ppidl)
|
|
|
|
{
|
2011-01-27 10:46:37 +01:00
|
|
|
RecycleBin *This = impl_from_IPersistFolder2(iface);
|
2006-08-03 19:11:07 +02:00
|
|
|
TRACE("\n");
|
|
|
|
*ppidl = ILClone(This->pidl);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2017-09-27 10:13:43 +02:00
|
|
|
static HRESULT WINAPI RecycleBin_GetDefaultSearchGUID(IShellFolder2 *iface, GUID *guid)
|
2006-08-03 19:11:07 +02:00
|
|
|
{
|
2017-09-27 10:13:43 +02:00
|
|
|
RecycleBin *This = impl_from_IShellFolder2(iface);
|
|
|
|
TRACE("(%p)->(%p)\n", This, guid);
|
2006-08-03 19:11:07 +02:00
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI RecycleBin_EnumSearches(IShellFolder2 *iface, IEnumExtraSearch **ppEnum)
|
|
|
|
{
|
|
|
|
FIXME("stub\n");
|
|
|
|
*ppEnum = NULL;
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
2017-09-27 10:13:42 +02:00
|
|
|
static HRESULT WINAPI RecycleBin_GetDefaultColumn(IShellFolder2 *iface, DWORD reserved, ULONG *sort, ULONG *display)
|
2006-08-03 19:11:07 +02:00
|
|
|
{
|
2011-01-27 10:46:37 +01:00
|
|
|
RecycleBin *This = impl_from_IShellFolder2(iface);
|
2017-09-27 10:13:42 +02:00
|
|
|
|
|
|
|
TRACE("(%p)->(%#x, %p, %p)\n", This, reserved, sort, display);
|
|
|
|
|
|
|
|
return E_NOTIMPL;
|
2006-08-03 19:11:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI RecycleBin_GetDefaultColumnState(IShellFolder2 *iface, UINT iColumn, SHCOLSTATEF *pcsFlags)
|
|
|
|
{
|
2011-01-27 10:46:37 +01:00
|
|
|
RecycleBin *This = impl_from_IShellFolder2(iface);
|
2006-08-03 19:11:07 +02:00
|
|
|
TRACE("(%p, %d, %p)\n", This, iColumn, pcsFlags);
|
2007-11-01 17:58:32 +01:00
|
|
|
if (iColumn >= COLUMNS_COUNT)
|
2006-08-03 19:11:07 +02:00
|
|
|
return E_INVALIDARG;
|
|
|
|
*pcsFlags = RecycleBinColumns[iColumn].pcsFlags;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI RecycleBin_GetDetailsEx(IShellFolder2 *iface, LPCITEMIDLIST pidl, const SHCOLUMNID *pscid, VARIANT *pv)
|
|
|
|
{
|
|
|
|
FIXME("stub\n");
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI RecycleBin_GetDetailsOf(IShellFolder2 *iface, LPCITEMIDLIST pidl, UINT iColumn, LPSHELLDETAILS pDetails)
|
|
|
|
{
|
2011-01-27 10:46:37 +01:00
|
|
|
RecycleBin *This = impl_from_IShellFolder2(iface);
|
2021-09-16 17:14:58 +02:00
|
|
|
const WIN32_FIND_DATAW *data;
|
2006-08-03 19:11:07 +02:00
|
|
|
WCHAR buffer[MAX_PATH];
|
|
|
|
|
|
|
|
TRACE("(%p, %p, %d, %p)\n", This, pidl, iColumn, pDetails);
|
2007-11-01 17:58:32 +01:00
|
|
|
if (iColumn >= COLUMNS_COUNT)
|
2006-08-03 19:11:07 +02:00
|
|
|
return E_FAIL;
|
2021-09-10 18:50:19 +02:00
|
|
|
|
|
|
|
if (!pidl) return SHELL32_GetColumnDetails( RecycleBinColumns, iColumn, pDetails );
|
2006-08-03 19:11:07 +02:00
|
|
|
|
|
|
|
if (iColumn == COLUMN_NAME)
|
|
|
|
return RecycleBin_GetDisplayNameOf(iface, pidl, SHGDN_NORMAL, &pDetails->str);
|
|
|
|
|
2021-09-16 17:14:58 +02:00
|
|
|
data = get_trash_item_data( pidl );
|
2006-08-03 19:11:07 +02:00
|
|
|
switch (iColumn)
|
|
|
|
{
|
|
|
|
case COLUMN_DATEDEL:
|
2021-09-16 17:14:58 +02:00
|
|
|
FormatDateTime(buffer, MAX_PATH, data->ftLastAccessTime);
|
2006-08-03 19:11:07 +02:00
|
|
|
break;
|
|
|
|
case COLUMN_DELFROM:
|
2021-09-16 17:14:58 +02:00
|
|
|
lstrcpyW(buffer, data->cFileName);
|
2006-08-03 19:11:07 +02:00
|
|
|
PathRemoveFileSpecW(buffer);
|
|
|
|
break;
|
|
|
|
case COLUMN_SIZE:
|
2021-09-16 17:14:58 +02:00
|
|
|
StrFormatKBSizeW(((LONGLONG)data->nFileSizeHigh<<32)|data->nFileSizeLow, buffer, MAX_PATH);
|
2006-08-03 19:11:07 +02:00
|
|
|
break;
|
|
|
|
case COLUMN_MTIME:
|
2021-09-16 17:14:58 +02:00
|
|
|
FormatDateTime(buffer, MAX_PATH, data->ftLastWriteTime);
|
2006-08-03 19:11:07 +02:00
|
|
|
break;
|
|
|
|
case COLUMN_TYPE:
|
|
|
|
/* TODO */
|
|
|
|
buffer[0] = 0;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
pDetails->str.uType = STRRET_WSTR;
|
2007-11-01 23:02:57 +01:00
|
|
|
return SHStrDupW(buffer, &pDetails->str.u.pOleStr);
|
2006-08-03 19:11:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI RecycleBin_MapColumnToSCID(IShellFolder2 *iface, UINT iColumn, SHCOLUMNID *pscid)
|
|
|
|
{
|
2011-01-27 10:46:37 +01:00
|
|
|
RecycleBin *This = impl_from_IShellFolder2(iface);
|
2006-08-03 19:11:07 +02:00
|
|
|
TRACE("(%p, %d, %p)\n", This, iColumn, pscid);
|
2007-11-01 17:58:32 +01:00
|
|
|
if (iColumn>=COLUMNS_COUNT)
|
2006-08-03 19:11:07 +02:00
|
|
|
return E_INVALIDARG;
|
2021-09-10 18:50:19 +02:00
|
|
|
|
|
|
|
return shellfolder_map_column_to_scid(RecycleBinColumns, iColumn, pscid);
|
2006-08-03 19:11:07 +02:00
|
|
|
}
|
|
|
|
|
2006-11-28 11:38:58 +01:00
|
|
|
static const IShellFolder2Vtbl recycleBinVtbl =
|
2006-08-03 19:11:07 +02:00
|
|
|
{
|
|
|
|
/* IUnknown */
|
|
|
|
RecycleBin_QueryInterface,
|
|
|
|
RecycleBin_AddRef,
|
|
|
|
RecycleBin_Release,
|
|
|
|
|
|
|
|
/* IShellFolder */
|
|
|
|
RecycleBin_ParseDisplayName,
|
|
|
|
RecycleBin_EnumObjects,
|
|
|
|
RecycleBin_BindToObject,
|
|
|
|
RecycleBin_BindToStorage,
|
|
|
|
RecycleBin_CompareIDs,
|
|
|
|
RecycleBin_CreateViewObject,
|
|
|
|
RecycleBin_GetAttributesOf,
|
|
|
|
RecycleBin_GetUIObjectOf,
|
|
|
|
RecycleBin_GetDisplayNameOf,
|
|
|
|
RecycleBin_SetNameOf,
|
|
|
|
|
|
|
|
/* IShellFolder2 */
|
|
|
|
RecycleBin_GetDefaultSearchGUID,
|
|
|
|
RecycleBin_EnumSearches,
|
|
|
|
RecycleBin_GetDefaultColumn,
|
|
|
|
RecycleBin_GetDefaultColumnState,
|
|
|
|
RecycleBin_GetDetailsEx,
|
|
|
|
RecycleBin_GetDetailsOf,
|
|
|
|
RecycleBin_MapColumnToSCID
|
|
|
|
};
|
|
|
|
|
2011-01-27 10:46:37 +01:00
|
|
|
static HRESULT WINAPI RecycleBin_IPersistFolder2_QueryInterface(IPersistFolder2 *iface, REFIID riid,
|
|
|
|
void **ppvObject)
|
2006-08-03 19:11:07 +02:00
|
|
|
{
|
2011-01-27 10:46:37 +01:00
|
|
|
RecycleBin *This = impl_from_IPersistFolder2(iface);
|
|
|
|
|
2013-09-03 15:09:07 +02:00
|
|
|
return IShellFolder2_QueryInterface(&This->IShellFolder2_iface, riid, ppvObject);
|
2006-08-03 19:11:07 +02:00
|
|
|
}
|
|
|
|
|
2011-01-27 10:46:37 +01:00
|
|
|
static ULONG WINAPI RecycleBin_IPersistFolder2_AddRef(IPersistFolder2 *iface)
|
2006-08-03 19:11:07 +02:00
|
|
|
{
|
2011-01-27 10:46:37 +01:00
|
|
|
RecycleBin *This = impl_from_IPersistFolder2(iface);
|
|
|
|
|
2013-09-03 15:09:07 +02:00
|
|
|
return IShellFolder2_AddRef(&This->IShellFolder2_iface);
|
2006-08-03 19:11:07 +02:00
|
|
|
}
|
|
|
|
|
2011-01-27 10:46:37 +01:00
|
|
|
static ULONG WINAPI RecycleBin_IPersistFolder2_Release(IPersistFolder2 *iface)
|
2006-08-03 19:11:07 +02:00
|
|
|
{
|
2011-01-27 10:46:37 +01:00
|
|
|
RecycleBin *This = impl_from_IPersistFolder2(iface);
|
|
|
|
|
2013-09-03 15:09:07 +02:00
|
|
|
return IShellFolder2_Release(&This->IShellFolder2_iface);
|
2006-08-03 19:11:07 +02:00
|
|
|
}
|
|
|
|
|
2006-11-28 11:38:58 +01:00
|
|
|
static const IPersistFolder2Vtbl recycleBinPersistVtbl =
|
2006-08-03 19:11:07 +02:00
|
|
|
{
|
|
|
|
/* IUnknown */
|
|
|
|
RecycleBin_IPersistFolder2_QueryInterface,
|
|
|
|
RecycleBin_IPersistFolder2_AddRef,
|
|
|
|
RecycleBin_IPersistFolder2_Release,
|
|
|
|
|
|
|
|
/* IPersist */
|
|
|
|
RecycleBin_GetClassID,
|
|
|
|
/* IPersistFolder */
|
|
|
|
RecycleBin_Initialize,
|
|
|
|
/* IPersistFolder2 */
|
|
|
|
RecycleBin_GetCurFolder
|
|
|
|
};
|
2007-06-10 13:08:09 +02:00
|
|
|
|
2011-07-08 16:46:57 +02:00
|
|
|
static HRESULT WINAPI RecycleBin_ISFHelper_QueryInterface(ISFHelper *iface, REFIID riid,
|
|
|
|
void **ppvObject)
|
|
|
|
{
|
|
|
|
RecycleBin *This = impl_from_ISFHelper(iface);
|
|
|
|
|
2013-09-03 15:09:07 +02:00
|
|
|
return IShellFolder2_QueryInterface(&This->IShellFolder2_iface, riid, ppvObject);
|
2011-07-08 16:46:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI RecycleBin_ISFHelper_AddRef(ISFHelper *iface)
|
|
|
|
{
|
|
|
|
RecycleBin *This = impl_from_ISFHelper(iface);
|
|
|
|
|
2013-09-03 15:09:07 +02:00
|
|
|
return IShellFolder2_AddRef(&This->IShellFolder2_iface);
|
2011-07-08 16:46:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI RecycleBin_ISFHelper_Release(ISFHelper *iface)
|
|
|
|
{
|
|
|
|
RecycleBin *This = impl_from_ISFHelper(iface);
|
|
|
|
|
2013-09-03 15:09:07 +02:00
|
|
|
return IShellFolder2_Release(&This->IShellFolder2_iface);
|
2011-07-08 16:46:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI RecycleBin_GetUniqueName(ISFHelper *iface,LPWSTR lpName,
|
|
|
|
UINT uLen)
|
|
|
|
{
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI RecycleBin_AddFolder(ISFHelper * iface, HWND hwnd,
|
|
|
|
LPCWSTR pwszName,
|
|
|
|
LPITEMIDLIST * ppidlOut)
|
|
|
|
{
|
|
|
|
/*Adding folders doesn't make sense in the recycle bin*/
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
2011-07-14 13:14:25 +02:00
|
|
|
static HRESULT erase_items(HWND parent,const LPCITEMIDLIST * apidl, UINT cidl, BOOL confirm)
|
2011-07-08 16:46:49 +02:00
|
|
|
{
|
|
|
|
UINT i=0;
|
|
|
|
HRESULT ret = S_OK;
|
|
|
|
LPITEMIDLIST recyclebin;
|
|
|
|
|
|
|
|
if(confirm)
|
|
|
|
{
|
|
|
|
WCHAR arg[MAX_PATH];
|
|
|
|
WCHAR message[100];
|
|
|
|
WCHAR caption[50];
|
|
|
|
switch(cidl)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
return S_OK;
|
|
|
|
case 1:
|
|
|
|
{
|
2021-09-16 17:14:58 +02:00
|
|
|
const WIN32_FIND_DATAW *data = get_trash_item_data( apidl[0] );
|
|
|
|
lstrcpynW(arg,data->cFileName,MAX_PATH);
|
2018-03-19 08:11:27 +01:00
|
|
|
LoadStringW(shell32_hInstance, IDS_RECYCLEBIN_ERASEITEM, message, ARRAY_SIZE(message));
|
2011-07-08 16:46:49 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
{
|
2018-03-19 08:11:27 +01:00
|
|
|
LoadStringW(shell32_hInstance, IDS_RECYCLEBIN_ERASEMULTIPLE, message, ARRAY_SIZE(message));
|
2021-09-17 17:16:11 +02:00
|
|
|
swprintf(arg, ARRAY_SIZE(arg), L"%u", cidl);
|
2011-07-08 16:46:49 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2018-03-19 08:11:27 +01:00
|
|
|
LoadStringW(shell32_hInstance, IDS_RECYCLEBIN_ERASE_CAPTION, caption, ARRAY_SIZE(caption));
|
2011-07-08 16:46:49 +02:00
|
|
|
if(ShellMessageBoxW(shell32_hInstance,parent,message,caption,
|
|
|
|
MB_YESNO|MB_ICONEXCLAMATION,arg)!=IDYES)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
}
|
|
|
|
SHGetFolderLocation(parent,CSIDL_BITBUCKET,0,0,&recyclebin);
|
|
|
|
for (; i<cidl; i++)
|
|
|
|
{
|
2021-09-16 17:16:57 +02:00
|
|
|
if(SUCCEEDED(erase_trash_item(apidl[i])))
|
2011-07-08 16:46:49 +02:00
|
|
|
SHChangeNotify(SHCNE_DELETE,SHCNF_IDLIST,
|
|
|
|
ILCombine(recyclebin,apidl[i]),0);
|
|
|
|
}
|
|
|
|
ILFree(recyclebin);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2011-07-08 16:46:57 +02:00
|
|
|
static HRESULT WINAPI RecycleBin_DeleteItems(ISFHelper * iface, UINT cidl,
|
|
|
|
LPCITEMIDLIST * apidl)
|
|
|
|
{
|
|
|
|
TRACE("(%p,%u,%p)\n",iface,cidl,apidl);
|
|
|
|
return erase_items(GetActiveWindow(),apidl,cidl,TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI RecycleBin_CopyItems(ISFHelper * iface,
|
|
|
|
IShellFolder * pSFFrom,
|
|
|
|
UINT cidl, LPCITEMIDLIST * apidl)
|
|
|
|
{
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const ISFHelperVtbl sfhelperVtbl =
|
|
|
|
{
|
|
|
|
RecycleBin_ISFHelper_QueryInterface,
|
|
|
|
RecycleBin_ISFHelper_AddRef,
|
|
|
|
RecycleBin_ISFHelper_Release,
|
|
|
|
RecycleBin_GetUniqueName,
|
|
|
|
RecycleBin_AddFolder,
|
|
|
|
RecycleBin_DeleteItems,
|
|
|
|
RecycleBin_CopyItems
|
|
|
|
};
|
|
|
|
|
2011-07-08 16:46:44 +02:00
|
|
|
HRESULT WINAPI SHQueryRecycleBinA(LPCSTR pszRootPath, LPSHQUERYRBINFO pSHQueryRBInfo)
|
|
|
|
{
|
|
|
|
WCHAR wszRootPath[MAX_PATH];
|
|
|
|
MultiByteToWideChar(CP_ACP, 0, pszRootPath, -1, wszRootPath, MAX_PATH);
|
|
|
|
return SHQueryRecycleBinW(wszRootPath, pSHQueryRBInfo);
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT WINAPI SHQueryRecycleBinW(LPCWSTR pszRootPath, LPSHQUERYRBINFO pSHQueryRBInfo)
|
|
|
|
{
|
|
|
|
LPITEMIDLIST *apidl;
|
|
|
|
INT cidl;
|
|
|
|
INT i=0;
|
2015-01-30 17:03:30 +01:00
|
|
|
HRESULT hr;
|
|
|
|
|
2011-07-08 16:46:44 +02:00
|
|
|
TRACE("(%s, %p)\n", debugstr_w(pszRootPath), pSHQueryRBInfo);
|
|
|
|
|
2021-09-16 17:16:57 +02:00
|
|
|
hr = enum_trash_items(&apidl, &cidl);
|
2015-01-30 17:03:30 +01:00
|
|
|
if (FAILED(hr))
|
|
|
|
return hr;
|
2011-07-08 16:46:44 +02:00
|
|
|
pSHQueryRBInfo->i64NumItems = cidl;
|
|
|
|
pSHQueryRBInfo->i64Size = 0;
|
|
|
|
for (; i<cidl; i++)
|
|
|
|
{
|
2021-09-16 17:14:58 +02:00
|
|
|
const WIN32_FIND_DATAW *data = get_trash_item_data( apidl[i] );
|
|
|
|
pSHQueryRBInfo->i64Size += ((DWORDLONG)data->nFileSizeHigh << 32) + data->nFileSizeLow;
|
2011-07-08 16:46:44 +02:00
|
|
|
ILFree(apidl[i]);
|
|
|
|
}
|
|
|
|
SHFree(apidl);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2011-07-08 16:46:49 +02:00
|
|
|
HRESULT WINAPI SHEmptyRecycleBinA(HWND hwnd, LPCSTR pszRootPath, DWORD dwFlags)
|
|
|
|
{
|
|
|
|
WCHAR wszRootPath[MAX_PATH];
|
|
|
|
MultiByteToWideChar(CP_ACP, 0, pszRootPath, -1, wszRootPath, MAX_PATH);
|
|
|
|
return SHEmptyRecycleBinW(hwnd, wszRootPath, dwFlags);
|
|
|
|
}
|
|
|
|
|
|
|
|
#define SHERB_NOCONFIRMATION 1
|
|
|
|
#define SHERB_NOPROGRESSUI 2
|
|
|
|
#define SHERB_NOSOUND 4
|
|
|
|
|
|
|
|
HRESULT WINAPI SHEmptyRecycleBinW(HWND hwnd, LPCWSTR pszRootPath, DWORD dwFlags)
|
|
|
|
{
|
|
|
|
LPITEMIDLIST *apidl;
|
|
|
|
INT cidl;
|
|
|
|
INT i=0;
|
|
|
|
HRESULT ret;
|
2015-01-30 17:03:30 +01:00
|
|
|
|
2011-07-08 16:46:49 +02:00
|
|
|
TRACE("(%p, %s, 0x%08x)\n", hwnd, debugstr_w(pszRootPath) , dwFlags);
|
2015-01-30 17:03:30 +01:00
|
|
|
|
2021-09-16 17:16:57 +02:00
|
|
|
ret = enum_trash_items(&apidl, &cidl);
|
2015-01-30 17:03:30 +01:00
|
|
|
if (FAILED(ret))
|
|
|
|
return ret;
|
|
|
|
|
2011-07-08 16:46:49 +02:00
|
|
|
ret = erase_items(hwnd,(const LPCITEMIDLIST*)apidl,cidl,!(dwFlags & SHERB_NOCONFIRMATION));
|
|
|
|
for (;i<cidl;i++)
|
|
|
|
ILFree(apidl[i]);
|
|
|
|
SHFree(apidl);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2007-06-10 13:08:09 +02:00
|
|
|
/*************************************************************************
|
|
|
|
* SHUpdateRecycleBinIcon [SHELL32.@]
|
|
|
|
*
|
|
|
|
* Undocumented
|
|
|
|
*/
|
|
|
|
HRESULT WINAPI SHUpdateRecycleBinIcon(void)
|
|
|
|
{
|
|
|
|
FIXME("stub\n");
|
|
|
|
return S_OK;
|
|
|
|
}
|