From 4021ed79d992dda1a66f926fa6fc19a48a191125 Mon Sep 17 00:00:00 2001 From: JamePeng Date: Sat, 18 Jun 2016 08:30:55 +0800 Subject: [PATCH] Implement File_Util::GetFileModificationTimestamp function --- src/common/file_util.cpp | 16 ++++++++++++++++ src/common/file_util.h | 8 ++++++++ 2 files changed, 24 insertions(+) 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);