1
0
mirror of https://github.com/TerryCavanagh/VVVVVV.git synced 2024-06-02 02:53:32 +02:00

Add FILESYSTEM_isFile()

This function will be used to differentiate files from directories.

Or at least that was the hope. Symlink support was added in 2.3, but it
doesn't seem like PHYSFS_stat() lets you follow the symlink to check if
what it points to is itself a file or directory. And there doesn't seem
to be any function to follow the symlink yourself...

So for now, this function considers symlinks to directories to be files.
This commit is contained in:
Misa 2021-03-04 16:39:07 -08:00 committed by Ethan Lee
parent d938a18504
commit 838ffbe68f
2 changed files with 24 additions and 0 deletions

View File

@ -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);

View File

@ -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;