11// Copyright (c) Files Community
22// Licensed under the MIT License.
33
4- using OwlCore . Storage ;
5- using System . Collections . Concurrent ;
64using System . Collections . Specialized ;
7- using System . Runtime . CompilerServices ;
85using System . Runtime . InteropServices ;
9- using System . Threading ;
106using Windows . Win32 ;
117using Windows . Win32 . Foundation ;
12- using Windows . Win32 . Graphics . Gdi ;
138using Windows . Win32 . System . Com ;
149using Windows . Win32 . UI . Shell ;
1510using Windows . Win32 . UI . Shell . Common ;
1611using Windows . Win32 . UI . WindowsAndMessaging ;
1712
1813namespace Files . App . Storage
1914{
15+ /// <summary>
16+ /// Represents an implementation of <see cref="IFolderWatcher"/> that uses Windows Shell notifications to watch for changes in a folder.
17+ /// </summary>
2018 public unsafe partial class WindowsFolderWatcher : IFolderWatcher
2119 {
2220 // Fields
2321
24- private const uint WM_SHFLDRWATCHER = PInvoke . WM_APP | 0x0001U ;
22+ private const uint WM_FOLDERWATCHER = PInvoke . WM_APP | 0x0001U ;
2523 private readonly WNDPROC _wndProc ;
2624
2725 private uint _registrationID = 0U ;
@@ -37,12 +35,14 @@ public unsafe partial class WindowsFolderWatcher : IFolderWatcher
3735
3836 // Constructor
3937
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>
4042 public WindowsFolderWatcher ( WindowsFolder folder )
4143 {
4244 Folder = folder ;
4345
44- HINSTANCE hInst = PInvoke . GetModuleHandle ( default ( PWSTR ) ) ;
45-
4646 _wndProc = new ( WndProc ) ;
4747 var pfnWndProc = ( delegate * unmanaged[ Stdcall] < HWND , uint , WPARAM , LPARAM , LRESULT > ) Marshal . GetFunctionPointerForDelegate ( _wndProc ) ;
4848
@@ -51,11 +51,11 @@ public WindowsFolderWatcher(WindowsFolder folder)
5151 WNDCLASSEXW wndClass = default ;
5252 wndClass . cbSize = ( uint ) sizeof ( WNDCLASSEXW ) ;
5353 wndClass . lpfnWndProc = pfnWndProc ;
54- wndClass . hInstance = hInst ;
54+ wndClass . hInstance = PInvoke . GetModuleHandle ( default ( PWSTR ) ) ; ;
5555 wndClass . lpszClassName = pszClassName ;
5656
5757 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 ) ;
5959 }
6060 }
6161
@@ -79,15 +79,15 @@ private unsafe LRESULT WndProc(HWND hWnd, uint uMessage, WPARAM wParam, LPARAM l
7979 hWnd ,
8080 SHCNRF_SOURCE . SHCNRF_ShellLevel | SHCNRF_SOURCE . SHCNRF_NewDelivery ,
8181 ( int ) SHCNE_ID . SHCNE_ALLEVENTS ,
82- PInvoke . WM_APP | 1 ,
82+ WM_FOLDERWATCHER ,
8383 1 ,
8484 & changeNotifyEntry ) ;
8585
8686 if ( _registrationID is 0U )
8787 break ;
8888 }
8989 break ;
90- case PInvoke . WM_APP | 1 :
90+ case WM_FOLDERWATCHER :
9191 {
9292 ITEMIDLIST * * ppidl ;
9393 int lEvent = 0 ;
0 commit comments