BsWin32FolderMonitor.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. #pragma once
  2. #include "BsCorePrerequisites.h"
  3. namespace BansheeEngine
  4. {
  5. /**
  6. * @brief These values types of notifications we would like to receive
  7. * when we start a FolderMonitor on a certain folder.
  8. */
  9. enum class FolderChange
  10. {
  11. FileName = 0x0001, /**< Called when filename changes. */
  12. DirName = 0x0002, /**< Called when directory name changes. */
  13. Attributes = 0x0004, /**< Called when attributes changes. */
  14. Size = 0x0008, /**< Called when file size changes. */
  15. LastWrite = 0x0010, /**< Called when file is written to. */
  16. LastAccess = 0x0020, /**< Called when file is accessed. */
  17. Creation = 0x0040, /**< Called when file is created. */
  18. Security = 0x0080 /**< Called when file security descriptor changes. */
  19. };
  20. /**
  21. * @brief Allows you to monitor a file system folder for changes. Depending on the flags
  22. * set this monitor can notify you when file is changed/moved/renamed, etc.
  23. */
  24. class BS_CORE_EXPORT FolderMonitor
  25. {
  26. struct Pimpl;
  27. class FileNotifyInfo;
  28. struct FolderWatchInfo;
  29. public:
  30. FolderMonitor();
  31. ~FolderMonitor();
  32. /**
  33. * @brief Starts monitoring a folder at the specified path.
  34. *
  35. * @param folderPath Absolute path to the folder you want to monitor.
  36. * @param subdirectories If true, provided folder and all of its subdirectories will be monitored
  37. * for changes. Otherwise only the provided folder will be monitored.
  38. * @param changeFilter A set of flags you may OR together. Different notification events will
  39. * trigger depending on which flags you set.
  40. */
  41. void startMonitor(const Path& folderPath, bool subdirectories, FolderChange changeFilter);
  42. /**
  43. * @brief Stops monitoring the folder at the specified path.
  44. */
  45. void stopMonitor(const Path& folderPath);
  46. /**
  47. * @brief Stops monitoring all folders that are currently being monitored.
  48. */
  49. void stopMonitorAll();
  50. /**
  51. * @brief Callbacks will only get fired after update is called().
  52. *
  53. * @note Internal method.
  54. */
  55. void _update();
  56. /**
  57. * @brief Triggers when a file is modified. Provides
  58. * full path to the file.
  59. */
  60. Event<void(const Path&)> onModified;
  61. /**
  62. * @brief Triggers when a file/folder is adeed. Provides
  63. * full path to the file/folder.
  64. */
  65. Event<void(const Path&)> onAdded;
  66. /**
  67. * @brief Triggers when a file/folder is removed. Provides
  68. * full path to the file/folder.
  69. */
  70. Event<void(const Path&)> onRemoved;
  71. /**
  72. * @brief Triggers when a file/folder is renamed. Provides
  73. * full path to the old and new name.
  74. */
  75. Event<void(const Path&, const Path&)> onRenamed;
  76. private:
  77. Pimpl* mPimpl;
  78. /**
  79. * @brief Worker method that monitors the IO ports for any modification notifications.
  80. */
  81. void workerThreadMain();
  82. /**
  83. * @brief Called by the worker thread whenever a modification notification is received.
  84. */
  85. void handleNotifications(FileNotifyInfo& notifyInfo, FolderWatchInfo& watchInfo);
  86. };
  87. }