summaryrefslogtreecommitdiff
path: root/Source/Core/Common/FileUtil.h
diff options
context:
space:
mode:
authorLeo Lam <leolino.lam@gmail.com>2017-07-11 00:28:34 +0200
committerGitHub <noreply@github.com>2017-07-11 00:28:34 +0200
commitb6c3479bb43f84da5cb3c4be6885f76b485b2147 (patch)
treec6f8fbe5ff05fdf67c238e165a197cbe2783c48e /Source/Core/Common/FileUtil.h
parent12f6d0b56b3c0eac7fd023de91f2e1f12a6f80af (diff)
parent5ca3aee00ac3ac1a906de68c216907a7b41825fe (diff)
Merge pull request #5720 from JosJuice/file-metadata
FileUtil: Redesign Exists/IsDirectory/GetSize
Diffstat (limited to 'Source/Core/Common/FileUtil.h')
-rw-r--r--Source/Core/Common/FileUtil.h42
1 files changed, 36 insertions, 6 deletions
diff --git a/Source/Core/Common/FileUtil.h b/Source/Core/Common/FileUtil.h
index 5eec5382ce..d8f1c660eb 100644
--- a/Source/Core/Common/FileUtil.h
+++ b/Source/Core/Common/FileUtil.h
@@ -9,6 +9,8 @@
#include <string>
#include <vector>
+#include <sys/stat.h>
+
#include "Common/CommonTypes.h"
#include "Common/NonCopyable.h"
@@ -78,14 +80,42 @@ struct FSTEntry
std::vector<FSTEntry> children;
};
-// Returns true if file filename exists
-bool Exists(const std::string& filename);
+// The functions in this class are functionally identical to the standalone functions
+// below, but if you are going to be calling more than one of the functions using the
+// same path, creating a single FileInfo object and calling its functions multiple
+// times is faster than calling standalone functions multiple times.
+class FileInfo final
+{
+public:
+ explicit FileInfo(const std::string& path);
+ explicit FileInfo(const char* path);
+ explicit FileInfo(int fd);
+
+ // Returns true if the path exists
+ bool Exists() const;
+ // Returns true if the path exists and is a directory
+ bool IsDirectory() const;
+ // Returns true if the path exists and is a file
+ bool IsFile() const;
+ // Returns the size of a file (or returns 0 if the path doesn't refer to a file)
+ u64 GetSize() const;
+
+private:
+ struct stat m_stat;
+ bool m_exists;
+};
+
+// Returns true if the path exists
+bool Exists(const std::string& path);
+
+// Returns true if the path exists and is a directory
+bool IsDirectory(const std::string& path);
-// Returns true if filename is a directory
-bool IsDirectory(const std::string& filename);
+// Returns true if the path exists and is a file
+bool IsFile(const std::string& path);
-// Returns the size of filename (64bit)
-u64 GetSize(const std::string& filename);
+// Returns the size of a file (or returns 0 if the path isn't a file that exists)
+u64 GetSize(const std::string& path);
// Overloaded GetSize, accepts file descriptor
u64 GetSize(const int fd);