Advertisement
Tkap1

Untitled

Jul 27th, 2022 (edited)
958
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.74 KB | None | 0 0
  1.  
  2.  
  3. // do this once somehwere
  4. CreateThread(
  5.             NULL,
  6.             0,
  7.             watch_for_changes_in_the_variables_file,
  8.             NULL,
  9.             0,
  10.             NULL
  11.         );
  12.  
  13.  
  14. func s32 WINAPI watch_for_changes_in_the_variables_file(void* param)
  15. {
  16.     HANDLE file = CreateFileA(
  17.         ".",
  18.         GENERIC_READ,
  19.         FILE_SHARE_READ | FILE_SHARE_WRITE,
  20.         NULL,
  21.         OPEN_EXISTING,
  22.         FILE_FLAG_BACKUP_SEMANTICS,
  23.         NULL
  24.     );
  25.  
  26.     FILE_NOTIFY_INFORMATION buffer[16] = ZERO;
  27.     s32 bytes_returned;
  28.  
  29.     while(true)
  30.     {
  31.         ReadDirectoryChangesW(
  32.             file,
  33.             buffer,
  34.             sizeof(buffer),
  35.             false,
  36.             FILE_NOTIFY_CHANGE_LAST_WRITE,
  37.             &bytes_returned,
  38.             NULL,
  39.             NULL
  40.         );
  41.  
  42.         if(wcscmp(L"variables.txt", buffer[0].FileName) == 0)
  43.         {
  44.             read_hot_reload_variables();
  45.         }
  46.     }
  47.  
  48.     return 0;
  49.  
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement