diff --git a/gral.h b/gral.h index acc2b8f..4bcf42c 100644 --- a/gral.h +++ b/gral.h @@ -181,6 +181,7 @@ void gral_file_remove(char const *path); void gral_directory_create(char const *path); void gral_directory_iterate(char const *path, void (*callback)(char const *name, void *user_data), void *user_data); void gral_directory_remove(char const *path); +void gral_directory_monitor(char const *path, void (*callback)(void *user_data), void *user_data); /*========= diff --git a/gral_linux.c b/gral_linux.c index e5d9648..d7a81f2 100644 --- a/gral_linux.c +++ b/gral_linux.c @@ -768,6 +768,10 @@ void gral_directory_remove(char const *path) { rmdir(path); } +void gral_directory_monitor(char const *path, void (*callback)(void *user_data), void *user_data) { + // TODO: implement +} + /*========= TIME diff --git a/gral_macos.m b/gral_macos.m index 47a8a8f..c14f9e7 100644 --- a/gral_macos.m +++ b/gral_macos.m @@ -803,6 +803,10 @@ void gral_directory_remove(char const *path) { rmdir(path); } +void gral_directory_monitor(char const *path, void (*callback)(void *user_data), void *user_data) { + // TODO: implement +} + /*========= TIME diff --git a/gral_windows.cpp b/gral_windows.cpp index f38f0dc..056290b 100644 --- a/gral_windows.cpp +++ b/gral_windows.cpp @@ -1171,6 +1171,22 @@ void gral_directory_remove(char const *path) { RemoveDirectory(utf8_to_utf16(path)); } +struct DirectoryMonitor { + OVERLAPPED overlapped; + FILE_NOTIFY_INFORMATION buffer[128]; +}; + +static void directory_monitor_callback(DWORD dwErrorCode, DWORD dwNumberOfBytesTransfered, LPOVERLAPPED lpOverlapped) { + DirectoryMonitor *monitor = (DirectoryMonitor *)lpOverlapped; +} + +void gral_directory_monitor(char const *path, void (*callback)(void *user_data), void *user_data) { + DirectoryMonitor *monitor = new DirectoryMonitor(); + HANDLE directory = CreateFile(utf8_to_utf16(path), FILE_LIST_DIRECTORY, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OVERLAPPED, NULL); + ReadDirectoryChangesW(directory, monitor->buffer, sizeof(monitor->buffer), FALSE, FILE_NOTIFY_CHANGE_FILE_NAME, NULL, &monitor->overlapped, directory_monitor_callback); + CloseHandle(directory); +} + /*========= TIME