/win32/shellext/Winstat.cpp

https://bitbucket.org/tortoisehg/hgtk/ · C++ · 42 lines · 19 code · 9 blank · 14 comment · 3 complexity · e0d23e5ebcf513c68f139e92dbc6bd01 MD5 · raw file

  1. // Copyright (C) 2009 Benjamin Pollack
  2. //
  3. // This program is free software: you can redistribute it and/or modify
  4. // it under the terms of the GNU General Public License as published by
  5. // the Free Software Foundation, either version 2 of the License, or
  6. // (at your option) any later version.
  7. //
  8. // This program is distributed in the hope that it will be useful,
  9. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. // GNU General Public License for more details.
  12. //
  13. // You should have received a copy of the GNU General Public License
  14. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. #include "stdafx.h"
  16. #include "Winstat.h"
  17. int Winstat::lstat(const char* file)
  18. {
  19. const __int64 days_between_epochs = 134774L; /* days between 1.1.1601 and 1.1.1970 */
  20. const __int64 secs_between_epochs = (__int64)days_between_epochs * 86400L;
  21. const __int64 divisor = 10000000L;
  22. WIN32_FIND_DATAA data;
  23. HANDLE hfind;
  24. hfind = FindFirstFileA(file, &data);
  25. if (hfind == INVALID_HANDLE_VALUE)
  26. return -1;
  27. FindClose(hfind);
  28. this->mtime = (((__int64)data.ftLastWriteTime.dwHighDateTime << 32) +
  29. data.ftLastWriteTime.dwLowDateTime) / divisor - secs_between_epochs;
  30. this->size = ((__int64)data.nFileSizeHigh << 32) + data.nFileSizeLow;
  31. this->isdir = (data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0;
  32. return 0;
  33. }