3636#include < string>
3737#include " scope_exit.h"
3838
39- template <typename EF>
40- class scope_exit
41- {
42- EF exit_func;
43-
44- public:
45- scope_exit (EF&& exit_func) : exit_func{ exit_func } {};
46- ~scope_exit ()
47- {
48- exit_func ();
49- }
50- };
51-
52- #define SCOPE_EXIT (x, action, ...) scope_exit x##_se([x, __VA_ARGS__] action);
53-
54- template <typename T>
55- static DWORD RegistryGetVal (PCWSTR SubKey, PCWSTR ValueName, T& Value)
39+ template <typename T> static DWORD RegistryGetVal (PCWSTR SubKey, PCWSTR ValueName, T &Value)
5640{
5741 LSTATUS Status;
5842 DWORD Val;
5943 DWORD ValSize = sizeof (Val);
6044
61- Status = RegGetValueW (HKEY_LOCAL_MACHINE, SubKey, ValueName,
62- RRF_RT_REG_DWORD, NULL , &Val, &ValSize);
45+ Status = RegGetValueW (HKEY_LOCAL_MACHINE, SubKey, ValueName, RRF_RT_REG_DWORD, NULL , &Val, &ValSize);
6346 if (Status == ERROR_SUCCESS)
6447 {
6548 Value = Val;
@@ -68,15 +51,14 @@ static DWORD RegistryGetVal(PCWSTR SubKey, PCWSTR ValueName, T& Value)
6851 return Status;
6952}
7053
71- static DWORD RegistryGetVal (PCWSTR SubKey, PCWSTR ValueName, std::wstring& Value)
54+ static DWORD RegistryGetVal (PCWSTR SubKey, PCWSTR ValueName, std::wstring & Value)
7255{
7356 LSTATUS Status;
7457 DWORD BufSize = 0 ;
7558 std::unique_ptr<WCHAR[]> Buf;
7659
7760 // Determine required buffer size
78- Status = RegGetValueW (HKEY_LOCAL_MACHINE, SubKey, ValueName,
79- RRF_RT_REG_SZ, NULL , NULL , &BufSize);
61+ Status = RegGetValueW (HKEY_LOCAL_MACHINE, SubKey, ValueName, RRF_RT_REG_SZ, NULL , NULL , &BufSize);
8062 if (Status != ERROR_SUCCESS)
8163 {
8264 return Status;
@@ -91,8 +73,7 @@ static DWORD RegistryGetVal(PCWSTR SubKey, PCWSTR ValueName, std::wstring& Value
9173 return ERROR_NO_SYSTEM_RESOURCES;
9274 }
9375
94- Status = RegGetValueW (HKEY_LOCAL_MACHINE, SubKey, ValueName,
95- RRF_RT_REG_SZ, NULL , Buf.get (), &BufSize);
76+ Status = RegGetValueW (HKEY_LOCAL_MACHINE, SubKey, ValueName, RRF_RT_REG_SZ, NULL , Buf.get (), &BufSize);
9677 if (Status == ERROR_SUCCESS)
9778 {
9879 Value.assign (Buf.get ());
@@ -109,8 +90,7 @@ static DWORD FindDeviceInterface(const GUID *ClassGuid, PHANDLE Device, DWORD Me
10990 PSP_DEVICE_INTERFACE_DETAIL_DATA DevIfaceDetail = NULL ;
11091 ULONG Length, RequiredLength = 0 ;
11192
112- DevInfo = SetupDiGetClassDevs (ClassGuid, NULL , NULL ,
113- (DIGCF_PRESENT | DIGCF_DEVICEINTERFACE));
93+ DevInfo = SetupDiGetClassDevs (ClassGuid, NULL , NULL , (DIGCF_PRESENT | DIGCF_DEVICEINTERFACE));
11494 if (DevInfo == INVALID_HANDLE_VALUE)
11595 {
11696 return GetLastError ();
@@ -119,17 +99,14 @@ static DWORD FindDeviceInterface(const GUID *ClassGuid, PHANDLE Device, DWORD Me
11999
120100 DevIfaceData.cbSize = sizeof (SP_DEVICE_INTERFACE_DATA);
121101
122- if (!SetupDiEnumDeviceInterfaces (DevInfo, 0 ,
123- ClassGuid, MemberIndex, &DevIfaceData))
102+ if (!SetupDiEnumDeviceInterfaces (DevInfo, 0 , ClassGuid, MemberIndex, &DevIfaceData))
124103 {
125104 return GetLastError ();
126105 }
127106
128- SetupDiGetDeviceInterfaceDetail (DevInfo, &DevIfaceData, NULL , 0 ,
129- &RequiredLength, NULL );
107+ SetupDiGetDeviceInterfaceDetail (DevInfo, &DevIfaceData, NULL , 0 , &RequiredLength, NULL );
130108
131- DevIfaceDetail = (PSP_DEVICE_INTERFACE_DETAIL_DATA)LocalAlloc (LMEM_FIXED,
132- RequiredLength);
109+ DevIfaceDetail = (PSP_DEVICE_INTERFACE_DETAIL_DATA)LocalAlloc (LMEM_FIXED, RequiredLength);
133110 if (DevIfaceDetail == NULL )
134111 {
135112 return GetLastError ();
@@ -139,8 +116,7 @@ static DWORD FindDeviceInterface(const GUID *ClassGuid, PHANDLE Device, DWORD Me
139116 DevIfaceDetail->cbSize = sizeof (SP_DEVICE_INTERFACE_DETAIL_DATA);
140117 Length = RequiredLength;
141118
142- if (!SetupDiGetDeviceInterfaceDetail (DevInfo, &DevIfaceData,
143- DevIfaceDetail, Length, &RequiredLength, NULL ))
119+ if (!SetupDiGetDeviceInterfaceDetail (DevInfo, &DevIfaceData, DevIfaceDetail, Length, &RequiredLength, NULL ))
144120 {
145121 return GetLastError ();
146122 }
@@ -149,8 +125,13 @@ static DWORD FindDeviceInterface(const GUID *ClassGuid, PHANDLE Device, DWORD Me
149125 SecurityAttributes.lpSecurityDescriptor = NULL ;
150126 SecurityAttributes.bInheritHandle = FALSE ;
151127
152- *Device = CreateFile (DevIfaceDetail->DevicePath , GENERIC_READ | GENERIC_WRITE,
153- 0 , &SecurityAttributes, OPEN_EXISTING, 0L , NULL );
128+ *Device = CreateFile (DevIfaceDetail->DevicePath ,
129+ GENERIC_READ | GENERIC_WRITE,
130+ 0 ,
131+ &SecurityAttributes,
132+ OPEN_EXISTING,
133+ 0L ,
134+ NULL );
154135 if (*Device == INVALID_HANDLE_VALUE)
155136 {
156137 return GetLastError ();
@@ -159,10 +140,9 @@ static DWORD FindDeviceInterface(const GUID *ClassGuid, PHANDLE Device, DWORD Me
159140 return ERROR_SUCCESS;
160141}
161142
162- static DWORD FindDeviceInterface (const GUID *ClassGuid, PHANDLE Device,
163- std::function<BOOLEAN(HANDLE Device)> cmp_fn)
143+ static DWORD FindDeviceInterface (const GUID *ClassGuid, PHANDLE Device, std::function<BOOLEAN(HANDLE Device)> cmp_fn)
164144{
165- for (DWORD MemberIndex = 0 ; ; MemberIndex++)
145+ for (DWORD MemberIndex = 0 ;; MemberIndex++)
166146 {
167147 DWORD Error = FindDeviceInterface (ClassGuid, Device, MemberIndex);
168148 if (Error != ERROR_SUCCESS)
@@ -210,14 +190,14 @@ static bool FileNameIgnoreCaseCompare(PCWSTR a, const char *b, uint32_t b_len)
210190
211191class DeviceInterfaceNotification
212192{
213- HCMNOTIFICATION Handle{ nullptr };
193+ HCMNOTIFICATION Handle{nullptr };
214194
215- DeviceInterfaceNotification (const DeviceInterfaceNotification&) = delete ;
216- DeviceInterfaceNotification& operator =(const DeviceInterfaceNotification&) = delete ;
217- DeviceInterfaceNotification (DeviceInterfaceNotification&&) = delete ;
218- DeviceInterfaceNotification& operator =(DeviceInterfaceNotification&&) = delete ;
195+ DeviceInterfaceNotification (const DeviceInterfaceNotification &) = delete ;
196+ DeviceInterfaceNotification & operator =(const DeviceInterfaceNotification &) = delete ;
197+ DeviceInterfaceNotification (DeviceInterfaceNotification &&) = delete ;
198+ DeviceInterfaceNotification & operator =(DeviceInterfaceNotification &&) = delete ;
219199
220- public:
200+ public:
221201 DeviceInterfaceNotification () = default ;
222202
223203 DWORD Register (PCM_NOTIFY_CALLBACK pCallback, PVOID pContext, const GUID &ClassGuid)
@@ -249,17 +229,17 @@ class DeviceInterfaceNotification
249229
250230class DeviceHandleNotification
251231{
252- HCMNOTIFICATION Handle{ nullptr };
253- CRITICAL_SECTION Lock;
254- BOOL UnregInProgress{ FALSE };
255- PTP_WORK UnregWork{ nullptr };
232+ HCMNOTIFICATION Handle{nullptr };
233+ CRITICAL_SECTION Lock;
234+ BOOL UnregInProgress{FALSE };
235+ PTP_WORK UnregWork{nullptr };
256236
257- DeviceHandleNotification (const DeviceHandleNotification&) = delete ;
258- DeviceHandleNotification& operator =(const DeviceHandleNotification&) = delete ;
259- DeviceHandleNotification (DeviceHandleNotification&&) = delete ;
260- DeviceHandleNotification& operator =(DeviceHandleNotification&&) = delete ;
237+ DeviceHandleNotification (const DeviceHandleNotification &) = delete ;
238+ DeviceHandleNotification & operator =(const DeviceHandleNotification &) = delete ;
239+ DeviceHandleNotification (DeviceHandleNotification &&) = delete ;
240+ DeviceHandleNotification & operator =(DeviceHandleNotification &&) = delete ;
261241
262- public:
242+ public:
263243 DeviceHandleNotification ()
264244 {
265245 InitializeCriticalSection (&Lock);
@@ -338,8 +318,7 @@ class DeviceHandleNotification
338318
339319 bool CreateUnregWork ()
340320 {
341- auto cb = [](PTP_CALLBACK_INSTANCE Instance, PVOID Context, PTP_WORK Work)
342- {
321+ auto cb = [](PTP_CALLBACK_INSTANCE Instance, PVOID Context, PTP_WORK Work) {
343322 auto Notification = static_cast <DeviceHandleNotification *>(Context);
344323
345324 UNREFERENCED_PARAMETER (Instance);
@@ -358,12 +337,12 @@ class DeviceHandleNotification
358337 }
359338};
360339
361- static bool ParseIds (const std::wstring& ids, uint32_t & uid, uint32_t & gid)
340+ static bool ParseIds (const std::wstring & ids, uint32_t & uid, uint32_t & gid)
362341{
363342 return (swscanf_s (ids.c_str (), L" %u:%u" , &uid, &gid) == 2 );
364343}
365344
366- static bool CheckIds (const std::wstring& ids)
345+ static bool CheckIds (const std::wstring & ids)
367346{
368347 uint32_t uid, gid;
369348
0 commit comments