1
1
// Copyright (c) Files Community
2
2
// Licensed under the MIT License.
3
3
4
- using OwlCore . Storage ;
5
- using System . Collections . Concurrent ;
6
4
using System . Collections . Specialized ;
7
- using System . Runtime . CompilerServices ;
8
5
using System . Runtime . InteropServices ;
9
- using System . Threading ;
10
6
using Windows . Win32 ;
11
7
using Windows . Win32 . Foundation ;
12
- using Windows . Win32 . Graphics . Gdi ;
13
8
using Windows . Win32 . System . Com ;
14
9
using Windows . Win32 . UI . Shell ;
15
10
using Windows . Win32 . UI . Shell . Common ;
16
11
using Windows . Win32 . UI . WindowsAndMessaging ;
17
12
18
13
namespace Files . App . Storage
19
14
{
15
+ /// <summary>
16
+ /// Represents an implementation of <see cref="IFolderWatcher"/> that uses Windows Shell notifications to watch for changes in a folder.
17
+ /// </summary>
20
18
public unsafe partial class WindowsFolderWatcher : IFolderWatcher
21
19
{
22
20
// Fields
23
21
24
- private const uint WM_SHFLDRWATCHER = PInvoke . WM_APP | 0x0001U ;
22
+ private const uint WM_FOLDERWATCHER = PInvoke . WM_APP | 0x0001U ;
25
23
private readonly WNDPROC _wndProc ;
26
24
27
25
private uint _registrationID = 0U ;
@@ -37,12 +35,14 @@ public unsafe partial class WindowsFolderWatcher : IFolderWatcher
37
35
38
36
// Constructor
39
37
38
+ /// <summary>
39
+ /// Initializes a new instance of the <see cref="WindowsFolderWatcher"/> class.
40
+ /// </summary>
41
+ /// <param name="folder">Specifies the folder to be monitored for changes.</param>
40
42
public WindowsFolderWatcher ( WindowsFolder folder )
41
43
{
42
44
Folder = folder ;
43
45
44
- HINSTANCE hInst = PInvoke . GetModuleHandle ( default ( PWSTR ) ) ;
45
-
46
46
_wndProc = new ( WndProc ) ;
47
47
var pfnWndProc = ( delegate * unmanaged[ Stdcall] < HWND , uint , WPARAM , LPARAM , LRESULT > ) Marshal . GetFunctionPointerForDelegate ( _wndProc ) ;
48
48
@@ -51,11 +51,11 @@ public WindowsFolderWatcher(WindowsFolder folder)
51
51
WNDCLASSEXW wndClass = default ;
52
52
wndClass . cbSize = ( uint ) sizeof ( WNDCLASSEXW ) ;
53
53
wndClass . lpfnWndProc = pfnWndProc ;
54
- wndClass . hInstance = hInst ;
54
+ wndClass . hInstance = PInvoke . GetModuleHandle ( default ( PWSTR ) ) ; ;
55
55
wndClass . lpszClassName = pszClassName ;
56
56
57
57
PInvoke . RegisterClassEx ( & wndClass ) ;
58
- PInvoke . CreateWindowEx ( 0 , pszClassName , null , 0 , 0 , 0 , 0 , 0 , HWND . HWND_MESSAGE , default , hInst , null ) ;
58
+ PInvoke . CreateWindowEx ( 0 , pszClassName , null , 0 , 0 , 0 , 0 , 0 , HWND . HWND_MESSAGE , default , wndClass . hInstance , null ) ;
59
59
}
60
60
}
61
61
@@ -79,15 +79,15 @@ private unsafe LRESULT WndProc(HWND hWnd, uint uMessage, WPARAM wParam, LPARAM l
79
79
hWnd ,
80
80
SHCNRF_SOURCE . SHCNRF_ShellLevel | SHCNRF_SOURCE . SHCNRF_NewDelivery ,
81
81
( int ) SHCNE_ID . SHCNE_ALLEVENTS ,
82
- PInvoke . WM_APP | 1 ,
82
+ WM_FOLDERWATCHER ,
83
83
1 ,
84
84
& changeNotifyEntry ) ;
85
85
86
86
if ( _registrationID is 0U )
87
87
break ;
88
88
}
89
89
break ;
90
- case PInvoke . WM_APP | 1 :
90
+ case WM_FOLDERWATCHER :
91
91
{
92
92
ITEMIDLIST * * ppidl ;
93
93
int lEvent = 0 ;
0 commit comments