diff options
| author | 2021-09-13 23:02:53 -0400 | |
|---|---|---|
| committer | 2021-09-14 08:48:01 -0400 | |
| commit | 8d63ebcb645476d8a1efca7957d8308e32b0353c (patch) | |
| tree | 2767b5659f232f82a80191b970b014364798d7c2 /src/core/file_sys | |
| parent | Merge pull request #7009 from ameerj/main_process_cleanup (diff) | |
| download | yuzu-8d63ebcb645476d8a1efca7957d8308e32b0353c.tar.gz yuzu-8d63ebcb645476d8a1efca7957d8308e32b0353c.tar.xz yuzu-8d63ebcb645476d8a1efca7957d8308e32b0353c.zip | |
vfs: Partially implement GetFileTimeStampRaw
Gets rid of homebrew warnings using this func
Diffstat (limited to 'src/core/file_sys')
| -rw-r--r-- | src/core/file_sys/vfs.cpp | 4 | ||||
| -rw-r--r-- | src/core/file_sys/vfs.h | 3 | ||||
| -rw-r--r-- | src/core/file_sys/vfs_real.cpp | 29 | ||||
| -rw-r--r-- | src/core/file_sys/vfs_real.h | 1 | ||||
| -rw-r--r-- | src/core/file_sys/vfs_types.h | 9 |
5 files changed, 46 insertions, 0 deletions
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 { | |||
| 273 | return iter == files.end() ? nullptr : *iter; | 273 | return iter == files.end() ? nullptr : *iter; |
| 274 | } | 274 | } |
| 275 | 275 | ||
| 276 | FileTimeStampRaw VfsDirectory::GetFileTimeStamp([[maybe_unused]] std::string_view path) const { | ||
| 277 | return {}; | ||
| 278 | } | ||
| 279 | |||
| 276 | VirtualDir VfsDirectory::GetSubdirectory(std::string_view name) const { | 280 | VirtualDir VfsDirectory::GetSubdirectory(std::string_view name) const { |
| 277 | const auto& subs = GetSubdirectories(); | 281 | const auto& subs = GetSubdirectories(); |
| 278 | const auto iter = std::find_if(subs.begin(), subs.end(), | 282 | 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: | |||
| 199 | // file with name. | 199 | // file with name. |
| 200 | virtual VirtualFile GetFile(std::string_view name) const; | 200 | virtual VirtualFile GetFile(std::string_view name) const; |
| 201 | 201 | ||
| 202 | // Returns a struct containing the file's timestamp. | ||
| 203 | virtual FileTimeStampRaw GetFileTimeStamp(std::string_view path) const; | ||
| 204 | |||
| 202 | // Returns a vector containing all of the subdirectories in this directory. | 205 | // Returns a vector containing all of the subdirectories in this directory. |
| 203 | virtual std::vector<VirtualDir> GetSubdirectories() const = 0; | 206 | virtual std::vector<VirtualDir> GetSubdirectories() const = 0; |
| 204 | // Returns the directory with name matching name. Returns nullptr if directory dosen't have a | 207 | // 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 @@ | |||
| 13 | #include "common/logging/log.h" | 13 | #include "common/logging/log.h" |
| 14 | #include "core/file_sys/vfs_real.h" | 14 | #include "core/file_sys/vfs_real.h" |
| 15 | 15 | ||
| 16 | // For FileTimeStampRaw | ||
| 17 | #include <sys/stat.h> | ||
| 18 | |||
| 19 | #ifdef _MSC_VER | ||
| 20 | #define stat _stat64 | ||
| 21 | #endif | ||
| 22 | |||
| 16 | namespace FileSys { | 23 | namespace FileSys { |
| 17 | 24 | ||
| 18 | namespace FS = Common::FS; | 25 | namespace FS = Common::FS; |
| @@ -392,6 +399,28 @@ std::vector<VirtualFile> RealVfsDirectory::GetFiles() const { | |||
| 392 | return IterateEntries<RealVfsFile, VfsFile>(); | 399 | return IterateEntries<RealVfsFile, VfsFile>(); |
| 393 | } | 400 | } |
| 394 | 401 | ||
| 402 | FileTimeStampRaw RealVfsDirectory::GetFileTimeStamp(std::string_view path_) const { | ||
| 403 | const auto full_path = FS::SanitizePath(path + '/' + std::string(path_)); | ||
| 404 | const auto fs_path = std::filesystem::path{FS::ToU8String(full_path)}; | ||
| 405 | struct stat file_status; | ||
| 406 | |||
| 407 | #ifdef _WIN32 | ||
| 408 | const auto stat_result = _wstat64(fs_path.c_str(), &file_status); | ||
| 409 | #else | ||
| 410 | const auto stat_result = stat(fs_path.c_str(), &file_status); | ||
| 411 | #endif | ||
| 412 | |||
| 413 | if (stat_result != 0) { | ||
| 414 | return {}; | ||
| 415 | } | ||
| 416 | |||
| 417 | return { | ||
| 418 | .created{static_cast<u64>(file_status.st_ctime)}, | ||
| 419 | .accessed{static_cast<u64>(file_status.st_atime)}, | ||
| 420 | .modified{static_cast<u64>(file_status.st_mtime)}, | ||
| 421 | }; | ||
| 422 | } | ||
| 423 | |||
| 395 | std::vector<VirtualDir> RealVfsDirectory::GetSubdirectories() const { | 424 | std::vector<VirtualDir> RealVfsDirectory::GetSubdirectories() const { |
| 396 | return IterateEntries<RealVfsDirectory, VfsDirectory>(); | 425 | return IterateEntries<RealVfsDirectory, VfsDirectory>(); |
| 397 | } | 426 | } |
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: | |||
| 86 | VirtualDir CreateDirectoryRelative(std::string_view relative_path) override; | 86 | VirtualDir CreateDirectoryRelative(std::string_view relative_path) override; |
| 87 | bool DeleteSubdirectoryRecursive(std::string_view name) override; | 87 | bool DeleteSubdirectoryRecursive(std::string_view name) override; |
| 88 | std::vector<VirtualFile> GetFiles() const override; | 88 | std::vector<VirtualFile> GetFiles() const override; |
| 89 | FileTimeStampRaw GetFileTimeStamp(std::string_view path) const override; | ||
| 89 | std::vector<VirtualDir> GetSubdirectories() const override; | 90 | std::vector<VirtualDir> GetSubdirectories() const override; |
| 90 | bool IsWritable() const override; | 91 | bool IsWritable() const override; |
| 91 | bool IsReadable() const override; | 92 | 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 @@ | |||
| 6 | 6 | ||
| 7 | #include <memory> | 7 | #include <memory> |
| 8 | 8 | ||
| 9 | #include "common/common_types.h" | ||
| 10 | |||
| 9 | namespace FileSys { | 11 | namespace FileSys { |
| 10 | 12 | ||
| 11 | class VfsDirectory; | 13 | class VfsDirectory; |
| @@ -18,4 +20,11 @@ using VirtualDir = std::shared_ptr<VfsDirectory>; | |||
| 18 | using VirtualFile = std::shared_ptr<VfsFile>; | 20 | using VirtualFile = std::shared_ptr<VfsFile>; |
| 19 | using VirtualFilesystem = std::shared_ptr<VfsFilesystem>; | 21 | using VirtualFilesystem = std::shared_ptr<VfsFilesystem>; |
| 20 | 22 | ||
| 23 | struct FileTimeStampRaw { | ||
| 24 | u64 created{}; | ||
| 25 | u64 accessed{}; | ||
| 26 | u64 modified{}; | ||
| 27 | u64 padding{}; | ||
| 28 | }; | ||
| 29 | |||
| 21 | } // namespace FileSys | 30 | } // namespace FileSys |