2020-04-13 01:36:24 +00:00
|
|
|
/*
|
|
|
|
* 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"
|
2020-06-02 09:42:07 +00:00
|
|
|
#include "CDirectoryWatcher.h"
|
2020-05-04 05:53:23 +00:00
|
|
|
#include <assert.h> // for assert
|
2020-04-13 01:36:24 +00:00
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(shcn);
|
|
|
|
|
2020-05-04 05:53:23 +00:00
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2020-04-13 01:36:24 +00:00
|
|
|
// notification target item
|
2022-03-06 02:49:28 +00:00
|
|
|
struct CWatchItem
|
2020-04-13 01:36:24 +00:00
|
|
|
{
|
|
|
|
UINT nRegID; // The registration ID.
|
|
|
|
DWORD dwUserPID; // The user PID; that is the process ID of the target window.
|
2022-03-06 02:49:28 +00:00
|
|
|
LPREGENTRY pRegEntry; // The registration entry.
|
2020-04-13 01:36:24 +00:00
|
|
|
HWND hwndBroker; // Client broker window (if any).
|
2020-06-02 09:42:07 +00:00
|
|
|
CDirectoryWatcher *pDirWatch; // for filesystem notification
|
2020-04-13 01:36:24 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
// 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 :
|
2022-01-24 18:42:46 +00:00
|
|
|
public CWindowImpl<CChangeNotifyServer, CWindow, CWorkerTraits>,
|
2020-04-13 01:36:24 +00:00
|
|
|
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);
|
2020-05-04 05:53:23 +00:00
|
|
|
LRESULT OnDestroy(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
|
2020-04-13 01:36:24 +00:00
|
|
|
|
|
|
|
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);
|
2020-05-04 05:53:23 +00:00
|
|
|
MESSAGE_HANDLER(WM_DESTROY, OnDestroy);
|
2020-04-13 01:36:24 +00:00
|
|
|
END_MSG_MAP()
|
|
|
|
|
|
|
|
private:
|
|
|
|
UINT m_nNextRegID;
|
2022-03-06 02:49:28 +00:00
|
|
|
CSimpleArray<CWatchItem*> m_items;
|
2020-04-13 01:36:24 +00:00
|
|
|
|
2022-03-06 02:49:28 +00:00
|
|
|
BOOL AddItem(CWatchItem *pItem);
|
|
|
|
BOOL RemoveItemsByRegID(UINT nRegID);
|
|
|
|
BOOL RemoveItemsByProcess(DWORD dwUserPID);
|
|
|
|
void DestroyItem(CWatchItem *pItem, HWND *phwndBroker);
|
2022-03-06 03:33:10 +00:00
|
|
|
void DestroyAllItems();
|
2020-04-13 01:36:24 +00:00
|
|
|
|
|
|
|
UINT GetNextRegID();
|
|
|
|
BOOL DeliverNotification(HANDLE hTicket, DWORD dwOwnerPID);
|
|
|
|
BOOL ShouldNotify(LPDELITICKET pTicket, LPREGENTRY pRegEntry);
|
|
|
|
};
|
|
|
|
|
|
|
|
CChangeNotifyServer::CChangeNotifyServer()
|
|
|
|
: m_nNextRegID(INVALID_REG_ID)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
CChangeNotifyServer::~CChangeNotifyServer()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-03-06 02:49:28 +00:00
|
|
|
BOOL CChangeNotifyServer::AddItem(CWatchItem *pItem)
|
2020-04-13 01:36:24 +00:00
|
|
|
{
|
|
|
|
// find the empty room
|
|
|
|
for (INT i = 0; i < m_items.GetSize(); ++i)
|
|
|
|
{
|
2022-03-06 02:49:28 +00:00
|
|
|
if (m_items[i] == NULL)
|
2020-04-13 01:36:24 +00:00
|
|
|
{
|
|
|
|
// found the room, populate it
|
2022-03-06 02:49:28 +00:00
|
|
|
m_items[i] = pItem;
|
2020-04-13 01:36:24 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// no empty room found
|
2022-03-06 02:49:28 +00:00
|
|
|
m_items.Add(pItem);
|
2020-04-13 01:36:24 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2022-03-06 02:49:28 +00:00
|
|
|
void CChangeNotifyServer::DestroyItem(CWatchItem *pItem, HWND *phwndBroker)
|
2020-04-13 01:36:24 +00:00
|
|
|
{
|
2022-03-06 02:49:28 +00:00
|
|
|
assert(pItem);
|
|
|
|
|
2020-04-13 01:36:24 +00:00
|
|
|
// destroy broker if any and if first time
|
2022-03-06 02:49:28 +00:00
|
|
|
HWND hwndBroker = pItem->hwndBroker;
|
|
|
|
pItem->hwndBroker = NULL;
|
2020-05-04 05:53:23 +00:00
|
|
|
if (hwndBroker && hwndBroker != *phwndBroker)
|
2020-04-13 01:36:24 +00:00
|
|
|
{
|
2020-05-04 05:53:23 +00:00
|
|
|
::DestroyWindow(hwndBroker);
|
|
|
|
*phwndBroker = hwndBroker;
|
|
|
|
}
|
|
|
|
|
|
|
|
// request termination of pDirWatch if any
|
2022-03-06 02:49:28 +00:00
|
|
|
CDirectoryWatcher *pDirWatch = pItem->pDirWatch;
|
|
|
|
pItem->pDirWatch = NULL;
|
2020-06-02 09:42:07 +00:00
|
|
|
if (pDirWatch)
|
|
|
|
pDirWatch->RequestTermination();
|
2020-04-13 01:36:24 +00:00
|
|
|
|
|
|
|
// free
|
2022-03-06 02:49:28 +00:00
|
|
|
SHFree(pItem->pRegEntry);
|
|
|
|
delete pItem;
|
2020-04-13 01:36:24 +00:00
|
|
|
}
|
|
|
|
|
2022-03-06 03:33:10 +00:00
|
|
|
void CChangeNotifyServer::DestroyAllItems()
|
|
|
|
{
|
|
|
|
for (INT i = 0; i < m_items.GetSize(); ++i)
|
|
|
|
{
|
|
|
|
if (m_items[i])
|
|
|
|
{
|
|
|
|
HWND hwndBroker = NULL;
|
|
|
|
DestroyItem(m_items[i], &hwndBroker);
|
|
|
|
m_items[i] = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
m_items.RemoveAll();
|
|
|
|
}
|
|
|
|
|
2022-03-06 02:49:28 +00:00
|
|
|
BOOL CChangeNotifyServer::RemoveItemsByRegID(UINT nRegID)
|
2020-04-13 01:36:24 +00:00
|
|
|
{
|
|
|
|
BOOL bFound = FALSE;
|
|
|
|
HWND hwndBroker = NULL;
|
|
|
|
assert(nRegID != INVALID_REG_ID);
|
|
|
|
for (INT i = 0; i < m_items.GetSize(); ++i)
|
|
|
|
{
|
2022-03-06 02:49:28 +00:00
|
|
|
if (m_items[i] && m_items[i]->nRegID == nRegID)
|
2020-04-13 01:36:24 +00:00
|
|
|
{
|
|
|
|
bFound = TRUE;
|
2022-03-06 02:49:28 +00:00
|
|
|
DestroyItem(m_items[i], &hwndBroker);
|
|
|
|
m_items[i] = NULL;
|
2020-04-13 01:36:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return bFound;
|
|
|
|
}
|
|
|
|
|
2022-03-06 02:49:28 +00:00
|
|
|
BOOL CChangeNotifyServer::RemoveItemsByProcess(DWORD dwUserPID)
|
2020-04-13 01:36:24 +00:00
|
|
|
{
|
2022-03-06 02:49:28 +00:00
|
|
|
BOOL bFound = FALSE;
|
2020-04-13 01:36:24 +00:00
|
|
|
HWND hwndBroker = NULL;
|
|
|
|
assert(dwUserPID != 0);
|
|
|
|
for (INT i = 0; i < m_items.GetSize(); ++i)
|
|
|
|
{
|
2022-03-06 02:49:28 +00:00
|
|
|
if (m_items[i] && m_items[i]->dwUserPID == dwUserPID)
|
2020-04-13 01:36:24 +00:00
|
|
|
{
|
2022-03-06 02:49:28 +00:00
|
|
|
bFound = TRUE;
|
|
|
|
DestroyItem(m_items[i], &hwndBroker);
|
|
|
|
m_items[i] = NULL;
|
2020-04-13 01:36:24 +00:00
|
|
|
}
|
|
|
|
}
|
2022-03-06 02:49:28 +00:00
|
|
|
return bFound;
|
2020-04-13 01:36:24 +00:00
|
|
|
}
|
|
|
|
|
2020-06-02 09:42:07 +00:00
|
|
|
// create a CDirectoryWatcher from a REGENTRY
|
|
|
|
static CDirectoryWatcher *
|
|
|
|
CreateDirectoryWatcherFromRegEntry(LPREGENTRY pRegEntry)
|
2020-05-04 06:28:16 +00:00
|
|
|
{
|
2020-06-02 09:42:07 +00:00
|
|
|
if (pRegEntry->ibPidl == 0)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
// get the path
|
|
|
|
WCHAR szPath[MAX_PATH];
|
|
|
|
LPITEMIDLIST pidl = (LPITEMIDLIST)((LPBYTE)pRegEntry + pRegEntry->ibPidl);
|
|
|
|
if (!SHGetPathFromIDListW(pidl, szPath) || !PathIsDirectoryW(szPath))
|
|
|
|
return NULL;
|
2020-05-04 06:28:16 +00:00
|
|
|
|
2020-06-02 09:42:07 +00:00
|
|
|
// create a CDirectoryWatcher
|
|
|
|
CDirectoryWatcher *pDirectoryWatcher = CDirectoryWatcher::Create(szPath, pRegEntry->fRecursive);
|
|
|
|
if (pDirectoryWatcher == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return pDirectoryWatcher;
|
2020-05-04 06:28:16 +00:00
|
|
|
}
|
|
|
|
|
2020-04-13 01:36:24 +00:00
|
|
|
// 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
|
2022-03-06 02:49:28 +00:00
|
|
|
LPREGENTRY pNewEntry = (LPREGENTRY)SHAlloc(pRegEntry->cbSize);
|
|
|
|
if (pNewEntry == NULL)
|
2020-04-13 01:36:24 +00:00
|
|
|
{
|
|
|
|
ERR("Out of memory\n");
|
|
|
|
pRegEntry->nRegID = INVALID_REG_ID;
|
|
|
|
SHUnlockShared(pRegEntry);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2022-03-06 02:49:28 +00:00
|
|
|
CopyMemory(pNewEntry, pRegEntry, pRegEntry->cbSize);
|
2020-04-13 01:36:24 +00:00
|
|
|
|
2020-05-04 05:53:23 +00:00
|
|
|
// create a directory watch if necessary
|
2020-09-03 04:36:31 +00:00
|
|
|
CDirectoryWatcher *pDirWatch = NULL;
|
|
|
|
if (pRegEntry->ibPidl && (pRegEntry->fSources & SHCNRF_InterruptLevel))
|
2020-05-04 05:53:23 +00:00
|
|
|
{
|
2020-09-03 04:36:31 +00:00
|
|
|
pDirWatch = CreateDirectoryWatcherFromRegEntry(pRegEntry);
|
|
|
|
if (pDirWatch && !pDirWatch->RequestAddWatcher())
|
|
|
|
{
|
|
|
|
ERR("RequestAddWatcher failed: %u\n", pRegEntry->nRegID);
|
|
|
|
pRegEntry->nRegID = INVALID_REG_ID;
|
|
|
|
SHUnlockShared(pRegEntry);
|
|
|
|
delete pDirWatch;
|
|
|
|
return FALSE;
|
|
|
|
}
|
2020-05-04 05:53:23 +00:00
|
|
|
}
|
|
|
|
|
2020-04-13 01:36:24 +00:00
|
|
|
// unlock the registry entry
|
|
|
|
SHUnlockShared(pRegEntry);
|
|
|
|
|
2022-03-06 02:49:28 +00:00
|
|
|
// add an item
|
|
|
|
CWatchItem *pItem = new CWatchItem { m_nNextRegID, dwUserPID, pNewEntry, hwndBroker, pDirWatch };
|
|
|
|
return AddItem(pItem);
|
2020-04-13 01:36:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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
|
2022-03-06 02:49:28 +00:00
|
|
|
return RemoveItemsByRegID(nRegID);
|
2020-04-13 01:36:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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)
|
|
|
|
{
|
2022-03-06 02:49:28 +00:00
|
|
|
DWORD dwUserPID = (DWORD)wParam;
|
|
|
|
RemoveItemsByProcess(dwUserPID);
|
2020-04-13 01:36:24 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-05-04 05:53:23 +00:00
|
|
|
LRESULT CChangeNotifyServer::OnDestroy(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
|
|
|
|
{
|
2022-03-06 03:33:10 +00:00
|
|
|
DestroyAllItems();
|
2020-06-02 09:42:07 +00:00
|
|
|
CDirectoryWatcher::RequestAllWatchersTermination();
|
2020-05-04 05:53:23 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-04-13 01:36:24 +00:00
|
|
|
// 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)
|
|
|
|
{
|
2022-03-06 02:49:28 +00:00
|
|
|
if (m_items[i] == NULL)
|
2020-04-13 01:36:24 +00:00
|
|
|
continue;
|
|
|
|
|
2022-03-06 02:49:28 +00:00
|
|
|
LPREGENTRY pRegEntry = m_items[i]->pRegEntry;
|
2020-04-13 01:36:24 +00:00
|
|
|
if (pRegEntry == NULL || pRegEntry->dwMagic != REGENTRY_MAGIC)
|
|
|
|
{
|
|
|
|
ERR("pRegEntry is invalid\n");
|
|
|
|
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);
|
2020-09-03 04:36:31 +00:00
|
|
|
TRACE("GetLastError(): %ld\n", ::GetLastError());
|
2020-04-13 01:36:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// unlock the ticket
|
|
|
|
SHUnlockShared(pTicket);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL CChangeNotifyServer::ShouldNotify(LPDELITICKET pTicket, LPREGENTRY pRegEntry)
|
|
|
|
{
|
2020-09-03 04:36:31 +00:00
|
|
|
#define RETURN(x) do { \
|
|
|
|
TRACE("ShouldNotify return %d\n", (x)); \
|
|
|
|
return (x); \
|
|
|
|
} while (0)
|
2020-04-13 01:36:24 +00:00
|
|
|
|
2020-09-03 04:36:31 +00:00
|
|
|
if (pTicket->wEventId & SHCNE_INTERRUPT)
|
2020-05-04 05:53:23 +00:00
|
|
|
{
|
|
|
|
if (!(pRegEntry->fSources & SHCNRF_InterruptLevel))
|
2020-09-03 04:36:31 +00:00
|
|
|
RETURN(FALSE);
|
|
|
|
if (!pRegEntry->ibPidl)
|
|
|
|
RETURN(FALSE);
|
2020-05-04 05:53:23 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!(pRegEntry->fSources & SHCNRF_ShellLevel))
|
2020-09-03 04:36:31 +00:00
|
|
|
RETURN(FALSE);
|
2020-05-04 05:53:23 +00:00
|
|
|
}
|
|
|
|
|
2020-09-03 04:36:31 +00:00
|
|
|
if (!(pTicket->wEventId & pRegEntry->fEvents))
|
|
|
|
RETURN(FALSE);
|
2020-04-13 01:36:24 +00:00
|
|
|
|
2020-09-03 04:36:31 +00:00
|
|
|
LPITEMIDLIST pidl = NULL, pidl1 = NULL, pidl2 = NULL;
|
|
|
|
if (pRegEntry->ibPidl)
|
|
|
|
pidl = (LPITEMIDLIST)((LPBYTE)pRegEntry + pRegEntry->ibPidl);
|
2020-04-13 01:36:24 +00:00
|
|
|
if (pTicket->ibOffset1)
|
|
|
|
pidl1 = (LPITEMIDLIST)((LPBYTE)pTicket + pTicket->ibOffset1);
|
|
|
|
if (pTicket->ibOffset2)
|
|
|
|
pidl2 = (LPITEMIDLIST)((LPBYTE)pTicket + pTicket->ibOffset2);
|
|
|
|
|
2020-09-03 04:36:31 +00:00
|
|
|
if (pidl == NULL || (pTicket->wEventId & SHCNE_GLOBALEVENTS))
|
|
|
|
RETURN(TRUE);
|
2020-04-13 01:36:24 +00:00
|
|
|
|
2020-09-03 04:36:31 +00:00
|
|
|
if (pRegEntry->fRecursive)
|
|
|
|
{
|
|
|
|
if (ILIsParent(pidl, pidl1, FALSE) ||
|
|
|
|
(pidl2 && ILIsParent(pidl, pidl2, FALSE)))
|
2020-04-13 01:36:24 +00:00
|
|
|
{
|
2020-09-03 04:36:31 +00:00
|
|
|
RETURN(TRUE);
|
2020-04-13 01:36:24 +00:00
|
|
|
}
|
2020-09-03 04:36:31 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (ILIsEqual(pidl, pidl1) ||
|
|
|
|
ILIsParent(pidl, pidl1, TRUE) ||
|
|
|
|
(pidl2 && ILIsParent(pidl, pidl2, TRUE)))
|
2020-04-13 01:36:24 +00:00
|
|
|
{
|
2020-09-03 04:36:31 +00:00
|
|
|
RETURN(TRUE);
|
2020-04-13 01:36:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-03 04:36:31 +00:00
|
|
|
RETURN(FALSE);
|
|
|
|
#undef RETURN
|
2020-04-13 01:36:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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.
|
2022-01-24 18:42:46 +00:00
|
|
|
HWND hwnd = SHCreateDefaultWorkerWindow();
|
|
|
|
if (!hwnd)
|
2020-04-13 01:36:24 +00:00
|
|
|
return E_FAIL;
|
2022-01-24 18:42:46 +00:00
|
|
|
SubclassWindow(hwnd);
|
2020-04-13 01:36:24 +00:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT CChangeNotifyServer_CreateInstance(REFIID riid, void **ppv)
|
|
|
|
{
|
|
|
|
return ShellObjectCreatorInit<CChangeNotifyServer>(riid, ppv);
|
|
|
|
}
|