summaryrefslogtreecommitdiff
path: root/shared/dst_hack.cpp
diff options
context:
space:
mode:
authorDaniel Wilhelm <daniel@wili.li>2014-04-18 17:14:37 +0200
committerDaniel Wilhelm <daniel@wili.li>2014-04-18 17:14:37 +0200
commit8bf668665b107469086f16cb8ad23e47d479d2b4 (patch)
tree66a91ef06a8caa7cd6819dcbe1860693d3eda8d5 /shared/dst_hack.cpp
parent3.21 (diff)
downloadFreeFileSync-8bf668665b107469086f16cb8ad23e47d479d2b4.tar.gz
FreeFileSync-8bf668665b107469086f16cb8ad23e47d479d2b4.tar.bz2
FreeFileSync-8bf668665b107469086f16cb8ad23e47d479d2b4.zip
4.0
Diffstat (limited to 'shared/dst_hack.cpp')
-rw-r--r--shared/dst_hack.cpp62
1 files changed, 58 insertions, 4 deletions
diff --git a/shared/dst_hack.cpp b/shared/dst_hack.cpp
index d52a335f..aa7a0f3e 100644
--- a/shared/dst_hack.cpp
+++ b/shared/dst_hack.cpp
@@ -9,6 +9,7 @@
#include <limits>
#include "int64.h"
#include "file_error.h"
+#include "dll_loader.h"
using namespace zen;
@@ -78,11 +79,64 @@ bool dst::isFatDrive(const Zstring& fileName) //throw()
assert(false); //shouldn't happen
return false;
}
- const Zstring fileSystem = fsName;
+ //DST hack seems to be working equally well for FAT and FAT32 (in particular creation time has 10^-2 s precision as advertised)
+ return fsName == Zstring(L"FAT") ||
+ fsName == Zstring(L"FAT32");
+}
+
+
+bool dst::vistaOrLater()
+{
+ OSVERSIONINFO osvi = {};
+ osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
+
+ //IFileOperation is supported with Vista and later
+ if (::GetVersionEx(&osvi))
+ return osvi.dwMajorVersion > 5;
+ //XP has majorVersion == 5, minorVersion == 1
+ //Vista has majorVersion == 6, minorVersion == 0
+ //version overview: http://msdn.microsoft.com/en-us/library/ms724834(VS.85).aspx
+ return false;
+}
+
+bool dst::isFatDrive(HANDLE hFile) //throw()
+{
+ //dynamically load windows API function
+ typedef BOOL (WINAPI *GetVolumeInformationByHandleWFunc)(HANDLE hFile,
+ LPWSTR lpVolumeNameBuffer,
+ DWORD nVolumeNameSize,
+ LPDWORD lpVolumeSerialNumber,
+ LPDWORD lpMaximumComponentLength,
+ LPDWORD lpFileSystemFlags,
+ LPWSTR lpFileSystemNameBuffer,
+ DWORD nFileSystemNameSize);
+
+ const util::DllFun<GetVolumeInformationByHandleWFunc> getVolumeInformationByHandle(L"kernel32.dll", "GetVolumeInformationByHandleW");
+ if (!getVolumeInformationByHandle)
+ {
+ assert(false);
+ return false;
+ }
+
+ const size_t BUFFER_SIZE = MAX_PATH + 1;
+ wchar_t fsName[BUFFER_SIZE];
+
+ if (!getVolumeInformationByHandle(hFile, //__in HANDLE hFile,
+ NULL, //__out LPTSTR lpVolumeNameBuffer,
+ 0, //__in DWORD nVolumeNameSize,
+ NULL, //__out_opt LPDWORD lpVolumeSerialNumber,
+ NULL, //__out_opt LPDWORD lpMaximumComponentLength,
+ NULL, //__out_opt LPDWORD lpFileSystemFlags,
+ fsName, //__out LPTSTR lpFileSystemNameBuffer,
+ BUFFER_SIZE)) //__in DWORD nFileSystemNameSize
+ {
+ assert(false); //shouldn't happen
+ return false;
+ }
//DST hack seems to be working equally well for FAT and FAT32 (in particular creation time has 10^-2 s precision as advertised)
- return fileSystem == Zstr("FAT") ||
- fileSystem == Zstr("FAT32");
+ return fsName == Zstring(L"FAT") ||
+ fsName == Zstring(L"FAT32");
}
@@ -244,7 +298,7 @@ std::bitset<UTC_LOCAL_OFFSET_BITS> getUtcLocalShift()
const int absValue = common::abs(timeShiftQuarter); //MSVC C++0x bug: std::bitset<>(unsigned long) is ambiguous
- if (std::bitset<UTC_LOCAL_OFFSET_BITS - 1>(absValue).to_ulong() != static_cast<unsigned long>(absValue) || //time shifts that big shouldn't be possible!
+ if (std::bitset < UTC_LOCAL_OFFSET_BITS - 1 > (absValue).to_ulong() != static_cast<unsigned long>(absValue) || //time shifts that big shouldn't be possible!
timeShiftSec % (60 * 15) != 0) //all known time shift have at least 15 minute granularity!
{
const std::wstring errorMessage = _("Conversion error:") + " Unexpected UTC <-> local time shift: " +
bgstack15