diff --git a/desktop_version/src/FileSystemUtils.cpp b/desktop_version/src/FileSystemUtils.cpp index d0190b1c..1a340f02 100644 --- a/desktop_version/src/FileSystemUtils.cpp +++ b/desktop_version/src/FileSystemUtils.cpp @@ -164,6 +164,28 @@ char *FILESYSTEM_getUserLevelDirectory(void) return levelDir; } +bool FILESYSTEM_isFile(const char* filename) +{ + PHYSFS_Stat stat; + + bool success = PHYSFS_stat(filename, &stat); + + if (!success) + { + printf( + "Could not stat file: %s\n", + PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode()) + ); + return false; + } + + /* We unfortunately cannot follow symlinks (PhysFS limitation). + * Let the caller deal with them. + */ + return stat.filetype == PHYSFS_FILETYPE_REGULAR + || stat.filetype == PHYSFS_FILETYPE_SYMLINK; +} + static bool FILESYSTEM_exists(const char *fname) { return PHYSFS_exists(fname); diff --git a/desktop_version/src/FileSystemUtils.h b/desktop_version/src/FileSystemUtils.h index ffb641a0..ddd163aa 100644 --- a/desktop_version/src/FileSystemUtils.h +++ b/desktop_version/src/FileSystemUtils.h @@ -12,6 +12,8 @@ void FILESYSTEM_deinit(void); char *FILESYSTEM_getUserSaveDirectory(void); char *FILESYSTEM_getUserLevelDirectory(void); +bool FILESYSTEM_isFile(const char* filename); + void FILESYSTEM_mount(const char *fname); void FILESYSTEM_loadZip(const char* filename); extern bool FILESYSTEM_assetsmounted;