X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/951cd18031e1408ed2a70dae2972273f8ed9e994..764566762c65cd4b65b139121221aa81f652a80f:/src/common/filename.cpp diff --git a/src/common/filename.cpp b/src/common/filename.cpp index 34fafde83d..ec00ae7bed 100644 --- a/src/common/filename.cpp +++ b/src/common/filename.cpp @@ -53,6 +53,8 @@ #ifdef __UNIX_LIKE__ #include #include + #include + #include #endif // ---------------------------------------------------------------------------- @@ -118,14 +120,32 @@ private: // convert between wxDateTime and FILETIME which is a 64-bit value representing // the number of 100-nanosecond intervals since January 1, 1601. -static void ConvertWxToFileTime(FILETIME *ft, const wxDateTime& dt) +// the number of milliseconds between the Unix Epoch (January 1, 1970) and the +// FILETIME reference point (January 1, 1601) +static const wxLongLong FILETIME_EPOCH_OFFSET = wxLongLong(0xa97, 0x30b66800); + +static void ConvertFileTimeToWx(wxDateTime *dt, const FILETIME &ft) { - // TODO + wxLongLong ll(ft.dwHighDateTime, ft.dwLowDateTime); + + // convert 100ns to ms + ll /= 10000; + + // move it to our Epoch + ll -= FILETIME_EPOCH_OFFSET; + + *dt = wxDateTime(ll); } -static void ConvertFileTimeToWx(wxDateTime *dt, const FILETIME &ft) +static void ConvertWxToFileTime(FILETIME *ft, const wxDateTime& dt) { - // TODO + // do the reverse of ConvertFileTimeToWx() + wxLongLong ll = dt.GetValue(); + ll *= 10000; + ll += FILETIME_EPOCH_OFFSET; + + ft->dwHighDateTime = ll.GetHi(); + ft->dwLowDateTime = ll.GetLo(); } #endif // __WIN32__ @@ -899,9 +919,17 @@ bool wxFileName::SetTimes(const wxDateTime *dtCreate, const wxDateTime *dtMod) { #if defined(__UNIX_LIKE__) + if ( !dtAccess && !dtMod ) + { + // can't modify the creation time anyhow, don't try + return TRUE; + } + + // if dtAccess or dtMod is not specified, use the other one (which must be + // non NULL because of the test above) for both times utimbuf utm; - utm.actime = dtAccess ? dtAccess : dtAccess->GetTicks(); - utm.modtime = dtMod ? dtMod : dtMod->GetTicks(); + utm.actime = dtAccess ? dtAccess->GetTicks() : dtMod->GetTicks(); + utm.modtime = dtMod ? dtMod->GetTicks() : dtAccess->GetTicks(); if ( utime(GetFullPath(), &utm) == 0 ) { return TRUE;