dirmon.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*-------------------------------------------------------------------------
  2. * DirMon.h
  3. *
  4. * The definitions, etc. for a class that helps monitor a directory for
  5. * file changes.
  6. *
  7. * Author: MarkSn
  8. * Owner:
  9. *
  10. * Copyright 1986-1998 Microsoft Corporation, All Rights Reserved
  11. *-----------------------------------------------------------------------*/
  12. #ifdef _DIRMON_H
  13. #error dirmon.h included twice
  14. #endif
  15. #define _DIRMON_H
  16. // ** Stuff for monitoring the directory
  17. struct FileChangeInfo
  18. {
  19. char * szFileName;
  20. FILETIME ftLastWriteTime;
  21. unsigned long cFileSize;
  22. };
  23. typedef bool (*LPIFFCIPROC) (FileChangeInfo*, void*);
  24. class DirectoryMonitor
  25. {
  26. private:
  27. HANDLE m_hDir;
  28. HANDLE m_hCompPort;
  29. OVERLAPPED m_overlapped;
  30. FILETIME m_ftLastWriteTime;
  31. char * m_pFileNamesBuffer; // allocation of memory for filenames in FileChangeInfo
  32. FileChangeInfo* m_pNewestFileCached;
  33. private:
  34. bool FilterFile(WIN32_FIND_DATA & finddata);
  35. protected:
  36. char m_szDir[MAX_PATH]; // directory where files to be watched are located
  37. char m_szDirWithSpec[MAX_PATH]; // same as m_szDir, but with file spec on the end
  38. int m_cFiles; // number of file info structs in m_pargFiles
  39. FileChangeInfo* m_pargFiles; // array of m_cFiles FileChangeInfo structs
  40. int m_nPollInterval; // number of ms to wait between checks for changes
  41. public:
  42. enum { edmNewerThan=1, edmEqualTo=2, edmOlderThan=4 };
  43. DirectoryMonitor();
  44. virtual ~DirectoryMonitor();
  45. BOOL SetupMonitor(LPCSTR szDir, int nPollingInterval);
  46. void CheckForFileChanges();
  47. bool IterateFiles(int nType, FILETIME* pft, LPIFFCIPROC FileChangeCallback, void* pData);
  48. FileChangeInfo* GetNewestFile();
  49. FileChangeInfo* GetOldestFile();
  50. };