From fefe20351d0720683990b666584b6879c90bd37d Mon Sep 17 00:00:00 2001 From: Daniel Wilhelm Date: Fri, 18 Apr 2014 16:58:10 +0200 Subject: 1.19 --- library/fileHandling.cpp | 46 +++++++++++++++++++++------------------------- 1 file changed, 21 insertions(+), 25 deletions(-) (limited to 'library/fileHandling.cpp') diff --git a/library/fileHandling.cpp b/library/fileHandling.cpp index 4f8caec6..b6d3d9d7 100644 --- a/library/fileHandling.cpp +++ b/library/fileHandling.cpp @@ -284,18 +284,25 @@ private: }; +class KernelDllHandler //dynamically load windows API functions +{ + typedef DWORD WINAPI (*GetFinalPath)( + HANDLE hFile, + LPTSTR lpszFilePath, + DWORD cchFilePath, + DWORD dwFlags); -typedef DWORD WINAPI (*GetFinalPath)( - HANDLE hFile, - LPTSTR lpszFilePath, - DWORD cchFilePath, - DWORD dwFlags); +public: + static const KernelDllHandler& getInstance() //lazy creation of KernelDllHandler + { + static KernelDllHandler instance; + return instance; + } + GetFinalPath getFinalPathNameByHandle; -class DllHandler //dynamically load windows API functions -{ -public: - DllHandler() : +private: + KernelDllHandler() : getFinalPathNameByHandle(NULL), hKernel(NULL) { @@ -305,26 +312,15 @@ public: getFinalPathNameByHandle = reinterpret_cast(::GetProcAddress(hKernel, "GetFinalPathNameByHandleW")); //load unicode version! } - ~DllHandler() + ~KernelDllHandler() { if (hKernel) ::FreeLibrary(hKernel); } - GetFinalPath getFinalPathNameByHandle; - -private: HINSTANCE hKernel; }; -inline -DllHandler& getDllHandler() //lazy creation of DllHandler -{ - static DllHandler instance; - return instance; -} - - Zstring resolveDirectorySymlink(const Zstring& dirLinkName) //get full target path of symbolic link to a directory { //open handle to target of symbolic link @@ -340,13 +336,13 @@ Zstring resolveDirectorySymlink(const Zstring& dirLinkName) //get full target pa CloseHandleOnExit dummy(hDir); - if (getDllHandler().getFinalPathNameByHandle == NULL ) + if (KernelDllHandler::getInstance().getFinalPathNameByHandle == NULL ) throw FileError(Zstring(_("Error loading library function:")) + wxT("\n\"") + wxT("GetFinalPathNameByHandleW") + wxT("\"")); const unsigned BUFFER_SIZE = 10000; TCHAR targetPath[BUFFER_SIZE]; - const DWORD rv = getDllHandler().getFinalPathNameByHandle( + const DWORD rv = KernelDllHandler::getInstance().getFinalPathNameByHandle( hDir, targetPath, BUFFER_SIZE, @@ -669,8 +665,8 @@ inline void setWin32FileInformation(const FILETIME& lastWriteTime, const DWORD fileSizeHigh, const DWORD fileSizeLow, FreeFileSync::FileInfo& output) { //convert UTC FILETIME to ANSI C format (number of seconds since Jan. 1st 1970 UTC) - wxLongLong writeTimeLong(lastWriteTime.dwHighDateTime, lastWriteTime.dwLowDateTime); - writeTimeLong /= 10000000; //reduce precision to 1 second (FILETIME has unit 10^-7 s) + wxLongLong writeTimeLong(wxInt32(lastWriteTime.dwHighDateTime), lastWriteTime.dwLowDateTime); + writeTimeLong /= 10000000; //reduce precision to 1 second (FILETIME has unit 10^-7 s) writeTimeLong -= wxLongLong(2, 3054539008UL); //timeshift between ansi C time and FILETIME in seconds == 11644473600s output.lastWriteTimeRaw = writeTimeLong; -- cgit