diff --git a/src/openrct2/core/File.cpp b/src/openrct2/core/File.cpp index af5753da13..df722e1196 100644 --- a/src/openrct2/core/File.cpp +++ b/src/openrct2/core/File.cpp @@ -121,30 +121,7 @@ namespace File uint64_t GetLastModified(const std::string& path) { - uint64_t lastModified = 0; -#ifdef _WIN32 - auto pathW = String::ToWideChar(path); - auto hFile = CreateFileW(pathW.c_str(), GENERIC_READ, FILE_SHARE_READ, nullptr, OPEN_EXISTING, 0, nullptr); - if (hFile != INVALID_HANDLE_VALUE) - { - FILETIME ftCreate, ftAccess, ftWrite; - if (GetFileTime(hFile, &ftCreate, &ftAccess, &ftWrite)) - { - lastModified = (static_cast(ftWrite.dwHighDateTime) << 32ULL) - | static_cast(ftWrite.dwLowDateTime); - } - CloseHandle(hFile); - } -#else - struct stat statInfo - { - }; - if (stat(path.c_str(), &statInfo) == 0) - { - lastModified = statInfo.st_mtime; - } -#endif - return lastModified; + return Platform::GetLastModified(path); } } // namespace File diff --git a/src/openrct2/platform/Platform.Posix.cpp b/src/openrct2/platform/Platform.Posix.cpp index aee87c5764..61e57976b5 100644 --- a/src/openrct2/platform/Platform.Posix.cpp +++ b/src/openrct2/platform/Platform.Posix.cpp @@ -18,6 +18,7 @@ # include # include # include +# include namespace Platform { @@ -159,6 +160,19 @@ namespace Platform return -1; # endif // __EMSCRIPTEN__ } + + uint64_t GetLastModified(const std::string& path) + { + uint64_t lastModified = 0; + struct stat statInfo + { + }; + if (stat(path.c_str(), &statInfo) == 0) + { + lastModified = statInfo.st_mtime; + } + return lastModified; + } } // namespace Platform #endif diff --git a/src/openrct2/platform/Platform.Win32.cpp b/src/openrct2/platform/Platform.Win32.cpp index 08e029887e..1ab0ca0764 100644 --- a/src/openrct2/platform/Platform.Win32.cpp +++ b/src/openrct2/platform/Platform.Win32.cpp @@ -535,6 +535,24 @@ namespace Platform log_warning("Execute() not implemented for Windows!"); return -1; } + + uint64_t GetLastModified(const std::string& path) + { + uint64_t lastModified = 0; + auto pathW = String::ToWideChar(path); + auto hFile = CreateFileW(pathW.c_str(), GENERIC_READ, FILE_SHARE_READ, nullptr, OPEN_EXISTING, 0, nullptr); + if (hFile != INVALID_HANDLE_VALUE) + { + FILETIME ftCreate, ftAccess, ftWrite; + if (GetFileTime(hFile, &ftCreate, &ftAccess, &ftWrite)) + { + lastModified = (static_cast(ftWrite.dwHighDateTime) << 32ULL) + | static_cast(ftWrite.dwLowDateTime); + } + CloseHandle(hFile); + } + return lastModified; + } } // namespace Platform #endif diff --git a/src/openrct2/platform/Platform2.h b/src/openrct2/platform/Platform2.h index 2c73971df0..c2b8216298 100644 --- a/src/openrct2/platform/Platform2.h +++ b/src/openrct2/platform/Platform2.h @@ -35,6 +35,7 @@ namespace Platform std::string GetCurrentExecutablePath(); std::string GetCurrentExecutableDirectory(); bool FileExists(const std::string path); + uint64_t GetLastModified(const std::string& path); rct2_time GetTimeLocal(); rct2_date GetDateLocal(); bool FindApp(const std::string& app, std::string* output);