MFC64bitFix.cpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. // FileZilla - a Windows ftp client
  2. // Copyright (C) 2002-2004 - Tim Kosse <[email protected]>
  3. // This program is free software; you can redistribute it and/or
  4. // modify it under the terms of the GNU General Public License
  5. // as published by the Free Software Foundation; either version 2
  6. // of the License, or (at your option) any later version.
  7. // This program is distributed in the hope that it will be useful,
  8. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. // GNU General Public License for more details.
  11. // You should have received a copy of the GNU General Public License
  12. // along with this program; if not, write to the Free Software
  13. // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  14. #include "stdafx.h"
  15. #ifndef MPEXT
  16. #include "MFC64bitFix.h"
  17. #endif
  18. __int64 GetLength64(CFile &file)
  19. {
  20. DWORD low;
  21. DWORD high;
  22. low=GetFileSize((void *)file.m_hFile, &high);
  23. _int64 size=((_int64)high<<32)+low;
  24. return size;
  25. }
  26. BOOL GetLength64(CString filename, _int64 &size)
  27. {
  28. WIN32_FIND_DATA findFileData;
  29. HANDLE hFind = FindFirstFile(filename, &findFileData);
  30. if (hFind == INVALID_HANDLE_VALUE)
  31. return FALSE;
  32. VERIFY(FindClose(hFind));
  33. size=((_int64)findFileData.nFileSizeHigh<<32)+findFileData.nFileSizeLow;
  34. return TRUE;
  35. }
  36. BOOL PASCAL GetStatus64(LPCTSTR lpszFileName, CFileStatus64& rStatus)
  37. {
  38. WIN32_FIND_DATA findFileData;
  39. HANDLE hFind = FindFirstFile((LPTSTR)lpszFileName, &findFileData);
  40. if (hFind == INVALID_HANDLE_VALUE)
  41. {
  42. return FALSE;
  43. }
  44. VERIFY(FindClose(hFind));
  45. // strip attribute of NORMAL bit, our API doesn't have a "normal" bit.
  46. rStatus.m_attribute = (BYTE)
  47. (findFileData.dwFileAttributes & ~FILE_ATTRIBUTE_NORMAL);
  48. rStatus.m_size = ((_int64)findFileData.nFileSizeHigh<<32)+findFileData.nFileSizeLow;
  49. // convert times as appropriate
  50. TRY
  51. {
  52. rStatus.m_ctime = CTime(findFileData.ftCreationTime);
  53. rStatus.m_has_ctime = true;
  54. }
  55. CATCH_ALL(e)
  56. {
  57. rStatus.m_has_ctime = false;
  58. }
  59. END_CATCH_ALL;
  60. TRY
  61. {
  62. rStatus.m_atime = CTime(findFileData.ftLastAccessTime);
  63. rStatus.m_has_atime = true;
  64. }
  65. CATCH_ALL(e)
  66. {
  67. rStatus.m_has_atime = false;
  68. }
  69. END_CATCH_ALL;
  70. TRY
  71. {
  72. rStatus.m_mtime = CTime(findFileData.ftLastWriteTime);
  73. rStatus.m_has_mtime = true;
  74. }
  75. CATCH_ALL(e)
  76. {
  77. rStatus.m_has_mtime = false;
  78. }
  79. END_CATCH_ALL;
  80. if (!rStatus.m_has_ctime || rStatus.m_ctime.GetTime() == 0)
  81. {
  82. if (rStatus.m_has_mtime)
  83. {
  84. rStatus.m_ctime = rStatus.m_mtime;
  85. rStatus.m_has_ctime = true;
  86. }
  87. else
  88. rStatus.m_has_ctime = false;
  89. }
  90. if (!rStatus.m_has_atime || rStatus.m_atime.GetTime() == 0)
  91. {
  92. if (rStatus.m_has_mtime)
  93. {
  94. rStatus.m_atime = rStatus.m_mtime;
  95. rStatus.m_has_atime = true;
  96. }
  97. else
  98. rStatus.m_has_atime = false;
  99. }
  100. if (!rStatus.m_has_mtime || rStatus.m_mtime.GetTime() == 0)
  101. {
  102. if (rStatus.m_has_ctime)
  103. {
  104. rStatus.m_mtime = rStatus.m_ctime;
  105. rStatus.m_has_mtime = true;
  106. }
  107. else
  108. rStatus.m_has_mtime = false;
  109. }
  110. return TRUE;
  111. }