Implement File_Util::GetFileModificationTimestamp function

This commit is contained in:
JamePeng 2016-06-18 08:30:55 +08:00
parent 3a1eaf2efc
commit 4021ed79d9
2 changed files with 24 additions and 0 deletions

View File

@ -100,6 +100,22 @@ bool Exists(const std::string& filename) {
return (result == 0); 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<u64>(file_info.st_mtime);
}
}
return 0;
}
// Returns true if filename is a directory // Returns true if filename is a directory
bool IsDirectory(const std::string& filename) { bool IsDirectory(const std::string& filename) {
struct stat file_info; struct stat file_info;

View File

@ -63,6 +63,14 @@ struct FSTEntry {
// Returns true if file filename exists // Returns true if file filename exists
bool Exists(const std::string& filename); 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 // Returns true if filename is a directory
bool IsDirectory(const std::string& filename); bool IsDirectory(const std::string& filename);