summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOwen Rudge <owen@owenrudge.net>2019-09-11 21:57:12 +0100
committerOwen Rudge <owen@owenrudge.net>2019-09-13 11:23:25 +0100
commit165eae0e8003662d4311de1e1e748e9ba6805348 (patch)
treeb0118fa428db9fada7b0357a984d7f926c3bb448
parentf81cb0a90dd0de517be773b2ef2347ba255fc361 (diff)
downloadopenttd-165eae0e8003662d4311de1e1e748e9ba6805348.tar.xz
Fix: Avoid using stat to retrieve file modification times on Windows (#7731)
-rw-r--r--src/fios.cpp22
1 files changed, 19 insertions, 3 deletions
diff --git a/src/fios.cpp b/src/fios.cpp
index 9153c53f1..4e614e498 100644
--- a/src/fios.cpp
+++ b/src/fios.cpp
@@ -300,13 +300,29 @@ bool FiosFileScanner::AddFile(const char *filename, size_t basepath_length, cons
FiosItem *fios = file_list.Append();
#ifdef _WIN32
- struct _stat sb;
- if (_tstat(OTTD2FS(filename), &sb) == 0) {
+ // Retrieve the file modified date using GetFileTime rather than stat to work around an obscure MSVC bug that affects Windows XP
+ HANDLE fh = CreateFile(OTTD2FS(filename), GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, nullptr, OPEN_EXISTING, 0, nullptr);
+
+ if (fh != INVALID_HANDLE_VALUE) {
+ FILETIME ft;
+ ULARGE_INTEGER ft_int64;
+
+ if (GetFileTime(fh, nullptr, nullptr, &ft) != 0) {
+ ft_int64.HighPart = ft.dwHighDateTime;
+ ft_int64.LowPart = ft.dwLowDateTime;
+
+ // Convert from hectonanoseconds since 01/01/1601 to seconds since 01/01/1970
+ fios->mtime = ft_int64.QuadPart / 10000000ULL - 11644473600ULL;
+ } else {
+ fios->mtime = 0;
+ }
+
+ CloseHandle(fh);
#else
struct stat sb;
if (stat(filename, &sb) == 0) {
-#endif
fios->mtime = sb.st_mtime;
+#endif
} else {
fios->mtime = 0;
}