77
88"""
99
10- import ctypes
10+ from ctypes import *
1111
1212try :
13- DokanMain = ctypes . windll .Dokan1 .DokanMain
14- DokanVersion = ctypes . windll .Dokan1 .DokanVersion
13+ DokanMain = windll .Dokan1 .DokanMain
14+ DokanVersion = windll .Dokan1 .DokanVersion
1515except AttributeError :
1616 raise ImportError ("Dokan DLL not found" )
1717
1818
1919from ctypes .wintypes import *
20- ULONG64 = ctypes . c_ulonglong
21- PULONGLONG = ctypes . POINTER (ctypes . c_ulonglong )
22- PVOID = ctypes . c_void_p
23- PULONG = ctypes . POINTER (ctypes . c_ulong )
24- UCHAR = ctypes . c_ubyte
25- LPDWORD = ctypes . POINTER (ctypes . c_ulong )
26- LONGLONG = ctypes . c_longlong
27- NTSTATUS = ctypes . c_long
28- USHORT = ctypes . c_ushort
29- WCHAR = ctypes . c_wchar
20+ ULONG64 = c_ulonglong
21+ PULONGLONG = POINTER (c_ulonglong )
22+ PVOID = c_void_p
23+ PULONG = POINTER (c_ulong )
24+ UCHAR = c_ubyte
25+ LPDWORD = POINTER (c_ulong )
26+ LONGLONG = c_longlong
27+ NTSTATUS = c_long
28+ USHORT = c_ushort
29+ WCHAR = c_wchar
3030
3131
3232DokanVersion .restype = ULONG
3838
3939MAX_PATH = 260
4040
41- class SECURITY_DESCRIPTOR (ctypes . Structure ): pass
41+ class SECURITY_DESCRIPTOR (Structure ): pass
4242
43- PSECURITY_DESCRIPTOR = ctypes . POINTER (SECURITY_DESCRIPTOR )
44- PPSECURITY_DESCRIPTOR = ctypes . POINTER (PSECURITY_DESCRIPTOR )
43+ PSECURITY_DESCRIPTOR = POINTER (SECURITY_DESCRIPTOR )
44+ PPSECURITY_DESCRIPTOR = POINTER (PSECURITY_DESCRIPTOR )
4545
4646SECURITY_INFORMATION = DWORD
47- PSECURITY_INFORMATION = ctypes . POINTER (SECURITY_INFORMATION )
47+ PSECURITY_INFORMATION = POINTER (SECURITY_INFORMATION )
4848
49- class FILETIME (ctypes . Structure ):
49+ class FILETIME (Structure ):
5050 _fields_ = [
5151 ("dwLowDateTime" , DWORD ),
5252 ("dwHighDateTime" , DWORD ),
5353 ]
5454
5555
56- class WIN32_FIND_DATAW (ctypes . Structure ):
56+ class WIN32_FIND_DATAW (Structure ):
5757 _fields_ = [
5858 ("dwFileAttributes" , DWORD ),
5959 ("ftCreationTime" , FILETIME ),
@@ -68,7 +68,7 @@ class WIN32_FIND_DATAW(ctypes.Structure):
6868 ]
6969
7070
71- class BY_HANDLE_FILE_INFORMATION (ctypes . Structure ):
71+ class BY_HANDLE_FILE_INFORMATION (Structure ):
7272 _fields_ = [
7373 ('dwFileAttributes' , DWORD ),
7474 ('ftCreationTime' , FILETIME ),
@@ -83,7 +83,7 @@ class BY_HANDLE_FILE_INFORMATION(ctypes.Structure):
8383 ]
8484
8585
86- class DOKAN_OPTIONS (ctypes . Structure ):
86+ class DOKAN_OPTIONS (Structure ):
8787 _fields_ = [
8888 ("Version" , USHORT ),
8989 ("ThreadCount" , USHORT ),
@@ -97,11 +97,11 @@ class DOKAN_OPTIONS(ctypes.Structure):
9797 ]
9898
9999
100- class DOKAN_FILE_INFO (ctypes . Structure ):
100+ class DOKAN_FILE_INFO (Structure ):
101101 _fields_ = [
102102 ("Context" , ULONG64 ),
103103 ("DokanContext" , ULONG64 ),
104- ("DokanOptions" , ctypes . POINTER (DOKAN_OPTIONS )),
104+ ("DokanOptions" , POINTER (DOKAN_OPTIONS )),
105105 ("ProcessId" , ULONG ),
106106 ("IsDirectory" , UCHAR ),
107107 ("DeleteOnClose" , UCHAR ),
@@ -112,13 +112,13 @@ class DOKAN_FILE_INFO(ctypes.Structure):
112112 ]
113113
114114
115- PDOKAN_FILE_INFO = ctypes . POINTER (DOKAN_FILE_INFO )
116- PFillFindData = ctypes . WINFUNCTYPE (ctypes . c_int , ctypes . POINTER (WIN32_FIND_DATAW ), PDOKAN_FILE_INFO )
115+ PDOKAN_FILE_INFO = POINTER (DOKAN_FILE_INFO )
116+ PFillFindData = WINFUNCTYPE (c_int , POINTER (WIN32_FIND_DATAW ), PDOKAN_FILE_INFO )
117117
118118
119- class DOKAN_OPERATIONS (ctypes . Structure ):
119+ class DOKAN_OPERATIONS (Structure ):
120120 _fields_ = [
121- ("ZwCreateFile" , ctypes . WINFUNCTYPE (NTSTATUS ,
121+ ("ZwCreateFile" , WINFUNCTYPE (NTSTATUS ,
122122 LPCWSTR , # FileName
123123 PVOID , # SecurityContext, see
124124 # https://msdn.microsoft.com/en-us/library/windows/hardware/ff550613(v=vs.85).aspx
@@ -128,87 +128,87 @@ class DOKAN_OPERATIONS(ctypes.Structure):
128128 ULONG , # CreateDisposition
129129 ULONG , # CreateOptions
130130 PDOKAN_FILE_INFO )),
131- ("Cleanup" , ctypes . WINFUNCTYPE (None ,
131+ ("Cleanup" , WINFUNCTYPE (None ,
132132 LPCWSTR , # FileName
133133 PDOKAN_FILE_INFO )),
134- ("CloseFile" , ctypes . WINFUNCTYPE (None ,
134+ ("CloseFile" , WINFUNCTYPE (None ,
135135 LPCWSTR , # FileName
136136 PDOKAN_FILE_INFO )),
137- ("ReadFile" , ctypes . WINFUNCTYPE (NTSTATUS ,
137+ ("ReadFile" , WINFUNCTYPE (NTSTATUS ,
138138 LPCWSTR , # FileName
139139 LPVOID , # Buffer
140140 DWORD , # NumberOfBytesToRead
141141 LPDWORD , # NumberOfBytesRead
142142 LONGLONG , # Offset
143143 PDOKAN_FILE_INFO )),
144- ("WriteFile" , ctypes . WINFUNCTYPE (NTSTATUS ,
144+ ("WriteFile" , WINFUNCTYPE (NTSTATUS ,
145145 LPCWSTR , # FileName
146146 LPCVOID , # Buffer
147147 DWORD , # NumberOfBytesToWrite
148148 LPDWORD , # NumberOfBytesWritten
149149 LONGLONG , # Offset
150150 PDOKAN_FILE_INFO )),
151- ("FlushFileBuffers" , ctypes . WINFUNCTYPE (NTSTATUS ,
151+ ("FlushFileBuffers" , WINFUNCTYPE (NTSTATUS ,
152152 LPCWSTR , # FileName
153153 PDOKAN_FILE_INFO )),
154- ("GetFileInformation" , ctypes . WINFUNCTYPE (NTSTATUS ,
154+ ("GetFileInformation" , WINFUNCTYPE (NTSTATUS ,
155155 LPCWSTR , # FileName
156- ctypes . POINTER (BY_HANDLE_FILE_INFORMATION ), # Buffer
156+ POINTER (BY_HANDLE_FILE_INFORMATION ), # Buffer
157157 PDOKAN_FILE_INFO )),
158- ("FindFiles" , ctypes . WINFUNCTYPE (NTSTATUS ,
158+ ("FindFiles" , WINFUNCTYPE (NTSTATUS ,
159159 LPCWSTR , # PathName
160160 PFillFindData , # call this function with PWIN32_FIND_DATAW
161161 PDOKAN_FILE_INFO )),
162- ("FindFilesWithPattern" , ctypes . WINFUNCTYPE (NTSTATUS ,
162+ ("FindFilesWithPattern" , WINFUNCTYPE (NTSTATUS ,
163163 LPCWSTR , # PathName
164164 LPCWSTR , # SearchPattern
165165 PFillFindData , #call this function with PWIN32_FIND_DATAW
166166 PDOKAN_FILE_INFO )),
167- ("SetFileAttributes" , ctypes . WINFUNCTYPE (NTSTATUS ,
167+ ("SetFileAttributes" , WINFUNCTYPE (NTSTATUS ,
168168 LPCWSTR , # FileName
169169 DWORD , # FileAttributes
170170 PDOKAN_FILE_INFO )),
171- ("SetFileTime" , ctypes . WINFUNCTYPE (NTSTATUS ,
171+ ("SetFileTime" , WINFUNCTYPE (NTSTATUS ,
172172 LPCWSTR , # FileName
173- ctypes . POINTER (FILETIME ), # CreationTime
174- ctypes . POINTER (FILETIME ), # LastAccessTime
175- ctypes . POINTER (FILETIME ), # LastWriteTime
173+ POINTER (FILETIME ), # CreationTime
174+ POINTER (FILETIME ), # LastAccessTime
175+ POINTER (FILETIME ), # LastWriteTime
176176 PDOKAN_FILE_INFO )),
177- ("DeleteFile" , ctypes . WINFUNCTYPE (NTSTATUS ,
177+ ("DeleteFile" , WINFUNCTYPE (NTSTATUS ,
178178 LPCWSTR , # FileName
179179 PDOKAN_FILE_INFO )),
180- ("DeleteDirectory" , ctypes . WINFUNCTYPE (NTSTATUS ,
180+ ("DeleteDirectory" , WINFUNCTYPE (NTSTATUS ,
181181 LPCWSTR , # FileName
182182 PDOKAN_FILE_INFO )),
183- ("MoveFile" , ctypes . WINFUNCTYPE (NTSTATUS ,
183+ ("MoveFile" , WINFUNCTYPE (NTSTATUS ,
184184 LPCWSTR , # ExistingFileName
185185 LPCWSTR , # NewFileName
186186 BOOL , # ReplaceExisiting
187187 PDOKAN_FILE_INFO )),
188- ("SetEndOfFile" , ctypes . WINFUNCTYPE (NTSTATUS ,
188+ ("SetEndOfFile" , WINFUNCTYPE (NTSTATUS ,
189189 LPCWSTR , # FileName
190190 LONGLONG , # Length
191191 PDOKAN_FILE_INFO )),
192- ("SetAllocationSize" , ctypes . WINFUNCTYPE (NTSTATUS ,
192+ ("SetAllocationSize" , WINFUNCTYPE (NTSTATUS ,
193193 LPCWSTR , # FileName
194194 LONGLONG , # Length
195195 PDOKAN_FILE_INFO )),
196- ("LockFile" , ctypes . WINFUNCTYPE (NTSTATUS ,
196+ ("LockFile" , WINFUNCTYPE (NTSTATUS ,
197197 LPCWSTR , # FileName
198198 LONGLONG , # ByteOffset
199199 LONGLONG , # Length
200200 PDOKAN_FILE_INFO )),
201- ("UnlockFile" , ctypes . WINFUNCTYPE (NTSTATUS ,
201+ ("UnlockFile" , WINFUNCTYPE (NTSTATUS ,
202202 LPCWSTR , # FileName
203203 LONGLONG , # ByteOffset
204204 LONGLONG , # Length
205205 PDOKAN_FILE_INFO )),
206- ("GetDiskFreeSpace" , ctypes . WINFUNCTYPE (NTSTATUS ,
206+ ("GetDiskFreeSpace" , WINFUNCTYPE (NTSTATUS ,
207207 PULONGLONG , # FreeBytesAvailable
208208 PULONGLONG , # TotalNumberOfBytes
209209 PULONGLONG , # TotalNumberOfFreeBytes
210210 PDOKAN_FILE_INFO )),
211- ("GetVolumeInformation" , ctypes . WINFUNCTYPE (NTSTATUS ,
211+ ("GetVolumeInformation" , WINFUNCTYPE (NTSTATUS ,
212212 PVOID , # VolumeNameBuffer
213213 DWORD , # VolumeNameSize in num of chars
214214 LPDWORD , # VolumeSerialNumber
@@ -217,63 +217,63 @@ class DOKAN_OPERATIONS(ctypes.Structure):
217217 PVOID , # FileSystemNameBuffer
218218 DWORD , # FileSystemNameSize in num of chars
219219 PDOKAN_FILE_INFO )),
220- ("Mounted" , ctypes . WINFUNCTYPE (NTSTATUS ,
220+ ("Mounted" , WINFUNCTYPE (NTSTATUS ,
221221 PDOKAN_FILE_INFO )),
222- ("Unmounted" , ctypes . WINFUNCTYPE (NTSTATUS ,
222+ ("Unmounted" , WINFUNCTYPE (NTSTATUS ,
223223 DOKAN_FILE_INFO )),
224- ("GetFileSecurity" , ctypes . WINFUNCTYPE (NTSTATUS ,
224+ ("GetFileSecurity" , WINFUNCTYPE (NTSTATUS ,
225225 LPCWSTR , # FileName
226226 PULONG , # A pointer to SECURITY_INFORMATION value being requested
227227 PVOID , # A pointer to SECURITY_DESCRIPTOR buffer to be filled
228228 ULONG , # Length of Security descriptor buffer
229229 PULONG , # Length Needed
230230 PDOKAN_FILE_INFO )),
231- ("SetFileSecurity" , ctypes . WINFUNCTYPE (NTSTATUS ,
231+ ("SetFileSecurity" , WINFUNCTYPE (NTSTATUS ,
232232 LPCWSTR , # FileName
233233 PVOID , # A pointer to SECURITY_INFORMATION value being
234234 PVOID , # A pointer to SECURITY_DESCRIPTOR buffer
235235 ULONG , # Length of Security descriptor buffer
236236 PDOKAN_FILE_INFO )),
237- ("FindStreams" , ctypes . WINFUNCTYPE (NTSTATUS ,
237+ ("FindStreams" , WINFUNCTYPE (NTSTATUS ,
238238 LPCWSTR , # FileName
239239 PVOID , # call this function with PWIN32_FIND_STREAM_DATA
240240 PDOKAN_FILE_INFO ))
241241 ]
242242
243243
244- DokanMain .restype = ctypes . c_int
244+ DokanMain .restype = c_int
245245DokanMain .argtypes = (
246- ctypes . POINTER (DOKAN_OPTIONS ),
247- ctypes . POINTER (DOKAN_OPERATIONS ),
246+ POINTER (DOKAN_OPTIONS ),
247+ POINTER (DOKAN_OPERATIONS ),
248248)
249249
250- DokanRemoveMountPoint = ctypes . windll .Dokan1 .DokanRemoveMountPoint
250+ DokanRemoveMountPoint = windll .Dokan1 .DokanRemoveMountPoint
251251DokanRemoveMountPoint .restype = BOOL
252252DokanRemoveMountPoint .argtypes = (
253253 LPCWSTR ,
254254)
255255
256- DokanIsNameInExpression = ctypes . windll .Dokan1 .DokanIsNameInExpression
256+ DokanIsNameInExpression = windll .Dokan1 .DokanIsNameInExpression
257257DokanIsNameInExpression .restype = BOOL
258258DokanIsNameInExpression .argtypes = (
259259 LPCWSTR , # pattern
260260 LPCWSTR , # name
261261 BOOL , # ignore case
262262)
263263
264- DokanDriverVersion = ctypes . windll .Dokan1 .DokanDriverVersion
264+ DokanDriverVersion = windll .Dokan1 .DokanDriverVersion
265265DokanDriverVersion .restype = ULONG
266266DokanDriverVersion .argtypes = (
267267)
268268
269- DokanResetTimeout = ctypes . windll .Dokan1 .DokanResetTimeout
269+ DokanResetTimeout = windll .Dokan1 .DokanResetTimeout
270270DokanResetTimeout .restype = BOOL
271271DokanResetTimeout .argtypes = (
272272 ULONG , #timeout
273273 PDOKAN_FILE_INFO , # file info pointer
274274)
275275
276- GetFileSecurity = ctypes . windll .advapi32 .GetFileSecurityW
276+ GetFileSecurity = windll .advapi32 .GetFileSecurityW
277277GetFileSecurity .restype = BOOL
278278GetFileSecurity .argtypes = (
279279 LPWSTR , # _In_ LPCTSTR lpFileName,
0 commit comments