From: Vadim Zeitlin Date: Wed, 31 Oct 2001 02:42:50 +0000 (+0000) Subject: made wxFileName::Set/GetTimes() work under Win32 X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/d56e2b972fcf1c8948d65242a697c77a004972a6?ds=sidebyside made wxFileName::Set/GetTimes() work under Win32 git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@12225 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/samples/console/console.cpp b/samples/console/console.cpp index 7795300fae..891c05f4e7 100644 --- a/samples/console/console.cpp +++ b/samples/console/console.cpp @@ -43,7 +43,7 @@ //#define TEST_ARRAYS //#define TEST_CHARSET -#define TEST_CMDLINE +//#define TEST_CMDLINE //#define TEST_DATETIME //#define TEST_DIR //#define TEST_DLLLOADER @@ -52,6 +52,7 @@ //#define TEST_FILE //#define TEST_FILECONF //#define TEST_FILENAME +#define TEST_FILETIME //#define TEST_FTP //#define TEST_HASH //#define TEST_INFO_FUNCTIONS @@ -64,7 +65,7 @@ //#define TEST_REGCONF //#define TEST_REGEX //#define TEST_REGISTRY -#define TEST_SNGLINST +//#define TEST_SNGLINST //#define TEST_SOCKETS //#define TEST_STREAMS //#define TEST_STRINGS @@ -788,6 +789,48 @@ static void TestFileNameCwd() #endif // TEST_FILENAME +// ---------------------------------------------------------------------------- +// wxFileName time functions +// ---------------------------------------------------------------------------- + +#ifdef TEST_FILETIME + +#include +#include + +static void TestFileGetTimes() +{ + wxFileName fn(_T("testdata.fc")); + + wxDateTime dtAccess, dtMod, dtChange; + if ( !fn.GetTimes(&dtAccess, &dtMod, &dtChange) ) + { + wxPrintf(_T("ERROR: GetTimes() failed.\n")); + } + else + { + static const wxChar *fmt = _T("%Y-%b-%d %H:%M:%S"); + + wxPrintf(_T("File times for '%s':\n"), fn.GetFullPath().c_str()); + wxPrintf(_T("Access: \t%s\n"), dtAccess.Format(fmt).c_str()); + wxPrintf(_T("Mod/creation:\t%s\n"), dtMod.Format(fmt).c_str()); + wxPrintf(_T("Change: \t%s\n"), dtChange.Format(fmt).c_str()); + } +} + +static void TestFileSetTimes() +{ + wxFileName fn(_T("testdata.fc")); + + wxDateTime dtAccess, dtMod, dtChange; + if ( !fn.Touch() ) + { + wxPrintf(_T("ERROR: Touch() failed.\n")); + } +} + +#endif // TEST_FILETIME + // ---------------------------------------------------------------------------- // wxHashTable // ---------------------------------------------------------------------------- @@ -5078,6 +5121,11 @@ int main(int argc, char **argv) } #endif // TEST_FILENAME +#ifdef TEST_FILETIME + TestFileGetTimes(); + TestFileSetTimes(); +#endif // TEST_FILETIME + #ifdef TEST_FTP wxLog::AddTraceMask(FTP_TRACE_MASK); if ( TestFtpConnect() ) diff --git a/src/common/filename.cpp b/src/common/filename.cpp index 33361e5ba6..ec00ae7bed 100644 --- a/src/common/filename.cpp +++ b/src/common/filename.cpp @@ -120,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__