From 8d63ebcb645476d8a1efca7957d8308e32b0353c Mon Sep 17 00:00:00 2001 From: Morph <39850852+Morph1984@users.noreply.github.com> Date: Mon, 13 Sep 2021 23:02:53 -0400 Subject: vfs: Partially implement GetFileTimeStampRaw Gets rid of homebrew warnings using this func --- src/core/file_sys/vfs.cpp | 4 ++++ src/core/file_sys/vfs.h | 3 +++ src/core/file_sys/vfs_real.cpp | 29 +++++++++++++++++++++++++++++ src/core/file_sys/vfs_real.h | 1 + src/core/file_sys/vfs_types.h | 9 +++++++++ 5 files changed, 46 insertions(+) (limited to 'src/core/file_sys') diff --git a/src/core/file_sys/vfs.cpp b/src/core/file_sys/vfs.cpp index 368419eca..f5ad10b15 100644 --- a/src/core/file_sys/vfs.cpp +++ b/src/core/file_sys/vfs.cpp @@ -273,6 +273,10 @@ VirtualFile VfsDirectory::GetFile(std::string_view name) const { return iter == files.end() ? nullptr : *iter; } +FileTimeStampRaw VfsDirectory::GetFileTimeStamp([[maybe_unused]] std::string_view path) const { + return {}; +} + VirtualDir VfsDirectory::GetSubdirectory(std::string_view name) const { const auto& subs = GetSubdirectories(); const auto iter = std::find_if(subs.begin(), subs.end(), diff --git a/src/core/file_sys/vfs.h b/src/core/file_sys/vfs.h index afd64e95c..ff6935da6 100644 --- a/src/core/file_sys/vfs.h +++ b/src/core/file_sys/vfs.h @@ -199,6 +199,9 @@ public: // file with name. virtual VirtualFile GetFile(std::string_view name) const; + // Returns a struct containing the file's timestamp. + virtual FileTimeStampRaw GetFileTimeStamp(std::string_view path) const; + // Returns a vector containing all of the subdirectories in this directory. virtual std::vector GetSubdirectories() const = 0; // Returns the directory with name matching name. Returns nullptr if directory dosen't have a diff --git a/src/core/file_sys/vfs_real.cpp b/src/core/file_sys/vfs_real.cpp index 3dad54f49..f4073b76a 100644 --- a/src/core/file_sys/vfs_real.cpp +++ b/src/core/file_sys/vfs_real.cpp @@ -13,6 +13,13 @@ #include "common/logging/log.h" #include "core/file_sys/vfs_real.h" +// For FileTimeStampRaw +#include + +#ifdef _MSC_VER +#define stat _stat64 +#endif + namespace FileSys { namespace FS = Common::FS; @@ -392,6 +399,28 @@ std::vector RealVfsDirectory::GetFiles() const { return IterateEntries(); } +FileTimeStampRaw RealVfsDirectory::GetFileTimeStamp(std::string_view path_) const { + const auto full_path = FS::SanitizePath(path + '/' + std::string(path_)); + const auto fs_path = std::filesystem::path{FS::ToU8String(full_path)}; + struct stat file_status; + +#ifdef _WIN32 + const auto stat_result = _wstat64(fs_path.c_str(), &file_status); +#else + const auto stat_result = stat(fs_path.c_str(), &file_status); +#endif + + if (stat_result != 0) { + return {}; + } + + return { + .created{static_cast(file_status.st_ctime)}, + .accessed{static_cast(file_status.st_atime)}, + .modified{static_cast(file_status.st_mtime)}, + }; +} + std::vector RealVfsDirectory::GetSubdirectories() const { return IterateEntries(); } diff --git a/src/core/file_sys/vfs_real.h b/src/core/file_sys/vfs_real.h index e4d1bba79..746e624cb 100644 --- a/src/core/file_sys/vfs_real.h +++ b/src/core/file_sys/vfs_real.h @@ -86,6 +86,7 @@ public: VirtualDir CreateDirectoryRelative(std::string_view relative_path) override; bool DeleteSubdirectoryRecursive(std::string_view name) override; std::vector GetFiles() const override; + FileTimeStampRaw GetFileTimeStamp(std::string_view path) const override; std::vector GetSubdirectories() const override; bool IsWritable() const override; bool IsReadable() const override; diff --git a/src/core/file_sys/vfs_types.h b/src/core/file_sys/vfs_types.h index 6215ed7af..ed0724717 100644 --- a/src/core/file_sys/vfs_types.h +++ b/src/core/file_sys/vfs_types.h @@ -6,6 +6,8 @@ #include +#include "common/common_types.h" + namespace FileSys { class VfsDirectory; @@ -18,4 +20,11 @@ using VirtualDir = std::shared_ptr; using VirtualFile = std::shared_ptr; using VirtualFilesystem = std::shared_ptr; +struct FileTimeStampRaw { + u64 created{}; + u64 accessed{}; + u64 modified{}; + u64 padding{}; +}; + } // namespace FileSys -- cgit v1.2.3