Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

70 lines
1.9 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================
  6. #ifndef FILECHANGEWATCHER_H
  7. #define FILECHANGEWATCHER_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #include "tier1/utlvector.h"
  12. //-----------------------------------------------------------------------------
  13. // Purpose: This class provides notifications of changes in directories.
  14. // Call AddDirectory to tell it which directories to watch, then
  15. // call Update() periodically to check for updates.
  16. //-----------------------------------------------------------------------------
  17. class CFileChangeWatcher
  18. {
  19. public:
  20. class ICallbacks
  21. {
  22. public:
  23. // Note: this is called if the file is added, removed, or modified. It's up to the app to figure out
  24. // what it wants to do with the change.
  25. virtual void OnFileChange( const char *pRelativeFilename, const char *pFullFilename ) = 0;
  26. };
  27. CFileChangeWatcher();
  28. ~CFileChangeWatcher();
  29. void Init( ICallbacks *pCallbacks );
  30. // pSearchPathBase would be like "c:\valve\hl2" and pDirName would be like "materials".
  31. bool AddDirectory( const char *pSearchPathBase, const char *pDirName, bool bRecursive );
  32. void Term();
  33. // Call this periodically to update. It'll call your ICallbacks functions for anything it finds.
  34. // Returns the number of updates it got.
  35. int Update();
  36. private:
  37. class CDirWatch
  38. {
  39. public:
  40. char m_SearchPathBase[MAX_PATH];
  41. char m_DirName[MAX_PATH];
  42. char m_FullDirName[MAX_PATH];
  43. OVERLAPPED m_Overlapped;
  44. HANDLE m_hEvent;
  45. HANDLE m_hDir; // Created with CreateFile.
  46. char m_Buffer[1024 * 16];
  47. };
  48. void SendNotification( CFileChangeWatcher::CDirWatch *pDirWatch, const char *pRelativeFilename );
  49. BOOL CallReadDirectoryChanges( CFileChangeWatcher::CDirWatch *pDirWatch );
  50. private:
  51. // Override these.
  52. CUtlVector<CDirWatch*> m_DirWatches;
  53. ICallbacks *m_pCallbacks;
  54. };
  55. #endif // FILECHANGEWATCHER_H