haskell / win32

Haskell support for the Win32 API
http://hackage.haskell.org/package/Win32
Other
98 stars 62 forks source link

Expose `FindData` struct #205

Open hasufell opened 2 years ago

hasufell commented 2 years ago

Expose FindData struct: https://docs.microsoft.com/en-us/windows/win32/api/minwinbase/ns-minwinbase-win32_find_dataa

typedef struct _WIN32_FIND_DATAW {
  DWORD    dwFileAttributes;
  FILETIME ftCreationTime;
  FILETIME ftLastAccessTime;
  FILETIME ftLastWriteTime;
  DWORD    nFileSizeHigh;
  DWORD    nFileSizeLow;
  DWORD    dwReserved0;
  DWORD    dwReserved1;
  WCHAR    cFileName[MAX_PATH];
  WCHAR    cAlternateFileName[14];
  DWORD    dwFileType; // Obsolete. Do not use.
  DWORD    dwCreatorType; // Obsolete. Do not use
  WORD     wFinderFlags; // Obsolete. Do not use
} WIN32_FIND_DATAW, *PWIN32_FIND_DATAW, *LPWIN32_FIND_DATAW;

Otherwise it's hard to determine file-type efficiently when using findFirstFile/findNextFile: https://hackage.haskell.org/package/Win32-2.13.2.0/docs/System-Win32-File.html#v:findFirstFile

hasufell commented 4 months ago

ping @Mistuke

Mistuke commented 4 months ago

Ah I missed this, I'm on holiday atm and will do it when I'm back in two weeks.

hasufell commented 4 months ago

The comment in the struct for dwFileType seem to say:

Obsolete. Do not use

What else do we use without incurring another syscall?

Mistuke commented 3 months ago

The comment in the struct for dwFileType seem to say:

Obsolete. Do not use

Those entries never existed on Windows. This is a documentation bug, if you look in the windows sdk headers, they're guarded by _MAC. i.e. they only ever worked on MACOS from the early days of Microsoft and Apple.

It's just that MSDN seems to render them that way. the mingw-w64 headers for instance don't even contain them

https://github.com/Alexpux/mingw-w64/blob/master/mingw-w64-headers/include/minwinbase.h#L61

What else do we use without incurring another syscall?

It's not entirely clear to me what dwFileType actually contained.. Is what you're after in https://learn.microsoft.com/en-us/windows/win32/fileio/file-attribute-constants? i.e. dwFileAttributes.

hasufell commented 3 months ago

If dwFileAttributes allows us to determine the file type, then that will be enough.