mirror of
https://github.com/reactos/reactos.git
synced 2024-07-01 02:10:07 +00:00
[SHELL32] Shell notify rework for simplicity and readability (#2539)
Shell change notification has been implemented in #2432. But as @yagoulas said, source code structure is in mess. We improved simplicity and human readability of our source code. - Move wine/changenotify.c code into changenotify.c and shelldesktop/CChangeNotify.cpp. - Simplify code and rename the identifiers and add many comments. CORE-13950
This commit is contained in:
parent
b68749c727
commit
2727245c86
|
@ -8,14 +8,6 @@
|
||||||
|
|
||||||
#include "precomp.h"
|
#include "precomp.h"
|
||||||
|
|
||||||
extern "C"
|
|
||||||
{
|
|
||||||
//fixme: this isn't in wine's shlwapi header, and the definition doesnt match the
|
|
||||||
// windows headers. When wine's header and lib are fixed this can be removed.
|
|
||||||
DWORD WINAPI SHAnsiToUnicode(LPCSTR lpSrcStr, LPWSTR lpDstStr, int iLen);
|
|
||||||
INT WINAPI SHUnicodeToAnsi(LPCWSTR lpSrcStr, LPSTR lpDstStr, INT iLen);
|
|
||||||
};
|
|
||||||
|
|
||||||
WINE_DEFAULT_DEBUG_CHANNEL(dmenu);
|
WINE_DEFAULT_DEBUG_CHANNEL(dmenu);
|
||||||
|
|
||||||
typedef struct _DynamicShellEntry_
|
typedef struct _DynamicShellEntry_
|
||||||
|
|
|
@ -34,6 +34,7 @@ list(APPEND SOURCE
|
||||||
CActiveDesktop.h
|
CActiveDesktop.h
|
||||||
CIDLDataObj.cpp
|
CIDLDataObj.cpp
|
||||||
CQueryAssociations.cpp
|
CQueryAssociations.cpp
|
||||||
|
changenotify.cpp
|
||||||
debughlp.cpp
|
debughlp.cpp
|
||||||
dialogs/dialogs.cpp
|
dialogs/dialogs.cpp
|
||||||
dialogs/drive.cpp
|
dialogs/drive.cpp
|
||||||
|
@ -96,7 +97,6 @@ add_library(shell32 MODULE
|
||||||
${SOURCE}
|
${SOURCE}
|
||||||
wine/appbar.c
|
wine/appbar.c
|
||||||
wine/brsfolder.c
|
wine/brsfolder.c
|
||||||
wine/changenotify.c
|
|
||||||
wine/classes.c
|
wine/classes.c
|
||||||
wine/clipboard.c
|
wine/clipboard.c
|
||||||
wine/control.c
|
wine/control.c
|
||||||
|
|
612
dll/win32/shell32/changenotify.cpp
Normal file
612
dll/win32/shell32/changenotify.cpp
Normal file
|
@ -0,0 +1,612 @@
|
||||||
|
/*
|
||||||
|
* PROJECT: shell32
|
||||||
|
* LICENSE: LGPL-2.1-or-later (https://spdx.org/licenses/LGPL-2.1-or-later)
|
||||||
|
* PURPOSE: Shell change notification
|
||||||
|
* COPYRIGHT: Copyright 2020 Katayama Hirofumi MZ (katayama.hirofumi.mz@gmail.com)
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "precomp.h"
|
||||||
|
|
||||||
|
WINE_DEFAULT_DEBUG_CHANNEL(shcn);
|
||||||
|
|
||||||
|
CRITICAL_SECTION SHELL32_ChangenotifyCS;
|
||||||
|
|
||||||
|
// This function requests creation of the server window if it doesn't exist yet
|
||||||
|
static HWND
|
||||||
|
GetNotificationServer(BOOL bCreate)
|
||||||
|
{
|
||||||
|
static HWND s_hwndServer = NULL;
|
||||||
|
|
||||||
|
// use cache if any
|
||||||
|
if (s_hwndServer && IsWindow(s_hwndServer))
|
||||||
|
return s_hwndServer;
|
||||||
|
|
||||||
|
// get the shell window
|
||||||
|
HWND hwndShell = GetShellWindow();
|
||||||
|
if (hwndShell == NULL)
|
||||||
|
{
|
||||||
|
TRACE("GetShellWindow() returned NULL\n");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get the window of the notification server that runs in explorer
|
||||||
|
HWND hwndServer = (HWND)SendMessageW(hwndShell, WM_DESKTOP_GET_CNOTIFY_SERVER, bCreate, 0);
|
||||||
|
if (!IsWindow(hwndServer))
|
||||||
|
{
|
||||||
|
ERR("Unable to get server window\n");
|
||||||
|
hwndServer = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
// save and return
|
||||||
|
s_hwndServer = hwndServer;
|
||||||
|
return hwndServer;
|
||||||
|
}
|
||||||
|
|
||||||
|
// This function will be called from DllMain.DLL_PROCESS_ATTACH.
|
||||||
|
EXTERN_C void InitChangeNotifications(void)
|
||||||
|
{
|
||||||
|
InitializeCriticalSection(&SHELL32_ChangenotifyCS);
|
||||||
|
}
|
||||||
|
|
||||||
|
// This function will be called from DllMain.DLL_PROCESS_DETACH.
|
||||||
|
EXTERN_C void FreeChangeNotifications(void)
|
||||||
|
{
|
||||||
|
HWND hwndServer = GetNotificationServer(FALSE);
|
||||||
|
if (hwndServer)
|
||||||
|
SendMessageW(hwndServer, CN_UNREGISTER_PROCESS, GetCurrentProcessId(), 0);
|
||||||
|
DeleteCriticalSection(&SHELL32_ChangenotifyCS);
|
||||||
|
}
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// There are two delivery methods: "old delivery method" and "new delivery method".
|
||||||
|
//
|
||||||
|
// The old delivery method creates a broker window in the caller process
|
||||||
|
// for message trampoline. The old delivery method is slow and deprecated.
|
||||||
|
//
|
||||||
|
// The new delivery method is enabled by SHCNRF_NewDelivery flag.
|
||||||
|
// With the new delivery method the server directly sends the delivery message.
|
||||||
|
|
||||||
|
typedef CWinTraits <
|
||||||
|
WS_POPUP | WS_CLIPSIBLINGS | WS_CLIPCHILDREN,
|
||||||
|
WS_EX_TOOLWINDOW
|
||||||
|
> CBrokerTraits;
|
||||||
|
|
||||||
|
// This class brokers all notifications that don't have the SHCNRF_NewDelivery flag
|
||||||
|
class CChangeNotifyBroker :
|
||||||
|
public CWindowImpl<CChangeNotifyBroker, CWindow, CBrokerTraits>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
CChangeNotifyBroker(HWND hwndClient, UINT uMsg) :
|
||||||
|
m_hwndClient(hwndClient), m_uMsg(uMsg)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
// Message handlers
|
||||||
|
LRESULT OnBrokerNotification(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
|
||||||
|
{
|
||||||
|
return BrokerNotification((HANDLE)wParam, (DWORD)lParam);
|
||||||
|
}
|
||||||
|
|
||||||
|
void OnFinalMessage(HWND)
|
||||||
|
{
|
||||||
|
// The server will destroy this window.
|
||||||
|
// After the window gets destroyed we can delete this broker here.
|
||||||
|
delete this;
|
||||||
|
}
|
||||||
|
|
||||||
|
DECLARE_WND_CLASS_EX(L"WorkerW", 0, 0)
|
||||||
|
|
||||||
|
BEGIN_MSG_MAP(CChangeNotifyBroker)
|
||||||
|
MESSAGE_HANDLER(WM_BROKER_NOTIFICATION, OnBrokerNotification)
|
||||||
|
END_MSG_MAP()
|
||||||
|
|
||||||
|
private:
|
||||||
|
HWND m_hwndClient;
|
||||||
|
UINT m_uMsg;
|
||||||
|
|
||||||
|
BOOL BrokerNotification(HANDLE hTicket, DWORD dwOwnerPID)
|
||||||
|
{
|
||||||
|
// lock the ticket
|
||||||
|
PIDLIST_ABSOLUTE *ppidl = NULL;
|
||||||
|
LONG lEvent;
|
||||||
|
HANDLE hLock = SHChangeNotification_Lock(hTicket, dwOwnerPID, &ppidl, &lEvent);
|
||||||
|
if (hLock == NULL)
|
||||||
|
{
|
||||||
|
ERR("hLock is NULL\n");
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
// perform the delivery
|
||||||
|
TRACE("OldDeliveryWorker notifying: %p, 0x%x, %p, 0x%lx\n",
|
||||||
|
m_hwndClient, m_uMsg, ppidl, lEvent);
|
||||||
|
SendMessageW(m_hwndClient, m_uMsg, (WPARAM)ppidl, lEvent);
|
||||||
|
|
||||||
|
// unlock the ticket
|
||||||
|
SHChangeNotification_Unlock(hLock);
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// This function creates a notification broker for old method. Used in SHChangeNotifyRegister.
|
||||||
|
static HWND
|
||||||
|
CreateNotificationBroker(HWND hwnd, UINT wMsg)
|
||||||
|
{
|
||||||
|
// Create a new broker. It will be freed when the window gets destroyed
|
||||||
|
CChangeNotifyBroker* pBroker = new CChangeNotifyBroker(hwnd, wMsg);
|
||||||
|
if (pBroker == NULL)
|
||||||
|
{
|
||||||
|
ERR("Out of memory\n");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
HWND hwndBroker = pBroker->Create(0);
|
||||||
|
if (hwndBroker == NULL)
|
||||||
|
{
|
||||||
|
ERR("hwndBroker == NULL\n");
|
||||||
|
delete pBroker;
|
||||||
|
}
|
||||||
|
|
||||||
|
return hwndBroker;
|
||||||
|
}
|
||||||
|
|
||||||
|
// This function creates a delivery ticket for shell change nofitication.
|
||||||
|
// Used in SHChangeNotify.
|
||||||
|
static HANDLE
|
||||||
|
CreateNotificationParam(LONG wEventId, UINT uFlags, LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2,
|
||||||
|
DWORD dwOwnerPID, DWORD dwTick)
|
||||||
|
{
|
||||||
|
// pidl1 and pidl2 have variable length. To store them into the delivery ticket,
|
||||||
|
// we have to consider the offsets and the sizes of pidl1 and pidl2.
|
||||||
|
DWORD cbPidl1 = 0, cbPidl2 = 0, ibOffset1 = 0, ibOffset2 = 0;
|
||||||
|
if (pidl1)
|
||||||
|
{
|
||||||
|
cbPidl1 = ILGetSize(pidl1);
|
||||||
|
ibOffset1 = DWORD_ALIGNMENT(sizeof(DELITICKET));
|
||||||
|
}
|
||||||
|
if (pidl2)
|
||||||
|
{
|
||||||
|
cbPidl2 = ILGetSize(pidl2);
|
||||||
|
ibOffset2 = DWORD_ALIGNMENT(ibOffset1 + cbPidl1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// allocate the delivery ticket
|
||||||
|
DWORD cbSize = ibOffset2 + cbPidl2;
|
||||||
|
HANDLE hTicket = SHAllocShared(NULL, cbSize, dwOwnerPID);
|
||||||
|
if (hTicket == NULL)
|
||||||
|
{
|
||||||
|
ERR("Out of memory\n");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
// lock the ticket
|
||||||
|
LPDELITICKET pTicket = (LPDELITICKET)SHLockSharedEx(hTicket, dwOwnerPID, TRUE);
|
||||||
|
if (pTicket == NULL)
|
||||||
|
{
|
||||||
|
ERR("SHLockSharedEx failed\n");
|
||||||
|
SHFreeShared(hTicket, dwOwnerPID);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
// populate the ticket
|
||||||
|
pTicket->dwMagic = DELITICKET_MAGIC;
|
||||||
|
pTicket->wEventId = wEventId;
|
||||||
|
pTicket->uFlags = uFlags;
|
||||||
|
pTicket->ibOffset1 = ibOffset1;
|
||||||
|
pTicket->ibOffset2 = ibOffset2;
|
||||||
|
if (pidl1)
|
||||||
|
memcpy((LPBYTE)pTicket + ibOffset1, pidl1, cbPidl1);
|
||||||
|
if (pidl2)
|
||||||
|
memcpy((LPBYTE)pTicket + ibOffset2, pidl2, cbPidl2);
|
||||||
|
|
||||||
|
// unlock the ticket and return
|
||||||
|
SHUnlockShared(pTicket);
|
||||||
|
return hTicket;
|
||||||
|
}
|
||||||
|
|
||||||
|
// This function creates a "handbag" by using a delivery ticket.
|
||||||
|
// The handbag is created in SHChangeNotification_Lock and used in OnBrokerNotification.
|
||||||
|
// hTicket is a ticket handle of a shared memory block and dwOwnerPID is
|
||||||
|
// the owner PID of the ticket.
|
||||||
|
static LPHANDBAG
|
||||||
|
DoGetHandbagFromTicket(HANDLE hTicket, DWORD dwOwnerPID)
|
||||||
|
{
|
||||||
|
// lock and validate the delivery ticket
|
||||||
|
LPDELITICKET pTicket = (LPDELITICKET)SHLockSharedEx(hTicket, dwOwnerPID, FALSE);
|
||||||
|
if (pTicket == NULL || pTicket->dwMagic != DELITICKET_MAGIC)
|
||||||
|
{
|
||||||
|
ERR("pTicket is invalid\n");
|
||||||
|
SHUnlockShared(pTicket);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
// allocate the handbag
|
||||||
|
LPHANDBAG pHandbag = (LPHANDBAG)LocalAlloc(LMEM_FIXED, sizeof(HANDBAG));
|
||||||
|
if (pHandbag == NULL)
|
||||||
|
{
|
||||||
|
ERR("Out of memory\n");
|
||||||
|
SHUnlockShared(pTicket);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
// populate the handbag
|
||||||
|
pHandbag->dwMagic = HANDBAG_MAGIC;
|
||||||
|
pHandbag->pTicket = pTicket;
|
||||||
|
|
||||||
|
pHandbag->pidls[0] = pHandbag->pidls[1] = NULL;
|
||||||
|
if (pTicket->ibOffset1)
|
||||||
|
pHandbag->pidls[0] = (LPITEMIDLIST)((LPBYTE)pTicket + pTicket->ibOffset1);
|
||||||
|
if (pTicket->ibOffset2)
|
||||||
|
pHandbag->pidls[1] = (LPITEMIDLIST)((LPBYTE)pTicket + pTicket->ibOffset2);
|
||||||
|
|
||||||
|
return pHandbag;
|
||||||
|
}
|
||||||
|
|
||||||
|
// This function creates a registration entry in SHChangeNotifyRegister function.
|
||||||
|
static HANDLE
|
||||||
|
CreateRegistrationParam(ULONG nRegID, HWND hwnd, UINT wMsg, INT fSources, LONG fEvents,
|
||||||
|
LONG fRecursive, LPCITEMIDLIST pidl, DWORD dwOwnerPID,
|
||||||
|
HWND hwndBroker)
|
||||||
|
{
|
||||||
|
// pidl has variable length. To store it into the registration entry,
|
||||||
|
// we have to consider the length of pidl.
|
||||||
|
DWORD cbPidl = ILGetSize(pidl);
|
||||||
|
DWORD ibPidl = DWORD_ALIGNMENT(sizeof(REGENTRY));
|
||||||
|
DWORD cbSize = ibPidl + cbPidl;
|
||||||
|
|
||||||
|
// create the registration entry and lock it
|
||||||
|
HANDLE hRegEntry = SHAllocShared(NULL, cbSize, dwOwnerPID);
|
||||||
|
if (hRegEntry == NULL)
|
||||||
|
{
|
||||||
|
ERR("Out of memory\n");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
LPREGENTRY pRegEntry = (LPREGENTRY)SHLockSharedEx(hRegEntry, dwOwnerPID, TRUE);
|
||||||
|
if (pRegEntry == NULL)
|
||||||
|
{
|
||||||
|
ERR("SHLockSharedEx failed\n");
|
||||||
|
SHFreeShared(hRegEntry, dwOwnerPID);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
// populate the registration entry
|
||||||
|
pRegEntry->dwMagic = REGENTRY_MAGIC;
|
||||||
|
pRegEntry->cbSize = cbSize;
|
||||||
|
pRegEntry->nRegID = nRegID;
|
||||||
|
pRegEntry->hwnd = hwnd;
|
||||||
|
pRegEntry->uMsg = wMsg;
|
||||||
|
pRegEntry->fSources = fSources;
|
||||||
|
pRegEntry->fEvents = fEvents;
|
||||||
|
pRegEntry->fRecursive = fRecursive;
|
||||||
|
pRegEntry->hwndBroker = hwndBroker;
|
||||||
|
pRegEntry->ibPidl = 0;
|
||||||
|
if (pidl)
|
||||||
|
{
|
||||||
|
pRegEntry->ibPidl = ibPidl;
|
||||||
|
memcpy((LPBYTE)pRegEntry + ibPidl, pidl, cbPidl);
|
||||||
|
}
|
||||||
|
|
||||||
|
// unlock and return
|
||||||
|
SHUnlockShared(pRegEntry);
|
||||||
|
return hRegEntry;
|
||||||
|
}
|
||||||
|
|
||||||
|
// This function is the body of SHChangeNotify function.
|
||||||
|
// It creates a delivery ticket and send CN_DELIVER_NOTIFICATION message to
|
||||||
|
// transport the change.
|
||||||
|
static void
|
||||||
|
CreateNotificationParamAndSend(LONG wEventId, UINT uFlags, LPITEMIDLIST pidl1, LPITEMIDLIST pidl2,
|
||||||
|
DWORD dwTick)
|
||||||
|
{
|
||||||
|
// get server window
|
||||||
|
HWND hwndServer = GetNotificationServer(FALSE);
|
||||||
|
if (hwndServer == NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
|
// the ticket owner is the process of the server process
|
||||||
|
DWORD pid;
|
||||||
|
GetWindowThreadProcessId(hwndServer, &pid);
|
||||||
|
|
||||||
|
// create a delivery ticket
|
||||||
|
HANDLE hTicket = CreateNotificationParam(wEventId, uFlags, pidl1, pidl2, pid, dwTick);
|
||||||
|
if (hTicket == NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
|
TRACE("hTicket: %p, 0x%lx\n", hTicket, pid);
|
||||||
|
|
||||||
|
// send the ticket by using CN_DELIVER_NOTIFICATION
|
||||||
|
if ((uFlags & (SHCNF_FLUSH | SHCNF_FLUSHNOWAIT)) == SHCNF_FLUSH)
|
||||||
|
SendMessageW(hwndServer, CN_DELIVER_NOTIFICATION, (WPARAM)hTicket, pid);
|
||||||
|
else
|
||||||
|
SendNotifyMessageW(hwndServer, CN_DELIVER_NOTIFICATION, (WPARAM)hTicket, pid);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*************************************************************************
|
||||||
|
* SHChangeNotifyRegister [SHELL32.2]
|
||||||
|
*/
|
||||||
|
EXTERN_C ULONG WINAPI
|
||||||
|
SHChangeNotifyRegister(HWND hwnd, INT fSources, LONG wEventMask, UINT uMsg,
|
||||||
|
INT cItems, SHChangeNotifyEntry *lpItems)
|
||||||
|
{
|
||||||
|
HWND hwndServer, hwndBroker = NULL;
|
||||||
|
HANDLE hRegEntry;
|
||||||
|
INT iItem;
|
||||||
|
ULONG nRegID = INVALID_REG_ID;
|
||||||
|
DWORD dwOwnerPID;
|
||||||
|
LPREGENTRY pRegEntry;
|
||||||
|
|
||||||
|
TRACE("(%p,0x%08x,0x%08x,0x%08x,%d,%p)\n",
|
||||||
|
hwnd, fSources, wEventMask, uMsg, cItems, lpItems);
|
||||||
|
|
||||||
|
// sanity check
|
||||||
|
if (wEventMask == 0 || cItems <= 0 || cItems > 0x7FFF || lpItems == NULL ||
|
||||||
|
hwnd == NULL || !IsWindow(hwnd))
|
||||||
|
{
|
||||||
|
return INVALID_REG_ID;
|
||||||
|
}
|
||||||
|
|
||||||
|
// request the window of the server
|
||||||
|
hwndServer = GetNotificationServer(TRUE);
|
||||||
|
if (hwndServer == NULL)
|
||||||
|
return INVALID_REG_ID;
|
||||||
|
|
||||||
|
// disable new delivery method in specific condition
|
||||||
|
if ((fSources & SHCNRF_RecursiveInterrupt) != 0 &&
|
||||||
|
(fSources & SHCNRF_InterruptLevel) == 0)
|
||||||
|
{
|
||||||
|
fSources &= ~SHCNRF_NewDelivery;
|
||||||
|
}
|
||||||
|
|
||||||
|
// if it is old delivery method, then create a broker window
|
||||||
|
if ((fSources & SHCNRF_NewDelivery) == 0)
|
||||||
|
{
|
||||||
|
hwndBroker = hwnd = CreateNotificationBroker(hwnd, uMsg);
|
||||||
|
uMsg = WM_BROKER_NOTIFICATION;
|
||||||
|
}
|
||||||
|
|
||||||
|
// The owner PID is the process ID of the server
|
||||||
|
GetWindowThreadProcessId(hwndServer, &dwOwnerPID);
|
||||||
|
|
||||||
|
EnterCriticalSection(&SHELL32_ChangenotifyCS);
|
||||||
|
for (iItem = 0; iItem < cItems; ++iItem)
|
||||||
|
{
|
||||||
|
// create a registration entry
|
||||||
|
hRegEntry = CreateRegistrationParam(nRegID, hwnd, uMsg, fSources, wEventMask,
|
||||||
|
lpItems[iItem].fRecursive, lpItems[iItem].pidl,
|
||||||
|
dwOwnerPID, hwndBroker);
|
||||||
|
if (hRegEntry)
|
||||||
|
{
|
||||||
|
TRACE("CN_REGISTER: hwnd:%p, hRegEntry:%p, pid:0x%lx\n",
|
||||||
|
hwndServer, hRegEntry, dwOwnerPID);
|
||||||
|
|
||||||
|
// send CN_REGISTER to the server
|
||||||
|
SendMessageW(hwndServer, CN_REGISTER, (WPARAM)hRegEntry, dwOwnerPID);
|
||||||
|
|
||||||
|
// update nRegID
|
||||||
|
pRegEntry = (LPREGENTRY)SHLockSharedEx(hRegEntry, dwOwnerPID, FALSE);
|
||||||
|
if (pRegEntry)
|
||||||
|
{
|
||||||
|
nRegID = pRegEntry->nRegID;
|
||||||
|
SHUnlockShared(pRegEntry);
|
||||||
|
}
|
||||||
|
|
||||||
|
// free registration entry
|
||||||
|
SHFreeShared(hRegEntry, dwOwnerPID);
|
||||||
|
}
|
||||||
|
|
||||||
|
// if failed, then destroy the broker
|
||||||
|
if (nRegID == INVALID_REG_ID && (fSources & SHCNRF_NewDelivery) == 0)
|
||||||
|
{
|
||||||
|
ERR("Delivery failed\n");
|
||||||
|
DestroyWindow(hwndBroker);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
LeaveCriticalSection(&SHELL32_ChangenotifyCS);
|
||||||
|
|
||||||
|
return nRegID;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*************************************************************************
|
||||||
|
* SHChangeNotifyDeregister [SHELL32.4]
|
||||||
|
*/
|
||||||
|
EXTERN_C BOOL WINAPI
|
||||||
|
SHChangeNotifyDeregister(ULONG hNotify)
|
||||||
|
{
|
||||||
|
TRACE("(0x%08x)\n", hNotify);
|
||||||
|
|
||||||
|
// get the server window
|
||||||
|
HWND hwndServer = GetNotificationServer(FALSE);
|
||||||
|
if (hwndServer == NULL)
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
// send CN_UNREGISTER message and try to unregister
|
||||||
|
BOOL ret = (BOOL)SendMessageW(hwndServer, CN_UNREGISTER, hNotify, 0);
|
||||||
|
if (!ret)
|
||||||
|
ERR("CN_UNREGISTER failed\n");
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*************************************************************************
|
||||||
|
* SHChangeNotifyUpdateEntryList [SHELL32.5]
|
||||||
|
*/
|
||||||
|
EXTERN_C BOOL WINAPI
|
||||||
|
SHChangeNotifyUpdateEntryList(DWORD unknown1, DWORD unknown2,
|
||||||
|
DWORD unknown3, DWORD unknown4)
|
||||||
|
{
|
||||||
|
FIXME("(0x%08x, 0x%08x, 0x%08x, 0x%08x)\n",
|
||||||
|
unknown1, unknown2, unknown3, unknown4);
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* for dumping events */
|
||||||
|
static LPCSTR DumpEvent(LONG event)
|
||||||
|
{
|
||||||
|
if (event == SHCNE_ALLEVENTS)
|
||||||
|
return "SHCNE_ALLEVENTS";
|
||||||
|
#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
|
||||||
|
}
|
||||||
|
|
||||||
|
/*************************************************************************
|
||||||
|
* SHChangeNotify [SHELL32.@]
|
||||||
|
*/
|
||||||
|
EXTERN_C void WINAPI
|
||||||
|
SHChangeNotify(LONG wEventId, UINT uFlags, LPCVOID dwItem1, LPCVOID dwItem2)
|
||||||
|
{
|
||||||
|
LPITEMIDLIST pidl1 = NULL, pidl2 = NULL, pidlTemp1 = NULL, pidlTemp2 = NULL;
|
||||||
|
DWORD dwTick = GetTickCount();
|
||||||
|
WCHAR szPath1[MAX_PATH], szPath2[MAX_PATH];
|
||||||
|
LPWSTR psz1, psz2;
|
||||||
|
TRACE("(0x%08x,0x%08x,%p,%p)\n", wEventId, uFlags, dwItem1, dwItem2);
|
||||||
|
|
||||||
|
switch (uFlags & SHCNF_TYPE)
|
||||||
|
{
|
||||||
|
case SHCNF_IDLIST:
|
||||||
|
pidl1 = (LPITEMIDLIST)dwItem1;
|
||||||
|
pidl2 = (LPITEMIDLIST)dwItem2;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case SHCNF_PATHA:
|
||||||
|
psz1 = psz2 = NULL;
|
||||||
|
if (dwItem1)
|
||||||
|
{
|
||||||
|
SHAnsiToUnicode((LPCSTR)dwItem1, szPath1, _countof(szPath1));
|
||||||
|
psz1 = szPath1;
|
||||||
|
}
|
||||||
|
if (dwItem2)
|
||||||
|
{
|
||||||
|
SHAnsiToUnicode((LPCSTR)dwItem2, szPath2, _countof(szPath2));
|
||||||
|
psz2 = szPath2;
|
||||||
|
}
|
||||||
|
uFlags &= ~SHCNF_TYPE;
|
||||||
|
uFlags |= SHCNF_PATHW;
|
||||||
|
SHChangeNotify(wEventId, uFlags, psz1, psz2);
|
||||||
|
return;
|
||||||
|
|
||||||
|
case SHCNF_PATHW:
|
||||||
|
if (dwItem1)
|
||||||
|
{
|
||||||
|
pidl1 = pidlTemp1 = SHSimpleIDListFromPathW((LPCWSTR)dwItem1);
|
||||||
|
}
|
||||||
|
if (dwItem2)
|
||||||
|
{
|
||||||
|
pidl2 = pidlTemp2 = SHSimpleIDListFromPathW((LPCWSTR)dwItem2);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case SHCNF_PRINTERA:
|
||||||
|
case SHCNF_PRINTERW:
|
||||||
|
FIXME("SHChangeNotify with (uFlags & SHCNF_PRINTER)\n");
|
||||||
|
return;
|
||||||
|
|
||||||
|
default:
|
||||||
|
FIXME("unknown type %08x\n", uFlags & SHCNF_TYPE);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (wEventId == 0 || (wEventId & SHCNE_ASSOCCHANGED) || pidl1 != NULL)
|
||||||
|
{
|
||||||
|
TRACE("notifying event %s(%x)\n", DumpEvent(wEventId), wEventId);
|
||||||
|
CreateNotificationParamAndSend(wEventId, uFlags, pidl1, pidl2, dwTick);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pidlTemp1)
|
||||||
|
ILFree(pidlTemp1);
|
||||||
|
if (pidlTemp2)
|
||||||
|
ILFree(pidlTemp2);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*************************************************************************
|
||||||
|
* NTSHChangeNotifyRegister [SHELL32.640]
|
||||||
|
*/
|
||||||
|
EXTERN_C ULONG WINAPI
|
||||||
|
NTSHChangeNotifyRegister(HWND hwnd, INT fSources, LONG fEvents, UINT msg,
|
||||||
|
INT count, SHChangeNotifyEntry *idlist)
|
||||||
|
{
|
||||||
|
return SHChangeNotifyRegister(hwnd, fSources | SHCNRF_NewDelivery,
|
||||||
|
fEvents, msg, count, idlist);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*************************************************************************
|
||||||
|
* SHChangeNotification_Lock [SHELL32.644]
|
||||||
|
*/
|
||||||
|
EXTERN_C HANDLE WINAPI
|
||||||
|
SHChangeNotification_Lock(HANDLE hTicket, DWORD dwOwnerPID, LPITEMIDLIST **lppidls,
|
||||||
|
LPLONG lpwEventId)
|
||||||
|
{
|
||||||
|
TRACE("%p %08x %p %p\n", hTicket, dwOwnerPID, lppidls, lpwEventId);
|
||||||
|
|
||||||
|
// create a handbag from the ticket
|
||||||
|
LPHANDBAG pHandbag = DoGetHandbagFromTicket(hTicket, dwOwnerPID);
|
||||||
|
if (pHandbag == NULL || pHandbag->dwMagic != HANDBAG_MAGIC)
|
||||||
|
{
|
||||||
|
ERR("pHandbag is invalid\n");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
// populate parameters from the handbag
|
||||||
|
if (lppidls)
|
||||||
|
*lppidls = pHandbag->pidls;
|
||||||
|
if (lpwEventId)
|
||||||
|
*lpwEventId = pHandbag->pTicket->wEventId;
|
||||||
|
|
||||||
|
// return the handbag
|
||||||
|
return pHandbag;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*************************************************************************
|
||||||
|
* SHChangeNotification_Unlock [SHELL32.645]
|
||||||
|
*/
|
||||||
|
EXTERN_C BOOL WINAPI
|
||||||
|
SHChangeNotification_Unlock(HANDLE hLock)
|
||||||
|
{
|
||||||
|
TRACE("%p\n", hLock);
|
||||||
|
|
||||||
|
// validate the handbag
|
||||||
|
LPHANDBAG pHandbag = (LPHANDBAG)hLock;
|
||||||
|
if (pHandbag == NULL || pHandbag->dwMagic != HANDBAG_MAGIC)
|
||||||
|
{
|
||||||
|
ERR("pHandbag is invalid\n");
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
// free the handbag
|
||||||
|
BOOL ret = SHUnlockShared(pHandbag->pTicket);
|
||||||
|
LocalFree(hLock);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*************************************************************************
|
||||||
|
* NTSHChangeNotifyDeregister [SHELL32.641]
|
||||||
|
*/
|
||||||
|
EXTERN_C DWORD WINAPI
|
||||||
|
NTSHChangeNotifyDeregister(ULONG hNotify)
|
||||||
|
{
|
||||||
|
FIXME("(0x%08x):semi stub.\n", hNotify);
|
||||||
|
return SHChangeNotifyDeregister(hNotify);
|
||||||
|
}
|
|
@ -91,6 +91,7 @@
|
||||||
#include "shellmenu/shellmenu.h"
|
#include "shellmenu/shellmenu.h"
|
||||||
#include "CUserNotification.h"
|
#include "CUserNotification.h"
|
||||||
#include "dialogs/folder_options.h"
|
#include "dialogs/folder_options.h"
|
||||||
|
#include "shelldesktop/CChangeNotifyServer.h"
|
||||||
|
|
||||||
#include <wine/debug.h>
|
#include <wine/debug.h>
|
||||||
#include <wine/unicode.h>
|
#include <wine/unicode.h>
|
||||||
|
|
|
@ -1,605 +0,0 @@
|
||||||
/*
|
|
||||||
* PROJECT: shell32
|
|
||||||
* LICENSE: LGPL-2.1-or-later (https://spdx.org/licenses/LGPL-2.1-or-later)
|
|
||||||
* PURPOSE: Shell change notification
|
|
||||||
* COPYRIGHT: Copyright 2020 Katayama Hirofumi MZ (katayama.hirofumi.mz@gmail.com)
|
|
||||||
*/
|
|
||||||
#include "shelldesktop.h"
|
|
||||||
#include "shlwapi_undoc.h"
|
|
||||||
#include <atlsimpcoll.h>
|
|
||||||
|
|
||||||
WINE_DEFAULT_DEBUG_CHANNEL(shcn);
|
|
||||||
|
|
||||||
static HWND s_hwndNewWorker = NULL;
|
|
||||||
|
|
||||||
EXTERN_C void
|
|
||||||
DoNotifyFreeSpace(LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2)
|
|
||||||
{
|
|
||||||
WCHAR path1[MAX_PATH], path2[MAX_PATH];
|
|
||||||
|
|
||||||
path1[0] = 0;
|
|
||||||
if (pidl1)
|
|
||||||
SHGetPathFromIDListW(pidl1, path1);
|
|
||||||
|
|
||||||
path2[0] = 0;
|
|
||||||
if (pidl2)
|
|
||||||
SHGetPathFromIDListW(pidl2, path2);
|
|
||||||
|
|
||||||
if (path1[0])
|
|
||||||
{
|
|
||||||
if (path2[0])
|
|
||||||
SHChangeNotify(SHCNE_FREESPACE, SHCNF_PATHW, path1, path2);
|
|
||||||
else
|
|
||||||
SHChangeNotify(SHCNE_FREESPACE, SHCNF_PATHW, path1, NULL);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
SHChangeNotify(SHCNE_FREESPACE, SHCNF_PATHW, NULL, NULL);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
EXTERN_C HWND
|
|
||||||
DoGetNewDeliveryWorker(void)
|
|
||||||
{
|
|
||||||
if (s_hwndNewWorker && IsWindow(s_hwndNewWorker))
|
|
||||||
return s_hwndNewWorker;
|
|
||||||
|
|
||||||
HWND hwndShell = GetShellWindow();
|
|
||||||
if (hwndShell == NULL)
|
|
||||||
{
|
|
||||||
TRACE("GetShellWindow() returned NULL\n");
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
HWND hwndWorker = (HWND)SendMessageW(hwndShell, WM_GETDELIWORKERWND, 0, 0);
|
|
||||||
if (!IsWindow(hwndWorker))
|
|
||||||
{
|
|
||||||
ERR("Unable to get notification window\n");
|
|
||||||
hwndWorker = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
s_hwndNewWorker = hwndWorker;
|
|
||||||
return hwndWorker;
|
|
||||||
}
|
|
||||||
|
|
||||||
static LRESULT CALLBACK
|
|
||||||
OldDeliveryWorkerWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
|
||||||
{
|
|
||||||
HANDLE hLock;
|
|
||||||
PIDLIST_ABSOLUTE *ppidl;
|
|
||||||
LONG lEvent;
|
|
||||||
LPOLDDELIVERYWORKER pWorker;
|
|
||||||
HANDLE hShared;
|
|
||||||
DWORD dwOwnerPID;
|
|
||||||
|
|
||||||
switch (uMsg)
|
|
||||||
{
|
|
||||||
case WM_OLDDELI_HANDOVER:
|
|
||||||
hShared = (HANDLE)wParam;
|
|
||||||
dwOwnerPID = (DWORD)lParam;
|
|
||||||
TRACE("WM_OLDDELI_HANDOVER: hwnd:%p, hShared:%p, pid:0x%lx\n",
|
|
||||||
hwnd, hShared, dwOwnerPID);
|
|
||||||
|
|
||||||
pWorker = (LPOLDDELIVERYWORKER)GetWindowLongPtrW(hwnd, 0);
|
|
||||||
if (!pWorker)
|
|
||||||
{
|
|
||||||
ERR("!pWorker\n");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
ppidl = NULL;
|
|
||||||
hLock = SHChangeNotification_Lock(hShared, dwOwnerPID, &ppidl, &lEvent);
|
|
||||||
if (!hLock)
|
|
||||||
{
|
|
||||||
ERR("!hLock\n");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
TRACE("OldDeliveryWorker notifying: %p, 0x%x, %p, 0x%lx\n",
|
|
||||||
pWorker->hwnd, pWorker->uMsg, ppidl, lEvent);
|
|
||||||
SendMessageW(pWorker->hwnd, pWorker->uMsg, (WPARAM)ppidl, lEvent);
|
|
||||||
SHChangeNotification_Unlock(hLock);
|
|
||||||
return TRUE;
|
|
||||||
|
|
||||||
case WM_NCDESTROY:
|
|
||||||
TRACE("WM_NCDESTROY\n");
|
|
||||||
pWorker = (LPOLDDELIVERYWORKER)GetWindowLongPtrW(hwnd, 0);
|
|
||||||
SetWindowLongW(hwnd, 0, 0);
|
|
||||||
delete pWorker;
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
return DefWindowProcW(hwnd, uMsg, wParam, lParam);
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
EXTERN_C HWND
|
|
||||||
DoHireOldDeliveryWorker(HWND hwnd, UINT wMsg)
|
|
||||||
{
|
|
||||||
LPOLDDELIVERYWORKER pWorker;
|
|
||||||
HWND hwndOldWorker;
|
|
||||||
|
|
||||||
pWorker = new OLDDELIVERYWORKER;
|
|
||||||
if (!pWorker)
|
|
||||||
{
|
|
||||||
ERR("Out of memory\n");
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
pWorker->hwnd = hwnd;
|
|
||||||
pWorker->uMsg = wMsg;
|
|
||||||
hwndOldWorker = SHCreateWorkerWindowW(OldDeliveryWorkerWndProc, NULL, 0, 0,
|
|
||||||
NULL, (LONG_PTR)pWorker);
|
|
||||||
if (hwndOldWorker == NULL)
|
|
||||||
{
|
|
||||||
ERR("hwndOldWorker == NULL\n");
|
|
||||||
delete pWorker;
|
|
||||||
}
|
|
||||||
|
|
||||||
DWORD pid;
|
|
||||||
GetWindowThreadProcessId(hwndOldWorker, &pid);
|
|
||||||
TRACE("hwndOldWorker: %p, 0x%lx\n", hwndOldWorker, pid);
|
|
||||||
return hwndOldWorker;
|
|
||||||
}
|
|
||||||
|
|
||||||
EXTERN_C HANDLE
|
|
||||||
DoCreateNotifShare(ULONG nRegID, HWND hwnd, UINT wMsg, INT fSources, LONG fEvents,
|
|
||||||
LONG fRecursive, LPCITEMIDLIST pidl, DWORD dwOwnerPID,
|
|
||||||
HWND hwndOldWorker)
|
|
||||||
{
|
|
||||||
DWORD cbPidl = ILGetSize(pidl);
|
|
||||||
DWORD ibPidl = DWORD_ALIGNMENT(sizeof(NOTIFSHARE));
|
|
||||||
DWORD cbSize = ibPidl + cbPidl;
|
|
||||||
HANDLE hShared = SHAllocShared(NULL, cbSize, dwOwnerPID);
|
|
||||||
if (!hShared)
|
|
||||||
{
|
|
||||||
ERR("Out of memory\n");
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
LPNOTIFSHARE pShared = (LPNOTIFSHARE)SHLockSharedEx(hShared, dwOwnerPID, TRUE);
|
|
||||||
if (pShared == NULL)
|
|
||||||
{
|
|
||||||
ERR("SHLockSharedEx failed\n");
|
|
||||||
SHFreeShared(hShared, dwOwnerPID);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
pShared->dwMagic = NOTIFSHARE_MAGIC;
|
|
||||||
pShared->cbSize = cbSize;
|
|
||||||
pShared->nRegID = nRegID;
|
|
||||||
pShared->hwnd = hwnd;
|
|
||||||
pShared->hwndOldWorker = hwndOldWorker;
|
|
||||||
pShared->uMsg = wMsg;
|
|
||||||
pShared->fSources = fSources;
|
|
||||||
pShared->fEvents = fEvents;
|
|
||||||
pShared->fRecursive = fRecursive;
|
|
||||||
pShared->ibPidl = 0;
|
|
||||||
if (pidl)
|
|
||||||
{
|
|
||||||
pShared->ibPidl = ibPidl;
|
|
||||||
memcpy((LPBYTE)pShared + ibPidl, pidl, cbPidl);
|
|
||||||
}
|
|
||||||
SHUnlockShared(pShared);
|
|
||||||
return hShared;
|
|
||||||
}
|
|
||||||
|
|
||||||
EXTERN_C HANDLE
|
|
||||||
DoCreateDeliTicket(LONG wEventId, UINT uFlags, LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2,
|
|
||||||
DWORD dwOwnerPID, DWORD dwTick)
|
|
||||||
{
|
|
||||||
LPDELITICKET pTicket;
|
|
||||||
HANDLE hTicket = NULL;
|
|
||||||
DWORD cbPidl1 = 0, cbPidl2 = 0, ibOffset1 = 0, ibOffset2 = 0, cbSize;
|
|
||||||
|
|
||||||
if (pidl1)
|
|
||||||
{
|
|
||||||
cbPidl1 = ILGetSize(pidl1);
|
|
||||||
ibOffset1 = DWORD_ALIGNMENT(sizeof(DELITICKET));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pidl2)
|
|
||||||
{
|
|
||||||
cbPidl2 = ILGetSize(pidl2);
|
|
||||||
ibOffset2 = DWORD_ALIGNMENT(ibOffset1 + cbPidl1);
|
|
||||||
}
|
|
||||||
|
|
||||||
cbSize = ibOffset2 + cbPidl2;
|
|
||||||
hTicket = SHAllocShared(NULL, cbSize, dwOwnerPID);
|
|
||||||
if (hTicket == NULL)
|
|
||||||
{
|
|
||||||
ERR("Out of memory\n");
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
pTicket = (LPDELITICKET)SHLockSharedEx(hTicket, dwOwnerPID, TRUE);
|
|
||||||
if (pTicket == NULL)
|
|
||||||
{
|
|
||||||
ERR("SHLockSharedEx failed\n");
|
|
||||||
SHFreeShared(hTicket, dwOwnerPID);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
pTicket->dwMagic = DELITICKET_MAGIC;
|
|
||||||
pTicket->wEventId = wEventId;
|
|
||||||
pTicket->uFlags = uFlags;
|
|
||||||
pTicket->ibOffset1 = ibOffset1;
|
|
||||||
pTicket->ibOffset2 = ibOffset2;
|
|
||||||
|
|
||||||
if (pidl1)
|
|
||||||
memcpy((LPBYTE)pTicket + ibOffset1, pidl1, cbPidl1);
|
|
||||||
if (pidl2)
|
|
||||||
memcpy((LPBYTE)pTicket + ibOffset2, pidl2, cbPidl2);
|
|
||||||
|
|
||||||
SHUnlockShared(pTicket);
|
|
||||||
return hTicket;
|
|
||||||
}
|
|
||||||
|
|
||||||
EXTERN_C LPHANDBAG
|
|
||||||
DoGetHandbagFromTicket(HANDLE hTicket, DWORD dwOwnerPID)
|
|
||||||
{
|
|
||||||
LPDELITICKET pTicket = (LPDELITICKET)SHLockSharedEx(hTicket, dwOwnerPID, FALSE);
|
|
||||||
if (!pTicket || pTicket->dwMagic != DELITICKET_MAGIC)
|
|
||||||
{
|
|
||||||
ERR("pTicket is invalid\n");
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
LPHANDBAG pHandbag = (LPHANDBAG)LocalAlloc(LMEM_FIXED, sizeof(HANDBAG));
|
|
||||||
if (pHandbag == NULL)
|
|
||||||
{
|
|
||||||
ERR("Out of memory\n");
|
|
||||||
SHUnlockShared(pTicket);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
pHandbag->dwMagic = HANDBAG_MAGIC;
|
|
||||||
pHandbag->pTicket = pTicket;
|
|
||||||
|
|
||||||
pHandbag->pidls[0] = pHandbag->pidls[1] = NULL;
|
|
||||||
if (pTicket->ibOffset1)
|
|
||||||
pHandbag->pidls[0] = (LPITEMIDLIST)((LPBYTE)pTicket + pTicket->ibOffset1);
|
|
||||||
if (pTicket->ibOffset2)
|
|
||||||
pHandbag->pidls[1] = (LPITEMIDLIST)((LPBYTE)pTicket + pTicket->ibOffset2);
|
|
||||||
|
|
||||||
return pHandbag;
|
|
||||||
}
|
|
||||||
|
|
||||||
EXTERN_C void
|
|
||||||
DoTransportChange(LONG wEventId, UINT uFlags, LPITEMIDLIST pidl1, LPITEMIDLIST pidl2,
|
|
||||||
DWORD dwTick)
|
|
||||||
{
|
|
||||||
HWND hwndNotif = DoGetNewDeliveryWorker();
|
|
||||||
if (!hwndNotif)
|
|
||||||
return;
|
|
||||||
|
|
||||||
DWORD pid;
|
|
||||||
GetWindowThreadProcessId(hwndNotif, &pid);
|
|
||||||
|
|
||||||
HANDLE hTicket = DoCreateDeliTicket(wEventId, uFlags, pidl1, pidl2, pid, dwTick);
|
|
||||||
if (hTicket)
|
|
||||||
{
|
|
||||||
TRACE("hTicket: %p, 0x%lx\n", hTicket, pid);
|
|
||||||
if ((uFlags & (SHCNF_FLUSH | SHCNF_FLUSHNOWAIT)) == SHCNF_FLUSH)
|
|
||||||
SendMessageW(hwndNotif, WM_NOTIF_DELIVERY, (WPARAM)hTicket, pid);
|
|
||||||
else
|
|
||||||
SendNotifyMessageW(hwndNotif, WM_NOTIF_DELIVERY, (WPARAM)hTicket, pid);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*static*/ LRESULT CALLBACK
|
|
||||||
CWorker::WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
|
||||||
{
|
|
||||||
CWorker *pThis = (CWorker *)GetWindowLongPtrW(hwnd, 0);
|
|
||||||
if (pThis)
|
|
||||||
{
|
|
||||||
LRESULT lResult = 0;
|
|
||||||
pThis->ProcessWindowMessage(hwnd, uMsg, wParam, lParam, lResult, 0);
|
|
||||||
return lResult;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
BOOL CWorker::CreateWorker(HWND hwndParent, DWORD dwExStyle, DWORD dwStyle)
|
|
||||||
{
|
|
||||||
if (::IsWindow(m_hWnd))
|
|
||||||
::DestroyWindow(m_hWnd);
|
|
||||||
m_hWnd = SHCreateWorkerWindowW(WindowProc, hwndParent, dwExStyle, dwStyle,
|
|
||||||
NULL, (LONG_PTR)this);
|
|
||||||
return m_hWnd != NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct CChangeNotifyImpl
|
|
||||||
{
|
|
||||||
typedef CChangeNotify::ITEM ITEM;
|
|
||||||
CSimpleArray<ITEM> m_items;
|
|
||||||
|
|
||||||
BOOL AddItem(UINT nRegID, DWORD dwUserPID, HANDLE hShare, HWND hwndOldWorker)
|
|
||||||
{
|
|
||||||
for (INT i = 0; i < m_items.GetSize(); ++i)
|
|
||||||
{
|
|
||||||
if (m_items[i].nRegID == INVALID_REG_ID)
|
|
||||||
{
|
|
||||||
m_items[i].nRegID = nRegID;
|
|
||||||
m_items[i].dwUserPID = dwUserPID;
|
|
||||||
m_items[i].hShare = hShare;
|
|
||||||
m_items[i].hwndOldWorker = hwndOldWorker;
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ITEM item = { nRegID, dwUserPID, hShare, hwndOldWorker };
|
|
||||||
m_items.Add(item);
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
void DestroyItem(ITEM& item, DWORD dwOwnerPID, HWND *phwndOldWorker)
|
|
||||||
{
|
|
||||||
if (item.hwndOldWorker && item.hwndOldWorker != *phwndOldWorker)
|
|
||||||
{
|
|
||||||
DestroyWindow(item.hwndOldWorker);
|
|
||||||
*phwndOldWorker = item.hwndOldWorker;
|
|
||||||
}
|
|
||||||
|
|
||||||
SHFreeShared(item.hShare, dwOwnerPID);
|
|
||||||
item.nRegID = INVALID_REG_ID;
|
|
||||||
item.dwUserPID = 0;
|
|
||||||
item.hShare = NULL;
|
|
||||||
item.hwndOldWorker = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
BOOL RemoveItem(UINT nRegID, DWORD dwOwnerPID)
|
|
||||||
{
|
|
||||||
BOOL bFound = FALSE;
|
|
||||||
HWND hwndOldWorker = NULL;
|
|
||||||
for (INT i = 0; i < m_items.GetSize(); ++i)
|
|
||||||
{
|
|
||||||
if (m_items[i].nRegID == nRegID)
|
|
||||||
{
|
|
||||||
bFound = TRUE;
|
|
||||||
DestroyItem(m_items[i], dwOwnerPID, &hwndOldWorker);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return bFound;
|
|
||||||
}
|
|
||||||
|
|
||||||
void RemoveItemsByProcess(DWORD dwOwnerPID, DWORD dwUserPID)
|
|
||||||
{
|
|
||||||
HWND hwndOldWorker = NULL;
|
|
||||||
for (INT i = 0; i < m_items.GetSize(); ++i)
|
|
||||||
{
|
|
||||||
if (m_items[i].dwUserPID == dwUserPID)
|
|
||||||
{
|
|
||||||
DestroyItem(m_items[i], dwOwnerPID, &hwndOldWorker);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
CChangeNotify::CChangeNotify()
|
|
||||||
: m_nNextRegID(INVALID_REG_ID)
|
|
||||||
, m_pimpl(new CChangeNotifyImpl)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
CChangeNotify::~CChangeNotify()
|
|
||||||
{
|
|
||||||
delete m_pimpl;
|
|
||||||
}
|
|
||||||
|
|
||||||
BOOL CChangeNotify::AddItem(UINT nRegID, DWORD dwUserPID, HANDLE hShare, HWND hwndOldWorker)
|
|
||||||
{
|
|
||||||
return m_pimpl->AddItem(nRegID, dwUserPID, hShare, hwndOldWorker);
|
|
||||||
}
|
|
||||||
|
|
||||||
BOOL CChangeNotify::RemoveItem(UINT nRegID, DWORD dwOwnerPID)
|
|
||||||
{
|
|
||||||
return m_pimpl->RemoveItem(nRegID, dwOwnerPID);
|
|
||||||
}
|
|
||||||
|
|
||||||
void CChangeNotify::RemoveItemsByProcess(DWORD dwOwnerPID, DWORD dwUserPID)
|
|
||||||
{
|
|
||||||
m_pimpl->RemoveItemsByProcess(dwOwnerPID, dwUserPID);
|
|
||||||
}
|
|
||||||
|
|
||||||
LRESULT CChangeNotify::OnReg(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
|
|
||||||
{
|
|
||||||
TRACE("OnReg(%p, %u, %p, %p)\n", m_hWnd, uMsg, wParam, lParam);
|
|
||||||
|
|
||||||
HANDLE hShared = (HANDLE)wParam;
|
|
||||||
DWORD dwOwnerPID = (DWORD)lParam;
|
|
||||||
|
|
||||||
LPNOTIFSHARE pShared = (LPNOTIFSHARE)SHLockSharedEx(hShared, dwOwnerPID, TRUE);
|
|
||||||
if (!pShared || pShared->dwMagic != NOTIFSHARE_MAGIC)
|
|
||||||
{
|
|
||||||
ERR("pShared is invalid\n");
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pShared->nRegID == INVALID_REG_ID)
|
|
||||||
pShared->nRegID = GetNextRegID();
|
|
||||||
|
|
||||||
TRACE("pShared->nRegID: %u\n", pShared->nRegID);
|
|
||||||
|
|
||||||
DWORD dwUserPID;
|
|
||||||
GetWindowThreadProcessId(pShared->hwnd, &dwUserPID);
|
|
||||||
|
|
||||||
HWND hwndOldWorker = pShared->hwndOldWorker;
|
|
||||||
|
|
||||||
HANDLE hNewShared = SHAllocShared(pShared, pShared->cbSize, dwOwnerPID);
|
|
||||||
if (!hNewShared)
|
|
||||||
{
|
|
||||||
ERR("Out of memory\n");
|
|
||||||
pShared->nRegID = INVALID_REG_ID;
|
|
||||||
SHUnlockShared(pShared);
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
SHUnlockShared(pShared);
|
|
||||||
|
|
||||||
return AddItem(m_nNextRegID, dwUserPID, hNewShared, hwndOldWorker);
|
|
||||||
}
|
|
||||||
|
|
||||||
LRESULT CChangeNotify::OnUnReg(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
|
|
||||||
{
|
|
||||||
TRACE("OnUnReg(%p, %u, %p, %p)\n", m_hWnd, uMsg, wParam, lParam);
|
|
||||||
|
|
||||||
UINT nRegID = (UINT)wParam;
|
|
||||||
if (nRegID == INVALID_REG_ID)
|
|
||||||
{
|
|
||||||
ERR("INVALID_REG_ID\n");
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
DWORD dwOwnerPID;
|
|
||||||
GetWindowThreadProcessId(m_hWnd, &dwOwnerPID);
|
|
||||||
return RemoveItem(nRegID, dwOwnerPID);
|
|
||||||
}
|
|
||||||
|
|
||||||
LRESULT CChangeNotify::OnDelivery(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
|
|
||||||
{
|
|
||||||
TRACE("OnDelivery(%p, %u, %p, %p)\n", m_hWnd, uMsg, wParam, lParam);
|
|
||||||
|
|
||||||
HANDLE hTicket = (HANDLE)wParam;
|
|
||||||
DWORD dwOwnerPID = (DWORD)lParam;
|
|
||||||
BOOL ret = FALSE;
|
|
||||||
|
|
||||||
LPHANDBAG pHandbag = DoGetHandbagFromTicket(hTicket, dwOwnerPID);
|
|
||||||
if (pHandbag && pHandbag->dwMagic == HANDBAG_MAGIC)
|
|
||||||
{
|
|
||||||
LPDELITICKET pTicket = pHandbag->pTicket;
|
|
||||||
if (pTicket && pTicket->dwMagic == DELITICKET_MAGIC)
|
|
||||||
{
|
|
||||||
ret = DoDelivery(hTicket, dwOwnerPID);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
SHChangeNotification_Unlock(pHandbag);
|
|
||||||
SHFreeShared(hTicket, dwOwnerPID);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
LRESULT CChangeNotify::OnSuspendResume(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
|
|
||||||
{
|
|
||||||
TRACE("OnSuspendResume\n");
|
|
||||||
|
|
||||||
// FIXME
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
LRESULT CChangeNotify::OnRemoveByPID(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
|
|
||||||
{
|
|
||||||
DWORD dwOwnerPID, dwUserPID = (DWORD)wParam;
|
|
||||||
GetWindowThreadProcessId(m_hWnd, &dwOwnerPID);
|
|
||||||
RemoveItemsByProcess(dwOwnerPID, dwUserPID);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
UINT CChangeNotify::GetNextRegID()
|
|
||||||
{
|
|
||||||
m_nNextRegID++;
|
|
||||||
if (m_nNextRegID == INVALID_REG_ID)
|
|
||||||
m_nNextRegID++;
|
|
||||||
return m_nNextRegID;
|
|
||||||
}
|
|
||||||
|
|
||||||
BOOL CChangeNotify::DoDelivery(HANDLE hTicket, DWORD dwOwnerPID)
|
|
||||||
{
|
|
||||||
TRACE("DoDelivery(%p, %p, 0x%lx)\n", m_hWnd, hTicket, dwOwnerPID);
|
|
||||||
|
|
||||||
for (INT i = 0; i < m_pimpl->m_items.GetSize(); ++i)
|
|
||||||
{
|
|
||||||
HANDLE hShare = m_pimpl->m_items[i].hShare;
|
|
||||||
if (!m_pimpl->m_items[i].nRegID || !hShare)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
LPNOTIFSHARE pShared = (LPNOTIFSHARE)SHLockSharedEx(hShare, dwOwnerPID, FALSE);
|
|
||||||
if (!pShared || pShared->dwMagic != NOTIFSHARE_MAGIC)
|
|
||||||
{
|
|
||||||
ERR("pShared is invalid\n");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
LPDELITICKET pTicket = (LPDELITICKET)SHLockSharedEx(hTicket, dwOwnerPID, FALSE);
|
|
||||||
if (!pTicket || pTicket->dwMagic != DELITICKET_MAGIC)
|
|
||||||
{
|
|
||||||
ERR("pTicket is invalid\n");
|
|
||||||
SHUnlockShared(pShared);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
BOOL bNotify = ShouldNotify(pTicket, pShared);
|
|
||||||
SHUnlockShared(pTicket);
|
|
||||||
|
|
||||||
if (bNotify)
|
|
||||||
{
|
|
||||||
TRACE("Notifying: %p, 0x%x, %p, %lu\n",
|
|
||||||
pShared->hwnd, pShared->uMsg, hTicket, dwOwnerPID);
|
|
||||||
SendMessageW(pShared->hwnd, pShared->uMsg, (WPARAM)hTicket, dwOwnerPID);
|
|
||||||
}
|
|
||||||
SHUnlockShared(pShared);
|
|
||||||
}
|
|
||||||
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
BOOL CChangeNotify::ShouldNotify(LPDELITICKET pTicket, LPNOTIFSHARE pShared)
|
|
||||||
{
|
|
||||||
LPITEMIDLIST pidl, pidl1 = NULL, pidl2 = NULL;
|
|
||||||
WCHAR szPath[MAX_PATH], szPath1[MAX_PATH], szPath2[MAX_PATH];
|
|
||||||
INT cch, cch1, cch2;
|
|
||||||
|
|
||||||
if (!pShared->ibPidl)
|
|
||||||
return TRUE;
|
|
||||||
|
|
||||||
pidl = (LPITEMIDLIST)((LPBYTE)pShared + pShared->ibPidl);
|
|
||||||
if (pidl->mkid.cb == 0 && pShared->fRecursive)
|
|
||||||
return TRUE;
|
|
||||||
|
|
||||||
if (pTicket->ibOffset1)
|
|
||||||
{
|
|
||||||
pidl1 = (LPITEMIDLIST)((LPBYTE)pTicket + pTicket->ibOffset1);
|
|
||||||
if (ILIsEqual(pidl, pidl1) || ILIsParent(pidl, pidl1, !pShared->fRecursive))
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pTicket->ibOffset2)
|
|
||||||
{
|
|
||||||
pidl2 = (LPITEMIDLIST)((LPBYTE)pTicket + pTicket->ibOffset2);
|
|
||||||
if (ILIsEqual(pidl, pidl2) || ILIsParent(pidl, pidl2, !pShared->fRecursive))
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (SHGetPathFromIDListW(pidl, szPath))
|
|
||||||
{
|
|
||||||
PathAddBackslashW(szPath);
|
|
||||||
cch = lstrlenW(szPath);
|
|
||||||
|
|
||||||
if (pidl1 && SHGetPathFromIDListW(pidl1, szPath1))
|
|
||||||
{
|
|
||||||
PathAddBackslashW(szPath1);
|
|
||||||
cch1 = lstrlenW(szPath1);
|
|
||||||
if (cch < cch1 &&
|
|
||||||
(pShared->fRecursive ||
|
|
||||||
wcschr(&szPath1[cch], L'\\') == &szPath1[cch1 - 1]))
|
|
||||||
{
|
|
||||||
szPath1[cch] = 0;
|
|
||||||
if (lstrcmpiW(szPath, szPath1) == 0)
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pidl2 && SHGetPathFromIDListW(pidl2, szPath2))
|
|
||||||
{
|
|
||||||
PathAddBackslashW(szPath2);
|
|
||||||
cch2 = lstrlenW(szPath2);
|
|
||||||
if (cch < cch2 &&
|
|
||||||
(pShared->fRecursive ||
|
|
||||||
wcschr(&szPath2[cch], L'\\') == &szPath2[cch2 - 1]))
|
|
||||||
{
|
|
||||||
szPath2[cch] = 0;
|
|
||||||
if (lstrcmpiW(szPath, szPath2) == 0)
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
|
@ -1,151 +0,0 @@
|
||||||
/*
|
|
||||||
* PROJECT: shell32
|
|
||||||
* LICENSE: LGPL-2.1-or-later (https://spdx.org/licenses/LGPL-2.1-or-later)
|
|
||||||
* PURPOSE: Shell change notification
|
|
||||||
* COPYRIGHT: Copyright 2020 Katayama Hirofumi MZ (katayama.hirofumi.mz@gmail.com)
|
|
||||||
*/
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#define INVALID_REG_ID 0
|
|
||||||
|
|
||||||
#define WM_GETDELIWORKERWND (WM_USER + 25) /* 0x419 */
|
|
||||||
#define WM_OLDDELI_HANDOVER (WM_USER + 1) /* 0x401 */
|
|
||||||
#define WM_NOTIF_REG (WM_USER + 1) /* 0x401 */
|
|
||||||
#define WM_NOTIF_UNREG (WM_USER + 2) /* 0x402 */
|
|
||||||
#define WM_NOTIF_DELIVERY (WM_USER + 3) /* 0x403 */
|
|
||||||
#define WM_NOTIF_SUSPEND (WM_USER + 6) /* 0x406 */
|
|
||||||
#define WM_NOTIF_REMOVEBYPID (WM_USER + 7) /* 0x407 */
|
|
||||||
|
|
||||||
#define DWORD_ALIGNMENT(offset) \
|
|
||||||
((((offset) + sizeof(DWORD) - 1) / sizeof(DWORD)) * sizeof(DWORD))
|
|
||||||
|
|
||||||
typedef struct OLDDELIVERYWORKER
|
|
||||||
{
|
|
||||||
HWND hwnd;
|
|
||||||
UINT uMsg;
|
|
||||||
} OLDDELIVERYWORKER, *LPOLDDELIVERYWORKER;
|
|
||||||
|
|
||||||
typedef struct DELITICKET
|
|
||||||
{
|
|
||||||
DWORD dwMagic;
|
|
||||||
LONG wEventId;
|
|
||||||
UINT uFlags;
|
|
||||||
DWORD dwTick;
|
|
||||||
DWORD ibOffset1; /* offset to pidl1 */
|
|
||||||
DWORD ibOffset2; /* offset to pidl2 */
|
|
||||||
} DELITICKET, *LPDELITICKET;
|
|
||||||
|
|
||||||
typedef struct NOTIFSHARE
|
|
||||||
{
|
|
||||||
DWORD dwMagic;
|
|
||||||
DWORD cbSize;
|
|
||||||
UINT nRegID;
|
|
||||||
HWND hwnd;
|
|
||||||
HWND hwndOldWorker;
|
|
||||||
UINT uMsg;
|
|
||||||
INT fSources;
|
|
||||||
LONG fEvents;
|
|
||||||
BOOL fRecursive;
|
|
||||||
UINT ibPidl;
|
|
||||||
} NOTIFSHARE, *LPNOTIFSHARE;
|
|
||||||
|
|
||||||
typedef struct HANDBAG
|
|
||||||
{
|
|
||||||
DWORD dwMagic;
|
|
||||||
LPITEMIDLIST pidls[2];
|
|
||||||
LPDELITICKET pTicket;
|
|
||||||
} HANDBAG, *LPHANDBAG;
|
|
||||||
|
|
||||||
#define DELITICKET_MAGIC 0xDEADFACE
|
|
||||||
#define NOTIFSHARE_MAGIC 0xB0B32D1E
|
|
||||||
#define HANDBAG_MAGIC 0xFACEB00C
|
|
||||||
|
|
||||||
EXTERN_C HWND DoGetNewDeliveryWorker(void);
|
|
||||||
EXTERN_C void DoNotifyFreeSpace(LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2);
|
|
||||||
EXTERN_C HWND DoHireOldDeliveryWorker(HWND hwnd, UINT wMsg);
|
|
||||||
EXTERN_C LPHANDBAG DoGetHandbagFromTicket(HANDLE hTicket, DWORD dwOwnerPID);
|
|
||||||
|
|
||||||
EXTERN_C HANDLE
|
|
||||||
DoCreateNotifShare(ULONG nRegID, HWND hwnd, UINT wMsg, INT fSources,
|
|
||||||
LONG fEvents, LONG fRecursive, LPCITEMIDLIST pidl,
|
|
||||||
DWORD dwOwnerPID, HWND hwndOldWorker);
|
|
||||||
|
|
||||||
EXTERN_C HANDLE
|
|
||||||
DoCreateDeliTicket(LONG wEventId, UINT uFlags, LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2,
|
|
||||||
DWORD dwOwnerPID, DWORD dwTick);
|
|
||||||
|
|
||||||
EXTERN_C void
|
|
||||||
DoTransportChange(LONG wEventId, UINT uFlags, LPITEMIDLIST pidl1, LPITEMIDLIST pidl2,
|
|
||||||
DWORD dwTick);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
class CWorker : public CMessageMap
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
CWorker() : m_hWnd(NULL)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual ~CWorker()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
static LRESULT CALLBACK
|
|
||||||
WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
|
|
||||||
|
|
||||||
BOOL CreateWorker(HWND hwndParent, DWORD dwExStyle, DWORD dwStyle);
|
|
||||||
|
|
||||||
protected:
|
|
||||||
HWND m_hWnd;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct CChangeNotifyImpl;
|
|
||||||
|
|
||||||
class CChangeNotify : public CWorker
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
struct ITEM
|
|
||||||
{
|
|
||||||
UINT nRegID;
|
|
||||||
DWORD dwUserPID;
|
|
||||||
HANDLE hShare;
|
|
||||||
HWND hwndOldWorker;
|
|
||||||
};
|
|
||||||
|
|
||||||
CChangeNotify();
|
|
||||||
virtual ~CChangeNotify();
|
|
||||||
|
|
||||||
operator HWND()
|
|
||||||
{
|
|
||||||
return m_hWnd;
|
|
||||||
}
|
|
||||||
|
|
||||||
BOOL AddItem(UINT nRegID, DWORD dwUserPID, HANDLE hShare, HWND hwndOldWorker);
|
|
||||||
BOOL RemoveItem(UINT nRegID, DWORD dwOwnerPID);
|
|
||||||
void RemoveItemsByProcess(DWORD dwOwnerPID, DWORD dwUserPID);
|
|
||||||
|
|
||||||
UINT GetNextRegID();
|
|
||||||
BOOL DoDelivery(HANDLE hTicket, DWORD dwOwnerPID);
|
|
||||||
|
|
||||||
BOOL ShouldNotify(LPDELITICKET pTicket, LPNOTIFSHARE pShared);
|
|
||||||
BOOL DoNotify(LPHANDBAG pHandbag, LPDELITICKET pTicket, LPNOTIFSHARE pShared);
|
|
||||||
|
|
||||||
LRESULT OnReg(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
|
|
||||||
LRESULT OnUnReg(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
|
|
||||||
LRESULT OnDelivery(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
|
|
||||||
LRESULT OnSuspendResume(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
|
|
||||||
LRESULT OnRemoveByPID(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
|
|
||||||
|
|
||||||
BEGIN_MSG_MAP(CChangeNotify)
|
|
||||||
MESSAGE_HANDLER(WM_NOTIF_REG, OnReg)
|
|
||||||
MESSAGE_HANDLER(WM_NOTIF_UNREG, OnUnReg)
|
|
||||||
MESSAGE_HANDLER(WM_NOTIF_DELIVERY, OnDelivery)
|
|
||||||
MESSAGE_HANDLER(WM_NOTIF_SUSPEND, OnSuspendResume)
|
|
||||||
MESSAGE_HANDLER(WM_NOTIF_REMOVEBYPID, OnRemoveByPID);
|
|
||||||
END_MSG_MAP()
|
|
||||||
|
|
||||||
protected:
|
|
||||||
UINT m_nNextRegID;
|
|
||||||
CChangeNotifyImpl *m_pimpl;
|
|
||||||
};
|
|
||||||
#endif
|
|
444
dll/win32/shell32/shelldesktop/CChangeNotifyServer.cpp
Normal file
444
dll/win32/shell32/shelldesktop/CChangeNotifyServer.cpp
Normal file
|
@ -0,0 +1,444 @@
|
||||||
|
/*
|
||||||
|
* PROJECT: shell32
|
||||||
|
* LICENSE: LGPL-2.1-or-later (https://spdx.org/licenses/LGPL-2.1-or-later)
|
||||||
|
* PURPOSE: Shell change notification
|
||||||
|
* COPYRIGHT: Copyright 2020 Katayama Hirofumi MZ (katayama.hirofumi.mz@gmail.com)
|
||||||
|
*/
|
||||||
|
#include "shelldesktop.h"
|
||||||
|
#include "shlwapi_undoc.h"
|
||||||
|
#include <atlsimpcoll.h>
|
||||||
|
#include <assert.h>
|
||||||
|
|
||||||
|
WINE_DEFAULT_DEBUG_CHANNEL(shcn);
|
||||||
|
|
||||||
|
// notification target item
|
||||||
|
struct ITEM
|
||||||
|
{
|
||||||
|
UINT nRegID; // The registration ID.
|
||||||
|
DWORD dwUserPID; // The user PID; that is the process ID of the target window.
|
||||||
|
HANDLE hRegEntry; // The registration entry.
|
||||||
|
HWND hwndBroker; // Client broker window (if any).
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef CWinTraits <
|
||||||
|
WS_POPUP | WS_CLIPSIBLINGS | WS_CLIPCHILDREN,
|
||||||
|
WS_EX_TOOLWINDOW
|
||||||
|
> CChangeNotifyServerTraits;
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
// CChangeNotifyServer
|
||||||
|
//
|
||||||
|
// CChangeNotifyServer implements a window that handles all shell change notifications.
|
||||||
|
// It runs in the context of explorer and specifically in the thread of the shell desktop.
|
||||||
|
// Shell change notification api exported from shell32 forwards all their calls
|
||||||
|
// to this window where all processing takes place.
|
||||||
|
|
||||||
|
class CChangeNotifyServer :
|
||||||
|
public CWindowImpl<CChangeNotifyServer, CWindow, CChangeNotifyServerTraits>,
|
||||||
|
public CComObjectRootEx<CComMultiThreadModelNoCS>,
|
||||||
|
public IOleWindow
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
CChangeNotifyServer();
|
||||||
|
virtual ~CChangeNotifyServer();
|
||||||
|
HRESULT Initialize();
|
||||||
|
|
||||||
|
// *** IOleWindow methods ***
|
||||||
|
virtual HRESULT STDMETHODCALLTYPE GetWindow(HWND *lphwnd);
|
||||||
|
virtual HRESULT STDMETHODCALLTYPE ContextSensitiveHelp(BOOL fEnterMode);
|
||||||
|
|
||||||
|
// Message handlers
|
||||||
|
LRESULT OnRegister(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
|
||||||
|
LRESULT OnUnRegister(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
|
||||||
|
LRESULT OnDeliverNotification(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
|
||||||
|
LRESULT OnSuspendResume(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
|
||||||
|
LRESULT OnRemoveByPID(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
|
||||||
|
|
||||||
|
DECLARE_NOT_AGGREGATABLE(CChangeNotifyServer)
|
||||||
|
|
||||||
|
DECLARE_PROTECT_FINAL_CONSTRUCT()
|
||||||
|
BEGIN_COM_MAP(CChangeNotifyServer)
|
||||||
|
COM_INTERFACE_ENTRY_IID(IID_IOleWindow, IOleWindow)
|
||||||
|
END_COM_MAP()
|
||||||
|
|
||||||
|
DECLARE_WND_CLASS_EX(L"WorkerW", 0, 0)
|
||||||
|
|
||||||
|
BEGIN_MSG_MAP(CChangeNotifyServer)
|
||||||
|
MESSAGE_HANDLER(CN_REGISTER, OnRegister)
|
||||||
|
MESSAGE_HANDLER(CN_UNREGISTER, OnUnRegister)
|
||||||
|
MESSAGE_HANDLER(CN_DELIVER_NOTIFICATION, OnDeliverNotification)
|
||||||
|
MESSAGE_HANDLER(CN_SUSPEND_RESUME, OnSuspendResume)
|
||||||
|
MESSAGE_HANDLER(CN_UNREGISTER_PROCESS, OnRemoveByPID);
|
||||||
|
END_MSG_MAP()
|
||||||
|
|
||||||
|
private:
|
||||||
|
UINT m_nNextRegID;
|
||||||
|
CSimpleArray<ITEM> m_items;
|
||||||
|
|
||||||
|
BOOL AddItem(UINT nRegID, DWORD dwUserPID, HANDLE hRegEntry, HWND hwndBroker);
|
||||||
|
BOOL RemoveItemsByRegID(UINT nRegID, DWORD dwOwnerPID);
|
||||||
|
void RemoveItemsByProcess(DWORD dwOwnerPID, DWORD dwUserPID);
|
||||||
|
void DestroyItem(ITEM& item, DWORD dwOwnerPID, HWND *phwndBroker);
|
||||||
|
|
||||||
|
UINT GetNextRegID();
|
||||||
|
BOOL DeliverNotification(HANDLE hTicket, DWORD dwOwnerPID);
|
||||||
|
BOOL ShouldNotify(LPDELITICKET pTicket, LPREGENTRY pRegEntry);
|
||||||
|
};
|
||||||
|
|
||||||
|
CChangeNotifyServer::CChangeNotifyServer()
|
||||||
|
: m_nNextRegID(INVALID_REG_ID)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
CChangeNotifyServer::~CChangeNotifyServer()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOL CChangeNotifyServer::AddItem(UINT nRegID, DWORD dwUserPID, HANDLE hRegEntry, HWND hwndBroker)
|
||||||
|
{
|
||||||
|
// find the empty room
|
||||||
|
for (INT i = 0; i < m_items.GetSize(); ++i)
|
||||||
|
{
|
||||||
|
if (m_items[i].nRegID == INVALID_REG_ID)
|
||||||
|
{
|
||||||
|
// found the room, populate it
|
||||||
|
m_items[i].nRegID = nRegID;
|
||||||
|
m_items[i].dwUserPID = dwUserPID;
|
||||||
|
m_items[i].hRegEntry = hRegEntry;
|
||||||
|
m_items[i].hwndBroker = hwndBroker;
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// no empty room found
|
||||||
|
ITEM item = { nRegID, dwUserPID, hRegEntry, hwndBroker };
|
||||||
|
m_items.Add(item);
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CChangeNotifyServer::DestroyItem(ITEM& item, DWORD dwOwnerPID, HWND *phwndBroker)
|
||||||
|
{
|
||||||
|
// destroy broker if any and if first time
|
||||||
|
if (item.hwndBroker && item.hwndBroker != *phwndBroker)
|
||||||
|
{
|
||||||
|
::DestroyWindow(item.hwndBroker);
|
||||||
|
*phwndBroker = item.hwndBroker;
|
||||||
|
}
|
||||||
|
|
||||||
|
// free
|
||||||
|
SHFreeShared(item.hRegEntry, dwOwnerPID);
|
||||||
|
item.nRegID = INVALID_REG_ID;
|
||||||
|
item.dwUserPID = 0;
|
||||||
|
item.hRegEntry = NULL;
|
||||||
|
item.hwndBroker = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOL CChangeNotifyServer::RemoveItemsByRegID(UINT nRegID, DWORD dwOwnerPID)
|
||||||
|
{
|
||||||
|
BOOL bFound = FALSE;
|
||||||
|
HWND hwndBroker = NULL;
|
||||||
|
assert(nRegID != INVALID_REG_ID);
|
||||||
|
for (INT i = 0; i < m_items.GetSize(); ++i)
|
||||||
|
{
|
||||||
|
if (m_items[i].nRegID == nRegID)
|
||||||
|
{
|
||||||
|
bFound = TRUE;
|
||||||
|
DestroyItem(m_items[i], dwOwnerPID, &hwndBroker);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return bFound;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CChangeNotifyServer::RemoveItemsByProcess(DWORD dwOwnerPID, DWORD dwUserPID)
|
||||||
|
{
|
||||||
|
HWND hwndBroker = NULL;
|
||||||
|
assert(dwUserPID != 0);
|
||||||
|
for (INT i = 0; i < m_items.GetSize(); ++i)
|
||||||
|
{
|
||||||
|
if (m_items[i].dwUserPID == dwUserPID)
|
||||||
|
{
|
||||||
|
DestroyItem(m_items[i], dwOwnerPID, &hwndBroker);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Message CN_REGISTER: Register the registration entry.
|
||||||
|
// wParam: The handle of registration entry.
|
||||||
|
// lParam: The owner PID of registration entry.
|
||||||
|
// return: TRUE if successful.
|
||||||
|
LRESULT CChangeNotifyServer::OnRegister(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
|
||||||
|
{
|
||||||
|
TRACE("OnRegister(%p, %u, %p, %p)\n", m_hWnd, uMsg, wParam, lParam);
|
||||||
|
|
||||||
|
// lock the registration entry
|
||||||
|
HANDLE hRegEntry = (HANDLE)wParam;
|
||||||
|
DWORD dwOwnerPID = (DWORD)lParam;
|
||||||
|
LPREGENTRY pRegEntry = (LPREGENTRY)SHLockSharedEx(hRegEntry, dwOwnerPID, TRUE);
|
||||||
|
if (pRegEntry == NULL || pRegEntry->dwMagic != REGENTRY_MAGIC)
|
||||||
|
{
|
||||||
|
ERR("pRegEntry is invalid\n");
|
||||||
|
SHUnlockShared(pRegEntry);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
// update registration ID if necessary
|
||||||
|
if (pRegEntry->nRegID == INVALID_REG_ID)
|
||||||
|
pRegEntry->nRegID = GetNextRegID();
|
||||||
|
|
||||||
|
TRACE("pRegEntry->nRegID: %u\n", pRegEntry->nRegID);
|
||||||
|
|
||||||
|
// get the user PID; that is the process ID of the target window
|
||||||
|
DWORD dwUserPID;
|
||||||
|
GetWindowThreadProcessId(pRegEntry->hwnd, &dwUserPID);
|
||||||
|
|
||||||
|
// get broker if any
|
||||||
|
HWND hwndBroker = pRegEntry->hwndBroker;
|
||||||
|
|
||||||
|
// clone the registration entry
|
||||||
|
HANDLE hNewEntry = SHAllocShared(pRegEntry, pRegEntry->cbSize, dwOwnerPID);
|
||||||
|
if (hNewEntry == NULL)
|
||||||
|
{
|
||||||
|
ERR("Out of memory\n");
|
||||||
|
pRegEntry->nRegID = INVALID_REG_ID;
|
||||||
|
SHUnlockShared(pRegEntry);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
// unlock the registry entry
|
||||||
|
SHUnlockShared(pRegEntry);
|
||||||
|
|
||||||
|
// add an ITEM
|
||||||
|
return AddItem(m_nNextRegID, dwUserPID, hNewEntry, hwndBroker);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Message CN_UNREGISTER: Unregister registration entries.
|
||||||
|
// wParam: The registration ID.
|
||||||
|
// lParam: Ignored.
|
||||||
|
// return: TRUE if successful.
|
||||||
|
LRESULT CChangeNotifyServer::OnUnRegister(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
|
||||||
|
{
|
||||||
|
TRACE("OnUnRegister(%p, %u, %p, %p)\n", m_hWnd, uMsg, wParam, lParam);
|
||||||
|
|
||||||
|
// validate registration ID
|
||||||
|
UINT nRegID = (UINT)wParam;
|
||||||
|
if (nRegID == INVALID_REG_ID)
|
||||||
|
{
|
||||||
|
ERR("INVALID_REG_ID\n");
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
// remove it
|
||||||
|
DWORD dwOwnerPID;
|
||||||
|
GetWindowThreadProcessId(m_hWnd, &dwOwnerPID);
|
||||||
|
return RemoveItemsByRegID(nRegID, dwOwnerPID);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Message CN_DELIVER_NOTIFICATION: Perform a delivery.
|
||||||
|
// wParam: The handle of delivery ticket.
|
||||||
|
// lParam: The owner PID of delivery ticket.
|
||||||
|
// return: TRUE if necessary.
|
||||||
|
LRESULT CChangeNotifyServer::OnDeliverNotification(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
|
||||||
|
{
|
||||||
|
TRACE("OnDeliverNotification(%p, %u, %p, %p)\n", m_hWnd, uMsg, wParam, lParam);
|
||||||
|
|
||||||
|
HANDLE hTicket = (HANDLE)wParam;
|
||||||
|
DWORD dwOwnerPID = (DWORD)lParam;
|
||||||
|
|
||||||
|
// do delivery
|
||||||
|
BOOL ret = DeliverNotification(hTicket, dwOwnerPID);
|
||||||
|
|
||||||
|
// free the ticket
|
||||||
|
SHFreeShared(hTicket, dwOwnerPID);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Message CN_SUSPEND_RESUME: Suspend or resume the change notification.
|
||||||
|
// (specification is unknown)
|
||||||
|
LRESULT CChangeNotifyServer::OnSuspendResume(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
|
||||||
|
{
|
||||||
|
TRACE("OnSuspendResume\n");
|
||||||
|
|
||||||
|
// FIXME
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Message CN_UNREGISTER_PROCESS: Remove registration entries by PID.
|
||||||
|
// wParam: The user PID.
|
||||||
|
// lParam: Ignored.
|
||||||
|
// return: Zero.
|
||||||
|
LRESULT CChangeNotifyServer::OnRemoveByPID(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
|
||||||
|
{
|
||||||
|
DWORD dwOwnerPID, dwUserPID = (DWORD)wParam;
|
||||||
|
GetWindowThreadProcessId(m_hWnd, &dwOwnerPID);
|
||||||
|
RemoveItemsByProcess(dwOwnerPID, dwUserPID);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// get next valid registration ID
|
||||||
|
UINT CChangeNotifyServer::GetNextRegID()
|
||||||
|
{
|
||||||
|
m_nNextRegID++;
|
||||||
|
if (m_nNextRegID == INVALID_REG_ID)
|
||||||
|
m_nNextRegID++;
|
||||||
|
return m_nNextRegID;
|
||||||
|
}
|
||||||
|
|
||||||
|
// This function is called from CChangeNotifyServer::OnDeliverNotification.
|
||||||
|
// The function notifies to the registration entries that should be notified.
|
||||||
|
BOOL CChangeNotifyServer::DeliverNotification(HANDLE hTicket, DWORD dwOwnerPID)
|
||||||
|
{
|
||||||
|
TRACE("DeliverNotification(%p, %p, 0x%lx)\n", m_hWnd, hTicket, dwOwnerPID);
|
||||||
|
|
||||||
|
// lock the delivery ticket
|
||||||
|
LPDELITICKET pTicket = (LPDELITICKET)SHLockSharedEx(hTicket, dwOwnerPID, FALSE);
|
||||||
|
if (pTicket == NULL || pTicket->dwMagic != DELITICKET_MAGIC)
|
||||||
|
{
|
||||||
|
ERR("pTicket is invalid\n");
|
||||||
|
SHUnlockShared(pTicket);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
// for all items
|
||||||
|
for (INT i = 0; i < m_items.GetSize(); ++i)
|
||||||
|
{
|
||||||
|
// validate the item
|
||||||
|
if (m_items[i].nRegID == INVALID_REG_ID)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
HANDLE hRegEntry = m_items[i].hRegEntry;
|
||||||
|
if (hRegEntry == NULL)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
// lock the registration entry
|
||||||
|
LPREGENTRY pRegEntry = (LPREGENTRY)SHLockSharedEx(hRegEntry, dwOwnerPID, FALSE);
|
||||||
|
if (pRegEntry == NULL || pRegEntry->dwMagic != REGENTRY_MAGIC)
|
||||||
|
{
|
||||||
|
ERR("pRegEntry is invalid\n");
|
||||||
|
SHUnlockShared(pRegEntry);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// should we notify for it?
|
||||||
|
BOOL bNotify = ShouldNotify(pTicket, pRegEntry);
|
||||||
|
if (bNotify)
|
||||||
|
{
|
||||||
|
// do notify
|
||||||
|
TRACE("Notifying: %p, 0x%x, %p, %lu\n",
|
||||||
|
pRegEntry->hwnd, pRegEntry->uMsg, hTicket, dwOwnerPID);
|
||||||
|
SendMessageW(pRegEntry->hwnd, pRegEntry->uMsg, (WPARAM)hTicket, dwOwnerPID);
|
||||||
|
}
|
||||||
|
|
||||||
|
// unlock the registration entry
|
||||||
|
SHUnlockShared(pRegEntry);
|
||||||
|
}
|
||||||
|
|
||||||
|
// unlock the ticket
|
||||||
|
SHUnlockShared(pTicket);
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOL CChangeNotifyServer::ShouldNotify(LPDELITICKET pTicket, LPREGENTRY pRegEntry)
|
||||||
|
{
|
||||||
|
LPITEMIDLIST pidl, pidl1 = NULL, pidl2 = NULL;
|
||||||
|
WCHAR szPath[MAX_PATH], szPath1[MAX_PATH], szPath2[MAX_PATH];
|
||||||
|
INT cch, cch1, cch2;
|
||||||
|
|
||||||
|
if (pRegEntry->ibPidl == 0)
|
||||||
|
return TRUE;
|
||||||
|
|
||||||
|
// get the stored pidl
|
||||||
|
pidl = (LPITEMIDLIST)((LPBYTE)pRegEntry + pRegEntry->ibPidl);
|
||||||
|
if (pidl->mkid.cb == 0 && pRegEntry->fRecursive)
|
||||||
|
return TRUE; // desktop is the root
|
||||||
|
|
||||||
|
// check pidl1
|
||||||
|
if (pTicket->ibOffset1)
|
||||||
|
{
|
||||||
|
pidl1 = (LPITEMIDLIST)((LPBYTE)pTicket + pTicket->ibOffset1);
|
||||||
|
if (ILIsEqual(pidl, pidl1) || ILIsParent(pidl, pidl1, !pRegEntry->fRecursive))
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
// check pidl2
|
||||||
|
if (pTicket->ibOffset2)
|
||||||
|
{
|
||||||
|
pidl2 = (LPITEMIDLIST)((LPBYTE)pTicket + pTicket->ibOffset2);
|
||||||
|
if (ILIsEqual(pidl, pidl2) || ILIsParent(pidl, pidl2, !pRegEntry->fRecursive))
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
// The paths:
|
||||||
|
// "C:\\Path\\To\\File1"
|
||||||
|
// "C:\\Path\\To\\File1Test"
|
||||||
|
// should be distinguished in comparison, so we add backslash at last as follows:
|
||||||
|
// "C:\\Path\\To\\File1\\"
|
||||||
|
// "C:\\Path\\To\\File1Test\\"
|
||||||
|
if (SHGetPathFromIDListW(pidl, szPath))
|
||||||
|
{
|
||||||
|
PathAddBackslashW(szPath);
|
||||||
|
cch = lstrlenW(szPath);
|
||||||
|
|
||||||
|
if (pidl1 && SHGetPathFromIDListW(pidl1, szPath1))
|
||||||
|
{
|
||||||
|
PathAddBackslashW(szPath1);
|
||||||
|
cch1 = lstrlenW(szPath1);
|
||||||
|
|
||||||
|
// Is szPath1 a subfile or subdirectory of szPath?
|
||||||
|
if (cch < cch1 &&
|
||||||
|
(pRegEntry->fRecursive ||
|
||||||
|
wcschr(&szPath1[cch], L'\\') == &szPath1[cch1 - 1]))
|
||||||
|
{
|
||||||
|
szPath1[cch] = 0;
|
||||||
|
if (lstrcmpiW(szPath, szPath1) == 0)
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pidl2 && SHGetPathFromIDListW(pidl2, szPath2))
|
||||||
|
{
|
||||||
|
PathAddBackslashW(szPath2);
|
||||||
|
cch2 = lstrlenW(szPath2);
|
||||||
|
|
||||||
|
// Is szPath2 a subfile or subdirectory of szPath?
|
||||||
|
if (cch < cch2 &&
|
||||||
|
(pRegEntry->fRecursive ||
|
||||||
|
wcschr(&szPath2[cch], L'\\') == &szPath2[cch2 - 1]))
|
||||||
|
{
|
||||||
|
szPath2[cch] = 0;
|
||||||
|
if (lstrcmpiW(szPath, szPath2) == 0)
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
HRESULT WINAPI CChangeNotifyServer::GetWindow(HWND* phwnd)
|
||||||
|
{
|
||||||
|
if (!phwnd)
|
||||||
|
return E_INVALIDARG;
|
||||||
|
*phwnd = m_hWnd;
|
||||||
|
return S_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
HRESULT WINAPI CChangeNotifyServer::ContextSensitiveHelp(BOOL fEnterMode)
|
||||||
|
{
|
||||||
|
return E_NOTIMPL;
|
||||||
|
}
|
||||||
|
|
||||||
|
HRESULT CChangeNotifyServer::Initialize()
|
||||||
|
{
|
||||||
|
// This is called by CChangeNotifyServer_CreateInstance right after instantiation.
|
||||||
|
// Create the window of the server here.
|
||||||
|
Create(0);
|
||||||
|
if (!m_hWnd)
|
||||||
|
return E_FAIL;
|
||||||
|
return S_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
HRESULT CChangeNotifyServer_CreateInstance(REFIID riid, void **ppv)
|
||||||
|
{
|
||||||
|
return ShellObjectCreatorInit<CChangeNotifyServer>(riid, ppv);
|
||||||
|
}
|
91
dll/win32/shell32/shelldesktop/CChangeNotifyServer.h
Normal file
91
dll/win32/shell32/shelldesktop/CChangeNotifyServer.h
Normal file
|
@ -0,0 +1,91 @@
|
||||||
|
/*
|
||||||
|
* PROJECT: shell32
|
||||||
|
* LICENSE: LGPL-2.1-or-later (https://spdx.org/licenses/LGPL-2.1-or-later)
|
||||||
|
* PURPOSE: Shell change notification
|
||||||
|
* COPYRIGHT: Copyright 2020 Katayama Hirofumi MZ (katayama.hirofumi.mz@gmail.com)
|
||||||
|
*/
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
// CChangeNotifyServer is a delivery worker window that is managed by CDesktopBrowser.
|
||||||
|
// The process of CChangeNotifyServer is same as the process of CDesktopBrowser.
|
||||||
|
// The caller process of SHChangeNotify function might be different from the
|
||||||
|
// process of CChangeNotifyServer.
|
||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
// The shared memory block can be allocated by shlwapi!SHAllocShared function.
|
||||||
|
//
|
||||||
|
// HANDLE SHAllocShared(LPCVOID lpData, DWORD dwSize, DWORD dwProcessId);
|
||||||
|
// LPVOID SHLockShared(HANDLE hData, DWORD dwProcessId);
|
||||||
|
// LPVOID SHLockSharedEx(HANDLE hData, DWORD dwProcessId, BOOL bWriteAccess);
|
||||||
|
// BOOL SHUnlockShared(LPVOID lpData);
|
||||||
|
// BOOL SHFreeShared(HANDLE hData, DWORD dwProcessId);
|
||||||
|
//
|
||||||
|
// The shared memory block is managed by the pair of a HANDLE value and an owner PID.
|
||||||
|
// If the pair is known, it can be accessed by SHLockShared(Ex) function
|
||||||
|
// from another process.
|
||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#define INVALID_REG_ID 0 /* invalid registration ID */
|
||||||
|
|
||||||
|
// This message is handled by CDesktopBrowser and returns
|
||||||
|
// the window of CChangeNotifyServer which responds to the CN_* messages
|
||||||
|
#define WM_DESKTOP_GET_CNOTIFY_SERVER (WM_USER + 25) /* 0x419 */
|
||||||
|
|
||||||
|
// The following messages are implemented by CChangeNotifyServer
|
||||||
|
// CChangeNotifyServer lives in the context of explorer and delivers notifications
|
||||||
|
// across all processes that register themselves with the SHChangeNotifyRegister api
|
||||||
|
#define CN_REGISTER (WM_USER + 1) /* 0x401 */
|
||||||
|
#define CN_UNREGISTER (WM_USER + 2) /* 0x402 */
|
||||||
|
#define CN_DELIVER_NOTIFICATION (WM_USER + 3) /* 0x403 */
|
||||||
|
#define CN_SUSPEND_RESUME (WM_USER + 6) /* 0x406 */
|
||||||
|
#define CN_UNREGISTER_PROCESS (WM_USER + 7) /* 0x407 */
|
||||||
|
|
||||||
|
// This message is implemented by the broker window which lives in the context of the client
|
||||||
|
#define WM_BROKER_NOTIFICATION (WM_USER + 1) /* 0x401 */
|
||||||
|
|
||||||
|
#define DWORD_ALIGNMENT(offset) \
|
||||||
|
((((offset) + sizeof(DWORD) - 1) / sizeof(DWORD)) * sizeof(DWORD))
|
||||||
|
|
||||||
|
/* delivery ticket */
|
||||||
|
typedef struct DELITICKET
|
||||||
|
{
|
||||||
|
DWORD dwMagic; /* same as DELITICKET_MAGIC */
|
||||||
|
LONG wEventId; /* event id of SHChangeNotify() */
|
||||||
|
UINT uFlags; /* flags of SHChangeNotify() */
|
||||||
|
DWORD dwTick; /* value of GetTickCount() */
|
||||||
|
DWORD ibOffset1; /* offset to pidl1 */
|
||||||
|
DWORD ibOffset2; /* offset to pidl2 */
|
||||||
|
/* followed by pidl1 and pidl2 */
|
||||||
|
} DELITICKET, *LPDELITICKET;
|
||||||
|
|
||||||
|
/* registration entry */
|
||||||
|
typedef struct REGENTRY
|
||||||
|
{
|
||||||
|
DWORD dwMagic; /* same as REGENTRY_MAGIC */
|
||||||
|
DWORD cbSize; /* the real size of this structure */
|
||||||
|
UINT nRegID; /* the registration ID */
|
||||||
|
HWND hwnd; /* the target window */
|
||||||
|
UINT uMsg; /* the message ID used in notification */
|
||||||
|
INT fSources; /* the source flags */
|
||||||
|
LONG fEvents; /* the event flags */
|
||||||
|
BOOL fRecursive; /* is it recursive? */
|
||||||
|
HWND hwndBroker; /* broker window (if any) */
|
||||||
|
UINT ibPidl; /* offset to the PIDL */
|
||||||
|
/* followed by a PIDL */
|
||||||
|
} REGENTRY, *LPREGENTRY;
|
||||||
|
|
||||||
|
/* handbag */
|
||||||
|
typedef struct HANDBAG
|
||||||
|
{
|
||||||
|
DWORD dwMagic; /* same as HANDBAG_MAGIC */
|
||||||
|
LPITEMIDLIST pidls[2]; /* two PIDLs */
|
||||||
|
LPDELITICKET pTicket; /* the ticket */
|
||||||
|
} HANDBAG, *LPHANDBAG;
|
||||||
|
|
||||||
|
#define DELITICKET_MAGIC 0xDEADFACE
|
||||||
|
#define REGENTRY_MAGIC 0xB0B32D1E
|
||||||
|
#define HANDBAG_MAGIC 0xFACEB00C
|
||||||
|
|
||||||
|
HRESULT CChangeNotifyServer_CreateInstance(REFIID riid, void **ppv);
|
|
@ -40,10 +40,12 @@ class CDesktopBrowser :
|
||||||
private:
|
private:
|
||||||
HACCEL m_hAccel;
|
HACCEL m_hAccel;
|
||||||
HWND m_hWndShellView;
|
HWND m_hWndShellView;
|
||||||
CChangeNotify m_hwndDeliWorker;
|
|
||||||
CComPtr<IShellDesktopTray> m_Tray;
|
CComPtr<IShellDesktopTray> m_Tray;
|
||||||
CComPtr<IShellView> m_ShellView;
|
CComPtr<IShellView> m_ShellView;
|
||||||
|
|
||||||
|
CComPtr<IOleWindow> m_ChangeNotifyServer;
|
||||||
|
HWND m_hwndChangeNotifyServer;
|
||||||
|
|
||||||
LRESULT _NotifyTray(UINT uMsg, WPARAM wParam, LPARAM lParam);
|
LRESULT _NotifyTray(UINT uMsg, WPARAM wParam, LPARAM lParam);
|
||||||
HRESULT _Resize();
|
HRESULT _Resize();
|
||||||
|
|
||||||
|
@ -82,7 +84,7 @@ public:
|
||||||
LRESULT OnOpenNewWindow(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled);
|
LRESULT OnOpenNewWindow(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled);
|
||||||
LRESULT OnCommand(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled);
|
LRESULT OnCommand(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled);
|
||||||
LRESULT OnSetFocus(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled);
|
LRESULT OnSetFocus(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled);
|
||||||
LRESULT OnGetDeliveryWorkerWnd(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled);
|
LRESULT OnGetChangeNotifyServer(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled);
|
||||||
|
|
||||||
DECLARE_WND_CLASS_EX(szProgmanClassName, CS_DBLCLKS, COLOR_DESKTOP)
|
DECLARE_WND_CLASS_EX(szProgmanClassName, CS_DBLCLKS, COLOR_DESKTOP)
|
||||||
|
|
||||||
|
@ -95,7 +97,7 @@ BEGIN_MSG_MAP(CBaseBar)
|
||||||
MESSAGE_HANDLER(WM_EXPLORER_OPEN_NEW_WINDOW, OnOpenNewWindow)
|
MESSAGE_HANDLER(WM_EXPLORER_OPEN_NEW_WINDOW, OnOpenNewWindow)
|
||||||
MESSAGE_HANDLER(WM_COMMAND, OnCommand)
|
MESSAGE_HANDLER(WM_COMMAND, OnCommand)
|
||||||
MESSAGE_HANDLER(WM_SETFOCUS, OnSetFocus)
|
MESSAGE_HANDLER(WM_SETFOCUS, OnSetFocus)
|
||||||
MESSAGE_HANDLER(WM_GETDELIWORKERWND, OnGetDeliveryWorkerWnd)
|
MESSAGE_HANDLER(WM_DESKTOP_GET_CNOTIFY_SERVER, OnGetChangeNotifyServer)
|
||||||
END_MSG_MAP()
|
END_MSG_MAP()
|
||||||
|
|
||||||
BEGIN_COM_MAP(CDesktopBrowser)
|
BEGIN_COM_MAP(CDesktopBrowser)
|
||||||
|
@ -107,7 +109,8 @@ END_COM_MAP()
|
||||||
|
|
||||||
CDesktopBrowser::CDesktopBrowser():
|
CDesktopBrowser::CDesktopBrowser():
|
||||||
m_hAccel(NULL),
|
m_hAccel(NULL),
|
||||||
m_hWndShellView(NULL)
|
m_hWndShellView(NULL),
|
||||||
|
m_hwndChangeNotifyServer(NULL)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -117,6 +120,11 @@ CDesktopBrowser::~CDesktopBrowser()
|
||||||
{
|
{
|
||||||
m_ShellView->DestroyViewWindow();
|
m_ShellView->DestroyViewWindow();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (m_hwndChangeNotifyServer)
|
||||||
|
{
|
||||||
|
::DestroyWindow(m_hwndChangeNotifyServer);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef MULTIMONITOR_SUPPORT
|
#ifdef MULTIMONITOR_SUPPORT
|
||||||
|
@ -430,15 +438,24 @@ LRESULT CDesktopBrowser::OnSetFocus(UINT uMsg, WPARAM wParam, LPARAM lParam, BOO
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
LRESULT CDesktopBrowser::OnGetDeliveryWorkerWnd(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
|
// Message WM_DESKTOP_GET_CNOTIFY_SERVER: Get or create the worker.
|
||||||
|
// wParam: BOOL bCreate; The flag whether it creates or not.
|
||||||
|
// lParam: Ignored.
|
||||||
|
// return: The window handle of the server window.
|
||||||
|
LRESULT CDesktopBrowser::OnGetChangeNotifyServer(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
|
||||||
{
|
{
|
||||||
if (!::IsWindow(m_hwndDeliWorker))
|
BOOL bCreate = (BOOL)wParam;
|
||||||
|
if (bCreate && !::IsWindow(m_hwndChangeNotifyServer))
|
||||||
{
|
{
|
||||||
DWORD exstyle = WS_EX_TOOLWINDOW;
|
HRESULT hres = CChangeNotifyServer_CreateInstance(IID_PPV_ARG(IOleWindow, &m_ChangeNotifyServer));
|
||||||
DWORD style = WS_POPUP | WS_CLIPSIBLINGS | WS_CLIPCHILDREN;
|
if (FAILED_UNEXPECTEDLY(hres))
|
||||||
m_hwndDeliWorker.CreateWorker(NULL, exstyle, style);
|
return NULL;
|
||||||
|
|
||||||
|
hres = m_ChangeNotifyServer->GetWindow(&m_hwndChangeNotifyServer);
|
||||||
|
if (FAILED_UNEXPECTEDLY(hres))
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
return (LRESULT)(HWND)m_hwndDeliWorker;
|
return (LRESULT)m_hwndChangeNotifyServer;
|
||||||
}
|
}
|
||||||
|
|
||||||
HRESULT CDesktopBrowser_CreateInstance(IShellDesktopTray *Tray, REFIID riid, void **ppv)
|
HRESULT CDesktopBrowser_CreateInstance(IShellDesktopTray *Tray, REFIID riid, void **ppv)
|
||||||
|
|
|
@ -10,7 +10,7 @@ add_definitions(
|
||||||
include_directories(${REACTOS_SOURCE_DIR}/sdk/lib/atl)
|
include_directories(${REACTOS_SOURCE_DIR}/sdk/lib/atl)
|
||||||
|
|
||||||
list(APPEND SOURCE
|
list(APPEND SOURCE
|
||||||
CChangeNotify.cpp
|
CChangeNotifyServer.cpp
|
||||||
CDesktopBrowser.cpp
|
CDesktopBrowser.cpp
|
||||||
dde.cpp)
|
dde.cpp)
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,7 @@
|
||||||
#include <undocuser.h>
|
#include <undocuser.h>
|
||||||
|
|
||||||
#include <shellutils.h>
|
#include <shellutils.h>
|
||||||
#include "CChangeNotify.h"
|
#include "CChangeNotifyServer.h"
|
||||||
#include "../shresdef.h"
|
#include "../shresdef.h"
|
||||||
|
|
||||||
#include <wine/debug.h>
|
#include <wine/debug.h>
|
||||||
|
|
|
@ -1,717 +0,0 @@
|
||||||
/*
|
|
||||||
* shell change notification
|
|
||||||
*
|
|
||||||
* Copyright 2000 Juergen Schmied
|
|
||||||
*
|
|
||||||
* 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 WIN32_NO_STATUS
|
|
||||||
#define _INC_WINDOWS
|
|
||||||
#define COBJMACROS
|
|
||||||
#define NONAMELESSUNION
|
|
||||||
#define NONAMELESSSTRUCT
|
|
||||||
#define BUFFER_SIZE 1024
|
|
||||||
|
|
||||||
#include <windef.h>
|
|
||||||
#include <winbase.h>
|
|
||||||
#include <shlobj.h>
|
|
||||||
#include <strsafe.h>
|
|
||||||
#include <undocshell.h>
|
|
||||||
#include <shlwapi.h>
|
|
||||||
#include <wine/debug.h>
|
|
||||||
#include <wine/list.h>
|
|
||||||
#include <process.h>
|
|
||||||
#include <shellutils.h>
|
|
||||||
|
|
||||||
#include "pidl.h"
|
|
||||||
|
|
||||||
WINE_DEFAULT_DEBUG_CHANNEL(shell);
|
|
||||||
#ifdef __REACTOS__
|
|
||||||
#include "../shelldesktop/CChangeNotify.h"
|
|
||||||
DWORD WINAPI SHAnsiToUnicode(LPCSTR lpSrcStr, LPWSTR lpDstStr, int iLen);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static CRITICAL_SECTION SHELL32_ChangenotifyCS;
|
|
||||||
static CRITICAL_SECTION_DEBUG critsect_debug =
|
|
||||||
{
|
|
||||||
0, 0, &SHELL32_ChangenotifyCS,
|
|
||||||
{ &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList },
|
|
||||||
0, 0, { (DWORD_PTR)(__FILE__ ": SHELL32_ChangenotifyCS") }
|
|
||||||
};
|
|
||||||
static CRITICAL_SECTION SHELL32_ChangenotifyCS = { &critsect_debug, -1, 0, 0, 0, 0 };
|
|
||||||
|
|
||||||
typedef SHChangeNotifyEntry *LPNOTIFYREGISTER;
|
|
||||||
|
|
||||||
/* internal list of notification clients (internal) */
|
|
||||||
typedef struct _NOTIFICATIONLIST
|
|
||||||
{
|
|
||||||
struct list entry;
|
|
||||||
HWND hwnd; /* window to notify */
|
|
||||||
DWORD uMsg; /* message to send */
|
|
||||||
LPNOTIFYREGISTER apidl; /* array of entries to watch*/
|
|
||||||
UINT cidl; /* number of pidls in array */
|
|
||||||
LONG wEventMask; /* subscribed events */
|
|
||||||
DWORD dwFlags; /* client flags */
|
|
||||||
ULONG id;
|
|
||||||
} NOTIFICATIONLIST, *LPNOTIFICATIONLIST;
|
|
||||||
|
|
||||||
#ifndef __REACTOS__
|
|
||||||
static struct list notifications = LIST_INIT( notifications );
|
|
||||||
static LONG next_id;
|
|
||||||
#endif /* ndef __REACTOS__ */
|
|
||||||
|
|
||||||
#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 | \
|
|
||||||
SHCNE_UPDATEITEM )
|
|
||||||
|
|
||||||
#define SHCNE_TWOITEMEVENTS ( \
|
|
||||||
SHCNE_RENAMEFOLDER | SHCNE_RENAMEITEM )
|
|
||||||
|
|
||||||
/* for dumping events */
|
|
||||||
static const char * DumpEvent( LONG event )
|
|
||||||
{
|
|
||||||
if( event == SHCNE_ALLEVENTS )
|
|
||||||
return "SHCNE_ALLEVENTS";
|
|
||||||
#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
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifndef __REACTOS__
|
|
||||||
static const char * NodeName(const NOTIFICATIONLIST *item)
|
|
||||||
{
|
|
||||||
const char *str;
|
|
||||||
WCHAR path[MAX_PATH];
|
|
||||||
|
|
||||||
if(SHGetPathFromIDListW(item->apidl[0].pidl, path ))
|
|
||||||
str = wine_dbg_sprintf("%s", debugstr_w(path));
|
|
||||||
else
|
|
||||||
str = wine_dbg_sprintf("<not a disk file>" );
|
|
||||||
return str;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void DeleteNode(LPNOTIFICATIONLIST item)
|
|
||||||
{
|
|
||||||
UINT i;
|
|
||||||
|
|
||||||
TRACE("item=%p\n", item);
|
|
||||||
|
|
||||||
/* remove item from list */
|
|
||||||
list_remove( &item->entry );
|
|
||||||
|
|
||||||
/* free the item */
|
|
||||||
for (i=0; i<item->cidl; i++)
|
|
||||||
SHFree((LPITEMIDLIST)item->apidl[i].pidl);
|
|
||||||
SHFree(item->apidl);
|
|
||||||
SHFree(item);
|
|
||||||
}
|
|
||||||
#endif /* ndef __REACTOS__ */
|
|
||||||
|
|
||||||
void InitChangeNotifications(void)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void FreeChangeNotifications(void)
|
|
||||||
{
|
|
||||||
#ifdef __REACTOS__
|
|
||||||
HWND hwndWorker;
|
|
||||||
hwndWorker = DoGetNewDeliveryWorker();
|
|
||||||
SendMessageW(hwndWorker, WM_NOTIF_REMOVEBYPID, GetCurrentProcessId(), 0);
|
|
||||||
DeleteCriticalSection(&SHELL32_ChangenotifyCS);
|
|
||||||
#else
|
|
||||||
LPNOTIFICATIONLIST ptr, next;
|
|
||||||
|
|
||||||
TRACE("\n");
|
|
||||||
|
|
||||||
EnterCriticalSection(&SHELL32_ChangenotifyCS);
|
|
||||||
|
|
||||||
LIST_FOR_EACH_ENTRY_SAFE( ptr, next, ¬ifications, NOTIFICATIONLIST, entry )
|
|
||||||
DeleteNode( ptr );
|
|
||||||
|
|
||||||
LeaveCriticalSection(&SHELL32_ChangenotifyCS);
|
|
||||||
|
|
||||||
DeleteCriticalSection(&SHELL32_ChangenotifyCS);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
/*************************************************************************
|
|
||||||
* SHChangeNotifyRegister [SHELL32.2]
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
ULONG WINAPI
|
|
||||||
SHChangeNotifyRegister(
|
|
||||||
HWND hwnd,
|
|
||||||
int fSources,
|
|
||||||
LONG wEventMask,
|
|
||||||
UINT uMsg,
|
|
||||||
int cItems,
|
|
||||||
SHChangeNotifyEntry *lpItems)
|
|
||||||
{
|
|
||||||
#ifdef __REACTOS__
|
|
||||||
HWND hwndNotif, hwndOldWorker = NULL;
|
|
||||||
HANDLE hShared;
|
|
||||||
INT iItem;
|
|
||||||
ULONG nRegID = INVALID_REG_ID;
|
|
||||||
DWORD dwOwnerPID;
|
|
||||||
LPNOTIFSHARE pShare;
|
|
||||||
|
|
||||||
TRACE("(%p,0x%08x,0x%08x,0x%08x,%d,%p)\n",
|
|
||||||
hwnd, fSources, wEventMask, uMsg, cItems, lpItems);
|
|
||||||
|
|
||||||
if (wEventMask == 0 || cItems <= 0 || cItems > 0x7FFF || lpItems == NULL ||
|
|
||||||
!hwnd || !IsWindow(hwnd))
|
|
||||||
{
|
|
||||||
return INVALID_REG_ID;
|
|
||||||
}
|
|
||||||
|
|
||||||
hwndNotif = DoGetNewDeliveryWorker();
|
|
||||||
if (hwndNotif == NULL)
|
|
||||||
return INVALID_REG_ID;
|
|
||||||
|
|
||||||
if ((fSources & SHCNRF_NewDelivery) == 0)
|
|
||||||
{
|
|
||||||
hwndOldWorker = hwnd = DoHireOldDeliveryWorker(hwnd, uMsg);
|
|
||||||
uMsg = WM_OLDDELI_HANDOVER;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((fSources & SHCNRF_RecursiveInterrupt) != 0 &&
|
|
||||||
(fSources & SHCNRF_InterruptLevel) == 0)
|
|
||||||
{
|
|
||||||
fSources &= ~SHCNRF_NewDelivery;
|
|
||||||
}
|
|
||||||
|
|
||||||
GetWindowThreadProcessId(hwndNotif, &dwOwnerPID);
|
|
||||||
|
|
||||||
EnterCriticalSection(&SHELL32_ChangenotifyCS);
|
|
||||||
for (iItem = 0; iItem < cItems; ++iItem)
|
|
||||||
{
|
|
||||||
hShared = DoCreateNotifShare(nRegID, hwnd, uMsg, fSources, wEventMask,
|
|
||||||
lpItems[iItem].fRecursive, lpItems[iItem].pidl,
|
|
||||||
dwOwnerPID, hwndOldWorker);
|
|
||||||
if (hShared)
|
|
||||||
{
|
|
||||||
TRACE("WM_NOTIF_REG: hwnd:%p, hShared:%p, pid:0x%lx\n", hwndNotif, hShared, dwOwnerPID);
|
|
||||||
SendMessageW(hwndNotif, WM_NOTIF_REG, (WPARAM)hShared, dwOwnerPID);
|
|
||||||
|
|
||||||
pShare = (LPNOTIFSHARE)SHLockSharedEx(hShared, dwOwnerPID, FALSE);
|
|
||||||
if (pShare)
|
|
||||||
{
|
|
||||||
nRegID = pShare->nRegID;
|
|
||||||
SHUnlockShared(pShare);
|
|
||||||
}
|
|
||||||
SHFreeShared(hShared, dwOwnerPID);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (nRegID == INVALID_REG_ID && (fSources & SHCNRF_NewDelivery) == 0)
|
|
||||||
{
|
|
||||||
ERR("Old Delivery is failed\n");
|
|
||||||
DestroyWindow(hwnd);
|
|
||||||
LeaveCriticalSection(&SHELL32_ChangenotifyCS);
|
|
||||||
return INVALID_REG_ID;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
LeaveCriticalSection(&SHELL32_ChangenotifyCS);
|
|
||||||
return nRegID;
|
|
||||||
#else
|
|
||||||
LPNOTIFICATIONLIST item;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
item = SHAlloc(sizeof(NOTIFICATIONLIST));
|
|
||||||
|
|
||||||
TRACE("(%p,0x%08x,0x%08x,0x%08x,%d,%p) item=%p\n",
|
|
||||||
hwnd, fSources, wEventMask, uMsg, cItems, lpItems, item);
|
|
||||||
|
|
||||||
item->cidl = cItems;
|
|
||||||
item->apidl = SHAlloc(sizeof(SHChangeNotifyEntry) * cItems);
|
|
||||||
for(i=0;i<cItems;i++)
|
|
||||||
{
|
|
||||||
item->apidl[i].pidl = ILClone(lpItems[i].pidl);
|
|
||||||
item->apidl[i].fRecursive = lpItems[i].fRecursive;
|
|
||||||
}
|
|
||||||
item->hwnd = hwnd;
|
|
||||||
item->uMsg = uMsg;
|
|
||||||
item->wEventMask = wEventMask;
|
|
||||||
item->dwFlags = fSources;
|
|
||||||
item->id = InterlockedIncrement( &next_id );
|
|
||||||
|
|
||||||
TRACE("new node: %s\n", NodeName( item ));
|
|
||||||
|
|
||||||
EnterCriticalSection(&SHELL32_ChangenotifyCS);
|
|
||||||
|
|
||||||
list_add_tail( ¬ifications, &item->entry );
|
|
||||||
|
|
||||||
LeaveCriticalSection(&SHELL32_ChangenotifyCS);
|
|
||||||
|
|
||||||
return item->id;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
/*************************************************************************
|
|
||||||
* SHChangeNotifyDeregister [SHELL32.4]
|
|
||||||
*/
|
|
||||||
BOOL WINAPI SHChangeNotifyDeregister(ULONG hNotify)
|
|
||||||
{
|
|
||||||
#ifdef __REACTOS__
|
|
||||||
HWND hwndNotif;
|
|
||||||
LRESULT ret = 0;
|
|
||||||
TRACE("(0x%08x)\n", hNotify);
|
|
||||||
|
|
||||||
hwndNotif = DoGetNewDeliveryWorker();
|
|
||||||
if (hwndNotif)
|
|
||||||
{
|
|
||||||
ret = SendMessageW(hwndNotif, WM_NOTIF_UNREG, hNotify, 0);
|
|
||||||
if (!ret)
|
|
||||||
{
|
|
||||||
ERR("WM_NOTIF_UNREG failed\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
#else
|
|
||||||
LPNOTIFICATIONLIST node;
|
|
||||||
|
|
||||||
TRACE("(0x%08x)\n", hNotify);
|
|
||||||
|
|
||||||
EnterCriticalSection(&SHELL32_ChangenotifyCS);
|
|
||||||
|
|
||||||
LIST_FOR_EACH_ENTRY( node, ¬ifications, NOTIFICATIONLIST, entry )
|
|
||||||
{
|
|
||||||
if (node->id == hNotify)
|
|
||||||
{
|
|
||||||
DeleteNode( node );
|
|
||||||
LeaveCriticalSection(&SHELL32_ChangenotifyCS);
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
LeaveCriticalSection(&SHELL32_ChangenotifyCS);
|
|
||||||
return FALSE;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
/*************************************************************************
|
|
||||||
* SHChangeNotifyUpdateEntryList [SHELL32.5]
|
|
||||||
*/
|
|
||||||
BOOL WINAPI SHChangeNotifyUpdateEntryList(DWORD unknown1, DWORD unknown2,
|
|
||||||
DWORD unknown3, DWORD unknown4)
|
|
||||||
{
|
|
||||||
FIXME("(0x%08x, 0x%08x, 0x%08x, 0x%08x)\n",
|
|
||||||
unknown1, unknown2, unknown3, unknown4);
|
|
||||||
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct new_delivery_notification
|
|
||||||
{
|
|
||||||
LONG event;
|
|
||||||
DWORD pidl1_size;
|
|
||||||
DWORD pidl2_size;
|
|
||||||
LPITEMIDLIST pidls[2];
|
|
||||||
BYTE data[1];
|
|
||||||
};
|
|
||||||
|
|
||||||
#ifndef __REACTOS__
|
|
||||||
static BOOL should_notify( LPCITEMIDLIST changed, LPCITEMIDLIST 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;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/*************************************************************************
|
|
||||||
* SHChangeNotify [SHELL32.@]
|
|
||||||
*/
|
|
||||||
void WINAPI SHChangeNotify(LONG wEventId, UINT uFlags, LPCVOID dwItem1, LPCVOID dwItem2)
|
|
||||||
{
|
|
||||||
#ifdef __REACTOS__
|
|
||||||
LPITEMIDLIST pidl1 = NULL, pidl2 = NULL, pidlTemp1 = NULL, pidlTemp2 = NULL;
|
|
||||||
DWORD dwTick = GetTickCount();
|
|
||||||
WCHAR szPath1[MAX_PATH], szPath2[MAX_PATH];
|
|
||||||
LPWSTR psz1, psz2;
|
|
||||||
TRACE("(0x%08x,0x%08x,%p,%p)\n", wEventId, uFlags, dwItem1, dwItem2);
|
|
||||||
|
|
||||||
switch (uFlags & SHCNF_TYPE)
|
|
||||||
{
|
|
||||||
case SHCNF_IDLIST:
|
|
||||||
if (wEventId == SHCNE_FREESPACE)
|
|
||||||
{
|
|
||||||
DoNotifyFreeSpace(dwItem1, dwItem2);
|
|
||||||
goto Quit;
|
|
||||||
}
|
|
||||||
pidl1 = (LPITEMIDLIST)dwItem1;
|
|
||||||
pidl2 = (LPITEMIDLIST)dwItem2;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case SHCNF_PATHA:
|
|
||||||
psz1 = psz2 = NULL;
|
|
||||||
if (dwItem1)
|
|
||||||
{
|
|
||||||
SHAnsiToUnicode(dwItem1, szPath1, ARRAYSIZE(szPath1));
|
|
||||||
psz1 = szPath1;
|
|
||||||
}
|
|
||||||
if (dwItem2)
|
|
||||||
{
|
|
||||||
SHAnsiToUnicode(dwItem2, szPath2, ARRAYSIZE(szPath2));
|
|
||||||
psz2 = szPath2;
|
|
||||||
}
|
|
||||||
uFlags &= ~SHCNF_TYPE;
|
|
||||||
uFlags |= SHCNF_PATHW;
|
|
||||||
SHChangeNotify(wEventId, uFlags, psz1, psz2);
|
|
||||||
return;
|
|
||||||
|
|
||||||
case SHCNF_PATHW:
|
|
||||||
if (wEventId == SHCNE_FREESPACE)
|
|
||||||
{
|
|
||||||
/* FIXME */
|
|
||||||
goto Quit;
|
|
||||||
}
|
|
||||||
if (dwItem1)
|
|
||||||
{
|
|
||||||
pidl1 = pidlTemp1 = SHSimpleIDListFromPathW(dwItem1);
|
|
||||||
}
|
|
||||||
if (dwItem2)
|
|
||||||
{
|
|
||||||
pidl2 = pidlTemp2 = SHSimpleIDListFromPathW(dwItem2);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case SHCNF_PRINTERA:
|
|
||||||
case SHCNF_PRINTERW:
|
|
||||||
FIXME("SHChangeNotify with (uFlags & SHCNF_PRINTER)\n");
|
|
||||||
return;
|
|
||||||
|
|
||||||
default:
|
|
||||||
FIXME("unknown type %08x\n", uFlags & SHCNF_TYPE);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (wEventId == 0 || (wEventId & SHCNE_ASSOCCHANGED) || pidl1 != NULL)
|
|
||||||
{
|
|
||||||
TRACE("notifying event %s(%x)\n", DumpEvent(wEventId), wEventId);
|
|
||||||
DoTransportChange(wEventId, uFlags, pidl1, pidl2, dwTick);
|
|
||||||
}
|
|
||||||
|
|
||||||
Quit:
|
|
||||||
if (pidlTemp1)
|
|
||||||
ILFree(pidlTemp1);
|
|
||||||
if (pidlTemp2)
|
|
||||||
ILFree(pidlTemp2);
|
|
||||||
#else
|
|
||||||
struct notification_recipients {
|
|
||||||
struct list entry;
|
|
||||||
HWND hwnd;
|
|
||||||
DWORD msg;
|
|
||||||
DWORD flags;
|
|
||||||
} *cur, *next;
|
|
||||||
|
|
||||||
HANDLE shared_data = NULL;
|
|
||||||
LPITEMIDLIST Pidls[2];
|
|
||||||
LPNOTIFICATIONLIST ptr;
|
|
||||||
struct list recipients;
|
|
||||||
|
|
||||||
Pidls[0] = NULL;
|
|
||||||
Pidls[1] = NULL;
|
|
||||||
|
|
||||||
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 ) )
|
|
||||||
{
|
|
||||||
TRACE("dwItem1 and dwItem2 are not zero, but should be\n");
|
|
||||||
dwItem1 = 0;
|
|
||||||
dwItem2 = 0;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
else if( ( wEventId & SHCNE_ONEITEMEVENTS ) && dwItem2 )
|
|
||||||
{
|
|
||||||
TRACE("dwItem2 is not zero, but should be\n");
|
|
||||||
dwItem2 = 0;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if( ( ( wEventId & SHCNE_NOITEMEVENTS ) &&
|
|
||||||
( wEventId & ~(SHCNE_NOITEMEVENTS | SHCNE_INTERRUPT) ) ) ||
|
|
||||||
( ( wEventId & SHCNE_ONEITEMEVENTS ) &&
|
|
||||||
( wEventId & ~(SHCNE_ONEITEMEVENTS | SHCNE_INTERRUPT) ) ) ||
|
|
||||||
( ( wEventId & SHCNE_TWOITEMEVENTS ) &&
|
|
||||||
( wEventId & ~(SHCNE_TWOITEMEVENTS | SHCNE_INTERRUPT) ) ) )
|
|
||||||
{
|
|
||||||
WARN("mutually incompatible events listed\n");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* convert paths in IDLists*/
|
|
||||||
switch (uFlags & SHCNF_TYPE)
|
|
||||||
{
|
|
||||||
case SHCNF_PATHA:
|
|
||||||
if (dwItem1) Pidls[0] = SHSimpleIDListFromPathA(dwItem1); //FIXME
|
|
||||||
if (dwItem2) Pidls[1] = SHSimpleIDListFromPathA(dwItem2); //FIXME
|
|
||||||
break;
|
|
||||||
case SHCNF_PATHW:
|
|
||||||
if (dwItem1) Pidls[0] = SHSimpleIDListFromPathW(dwItem1);
|
|
||||||
if (dwItem2) Pidls[1] = SHSimpleIDListFromPathW(dwItem2);
|
|
||||||
break;
|
|
||||||
case SHCNF_IDLIST:
|
|
||||||
Pidls[0] = ILClone(dwItem1);
|
|
||||||
Pidls[1] = ILClone(dwItem2);
|
|
||||||
break;
|
|
||||||
case SHCNF_PRINTERA:
|
|
||||||
case SHCNF_PRINTERW:
|
|
||||||
FIXME("SHChangeNotify with (uFlags & SHCNF_PRINTER)\n");
|
|
||||||
return;
|
|
||||||
case SHCNF_DWORD:
|
|
||||||
default:
|
|
||||||
FIXME("unknown type %08x\n", uFlags & SHCNF_TYPE);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
list_init(&recipients);
|
|
||||||
EnterCriticalSection(&SHELL32_ChangenotifyCS);
|
|
||||||
LIST_FOR_EACH_ENTRY( ptr, ¬ifications, NOTIFICATIONLIST, entry )
|
|
||||||
{
|
|
||||||
struct notification_recipients *item;
|
|
||||||
BOOL notify = FALSE;
|
|
||||||
DWORD i;
|
|
||||||
|
|
||||||
for( i=0; (i<ptr->cidl) && !notify ; i++ )
|
|
||||||
{
|
|
||||||
LPCITEMIDLIST pidl = ptr->apidl[i].pidl;
|
|
||||||
BOOL subtree = ptr->apidl[i].fRecursive;
|
|
||||||
|
|
||||||
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;
|
|
||||||
|
|
||||||
item = SHAlloc(sizeof(struct notification_recipients));
|
|
||||||
if(!item) {
|
|
||||||
ERR("out of memory\n");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
item->hwnd = ptr->hwnd;
|
|
||||||
item->msg = ptr->uMsg;
|
|
||||||
item->flags = ptr->dwFlags;
|
|
||||||
list_add_tail(&recipients, &item->entry);
|
|
||||||
}
|
|
||||||
LeaveCriticalSection(&SHELL32_ChangenotifyCS);
|
|
||||||
|
|
||||||
LIST_FOR_EACH_ENTRY_SAFE(cur, next, &recipients, struct notification_recipients, entry)
|
|
||||||
{
|
|
||||||
TRACE("notifying %p, event %s(%x)\n", cur->hwnd, DumpEvent(wEventId), wEventId);
|
|
||||||
|
|
||||||
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]);
|
|
||||||
|
|
||||||
if (wEventId & SHCNE_ASSOCCHANGED)
|
|
||||||
{
|
|
||||||
static const WCHAR args[] = {' ','-','a',0 };
|
|
||||||
TRACE("refreshing file type associations\n");
|
|
||||||
run_winemenubuilder( args );
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
/*************************************************************************
|
|
||||||
* NTSHChangeNotifyRegister [SHELL32.640]
|
|
||||||
* NOTES
|
|
||||||
* Idlist is an array of structures and Count specifies how many items in the array.
|
|
||||||
* count should always be one when calling SHChangeNotifyRegister, or
|
|
||||||
* SHChangeNotifyDeregister will not work properly.
|
|
||||||
*/
|
|
||||||
EXTERN_C ULONG WINAPI NTSHChangeNotifyRegister(
|
|
||||||
HWND hwnd,
|
|
||||||
int fSources,
|
|
||||||
LONG fEvents,
|
|
||||||
UINT msg,
|
|
||||||
int count,
|
|
||||||
SHChangeNotifyEntry *idlist)
|
|
||||||
{
|
|
||||||
return SHChangeNotifyRegister(hwnd, fSources | SHCNRF_NewDelivery,
|
|
||||||
fEvents, msg, count, idlist);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*************************************************************************
|
|
||||||
* SHChangeNotification_Lock [SHELL32.644]
|
|
||||||
*/
|
|
||||||
HANDLE WINAPI SHChangeNotification_Lock(
|
|
||||||
HANDLE hChange,
|
|
||||||
DWORD dwProcessId,
|
|
||||||
LPITEMIDLIST **lppidls,
|
|
||||||
LPLONG lpwEventId)
|
|
||||||
{
|
|
||||||
#ifdef __REACTOS__
|
|
||||||
LPHANDBAG pHandbag;
|
|
||||||
TRACE("%p %08x %p %p\n", hChange, dwProcessId, lppidls, lpwEventId);
|
|
||||||
|
|
||||||
pHandbag = DoGetHandbagFromTicket(hChange, dwProcessId);
|
|
||||||
if (!pHandbag || pHandbag->dwMagic != HANDBAG_MAGIC)
|
|
||||||
{
|
|
||||||
ERR("pHandbag is invalid\n");
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (lppidls)
|
|
||||||
*lppidls = pHandbag->pidls;
|
|
||||||
|
|
||||||
if (lpwEventId)
|
|
||||||
*lpwEventId = pHandbag->pTicket->wEventId;
|
|
||||||
|
|
||||||
return pHandbag;
|
|
||||||
#else
|
|
||||||
struct new_delivery_notification *ndn;
|
|
||||||
UINT offset;
|
|
||||||
|
|
||||||
TRACE("%p %08x %p %p\n", hChange, dwProcessId, lppidls, lpwEventId);
|
|
||||||
|
|
||||||
ndn = SHLockShared(hChange, dwProcessId);
|
|
||||||
if(!ndn) {
|
|
||||||
WARN("SHLockShared failed\n");
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
/*************************************************************************
|
|
||||||
* SHChangeNotification_Unlock [SHELL32.645]
|
|
||||||
*/
|
|
||||||
BOOL WINAPI SHChangeNotification_Unlock ( HANDLE hLock)
|
|
||||||
{
|
|
||||||
#ifdef __REACTOS__
|
|
||||||
LPHANDBAG pHandbag = (LPHANDBAG)hLock;
|
|
||||||
BOOL ret;
|
|
||||||
TRACE("%p\n", hLock);
|
|
||||||
|
|
||||||
if (!pHandbag || pHandbag->dwMagic != HANDBAG_MAGIC)
|
|
||||||
{
|
|
||||||
ERR("pHandbag is invalid\n");
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = SHUnlockShared(pHandbag->pTicket);
|
|
||||||
LocalFree(hLock);
|
|
||||||
return ret;
|
|
||||||
#else
|
|
||||||
TRACE("%p\n", hLock);
|
|
||||||
return SHUnlockShared(hLock);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
/*************************************************************************
|
|
||||||
* NTSHChangeNotifyDeregister [SHELL32.641]
|
|
||||||
*/
|
|
||||||
DWORD WINAPI NTSHChangeNotifyDeregister(ULONG x1)
|
|
||||||
{
|
|
||||||
FIXME("(0x%08x):semi stub.\n",x1);
|
|
||||||
|
|
||||||
return SHChangeNotifyDeregister( x1 );
|
|
||||||
}
|
|
|
@ -114,6 +114,11 @@ HRESULT WINAPI IUnknown_HasFocusIO(IUnknown * punk);
|
||||||
HRESULT WINAPI IUnknown_TranslateAcceleratorIO(IUnknown * punk, MSG * pmsg);
|
HRESULT WINAPI IUnknown_TranslateAcceleratorIO(IUnknown * punk, MSG * pmsg);
|
||||||
HRESULT WINAPI IUnknown_OnFocusChangeIS(LPUNKNOWN lpUnknown, LPUNKNOWN pFocusObject, BOOL bFocus);
|
HRESULT WINAPI IUnknown_OnFocusChangeIS(LPUNKNOWN lpUnknown, LPUNKNOWN pFocusObject, BOOL bFocus);
|
||||||
|
|
||||||
|
DWORD WINAPI SHAnsiToUnicode(LPCSTR lpSrcStr, LPWSTR lpDstStr, INT iLen);
|
||||||
|
INT WINAPI SHUnicodeToAnsi(LPCWSTR lpSrcStr, LPSTR lpDstStr, INT iLen);
|
||||||
|
|
||||||
|
PVOID WINAPI SHLockSharedEx(HANDLE hData, DWORD dwProcessId, BOOL bWriteAccess);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
} /* extern "C" */
|
} /* extern "C" */
|
||||||
#endif /* defined(__cplusplus) */
|
#endif /* defined(__cplusplus) */
|
||||||
|
|
|
@ -702,13 +702,6 @@ IStream* WINAPI SHGetViewStream(LPCITEMIDLIST, DWORD, LPCTSTR, LPCTSTR, LPCTSTR)
|
||||||
|
|
||||||
EXTERN_C HRESULT WINAPI SHCreateSessionKey(REGSAM samDesired, PHKEY phKey);
|
EXTERN_C HRESULT WINAPI SHCreateSessionKey(REGSAM samDesired, PHKEY phKey);
|
||||||
|
|
||||||
PVOID
|
|
||||||
WINAPI
|
|
||||||
SHLockSharedEx(
|
|
||||||
_In_ HANDLE hData,
|
|
||||||
_In_ DWORD dwProcessId,
|
|
||||||
_In_ BOOL bWriteAccess);
|
|
||||||
|
|
||||||
/*****************************************************************************
|
/*****************************************************************************
|
||||||
* INVALID_FILETITLE_CHARACTERS
|
* INVALID_FILETITLE_CHARACTERS
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in a new issue