Skip to content

Commit 4d6a74e

Browse files
committed
Update
1 parent 8333137 commit 4d6a74e

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

src/Files.App.Storage/Storables/WindowsStorage/WindowsFolderWatcher.cs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ public unsafe partial class WindowsFolderWatcher : IFolderWatcher
2222
private const uint WM_FOLDERWATCHER = PInvoke.WM_APP | 0x0001U;
2323
private readonly WNDPROC _wndProc;
2424

25-
private uint _registrationID = 0U;
26-
private ITEMIDLIST* _pidl = default;
25+
private uint _watcherRegID = 0U;
26+
private ITEMIDLIST* _targetItemPIDL = default;
2727

2828
// Properties
2929

@@ -43,14 +43,13 @@ public WindowsFolderWatcher(WindowsFolder folder)
4343
{
4444
Folder = folder;
4545

46-
_wndProc = new(WndProc);
47-
var pfnWndProc = (delegate* unmanaged[Stdcall]<HWND, uint, WPARAM, LPARAM, LRESULT>)Marshal.GetFunctionPointerForDelegate(_wndProc);
48-
4946
fixed (char* pszClassName = $"FolderWatcherWindowClass{Guid.NewGuid():B}")
5047
{
48+
_wndProc = new(WndProc);
49+
5150
WNDCLASSEXW wndClass = default;
5251
wndClass.cbSize = (uint)sizeof(WNDCLASSEXW);
53-
wndClass.lpfnWndProc = pfnWndProc;
52+
wndClass.lpfnWndProc = (delegate* unmanaged[Stdcall]<HWND, uint, WPARAM, LPARAM, LRESULT>)Marshal.GetFunctionPointerForDelegate(_wndProc);
5453
wndClass.hInstance = PInvoke.GetModuleHandle(default(PWSTR));
5554
wndClass.lpszClassName = pszClassName;
5655

@@ -70,20 +69,20 @@ private unsafe LRESULT WndProc(HWND hWnd, uint uMessage, WPARAM wParam, LPARAM l
7069
ITEMIDLIST* pidl = default;
7170
IWindowsFolder folder = (IWindowsFolder)Folder;
7271
PInvoke.SHGetIDListFromObject((IUnknown*)folder.ThisPtr.Get(), &pidl);
73-
_pidl = pidl;
72+
_targetItemPIDL = pidl;
7473

7574
SHChangeNotifyEntry changeNotifyEntry = default;
7675
changeNotifyEntry.pidl = pidl;
7776

78-
_registrationID = PInvoke.SHChangeNotifyRegister(
77+
_watcherRegID = PInvoke.SHChangeNotifyRegister(
7978
hWnd,
8079
SHCNRF_SOURCE.SHCNRF_ShellLevel | SHCNRF_SOURCE.SHCNRF_NewDelivery,
8180
(int)SHCNE_ID.SHCNE_ALLEVENTS,
8281
WM_FOLDERWATCHER,
8382
1,
8483
&changeNotifyEntry);
8584

86-
if (_registrationID is 0U)
85+
if (_watcherRegID is 0U)
8786
break;
8887
}
8988
break;
@@ -113,8 +112,8 @@ private unsafe LRESULT WndProc(HWND hWnd, uint uMessage, WPARAM wParam, LPARAM l
113112

114113
public void Dispose()
115114
{
116-
PInvoke.SHChangeNotifyDeregister(_registrationID);
117-
PInvoke.CoTaskMemFree(_pidl);
115+
PInvoke.SHChangeNotifyDeregister(_watcherRegID);
116+
PInvoke.CoTaskMemFree(_targetItemPIDL);
118117
PInvoke.CoUninitialize();
119118
PInvoke.PostQuitMessage(0);
120119
}

0 commit comments

Comments
 (0)