From 8eb2561fcfdeb6b1c023b74b09936118445fb966 Mon Sep 17 00:00:00 2001 From: Kawe Mazidjatari <48657826+Mauler125@users.noreply.github.com> Date: Sat, 13 Jan 2024 19:38:06 +0100 Subject: [PATCH] FileSystem: implement IsDirectory in STD implementation --- src/filesystem/filesystem_std.cpp | 18 ++++++++++++++++++ src/filesystem/filesystem_std.h | 2 +- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/filesystem/filesystem_std.cpp b/src/filesystem/filesystem_std.cpp index 67eda9b6..4df79c53 100644 --- a/src/filesystem/filesystem_std.cpp +++ b/src/filesystem/filesystem_std.cpp @@ -6,6 +6,11 @@ //=============================================================================// #include "filesystem_std.h" +// These are used for the 'stat()' and 'access()' in CBaseFileSystem::IsDirectory(). +#include +#include +#include + ssize_t CBaseFileSystem::Read(void* pOutput, ssize_t size, FileHandle_t file) { return fread(pOutput, sizeof(uint8_t), size, (FILE*)file); @@ -331,6 +336,19 @@ int CBaseFileSystem::CreateDirHierarchy(const char* pFileName, const char* pPath return _mkdir(fullPath); } +bool CBaseFileSystem::IsDirectory(const char* path, const char* pathID) +{ + if (_access(path, 0) == 0) + { + struct stat status; + stat(path, &status); + + return (status.st_mode & S_IFDIR) != 0; + } + + return false; +} + char* CBaseFileSystem::ReadLine(char* maxChars, ssize_t maxOutputLength, FileHandle_t file) { return fgets(maxChars, (int)maxOutputLength, (FILE*)file); diff --git a/src/filesystem/filesystem_std.h b/src/filesystem/filesystem_std.h index c8d44a54..37262d01 100644 --- a/src/filesystem/filesystem_std.h +++ b/src/filesystem/filesystem_std.h @@ -42,7 +42,7 @@ public: virtual void RemoveFile(char const* pRelativePath, const char* pathID = 0) {}; // Deletes a file (on the WritePath) virtual bool RenameFile(char const* pOldPath, char const* pNewPath, const char* pathID = 0) { return false; }; // Renames a file (on the WritePath) virtual int CreateDirHierarchy(const char* path, const char* pathID = 0); // create a local directory structure - virtual bool IsDirectory(const char* pFileName, const char* pathID = 0) { return false; }; // File I/O and info + virtual bool IsDirectory(const char* pFileName, const char* pathID = 0); // File I/O and info virtual ssize_t FileTimeToString(char* pStrip, ssize_t maxCharsIncludingTerminator, long fileTime) { return NULL; }; // Returns the string size //--------------------------------------------------------