PageRenderTime 32ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/win32/shellext/Direntry.cpp

https://bitbucket.org/tortoisehg/hgtk/
C++ | 71 lines | 42 code | 14 blank | 15 comment | 7 complexity | 24fee94a2cbea06f61323a2590d4b181 MD5 | raw file
Possible License(s): GPL-2.0
  1. // Copyright (C) 2009 Benjamin Pollack
  2. // Copyright (C) 2009 Adrian Buehlmann
  3. //
  4. // This program is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation, either version 2 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // This program is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU General Public License
  15. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. #include "stdafx.h"
  17. #include "Direntry.h"
  18. #include "Winstat.h"
  19. int Direntry::read(FILE* f, std::vector<char>& relpath)
  20. {
  21. if (fread(&state, sizeof(state), 1, f) != 1)
  22. return 0;
  23. unsigned length = 0;
  24. fread(&mode, sizeof(mode), 1, f);
  25. fread(&size, sizeof(size), 1, f);
  26. fread(&mtime, sizeof(mtime), 1, f);
  27. fread(&length, sizeof(length), 1, f);
  28. mode = ntohl(mode);
  29. size = ntohl(size);
  30. mtime = ntohl(mtime);
  31. length = ntohl(length);
  32. relpath.resize(length + 1, 0);
  33. fread(&relpath[0], sizeof(char), length, f);
  34. relpath[length] = 0;
  35. ::CharLowerBuff(&relpath[0], length);
  36. return 1;
  37. }
  38. char Direntry::status(const Winstat& stat) const
  39. {
  40. switch (this->state)
  41. {
  42. case 'n':
  43. if (this->size != (unsigned)stat.size)
  44. return 'M'; // modified
  45. if (this->mtime == (unsigned)stat.mtime)
  46. return 'C'; // clean
  47. return 'P'; // must peek into file contents
  48. case 'm':
  49. return 'M';
  50. case 'r':
  51. return 'R';
  52. case 'a':
  53. return 'A';
  54. default:
  55. return '?';
  56. }
  57. }