Skip to content

rpsl_explorer FileMonitor does not notify on file change #33

Open
@ChemistAion

Description

@ChemistAion

There is a missing SHCNRF_ShellLevel flag here - in the type of events for which to receive notifications:

ULONG uId = SHChangeNotifyRegister(hWndListener,
SHCNRF_InterruptLevel | SHCNRF_NewDelivery,
SHCNE_RENAMEITEM | SHCNE_DELETE | SHCNE_UPDATEITEM,
UM_FILE_CHANGED,
1,
&notifyEntry);

It is necessary to include it to capture changes made, e.g. from text-editors (considered as a ShellLevel source).


Other, minor things:

  • UM_FILE_CHANGED should be type of UINT;
  • result of ILCreateFromPathA is not checked (in case of 0);
  • registered-to-notify file is not placed into m_registerIDs - so it would be wrongly considered again

Please find my snipped with corrected version:

static constexpr UINT UM_FILE_CHANGED = WM_USER + 4097;

bool BeginWatch(HWND hWndListener, const std::string& fileName)
{
    auto iter = m_registerIDs.find(fileName);
    
    if (iter != m_registerIDs.end())
    {
        return false;
    }

    PCIDLIST_ABSOLUTE pidl = ILCreateFromPathA(fileName.c_str());

    if (pidl == 0)
    {
        return false;
    }

    SHChangeNotifyEntry notifyEntry = { pidl, FALSE };

    ULONG uId = SHChangeNotifyRegister
    (
        hWndListener,
        SHCNRF_InterruptLevel | SHCNRF_ShellLevel | SHCNRF_NewDelivery,
        SHCNE_RENAMEITEM | SHCNE_DELETE | SHCNE_UPDATEITEM,
        UM_FILE_CHANGED,
        1,
        &notifyEntry
    );

    if (uId != 0)
    {
        m_registerIDs.emplace(fileName, uId);
    }

    return (uId != 0);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions