MFC64bitFix.cpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. //---------------------------------------------------------------------------
  2. #include "stdafx.h"
  3. __int64 GetLength64(CFile &file)
  4. {
  5. DWORD low;
  6. DWORD high;
  7. low=GetFileSize((void *)file.m_hFile, &high);
  8. _int64 size=((_int64)high<<32)+low;
  9. return size;
  10. }
  11. BOOL GetLength64(CString filename, _int64 &size)
  12. {
  13. WIN32_FIND_DATA findFileData;
  14. HANDLE hFind = FindFirstFile(filename, &findFileData);
  15. if (hFind == INVALID_HANDLE_VALUE)
  16. return FALSE;
  17. DebugCheck(FindClose(hFind));
  18. size=((_int64)findFileData.nFileSizeHigh<<32)+findFileData.nFileSizeLow;
  19. return TRUE;
  20. }
  21. BOOL PASCAL GetStatus64(LPCTSTR lpszFileName, CFileStatus64& rStatus)
  22. {
  23. WIN32_FIND_DATA findFileData;
  24. HANDLE hFind = FindFirstFile((LPTSTR)lpszFileName, &findFileData);
  25. if (hFind == INVALID_HANDLE_VALUE)
  26. {
  27. return FALSE;
  28. }
  29. DebugCheck(FindClose(hFind));
  30. // strip attribute of NORMAL bit, our API doesn't have a "normal" bit.
  31. rStatus.m_attribute = (BYTE)
  32. (findFileData.dwFileAttributes & ~FILE_ATTRIBUTE_NORMAL);
  33. rStatus.m_size = ((_int64)findFileData.nFileSizeHigh<<32)+findFileData.nFileSizeLow;
  34. // convert times as appropriate
  35. TRY
  36. {
  37. rStatus.m_ctime = CTime(findFileData.ftCreationTime);
  38. rStatus.m_has_ctime = true;
  39. }
  40. CATCH_ALL(e)
  41. {
  42. rStatus.m_has_ctime = false;
  43. }
  44. END_CATCH_ALL;
  45. TRY
  46. {
  47. rStatus.m_atime = CTime(findFileData.ftLastAccessTime);
  48. rStatus.m_has_atime = true;
  49. }
  50. CATCH_ALL(e)
  51. {
  52. rStatus.m_has_atime = false;
  53. }
  54. END_CATCH_ALL;
  55. TRY
  56. {
  57. rStatus.m_mtime = CTime(findFileData.ftLastWriteTime);
  58. rStatus.m_has_mtime = true;
  59. }
  60. CATCH_ALL(e)
  61. {
  62. rStatus.m_has_mtime = false;
  63. }
  64. END_CATCH_ALL;
  65. if (!rStatus.m_has_ctime || rStatus.m_ctime.GetTime() == 0)
  66. {
  67. if (rStatus.m_has_mtime)
  68. {
  69. rStatus.m_ctime = rStatus.m_mtime;
  70. rStatus.m_has_ctime = true;
  71. }
  72. else
  73. rStatus.m_has_ctime = false;
  74. }
  75. if (!rStatus.m_has_atime || rStatus.m_atime.GetTime() == 0)
  76. {
  77. if (rStatus.m_has_mtime)
  78. {
  79. rStatus.m_atime = rStatus.m_mtime;
  80. rStatus.m_has_atime = true;
  81. }
  82. else
  83. rStatus.m_has_atime = false;
  84. }
  85. if (!rStatus.m_has_mtime || rStatus.m_mtime.GetTime() == 0)
  86. {
  87. if (rStatus.m_has_ctime)
  88. {
  89. rStatus.m_mtime = rStatus.m_ctime;
  90. rStatus.m_has_mtime = true;
  91. }
  92. else
  93. rStatus.m_has_mtime = false;
  94. }
  95. return TRUE;
  96. }