2 * shell change notification
4 * Copyright 2000 Juergen Schmied
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 WINE_DEFAULT_DEBUG_CHANNEL(shell
);
26 static CRITICAL_SECTION SHELL32_ChangenotifyCS
;
27 static CRITICAL_SECTION_DEBUG critsect_debug
=
29 0, 0, &SHELL32_ChangenotifyCS
,
30 { &critsect_debug
.ProcessLocksList
, &critsect_debug
.ProcessLocksList
},
31 0, 0, { (DWORD_PTR
)(__FILE__
": SHELL32_ChangenotifyCS") }
33 static CRITICAL_SECTION SHELL32_ChangenotifyCS
= { &critsect_debug
, -1, 0, 0, 0, 0 };
35 typedef SHChangeNotifyEntry
*LPNOTIFYREGISTER
;
37 /* internal list of notification clients (internal) */
38 typedef struct _NOTIFICATIONLIST
40 struct _NOTIFICATIONLIST
*next
;
41 struct _NOTIFICATIONLIST
*prev
;
42 HWND hwnd
; /* window to notify */
43 DWORD uMsg
; /* message to send */
44 LPNOTIFYREGISTER apidl
; /* array of entries to watch*/
45 UINT cidl
; /* number of pidls in array */
46 LONG wEventMask
; /* subscribed events */
47 LONG wSignalledEvent
; /* event that occurred */
48 DWORD dwFlags
; /* client flags */
49 LPCITEMIDLIST pidlSignaled
; /*pidl of the path that caused the signal*/
51 } NOTIFICATIONLIST
, *LPNOTIFICATIONLIST
;
53 static NOTIFICATIONLIST
*head
, *tail
;
55 #define SHCNE_NOITEMEVENTS ( \
58 #define SHCNE_ONEITEMEVENTS ( \
59 SHCNE_ATTRIBUTES | SHCNE_CREATE | SHCNE_DELETE | SHCNE_DRIVEADD | \
60 SHCNE_DRIVEADDGUI | SHCNE_DRIVEREMOVED | SHCNE_FREESPACE | \
61 SHCNE_MEDIAINSERTED | SHCNE_MEDIAREMOVED | SHCNE_MKDIR | \
62 SHCNE_NETSHARE | SHCNE_NETUNSHARE | SHCNE_RMDIR | \
63 SHCNE_SERVERDISCONNECT | SHCNE_UPDATEDIR | SHCNE_UPDATEIMAGE )
65 #define SHCNE_TWOITEMEVENTS ( \
66 SHCNE_RENAMEFOLDER | SHCNE_RENAMEITEM | SHCNE_UPDATEITEM )
68 /* for dumping events */
69 static const char * DumpEvent( LONG event
)
71 if( event
== SHCNE_ALLEVENTS
)
72 return "SHCNE_ALLEVENTS";
73 #define DUMPEV(x) ,( event & SHCNE_##x )? #x " " : ""
74 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"
89 DUMPEV(SERVERDISCONNECT
)
94 DUMPEV(EXTENDED_EVENT
)
101 static const char * NodeName(const NOTIFICATIONLIST
*item
)
104 WCHAR path
[MAX_PATH
];
106 if(SHGetPathFromIDListW(item
->apidl
[0].pidl
, path
))
107 str
= wine_dbg_sprintf("%s", debugstr_w(path
));
109 str
= wine_dbg_sprintf("<not a disk file>" );
113 static void AddNode(LPNOTIFICATIONLIST item
)
115 TRACE("item %p\n", item
);
127 static LPNOTIFICATIONLIST
FindNode( HANDLE hitem
)
129 LPNOTIFICATIONLIST ptr
;
130 for( ptr
= head
; ptr
; ptr
= ptr
->next
)
131 if( ptr
== (LPNOTIFICATIONLIST
) hitem
)
136 static void DeleteNode(LPNOTIFICATIONLIST item
)
140 TRACE("item=%p prev=%p next=%p\n", item
, item
->prev
, item
->next
);
142 /* remove item from list */
144 item
->prev
->next
= item
->next
;
148 item
->next
->prev
= item
->prev
;
153 for (i
=0; i
<item
->cidl
; i
++)
154 SHFree((LPITEMIDLIST
)item
->apidl
[i
].pidl
);
159 void InitChangeNotifications(void)
163 void FreeChangeNotifications(void)
167 EnterCriticalSection(&SHELL32_ChangenotifyCS
);
172 LeaveCriticalSection(&SHELL32_ChangenotifyCS
);
174 // DeleteCriticalSection(&SHELL32_ChangenotifyCS); // static
177 /*************************************************************************
178 * SHChangeNotifyRegister [SHELL32.2]
182 SHChangeNotifyRegister(
188 const SHChangeNotifyEntry
*lpItems
)
190 LPNOTIFICATIONLIST item
;
193 item
= SHAlloc(sizeof(NOTIFICATIONLIST
));
195 TRACE("(%p,0x%08x,0x%08x,0x%08x,%d,%p) item=%p\n",
196 hwnd
, fSources
, wEventMask
, uMsg
, cItems
, lpItems
, item
);
201 item
->apidl
= SHAlloc(sizeof(SHChangeNotifyEntry
) * cItems
);
202 for(i
=0;i
<cItems
;i
++)
204 item
->apidl
[i
].pidl
= ILClone(lpItems
[i
].pidl
);
205 item
->apidl
[i
].fRecursive
= lpItems
[i
].fRecursive
;
209 item
->wEventMask
= wEventMask
;
210 item
->wSignalledEvent
= 0;
211 item
->dwFlags
= fSources
;
213 TRACE("new node: %s\n", NodeName( item
));
215 EnterCriticalSection(&SHELL32_ChangenotifyCS
);
219 LeaveCriticalSection(&SHELL32_ChangenotifyCS
);
224 /*************************************************************************
225 * SHChangeNotifyDeregister [SHELL32.4]
227 BOOL WINAPI
SHChangeNotifyDeregister(ULONG hNotify
)
229 LPNOTIFICATIONLIST node
;
231 TRACE("(0x%08x)\n", hNotify
);
233 EnterCriticalSection(&SHELL32_ChangenotifyCS
);
235 node
= FindNode((HANDLE
)hNotify
);
239 LeaveCriticalSection(&SHELL32_ChangenotifyCS
);
241 return node
?TRUE
:FALSE
;
244 /*************************************************************************
245 * SHChangeNotifyUpdateEntryList [SHELL32.5]
247 BOOL WINAPI
SHChangeNotifyUpdateEntryList(DWORD unknown1
, DWORD unknown2
,
248 DWORD unknown3
, DWORD unknown4
)
250 FIXME("(0x%08x, 0x%08x, 0x%08x, 0x%08x)\n",
251 unknown1
, unknown2
, unknown3
, unknown4
);
256 static BOOL
should_notify( LPCITEMIDLIST changed
, LPCITEMIDLIST watched
, BOOL sub
)
258 TRACE("%p %p %d\n", changed
, watched
, sub
);
261 if (ILIsEqual( watched
, changed
) )
263 if( sub
&& ILIsParent( watched
, changed
, TRUE
) )
268 /*************************************************************************
269 * SHChangeNotify [SHELL32.@]
271 void WINAPI
SHChangeNotify(LONG wEventId
, UINT uFlags
, LPCVOID dwItem1
, LPCVOID dwItem2
)
273 LPCITEMIDLIST Pidls
[2];
274 LPNOTIFICATIONLIST ptr
;
275 UINT typeFlag
= uFlags
& SHCNF_TYPE
;
280 TRACE("(0x%08x,0x%08x,%p,%p):stub.\n", wEventId
, uFlags
, dwItem1
, dwItem2
);
282 if( ( wEventId
& SHCNE_NOITEMEVENTS
) && ( dwItem1
|| dwItem2
) )
284 TRACE("dwItem1 and dwItem2 are not zero, but should be\n");
289 else if( ( wEventId
& SHCNE_ONEITEMEVENTS
) && dwItem2
)
291 TRACE("dwItem2 is not zero, but should be\n");
296 if( ( ( wEventId
& SHCNE_NOITEMEVENTS
) &&
297 ( wEventId
& ~SHCNE_NOITEMEVENTS
) ) ||
298 ( ( wEventId
& SHCNE_ONEITEMEVENTS
) &&
299 ( wEventId
& ~SHCNE_ONEITEMEVENTS
) ) ||
300 ( ( wEventId
& SHCNE_TWOITEMEVENTS
) &&
301 ( wEventId
& ~SHCNE_TWOITEMEVENTS
) ) )
303 WARN("mutually incompatible events listed\n");
307 /* convert paths in IDLists*/
311 if (dwItem1
) Pidls
[0] = SHSimpleIDListFromPathA((LPCSTR
)dwItem1
); //FIXME
312 if (dwItem2
) Pidls
[1] = SHSimpleIDListFromPathA((LPCSTR
)dwItem2
); //FIXME
315 if (dwItem1
) Pidls
[0] = SHSimpleIDListFromPathW((LPCWSTR
)dwItem1
);
316 if (dwItem2
) Pidls
[1] = SHSimpleIDListFromPathW((LPCWSTR
)dwItem2
);
319 Pidls
[0] = (LPCITEMIDLIST
)dwItem1
;
320 Pidls
[1] = (LPCITEMIDLIST
)dwItem2
;
324 FIXME("SHChangeNotify with (uFlags & SHCNF_PRINTER)\n");
328 FIXME("unknown type %08x\n",typeFlag
);
333 WCHAR path
[MAX_PATH
];
335 if( Pidls
[0] && SHGetPathFromIDListW(Pidls
[0], path
))
336 TRACE("notify %08x on item1 = %s\n", wEventId
, debugstr_w(path
));
338 if( Pidls
[1] && SHGetPathFromIDListW(Pidls
[1], path
))
339 TRACE("notify %08x on item2 = %s\n", wEventId
, debugstr_w(path
));
342 EnterCriticalSection(&SHELL32_ChangenotifyCS
);
344 /* loop through the list */
345 for( ptr
= head
; ptr
; ptr
= ptr
->next
)
352 TRACE("trying %p\n", ptr
);
354 for( i
=0; (i
<ptr
->cidl
) && !notify
; i
++ )
356 LPCITEMIDLIST pidl
= ptr
->apidl
[i
].pidl
;
357 BOOL subtree
= ptr
->apidl
[i
].fRecursive
;
359 if (wEventId
& ptr
->wEventMask
)
361 if( !pidl
) /* all ? */
363 else if( wEventId
& SHCNE_NOITEMEVENTS
)
365 else if( wEventId
& ( SHCNE_ONEITEMEVENTS
| SHCNE_TWOITEMEVENTS
) )
366 notify
= should_notify( Pidls
[0], pidl
, subtree
);
367 else if( wEventId
& SHCNE_TWOITEMEVENTS
)
368 notify
= should_notify( Pidls
[1], pidl
, subtree
);
375 ptr
->pidlSignaled
= ILClone(Pidls
[0]);
377 TRACE("notifying %s, event %s(%x) before\n", NodeName( ptr
), DumpEvent(
378 wEventId
),wEventId
);
380 ptr
->wSignalledEvent
|= wEventId
;
382 if (ptr
->dwFlags
& SHCNRF_NewDelivery
)
383 SendMessageW(ptr
->hwnd
, ptr
->uMsg
, (WPARAM
) ptr
, (LPARAM
) GetCurrentProcessId());
385 SendMessageW(ptr
->hwnd
, ptr
->uMsg
, (WPARAM
)Pidls
, wEventId
);
387 TRACE("notifying %s, event %s(%x) after\n", NodeName( ptr
), DumpEvent(
388 wEventId
),wEventId
);
391 TRACE("notify Done\n");
392 LeaveCriticalSection(&SHELL32_ChangenotifyCS
);
394 /* if we allocated it, free it. The ANSI flag is also set in its Unicode sibling. */
395 if ((typeFlag
& SHCNF_PATHA
) || (typeFlag
& SHCNF_PRINTERA
))
397 SHFree((LPITEMIDLIST
)Pidls
[0]);
398 SHFree((LPITEMIDLIST
)Pidls
[1]);
402 /*************************************************************************
403 * NTSHChangeNotifyRegister [SHELL32.640]
405 * Idlist is an array of structures and Count specifies how many items in the array.
406 * count should always be one when calling SHChangeNotifyRegister, or
407 * SHChangeNotifyDeregister will not work properly.
409 ULONG WINAPI
NTSHChangeNotifyRegister(
415 SHChangeNotifyEntry
*idlist
)
417 return SHChangeNotifyRegister(hwnd
, fSources
| SHCNRF_NewDelivery
,
418 fEvents
, msg
, count
, idlist
);
421 /*************************************************************************
422 * SHChangeNotification_Lock [SHELL32.644]
424 HANDLE WINAPI
SHChangeNotification_Lock(
427 LPITEMIDLIST
**lppidls
,
431 LPNOTIFICATIONLIST node
;
432 LPCITEMIDLIST
*idlist
;
434 TRACE("%p %08x %p %p\n", hChange
, dwProcessId
, lppidls
, lpwEventId
);
436 /* EnterCriticalSection(&SHELL32_ChangenotifyCS); */
438 node
= FindNode( hChange
);
441 idlist
= SHAlloc( sizeof(LPCITEMIDLIST
*) * node
->cidl
);
442 for(i
=0; i
<node
->cidl
; i
++)
443 idlist
[i
] = (LPCITEMIDLIST
)node
->pidlSignaled
;
444 *lpwEventId
= node
->wSignalledEvent
;
445 *lppidls
= (LPITEMIDLIST
*)idlist
;
446 node
->wSignalledEvent
= 0;
449 ERR("Couldn't find %p\n", hChange
);
451 /* LeaveCriticalSection(&SHELL32_ChangenotifyCS); */
453 return (HANDLE
) node
;
456 /*************************************************************************
457 * SHChangeNotification_Unlock [SHELL32.645]
459 BOOL WINAPI
SHChangeNotification_Unlock ( HANDLE hLock
)
465 /*************************************************************************
466 * NTSHChangeNotifyDeregister [SHELL32.641]
468 DWORD WINAPI
NTSHChangeNotifyDeregister(ULONG x1
)
470 FIXME("(0x%08x):semi stub.\n",x1
);
472 return SHChangeNotifyDeregister( x1
);