]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/filefn.cpp
Applied [ 1213375 ] MSW wxMediaCtrl minor debugging and cleanup
[wxWidgets.git] / src / common / filefn.cpp
index ed73e4bd700d786c6e58ba6b81bf5ac3f6753f60..f0c139bb788d4abc11aa0151688208eb35d02dcc 100644 (file)
 
 #include "wx/log.h"
 
-// No, Cygwin doesn't appear to have fnmatch.h after all.
-#if defined(HAVE_FNMATCH_H)
-    #include "fnmatch.h"
-#endif
-
 #ifdef __WINDOWS__
     #include "wx/msw/private.h"
     #include "wx/msw/mslu.h"
@@ -1604,40 +1599,38 @@ time_t WXDLLEXPORT wxFileModificationTime(const wxString& filename)
 #if defined(__WXPALMOS__)
     return 0;
 #elif defined(__WXWINCE__)
-    FILETIME creationTime, lastAccessTime, lastWriteTime;
-    HANDLE fileHandle = ::CreateFile(filename, GENERIC_READ, FILE_SHARE_READ, NULL,
-        0, FILE_ATTRIBUTE_NORMAL, 0);
-    if (fileHandle == INVALID_HANDLE_VALUE)
+    FILETIME ftLastWrite;
+    AutoHANDLE hFile(::CreateFile(filename, GENERIC_READ, FILE_SHARE_READ,
+                                    NULL, 0, FILE_ATTRIBUTE_NORMAL, 0));
+
+    if ( !hFile.IsOk() )
         return 0;
-    else
+
+    if ( !::GetFileTime(hFile, NULL, NULL, &ftLastWrite) )
+        return 0;
+
+    // sure we want to translate to local time here?
+    FILETIME ftLocal;
+    if ( !::FileTimeToLocalFileTime(&ftLastWrite, &ftLocal) )
     {
-        if (GetFileTime(fileHandle, & creationTime, & lastAccessTime, & lastWriteTime))
-        {
-            CloseHandle(fileHandle);
+        wxLogLastError(_T("FileTimeToLocalFileTime"));
+    }
 
-            wxDateTime dateTime;
-            FILETIME ftLocal;
-            if ( !::FileTimeToLocalFileTime(&lastWriteTime, &ftLocal) )
-            {
-                wxLogLastError(_T("FileTimeToLocalFileTime"));
-            }
+    // FILETIME is a counted in 100-ns since 1601-01-01, convert it to
+    // number of seconds since 1970-01-01
+    ULARGE_INTEGER uli;
+    uli.LowPart = ftLocal.dwLowDateTime;
+    uli.HighPart = ftLocal.dwHighDateTime;
 
-            SYSTEMTIME st;
-            if ( !::FileTimeToSystemTime(&ftLocal, &st) )
-            {
-                wxLogLastError(_T("FileTimeToSystemTime"));
-            }
+    ULONGLONG ull = uli.QuadPart;
+    ull /= wxULL(10000000);     // number of 100ns intervals in 1s
+    ull -= wxULL(11644473600);  // 1970-01-01 - 1601-01-01 in seconds
 
-            dateTime.Set(st.wDay, wxDateTime::Month(st.wMonth - 1), st.wYear,
-                st.wHour, st.wMinute, st.wSecond, st.wMilliseconds);
-            return dateTime.GetTicks();
-        }
-        else
-            return 0;
-    }
+    return wx_static_cast(time_t, ull);
 #else
     wxStructStat buf;
-    wxStat( filename, &buf);
+    if ( wxStat( filename, &buf) != 0 )
+        return 0;
 
     return buf.st_mtime;
 #endif