From be600e509551ad87e29d66828e88479b47c202de Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Wed, 6 Mar 2013 23:58:12 -0800 Subject: [PATCH] Set the times when reading a dir on Windows. Test doesn't pass but it's not gonna. --- Core/FileSystems/DirectoryFileSystem.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/Core/FileSystems/DirectoryFileSystem.cpp b/Core/FileSystems/DirectoryFileSystem.cpp index 6938ed4fe0..bc9aeed86d 100644 --- a/Core/FileSystems/DirectoryFileSystem.cpp +++ b/Core/FileSystems/DirectoryFileSystem.cpp @@ -517,6 +517,19 @@ bool DirectoryFileSystem::GetHostPath(const std::string &inpath, std::string &ou return true; } +#ifdef _WIN32 +#define FILETIME_FROM_UNIX_EPOCH_US 11644473600000000ULL + +void tmFromFiletime(tm &dest, FILETIME &src) +{ + u64 from_1601_us = (((u64) src.dwHighDateTime << 32ULL) + (u64) src.dwLowDateTime) / 10ULL; + u64 from_1970_us = from_1601_us - FILETIME_FROM_UNIX_EPOCH_US; + + time_t t = (time_t) (from_1970_us / 1000000UL); + localtime_r(&t, &dest); +} +#endif + std::vector DirectoryFileSystem::GetDirListing(std::string path) { std::vector myVector; #ifdef _WIN32 @@ -537,6 +550,9 @@ std::vector DirectoryFileSystem::GetDirListing(std::string path) { entry.type = FILETYPE_DIRECTORY; else entry.type = FILETYPE_NORMAL; + + // TODO: Make this more correct? + entry.access = entry.type == FILETYPE_NORMAL ? 0666 : 0777; // TODO: is this just for .. or all subdirectories? Need to add a directory to the test // to find out. Also why so different than the old test results? if (!strcmp(findData.cFileName, "..") ) @@ -544,6 +560,9 @@ std::vector DirectoryFileSystem::GetDirListing(std::string path) { else entry.size = findData.nFileSizeLow | ((u64)findData.nFileSizeHigh<<32); entry.name = findData.cFileName; + tmFromFiletime(entry.atime, findData.ftLastAccessTime); + tmFromFiletime(entry.ctime, findData.ftCreationTime); + tmFromFiletime(entry.mtime, findData.ftLastWriteTime); myVector.push_back(entry); int retval = FindNextFile(hFind, &findData);