diff --git a/src/common/file_util.cpp b/src/common/file_util.cpp index c618495f7..a8302af14 100644 --- a/src/common/file_util.cpp +++ b/src/common/file_util.cpp @@ -100,6 +100,22 @@ bool Exists(const std::string& filename) { return (result == 0); } +u64 GetFileModificationTimestamp(const std::string& filepath) { + + if (FileUtil::Exists(filepath)) { + struct stat64 file_info; + +#ifdef _WIN32 + if (0 == _wstat64(Common::UTF8ToUTF16W(filepath).c_str(), &file_info)) { +#else + if (0 == stat64(filepath.c_str(), &file_info)) { +#endif + return static_cast(file_info.st_mtime); + } + } + return 0; +} + // Returns true if filename is a directory bool IsDirectory(const std::string& filename) { struct stat file_info; diff --git a/src/common/file_util.h b/src/common/file_util.h index ac58607c5..3bff9e8a5 100644 --- a/src/common/file_util.h +++ b/src/common/file_util.h @@ -63,6 +63,14 @@ struct FSTEntry { // Returns true if file filename exists bool Exists(const std::string& filename); +/** + * Function GetFileModificationTimestamp + * Return file timestamp if the file exists, return 0 if file no exists + * Note : + * Timestamp format: milliseconds since the Unix epoch + */ +u64 GetFileModificationTimestamp(const std::string& filepath); + // Returns true if filename is a directory bool IsDirectory(const std::string& filename);