1 /*
2  * PROJECT:     shell32
3  * LICENSE:     LGPL-2.1-or-later (https://spdx.org/licenses/LGPL-2.1-or-later)
4  * PURPOSE:     Shell change notification
5  * COPYRIGHT:   Copyright 2020 Katayama Hirofumi MZ (katayama.hirofumi.mz@gmail.com)
6  */
7 #pragma once
8 
9 #include "CDirectoryList.h"
10 
11 // NOTE: Regard to asynchronous procedure call (APC), please see:
12 // https://docs.microsoft.com/en-us/windows/win32/api/synchapi/nf-synchapi-sleepex
13 
14 class CDirectoryWatcher
15 {
16 public:
17     HANDLE m_hDirectory;
18     WCHAR m_szDirectoryPath[MAX_PATH];
19 
20     static CDirectoryWatcher *Create(HWND hNotifyWnd, LPCWSTR pszDirectoryPath, BOOL fSubTree);
21     static void RequestAllWatchersTermination();
22     ~CDirectoryWatcher();
23 
24     BOOL IsDead();
25     BOOL RestartWatching();
26     void QuitWatching();
27     BOOL RequestAddWatcher();
28     BOOL RequestTermination();
29     void ReadCompletion(DWORD dwErrorCode, DWORD dwNumberOfBytesTransfered);
30 
31 protected:
32     HWND m_hNotifyWnd;
33     BOOL m_fDead;
34     BOOL m_fRecursive;
35     CDirectoryList m_dir_list;
36     OVERLAPPED m_overlapped;
37 
38     BOOL CreateAPCThread();
39     void ProcessNotification();
40     CDirectoryWatcher(HWND hNotifyWnd, LPCWSTR pszDirectoryPath, BOOL fSubTree);
41 };
42