Change notification fixes.

This commit is contained in:
Mike McCormack 2003-06-23 19:49:40 +00:00 committed by Alexandre Julliard
parent 10c3764058
commit 1351e23b05
2 changed files with 314 additions and 163 deletions

View File

@ -39,108 +39,134 @@ typedef struct _NOTIFICATIONLIST
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 occured */
DWORD dwFlags; /* client flags */ DWORD dwFlags; /* client flags */
LPCITEMIDLIST pidlSignaled; /*pidl of the path that caused the signal*/
} NOTIFICATIONLIST, *LPNOTIFICATIONLIST; } NOTIFICATIONLIST, *LPNOTIFICATIONLIST;
static NOTIFICATIONLIST head; static NOTIFICATIONLIST *head, *tail;
static NOTIFICATIONLIST tail;
void InitChangeNotifications() #define SHCNE_NOITEMEVENTS ( \
SHCNE_ASSOCCHANGED )
#define SHCNE_ONEITEMEVENTS ( \
SHCNE_ATTRIBUTES | SHCNE_CREATE | SHCNE_DELETE | SHCNE_DRIVEADD | \
SHCNE_DRIVEADDGUI | SHCNE_DRIVEREMOVED | SHCNE_FREESPACE | \
SHCNE_MEDIAINSERTED | SHCNE_MEDIAREMOVED | SHCNE_MKDIR | \
SHCNE_NETSHARE | SHCNE_NETUNSHARE | SHCNE_RMDIR | \
SHCNE_SERVERDISCONNECT | SHCNE_UPDATEDIR | SHCNE_UPDATEIMAGE )
#define SHCNE_TWOITEMEVENTS ( \
SHCNE_RENAMEFOLDER | SHCNE_RENAMEITEM | SHCNE_UPDATEITEM )
/* for dumping events */
static const char * DumpEvent( LONG event )
{ {
TRACE("head=%p tail=%p\n", &head, &tail); if( event == SHCNE_ALLEVENTS )
head.next = &tail; return "SHCNE_ALLEVENTS";
tail.prev = &head; #define DUMPEV(x) ,( event & SHCNE_##x )? #x " " : ""
return wine_dbg_sprintf( "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s"
DUMPEV(RENAMEITEM)
DUMPEV(CREATE)
DUMPEV(DELETE)
DUMPEV(MKDIR)
DUMPEV(RMDIR)
DUMPEV(MEDIAINSERTED)
DUMPEV(MEDIAREMOVED)
DUMPEV(DRIVEREMOVED)
DUMPEV(DRIVEADD)
DUMPEV(NETSHARE)
DUMPEV(NETUNSHARE)
DUMPEV(ATTRIBUTES)
DUMPEV(UPDATEDIR)
DUMPEV(UPDATEITEM)
DUMPEV(SERVERDISCONNECT)
DUMPEV(UPDATEIMAGE)
DUMPEV(DRIVEADDGUI)
DUMPEV(RENAMEFOLDER)
DUMPEV(FREESPACE)
DUMPEV(EXTENDED_EVENT)
DUMPEV(ASSOCCHANGED)
DUMPEV(INTERRUPT)
);
#undef DUMPEV
} }
void FreeChangeNotifications() static const char * NodeName(LPNOTIFICATIONLIST item)
{ {
LPNOTIFICATIONLIST ptr, item; const char *str;
WCHAR path[MAX_PATH];
TRACE("\n"); if(SHGetPathFromIDListW(item->apidl[0].pidlPath, path ))
str = wine_dbg_sprintf("%s", debugstr_w(path));
EnterCriticalSection(&SHELL32_ChangenotifyCS); else
ptr = head.next; str = wine_dbg_sprintf("<not a disk file>" );
return str;
while(ptr != &tail)
{
UINT i;
item = ptr;
ptr = ptr->next;
TRACE("item=%p\n", item);
/* free the item */
for (i=0; i<item->cidl;i++) SHFree(item->apidl[i].pidlPath);
SHFree(item->apidl);
SHFree(item);
}
head.next = NULL;
tail.prev = NULL;
LeaveCriticalSection(&SHELL32_ChangenotifyCS);
DeleteCriticalSection(&SHELL32_ChangenotifyCS);
} }
static BOOL AddNode(LPNOTIFICATIONLIST item) static void AddNode(LPNOTIFICATIONLIST item)
{ {
LPNOTIFICATIONLIST last; TRACE("item %p\n", item );
EnterCriticalSection(&SHELL32_ChangenotifyCS); /* link items */
item->prev = tail;
/* get last entry */ item->next = NULL;
last = tail.prev; if( tail )
tail->next = item;
/* link items */ else
last->next = item; head = item;
item->prev = last; tail = item;
item->next = &tail;
tail.prev = item;
TRACE("item=%p prev=%p next=%p\n", item, item->prev, item->next);
LeaveCriticalSection(&SHELL32_ChangenotifyCS);
return TRUE;
} }
static BOOL DeleteNode(LPNOTIFICATIONLIST item) static LPNOTIFICATIONLIST FindNode( HANDLE hitem )
{ {
LPNOTIFICATIONLIST ptr; LPNOTIFICATIONLIST ptr;
int ret = FALSE; for( ptr = head; ptr; ptr = ptr->next )
if( ptr == (LPNOTIFICATIONLIST) hitem )
return ptr;
return NULL;
}
TRACE("item=%p\n", item); static void DeleteNode(LPNOTIFICATIONLIST item)
{
UINT i;
EnterCriticalSection(&SHELL32_ChangenotifyCS); TRACE("item=%p prev=%p next=%p\n", item, item->prev, item->next);
ptr = head.next; /* remove item from list */
while(ptr != &tail) if( item->prev )
{ item->prev->next = item->next;
TRACE("ptr=%p\n", ptr); else
head = item->next;
if( item->next )
item->next->prev = item->prev;
else
tail = item->prev;
if (ptr == item) /* free the item */
{ for (i=0; i<item->cidl; i++)
UINT i; SHFree(item->apidl[i].pidlPath);
SHFree(item->apidl);
SHFree(item);
}
TRACE("item=%p prev=%p next=%p\n", item, item->prev, item->next); void InitChangeNotifications(void)
{
}
/* remove item from list */ void FreeChangeNotifications(void)
item->prev->next = item->next; {
item->next->prev = item->prev; TRACE("\n");
/* free the item */ EnterCriticalSection(&SHELL32_ChangenotifyCS);
for (i=0; i<item->cidl;i++) SHFree(item->apidl[i].pidlPath);
SHFree(item->apidl);
SHFree(item);
ret = TRUE; while( head )
break; DeleteNode( head );
}
ptr = ptr->next;
}
LeaveCriticalSection(&SHELL32_ChangenotifyCS); LeaveCriticalSection(&SHELL32_ChangenotifyCS);
return ret;
DeleteCriticalSection(&SHELL32_ChangenotifyCS);
} }
/************************************************************************* /*************************************************************************
@ -156,53 +182,82 @@ SHChangeNotifyRegister(
int cItems, int cItems,
LPCNOTIFYREGISTER lpItems) LPCNOTIFYREGISTER lpItems)
{ {
LPNOTIFICATIONLIST item; LPNOTIFICATIONLIST item;
int i; DWORD i;
item = SHAlloc(sizeof(NOTIFICATIONLIST)); item = SHAlloc(sizeof(NOTIFICATIONLIST));
TRACE("(%p,0x%08lx,0x%08lx,0x%08lx,0x%08x,%p) item=%p\n", TRACE("(%p,0x%08lx,0x%08lx,0x%08lx,0x%08x,%p) item=%p\n",
hwnd,dwFlags,wEventMask,uMsg,cItems,lpItems,item); hwnd,dwFlags,wEventMask,uMsg,cItems,lpItems,item);
item->next = NULL; item->next = NULL;
item->prev = NULL; item->prev = NULL;
item->cidl = cItems; item->cidl = cItems;
item->apidl = SHAlloc(sizeof(NOTIFYREGISTER) * cItems); item->apidl = SHAlloc(sizeof(NOTIFYREGISTER) * cItems);
for(i=0;i<cItems;i++) for(i=0;i<cItems;i++)
{ {
item->apidl[i].pidlPath = ILClone(lpItems[i].pidlPath); item->apidl[i].pidlPath = ILClone(lpItems[i].pidlPath);
item->apidl[i].bWatchSubtree = lpItems[i].bWatchSubtree; item->apidl[i].bWatchSubtree = lpItems[i].bWatchSubtree;
} }
item->hwnd = hwnd; item->hwnd = hwnd;
item->uMsg = uMsg; item->uMsg = uMsg;
item->wEventMask = wEventMask; item->wEventMask = wEventMask;
item->dwFlags = dwFlags; item->wSignalledEvent = 0;
AddNode(item); item->dwFlags = dwFlags;
return (HANDLE)item;
TRACE("new node: %s\n", NodeName( item ));
EnterCriticalSection(&SHELL32_ChangenotifyCS);
AddNode(item);
LeaveCriticalSection(&SHELL32_ChangenotifyCS);
return (HANDLE)item;
} }
/************************************************************************* /*************************************************************************
* SHChangeNotifyDeregister [SHELL32.4] * SHChangeNotifyDeregister [SHELL32.4]
*/ */
BOOL WINAPI BOOL WINAPI SHChangeNotifyDeregister(HANDLE hNotify)
SHChangeNotifyDeregister(HANDLE hNotify)
{ {
TRACE("(%p)\n",hNotify); LPNOTIFICATIONLIST node;
return DeleteNode((LPNOTIFICATIONLIST)hNotify); TRACE("(%p)\n",hNotify);
EnterCriticalSection(&SHELL32_ChangenotifyCS);
node = FindNode(hNotify);
if( node )
DeleteNode(node);
LeaveCriticalSection(&SHELL32_ChangenotifyCS);
return node?TRUE:FALSE;
} }
/************************************************************************* /*************************************************************************
* SHChangeNotifyUpdateEntryList [SHELL32.5] * SHChangeNotifyUpdateEntryList [SHELL32.5]
*/ */
BOOL WINAPI BOOL WINAPI SHChangeNotifyUpdateEntryList(DWORD unknown1, DWORD unknown2,
SHChangeNotifyUpdateEntryList(DWORD unknown1, DWORD unknown2,
DWORD unknown3, DWORD unknown4) DWORD unknown3, DWORD unknown4)
{ {
FIXME("(0x%08lx, 0x%08lx, 0x%08lx, 0x%08lx)\n", FIXME("(0x%08lx, 0x%08lx, 0x%08lx, 0x%08lx)\n",
unknown1, unknown2, unknown3, unknown4); unknown1, unknown2, unknown3, unknown4);
return -1; return -1;
}
static BOOL should_notify( LPITEMIDLIST changed, LPITEMIDLIST watched, BOOL sub )
{
TRACE("%p %p %d\n", changed, watched, sub );
if ( !watched )
return FALSE;
if (ILIsEqual( watched, changed ) )
return TRUE;
if( sub && ILIsParent( watched, changed, FALSE ) )
return TRUE;
return FALSE;
} }
/************************************************************************* /*************************************************************************
@ -210,57 +265,130 @@ SHChangeNotifyUpdateEntryList(DWORD unknown1, DWORD unknown2,
*/ */
void WINAPI SHChangeNotify(LONG wEventId, UINT uFlags, LPCVOID dwItem1, LPCVOID dwItem2) void WINAPI SHChangeNotify(LONG wEventId, UINT uFlags, LPCVOID dwItem1, LPCVOID dwItem2)
{ {
LPITEMIDLIST Pidls[2]; LPITEMIDLIST Pidls[2];
LPNOTIFICATIONLIST ptr; LPNOTIFICATIONLIST ptr;
DWORD dummy; DWORD dummy;
UINT typeFlag = uFlags & SHCNF_TYPE; UINT typeFlag = uFlags & SHCNF_TYPE;
Pidls[0] = (LPITEMIDLIST)dwItem1; Pidls[0] = NULL;
Pidls[1] = (LPITEMIDLIST)dwItem2; Pidls[1] = NULL;
TRACE("(0x%08lx,0x%08x,%p,%p):stub.\n", wEventId, uFlags, dwItem1, dwItem2); TRACE("(0x%08lx,0x%08x,%p,%p):stub.\n", wEventId, uFlags, dwItem1, dwItem2);
/* convert paths in IDLists*/ if( ( wEventId & SHCNE_NOITEMEVENTS ) && ( dwItem1 || dwItem2 ) )
switch (typeFlag) {
{ TRACE("dwItem1 and dwItem2 are not zero, but should be\n");
case SHCNF_PATHA: dwItem1 = 0;
if (dwItem1) SHILCreateFromPathA((LPCSTR)dwItem1, &Pidls[0], &dummy); dwItem2 = 0;
if (dwItem2) SHILCreateFromPathA((LPCSTR)dwItem2, &Pidls[1], &dummy); return;
break; }
case SHCNF_PATHW: else if( ( wEventId & SHCNE_ONEITEMEVENTS ) && dwItem2 )
if (dwItem1) SHILCreateFromPathW((LPCWSTR)dwItem1, &Pidls[0], &dummy); {
if (dwItem2) SHILCreateFromPathW((LPCWSTR)dwItem2, &Pidls[1], &dummy); TRACE("dwItem2 is not zero, but should be\n");
break; dwItem2 = 0;
case SHCNF_PRINTERA: return;
case SHCNF_PRINTERW: }
FIXME("SHChangeNotify with (uFlags & SHCNF_PRINTER)");
break;
}
EnterCriticalSection(&SHELL32_ChangenotifyCS); if( ( ( wEventId & SHCNE_NOITEMEVENTS ) &&
( wEventId & ~SHCNE_NOITEMEVENTS ) ) ||
( ( wEventId & SHCNE_ONEITEMEVENTS ) &&
( wEventId & ~SHCNE_ONEITEMEVENTS ) ) ||
( ( wEventId & SHCNE_TWOITEMEVENTS ) &&
( wEventId & ~SHCNE_TWOITEMEVENTS ) ) )
{
WARN("mutually incompatible events listed\n");
return;
}
/* loop through the list */ /* convert paths in IDLists*/
ptr = head.next; switch (typeFlag)
while (ptr != &tail) {
{ case SHCNF_PATHA:
TRACE("trying %p\n", ptr); if (dwItem1) SHILCreateFromPathA((LPCSTR)dwItem1, &Pidls[0], &dummy);
if (dwItem2) SHILCreateFromPathA((LPCSTR)dwItem2, &Pidls[1], &dummy);
break;
case SHCNF_PATHW:
if (dwItem1) SHILCreateFromPathW((LPCWSTR)dwItem1, &Pidls[0], &dummy);
if (dwItem2) SHILCreateFromPathW((LPCWSTR)dwItem2, &Pidls[1], &dummy);
break;
case SHCNF_IDLIST:
Pidls[0] = (LPITEMIDLIST)dwItem1;
Pidls[1] = (LPITEMIDLIST)dwItem2;
break;
case SHCNF_PRINTERA:
case SHCNF_PRINTERW:
FIXME("SHChangeNotify with (uFlags & SHCNF_PRINTER)");
return;
case SHCNF_DWORD:
default:
FIXME("unknown type %08x\n",typeFlag);
return;
}
if (wEventId & ptr->wEventMask) {
{ WCHAR path[MAX_PATH];
TRACE("notifying\n");
SendMessageA(ptr->hwnd, ptr->uMsg, (WPARAM)&Pidls, (LPARAM)wEventId);
}
ptr = ptr->next;
}
LeaveCriticalSection(&SHELL32_ChangenotifyCS); if( Pidls[0] && SHGetPathFromIDListW(Pidls[0], path ))
TRACE("notify %08lx on item1 = %s\n", wEventId, debugstr_w(path));
if( Pidls[1] && SHGetPathFromIDListW(Pidls[1], path ))
TRACE("notify %08lx on item2 = %s\n", wEventId, debugstr_w(path));
}
/* if we allocated it, free it */ EnterCriticalSection(&SHELL32_ChangenotifyCS);
if ((typeFlag == SHCNF_PATHA) || (typeFlag == SHCNF_PATHW))
{ /* loop through the list */
if (Pidls[0]) SHFree(Pidls[0]); for( ptr = head; ptr; ptr = ptr->next )
if (Pidls[1]) SHFree(Pidls[1]); {
} BOOL notify;
DWORD i;
notify = FALSE;
TRACE("trying %p\n", ptr);
for( i=0; (i<ptr->cidl) && !notify ; i++ )
{
LPITEMIDLIST pidl = ptr->apidl[i].pidlPath;
BOOL subtree = ptr->apidl[i].bWatchSubtree;
if (wEventId & ptr->wEventMask)
{
if( !pidl ) /* all ? */
notify = TRUE;
else if( wEventId & SHCNE_NOITEMEVENTS )
notify = TRUE;
else if( wEventId & ( SHCNE_ONEITEMEVENTS | SHCNE_TWOITEMEVENTS ) )
notify = should_notify( Pidls[0], pidl, subtree );
else if( wEventId & SHCNE_TWOITEMEVENTS )
notify = should_notify( Pidls[1], pidl, subtree );
}
}
if( !notify )
continue;
ptr->pidlSignaled = ILClone(Pidls[0]);
TRACE("notifying %s, event %s(%lx) before\n", NodeName( ptr ), DumpEvent(
wEventId ),wEventId );
ptr->wSignalledEvent |= wEventId;
SendMessageA(ptr->hwnd, ptr->uMsg, (WPARAM)ptr, GetCurrentProcessId());
TRACE("notifying %s, event %s(%lx) after\n", NodeName( ptr ), DumpEvent(
wEventId ),wEventId );
}
TRACE("notify Done\n");
LeaveCriticalSection(&SHELL32_ChangenotifyCS);
/* if we allocated it, free it */
if ((typeFlag == SHCNF_PATHA) || (typeFlag == SHCNF_PATHW))
{
if (Pidls[0]) SHFree(Pidls[0]);
if (Pidls[1]) SHFree(Pidls[1]);
}
} }
/************************************************************************* /*************************************************************************
@ -275,34 +403,56 @@ DWORD WINAPI NTSHChangeNotifyRegister(
LONG events2, LONG events2,
DWORD msg, DWORD msg,
int count, int count,
LPNOTIFYREGISTER idlist) LPCNOTIFYREGISTER idlist)
{ {
FIXME("(%p,0x%08lx,0x%08lx,0x%08lx,0x%08x,%p):stub.\n", FIXME("(%p,0x%08lx,0x%08lx,0x%08lx,0x%08x,%p):semi stub.\n",
hwnd,events1,events2,msg,count,idlist); hwnd,events1,events2,msg,count,idlist);
return 0;
return (DWORD) SHChangeNotifyRegister(hwnd, events1, events2, msg, count, idlist);
} }
/************************************************************************* /*************************************************************************
* SHChangeNotification_Lock [SHELL32.644] * SHChangeNotification_Lock [SHELL32.644]
*/ */
HANDLE WINAPI SHChangeNotification_Lock( HANDLE WINAPI SHChangeNotification_Lock(
HANDLE hMemoryMap, HANDLE hChange,
DWORD dwProcessId, DWORD dwProcessId,
LPCITEMIDLIST **lppidls, LPITEMIDLIST **lppidls,
LPLONG lpwEventId) LPLONG lpwEventId)
{ {
FIXME("\n"); DWORD i;
return 0; LPNOTIFICATIONLIST node;
LPCITEMIDLIST *idlist;
TRACE("%p %08lx %p %p\n", hChange, dwProcessId, lppidls, lpwEventId);
/* EnterCriticalSection(&SHELL32_ChangenotifyCS); */
node = FindNode( hChange );
if( node )
{
idlist = SHAlloc( sizeof(LPCITEMIDLIST *) * node->cidl );
for(i=0; i<node->cidl; i++)
idlist[i] = node->pidlSignaled;
*lpwEventId = node->wSignalledEvent;
*lppidls = idlist;
node->wSignalledEvent = 0;
}
else
ERR("Couldn't find %p\n", hChange );
/* LeaveCriticalSection(&SHELL32_ChangenotifyCS); */
return (HANDLE) node;
} }
/************************************************************************* /*************************************************************************
* SHChangeNotification_Unlock [SHELL32.645] * SHChangeNotification_Unlock [SHELL32.645]
*/ */
BOOL WINAPI SHChangeNotification_Unlock ( BOOL WINAPI SHChangeNotification_Unlock ( HANDLE hLock)
HANDLE hLock)
{ {
FIXME("\n"); TRACE("\n");
return 0; return 1;
} }
/************************************************************************* /*************************************************************************
@ -310,6 +460,7 @@ BOOL WINAPI SHChangeNotification_Unlock (
*/ */
DWORD WINAPI NTSHChangeNotifyDeregister(LONG x1) DWORD WINAPI NTSHChangeNotifyDeregister(LONG x1)
{ {
FIXME("(0x%08lx):stub.\n",x1); FIXME("(0x%08lx):semi stub.\n",x1);
return 0;
return SHChangeNotifyDeregister( (HANDLE)x1 );
} }

View File

@ -281,8 +281,8 @@
641 stdcall NTSHChangeNotifyDeregister (long) 641 stdcall NTSHChangeNotifyDeregister (long)
643 stub SHChangeNotifyReceive@16 643 stub SHChangeNotifyReceive@16
644 stub SHChangeNotification_Lock@16 644 stdcall SHChangeNotification_Lock(long long ptr ptr)
645 stub SHChangeNotification_Unlock@4 645 stdcall SHChangeNotification_Unlock(long)
646 stub SHChangeRegistrationReceive@8 646 stub SHChangeRegistrationReceive@8
647 stub ReceiveAddToRecentDocs@8 647 stub ReceiveAddToRecentDocs@8
648 stub SHWaitOp_Operate@8 648 stub SHWaitOp_Operate@8