fileChanged.cpp 811 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #include "fileChanged.h"
  2. namespace pika
  3. {
  4. void FileChanged::setFile(const char *path)
  5. {
  6. this->path = path;
  7. WIN32_FILE_ATTRIBUTE_DATA Data = {};
  8. if (GetFileAttributesEx(path, GetFileExInfoStandard, &Data))
  9. {
  10. time = Data.ftLastWriteTime;
  11. }
  12. else
  13. {
  14. time = {};
  15. }
  16. }
  17. bool FileChanged::changed()
  18. {
  19. if (time.dwHighDateTime == 0
  20. && time.dwLowDateTime == 0)
  21. {
  22. return 0;
  23. }
  24. if (path.empty()) { return 0; }
  25. WIN32_FILE_ATTRIBUTE_DATA Data = {};
  26. if (GetFileAttributesEx(path.string().c_str(), GetFileExInfoStandard, &Data))
  27. {
  28. if (time.dwHighDateTime == Data.ftLastWriteTime.dwHighDateTime
  29. && time.dwLowDateTime == Data.ftLastWriteTime.dwLowDateTime)
  30. {
  31. return 0;
  32. }
  33. else
  34. {
  35. time = Data.ftLastWriteTime;
  36. return 1;
  37. }
  38. }
  39. return 0;
  40. }
  41. };