[SHELL32]

* Another partial sync of changenotify.c with Wine 1.7.27.
CORE-8540

svn path=/branches/shell-experiments/; revision=65288
This commit is contained in:
Amine Khaldi 2014-11-06 16:35:20 +00:00
parent 0bf0ff1e78
commit 4b78f524f2

View file

@ -29,6 +29,7 @@
#include <undocshell.h> #include <undocshell.h>
#include <shlwapi.h> #include <shlwapi.h>
#include <wine/debug.h> #include <wine/debug.h>
#include <wine/list.h>
#include "pidl.h" #include "pidl.h"
@ -48,20 +49,18 @@ typedef SHChangeNotifyEntry *LPNOTIFYREGISTER;
/* internal list of notification clients (internal) */ /* internal list of notification clients (internal) */
typedef struct _NOTIFICATIONLIST typedef struct _NOTIFICATIONLIST
{ {
struct _NOTIFICATIONLIST *next; struct list entry;
struct _NOTIFICATIONLIST *prev;
HWND hwnd; /* window to notify */ HWND hwnd; /* window to notify */
DWORD uMsg; /* message to send */ DWORD uMsg; /* message to send */
LPNOTIFYREGISTER apidl; /* array of entries to watch*/ LPNOTIFYREGISTER apidl; /* array of entries to watch*/
UINT cidl; /* number of pidls in array */ UINT cidl; /* number of pidls in array */
LONG wEventMask; /* subscribed events */ LONG wEventMask; /* subscribed events */
LONG wSignalledEvent; /* event that occurred */
DWORD dwFlags; /* client flags */ DWORD dwFlags; /* client flags */
LPCITEMIDLIST pidlSignaled; /*pidl of the path that caused the signal*/ ULONG id;
} NOTIFICATIONLIST, *LPNOTIFICATIONLIST; } NOTIFICATIONLIST, *LPNOTIFICATIONLIST;
static NOTIFICATIONLIST *head, *tail; static struct list notifications = LIST_INIT( notifications );
static LONG next_id;
#define SHCNE_NOITEMEVENTS ( \ #define SHCNE_NOITEMEVENTS ( \
SHCNE_ASSOCCHANGED ) SHCNE_ASSOCCHANGED )
@ -121,44 +120,14 @@ static const char * NodeName(const NOTIFICATIONLIST *item)
return str; return str;
} }
static void AddNode(LPNOTIFICATIONLIST item)
{
TRACE("item %p\n", item );
/* link items */
item->prev = tail;
item->next = NULL;
if( tail )
tail->next = item;
else
head = item;
tail = item;
}
static LPNOTIFICATIONLIST FindNode( HANDLE hitem )
{
LPNOTIFICATIONLIST ptr;
for( ptr = head; ptr; ptr = ptr->next )
if( ptr == (LPNOTIFICATIONLIST) hitem )
return ptr;
return NULL;
}
static void DeleteNode(LPNOTIFICATIONLIST item) static void DeleteNode(LPNOTIFICATIONLIST item)
{ {
UINT i; UINT i;
TRACE("item=%p prev=%p next=%p\n", item, item->prev, item->next); TRACE("item=%p\n", item);
/* remove item from list */ /* remove item from list */
if( item->prev ) list_remove( &item->entry );
item->prev->next = item->next;
else
head = item->next;
if( item->next )
item->next->prev = item->prev;
else
tail = item->prev;
/* free the item */ /* free the item */
for (i=0; i<item->cidl; i++) for (i=0; i<item->cidl; i++)
@ -173,16 +142,18 @@ void InitChangeNotifications(void)
void FreeChangeNotifications(void) void FreeChangeNotifications(void)
{ {
LPNOTIFICATIONLIST ptr, next;
TRACE("\n"); TRACE("\n");
EnterCriticalSection(&SHELL32_ChangenotifyCS); EnterCriticalSection(&SHELL32_ChangenotifyCS);
while( head ) LIST_FOR_EACH_ENTRY_SAFE( ptr, next, &notifications, NOTIFICATIONLIST, entry )
DeleteNode( head ); DeleteNode( ptr );
LeaveCriticalSection(&SHELL32_ChangenotifyCS); LeaveCriticalSection(&SHELL32_ChangenotifyCS);
// DeleteCriticalSection(&SHELL32_ChangenotifyCS); // static DeleteCriticalSection(&SHELL32_ChangenotifyCS);
} }
/************************************************************************* /*************************************************************************
@ -201,15 +172,13 @@ SHChangeNotifyRegister(
LPNOTIFICATIONLIST item; LPNOTIFICATIONLIST item;
int i; int i;
item = (NOTIFICATIONLIST *)SHAlloc(sizeof(NOTIFICATIONLIST)); item = SHAlloc(sizeof(NOTIFICATIONLIST));
TRACE("(%p,0x%08x,0x%08x,0x%08x,%d,%p) item=%p\n", TRACE("(%p,0x%08x,0x%08x,0x%08x,%d,%p) item=%p\n",
hwnd, fSources, wEventMask, uMsg, cItems, lpItems, item); hwnd, fSources, wEventMask, uMsg, cItems, lpItems, item);
item->next = NULL;
item->prev = NULL;
item->cidl = cItems; item->cidl = cItems;
item->apidl = (SHChangeNotifyEntry *)SHAlloc(sizeof(SHChangeNotifyEntry) * cItems); item->apidl = SHAlloc(sizeof(SHChangeNotifyEntry) * cItems);
for(i=0;i<cItems;i++) for(i=0;i<cItems;i++)
{ {
item->apidl[i].pidl = ILClone(lpItems[i].pidl); item->apidl[i].pidl = ILClone(lpItems[i].pidl);
@ -218,18 +187,18 @@ SHChangeNotifyRegister(
item->hwnd = hwnd; item->hwnd = hwnd;
item->uMsg = uMsg; item->uMsg = uMsg;
item->wEventMask = wEventMask; item->wEventMask = wEventMask;
item->wSignalledEvent = 0;
item->dwFlags = fSources; item->dwFlags = fSources;
item->id = InterlockedIncrement( &next_id );
TRACE("new node: %s\n", NodeName( item )); TRACE("new node: %s\n", NodeName( item ));
EnterCriticalSection(&SHELL32_ChangenotifyCS); EnterCriticalSection(&SHELL32_ChangenotifyCS);
AddNode(item); list_add_tail( &notifications, &item->entry );
LeaveCriticalSection(&SHELL32_ChangenotifyCS); LeaveCriticalSection(&SHELL32_ChangenotifyCS);
return (ULONG)item; return item->id;
} }
/************************************************************************* /*************************************************************************
@ -243,26 +212,40 @@ BOOL WINAPI SHChangeNotifyDeregister(ULONG hNotify)
EnterCriticalSection(&SHELL32_ChangenotifyCS); EnterCriticalSection(&SHELL32_ChangenotifyCS);
node = FindNode((HANDLE)hNotify); LIST_FOR_EACH_ENTRY( node, &notifications, NOTIFICATIONLIST, entry )
if( node ) {
if (node->id == hNotify)
{
DeleteNode( node ); DeleteNode( node );
LeaveCriticalSection(&SHELL32_ChangenotifyCS); LeaveCriticalSection(&SHELL32_ChangenotifyCS);
return node?TRUE:FALSE; return TRUE;
}
}
LeaveCriticalSection(&SHELL32_ChangenotifyCS);
return FALSE;
} }
/************************************************************************* /*************************************************************************
* SHChangeNotifyUpdateEntryList [SHELL32.5] * SHChangeNotifyUpdateEntryList [SHELL32.5]
*/ */
EXTERN_C BOOL WINAPI SHChangeNotifyUpdateEntryList(DWORD unknown1, DWORD unknown2, BOOL WINAPI SHChangeNotifyUpdateEntryList(DWORD unknown1, DWORD unknown2,
DWORD unknown3, DWORD unknown4) DWORD unknown3, DWORD unknown4)
{ {
FIXME("(0x%08x, 0x%08x, 0x%08x, 0x%08x)\n", FIXME("(0x%08x, 0x%08x, 0x%08x, 0x%08x)\n",
unknown1, unknown2, unknown3, unknown4); unknown1, unknown2, unknown3, unknown4);
return -1; return TRUE;
} }
struct new_delivery_notification
{
LONG event;
DWORD pidl1_size;
DWORD pidl2_size;
LPITEMIDLIST pidls[2];
BYTE data[1];
};
static BOOL should_notify( LPCITEMIDLIST changed, LPCITEMIDLIST watched, BOOL sub ) static BOOL should_notify( LPCITEMIDLIST changed, LPCITEMIDLIST watched, BOOL sub )
{ {
TRACE("%p %p %d\n", changed, watched, sub ); TRACE("%p %p %d\n", changed, watched, sub );
@ -270,8 +253,9 @@ static BOOL should_notify( LPCITEMIDLIST changed, LPCITEMIDLIST watched, BOOL su
return FALSE; return FALSE;
if (ILIsEqual( watched, changed ) ) if (ILIsEqual( watched, changed ) )
return TRUE; return TRUE;
if( sub && ILIsParent( watched, changed, TRUE ) ) if( sub && ILIsParent( watched, changed, FALSE ) )
return TRUE; return TRUE;
#ifdef __REACTOS__
if (sub && _ILIsDesktop(watched)) { if (sub && _ILIsDesktop(watched)) {
LPITEMIDLIST deskpidl; LPITEMIDLIST deskpidl;
WCHAR wszPath[MAX_PATH]; WCHAR wszPath[MAX_PATH];
@ -292,6 +276,7 @@ static BOOL should_notify( LPCITEMIDLIST changed, LPCITEMIDLIST watched, BOOL su
} }
ILFree(deskpidl); ILFree(deskpidl);
} }
#endif
return FALSE; return FALSE;
} }
@ -300,14 +285,25 @@ static BOOL should_notify( LPCITEMIDLIST changed, LPCITEMIDLIST watched, BOOL su
*/ */
void WINAPI SHChangeNotify(LONG wEventId, UINT uFlags, LPCVOID dwItem1, LPCVOID dwItem2) void WINAPI SHChangeNotify(LONG wEventId, UINT uFlags, LPCVOID dwItem1, LPCVOID dwItem2)
{ {
struct notification_recipients {
struct list entry;
HWND hwnd;
DWORD msg;
DWORD flags;
} *cur, *next;
HANDLE shared_data = NULL;
LPITEMIDLIST Pidls[2]; LPITEMIDLIST Pidls[2];
LPNOTIFICATIONLIST ptr; LPNOTIFICATIONLIST ptr;
UINT typeFlag = uFlags & SHCNF_TYPE; struct list recipients;
Pidls[0] = NULL; Pidls[0] = NULL;
Pidls[1] = NULL; Pidls[1] = NULL;
TRACE("(0x%08x,0x%08x,%p,%p):stub.\n", wEventId, uFlags, dwItem1, dwItem2); TRACE("(0x%08x,0x%08x,%p,%p)\n", wEventId, uFlags, dwItem1, dwItem2);
if(uFlags & ~(SHCNF_TYPE|SHCNF_FLUSH))
FIXME("ignoring unsupported flags: %x\n", uFlags);
if( ( wEventId & SHCNE_NOITEMEVENTS ) && ( dwItem1 || dwItem2 ) ) if( ( wEventId & SHCNE_NOITEMEVENTS ) && ( dwItem1 || dwItem2 ) )
{ {
@ -335,15 +331,16 @@ void WINAPI SHChangeNotify(LONG wEventId, UINT uFlags, LPCVOID dwItem1, LPCVOID
} }
/* convert paths in IDLists*/ /* convert paths in IDLists*/
switch (typeFlag) switch (uFlags & SHCNF_TYPE)
{ {
case SHCNF_PATHA: case SHCNF_PATHA:
if (dwItem1) Pidls[0] = SHSimpleIDListFromPathA((LPCSTR)dwItem1); //FIXME if (dwItem1) Pidls[0] = SHSimpleIDListFromPathA(dwItem1); //FIXME
if (dwItem2) Pidls[1] = SHSimpleIDListFromPathA((LPCSTR)dwItem2); //FIXME if (dwItem2) Pidls[1] = SHSimpleIDListFromPathA(dwItem2); //FIXME
break; break;
case SHCNF_PATHW: case SHCNF_PATHW:
if (dwItem1) Pidls[0] = SHSimpleIDListFromPathW((LPCWSTR)dwItem1); if (dwItem1) Pidls[0] = SHSimpleIDListFromPathW(dwItem1);
if (dwItem2) Pidls[1] = SHSimpleIDListFromPathW((LPCWSTR)dwItem2); if (dwItem2) Pidls[1] = SHSimpleIDListFromPathW(dwItem2);
#ifdef __REACTOS__
if (wEventId & (SHCNE_MKDIR | SHCNE_RMDIR | SHCNE_UPDATEDIR | SHCNE_RENAMEFOLDER)) if (wEventId & (SHCNE_MKDIR | SHCNE_RMDIR | SHCNE_UPDATEDIR | SHCNE_RENAMEFOLDER))
{ {
/* /*
@ -379,10 +376,11 @@ void WINAPI SHChangeNotify(LONG wEventId, UINT uFlags, LPCVOID dwItem1, LPCVOID
ILFree(oldpidl); ILFree(oldpidl);
} }
} }
#endif
break; break;
case SHCNF_IDLIST: case SHCNF_IDLIST:
Pidls[0] = (LPITEMIDLIST)dwItem1; Pidls[0] = ILClone(dwItem1);
Pidls[1] = (LPITEMIDLIST)dwItem2; Pidls[1] = ILClone(dwItem2);
break; break;
case SHCNF_PRINTERA: case SHCNF_PRINTERA:
case SHCNF_PRINTERW: case SHCNF_PRINTERW:
@ -390,32 +388,18 @@ void WINAPI SHChangeNotify(LONG wEventId, UINT uFlags, LPCVOID dwItem1, LPCVOID
return; return;
case SHCNF_DWORD: case SHCNF_DWORD:
default: default:
FIXME("unknown type %08x\n",typeFlag); FIXME("unknown type %08x\n", uFlags & SHCNF_TYPE);
return; return;
} }
{ list_init(&recipients);
WCHAR path[MAX_PATH];
if( Pidls[0] && SHGetPathFromIDListW(Pidls[0], path ))
TRACE("notify %08x on item1 = %s\n", wEventId, debugstr_w(path));
if( Pidls[1] && SHGetPathFromIDListW(Pidls[1], path ))
TRACE("notify %08x on item2 = %s\n", wEventId, debugstr_w(path));
}
EnterCriticalSection(&SHELL32_ChangenotifyCS); EnterCriticalSection(&SHELL32_ChangenotifyCS);
LIST_FOR_EACH_ENTRY( ptr, &notifications, NOTIFICATIONLIST, entry )
/* loop through the list */
for( ptr = head; ptr; ptr = ptr->next )
{ {
BOOL notify; struct notification_recipients *item;
BOOL notify = FALSE;
DWORD i; DWORD i;
notify = FALSE;
TRACE("trying %p\n", ptr);
for( i=0; (i<ptr->cidl) && !notify ; i++ ) for( i=0; (i<ptr->cidl) && !notify ; i++ )
{ {
LPCITEMIDLIST pidl = ptr->apidl[i].pidl; LPCITEMIDLIST pidl = ptr->apidl[i].pidl;
@ -437,33 +421,73 @@ void WINAPI SHChangeNotify(LONG wEventId, UINT uFlags, LPCVOID dwItem1, LPCVOID
if( !notify ) if( !notify )
continue; continue;
ptr->pidlSignaled = ILClone(Pidls[0]); item = SHAlloc(sizeof(struct notification_recipients));
if(!item) {
TRACE("notifying %s, event %s(%x) before\n", NodeName( ptr ), DumpEvent( ERR("out of memory\n");
wEventId ),wEventId ); continue;
}
ptr->wSignalledEvent |= wEventId;
item->hwnd = ptr->hwnd;
if (ptr->dwFlags & SHCNRF_NewDelivery) item->msg = ptr->uMsg;
SendMessageW(ptr->hwnd, ptr->uMsg, (WPARAM) ptr, (LPARAM) GetCurrentProcessId()); item->flags = ptr->dwFlags;
else list_add_tail(&recipients, &item->entry);
SendMessageW(ptr->hwnd, ptr->uMsg, (WPARAM)Pidls, wEventId);
TRACE("notifying %s, event %s(%x) after\n", NodeName( ptr ), DumpEvent(
wEventId ),wEventId );
} }
TRACE("notify Done\n");
LeaveCriticalSection(&SHELL32_ChangenotifyCS); LeaveCriticalSection(&SHELL32_ChangenotifyCS);
/* if we allocated it, free it. The ANSI flag is also set in its Unicode sibling. */ LIST_FOR_EACH_ENTRY_SAFE(cur, next, &recipients, struct notification_recipients, entry)
if ((typeFlag & SHCNF_PATHA) || (typeFlag & SHCNF_PRINTERA))
{ {
SHFree((LPITEMIDLIST)Pidls[0]); TRACE("notifying %p, event %s(%x)\n", cur->hwnd, DumpEvent(wEventId), wEventId);
SHFree((LPITEMIDLIST)Pidls[1]);
if (cur->flags & SHCNRF_NewDelivery) {
if(!shared_data) {
struct new_delivery_notification *notification;
UINT size1 = ILGetSize(Pidls[0]), size2 = ILGetSize(Pidls[1]);
UINT offset = (size1+sizeof(int)-1)/sizeof(int)*sizeof(int);
notification = SHAlloc(sizeof(struct new_delivery_notification)+offset+size2);
if(!notification) {
ERR("out of memory\n");
} else {
notification->event = wEventId;
notification->pidl1_size = size1;
notification->pidl2_size = size2;
if(size1)
memcpy(notification->data, Pidls[0], size1);
if(size2)
memcpy(notification->data+offset, Pidls[1], size2);
shared_data = SHAllocShared(notification,
sizeof(struct new_delivery_notification)+size1+size2,
GetCurrentProcessId());
SHFree(notification);
} }
} }
if(shared_data)
SendMessageA(cur->hwnd, cur->msg, (WPARAM)shared_data, GetCurrentProcessId());
else
ERR("out of memory\n");
} else {
SendMessageA(cur->hwnd, cur->msg, (WPARAM)Pidls, wEventId);
}
list_remove(&cur->entry);
SHFree(cur);
}
SHFreeShared(shared_data, GetCurrentProcessId());
SHFree(Pidls[0]);
SHFree(Pidls[1]);
#ifndef __REACTOS__
if (wEventId & SHCNE_ASSOCCHANGED)
{
static const WCHAR args[] = {' ','-','a',0 };
TRACE("refreshing file type associations\n");
run_winemenubuilder( args );
}
#endif
}
/************************************************************************* /*************************************************************************
* NTSHChangeNotifyRegister [SHELL32.640] * NTSHChangeNotifyRegister [SHELL32.640]
* NOTES * NOTES
@ -492,26 +516,28 @@ HANDLE WINAPI SHChangeNotification_Lock(
LPITEMIDLIST **lppidls, LPITEMIDLIST **lppidls,
LPLONG lpwEventId) LPLONG lpwEventId)
{ {
DWORD i; struct new_delivery_notification *ndn;
LPNOTIFICATIONLIST node; UINT offset;
LPCITEMIDLIST *idlist;
TRACE("%p %08x %p %p\n", hChange, dwProcessId, lppidls, lpwEventId); TRACE("%p %08x %p %p\n", hChange, dwProcessId, lppidls, lpwEventId);
node = FindNode( hChange ); ndn = SHLockShared(hChange, dwProcessId);
if( node ) if(!ndn) {
{ WARN("SHLockShared failed\n");
idlist = (LPCITEMIDLIST *)SHAlloc( sizeof(LPCITEMIDLIST *) * node->cidl ); return NULL;
for(i=0; i<node->cidl; i++)
idlist[i] = (LPCITEMIDLIST)node->pidlSignaled;
*lpwEventId = node->wSignalledEvent;
*lppidls = (LPITEMIDLIST*)idlist;
node->wSignalledEvent = 0;
} }
else
ERR("Couldn't find %p\n", hChange );
return (HANDLE) node; if(lppidls) {
offset = (ndn->pidl1_size+sizeof(int)-1)/sizeof(int)*sizeof(int);
ndn->pidls[0] = ndn->pidl1_size ? (LPITEMIDLIST)ndn->data : NULL;
ndn->pidls[1] = ndn->pidl2_size ? (LPITEMIDLIST)(ndn->data+offset) : NULL;
*lppidls = ndn->pidls;
}
if(lpwEventId)
*lpwEventId = ndn->event;
return ndn;
} }
/************************************************************************* /*************************************************************************
@ -519,14 +545,14 @@ HANDLE WINAPI SHChangeNotification_Lock(
*/ */
BOOL WINAPI SHChangeNotification_Unlock ( HANDLE hLock) BOOL WINAPI SHChangeNotification_Unlock ( HANDLE hLock)
{ {
TRACE("\n"); TRACE("%p\n", hLock);
return 1; return SHUnlockShared(hLock);
} }
/************************************************************************* /*************************************************************************
* NTSHChangeNotifyDeregister [SHELL32.641] * NTSHChangeNotifyDeregister [SHELL32.641]
*/ */
EXTERN_C DWORD WINAPI NTSHChangeNotifyDeregister(ULONG x1) DWORD WINAPI NTSHChangeNotifyDeregister(ULONG x1)
{ {
FIXME("(0x%08x):semi stub.\n",x1); FIXME("(0x%08x):semi stub.\n",x1);