BsWin32FolderMonitor.h 3.2 KB

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