Skip to content
Permalink
Browse files
THIS is Christoph's PHYSFS_stat() work.
I've merged some basic ideas from the other patch, which was Indy Sam's work,
 and cleaned up a few things.
  • Loading branch information
icculus committed Feb 15, 2010
1 parent 8e78e47 commit f1cd4d8f0d94e02e2001e628a0366d1aa113dc8c
@@ -105,6 +105,10 @@ OS/2 updates:
Bug fixes:
Patrice Mandin

PHYSFS_stat() API:
Christoph Nelles
Indy Sams

Other stuff:
Your name here! Patches go to icculus@icculus.org ...

@@ -83,6 +83,8 @@
%rename(symbolicLinksPermitted) PHYSFS_symbolicLinksPermitted;
%rename(mount) PHYSFS_mount;
%rename(getMountPoint) PHYSFS_getMountPoint;
%rename(Stat) PHYSFS_Stat; /* !!! FIXME: case insensitive script languages? */
%rename(stat) PHYSFS_stat;
#endif /* SWIGPERL */

%include "../src/physfs.h"
@@ -243,6 +243,18 @@ static void DIR_dirClose(dvoid *opaque)
} /* DIR_dirClose */


static int DIR_stat(fvoid *opaque, const char *name, int *exists,
PHYSFS_Stat *stat)
{
char *d = __PHYSFS_platformCvtToDependent((char *) opaque, name, NULL);
int retval = 0;

BAIL_IF_MACRO(d == NULL, NULL, 0);
retval = __PHYSFS_platformStat(d, exists, stat);
allocator.Free(d);
return retval;
} /* DIR_stat */


const PHYSFS_ArchiveInfo __PHYSFS_ArchiveInfo_DIR =
{
@@ -253,7 +265,6 @@ const PHYSFS_ArchiveInfo __PHYSFS_ArchiveInfo_DIR =
};



const PHYSFS_Archiver __PHYSFS_Archiver_DIR =
{
&__PHYSFS_ArchiveInfo_DIR,
@@ -276,7 +287,8 @@ const PHYSFS_Archiver __PHYSFS_Archiver_DIR =
DIR_tell, /* tell() method */
DIR_seek, /* seek() method */
DIR_fileLength, /* fileLength() method */
DIR_fileClose /* fileClose() method */
DIR_fileClose, /* fileClose() method */
DIR_stat /* stat() method */
};

/* end of dir.c ... */
@@ -316,7 +316,7 @@ static void GRP_enumerateFiles(dvoid *opaque, const char *dname,
} /* GRP_enumerateFiles */


static GRPentry *grp_find_entry(GRPinfo *info, const char *name)
static GRPentry *grp_find_entry(const GRPinfo *info, const char *name)
{
char *ptr = strchr(name, '.');
GRPentry *a = info->entries;
@@ -435,6 +435,27 @@ static int GRP_mkdir(dvoid *opaque, const char *name)
} /* GRP_mkdir */


static int GRP_stat(fvoid *opaque, const char *filename, int *exists,
PHYSFS_Stat *stat)
{
const GRPinfo *info = (const GRPinfo *) opaque;
const GRPentry *entry = grp_find_entry(info, filename);

*exists = (entry != 0);
if (!entry)
return 0;

stat->filesize = entry->size;
stat->filetype = PHYSFS_FILETYPE_REGULAR;
stat->modtime = info->last_mod_time;
stat->createtime = info->last_mod_time;
stat->accesstime = -1;
stat->readonly = 1;

return 0;
} /* GRP_stat */


const PHYSFS_ArchiveInfo __PHYSFS_ArchiveInfo_GRP =
{
"GRP",
@@ -466,7 +487,8 @@ const PHYSFS_Archiver __PHYSFS_Archiver_GRP =
GRP_tell, /* tell() method */
GRP_seek, /* seek() method */
GRP_fileLength, /* fileLength() method */
GRP_fileClose /* fileClose() method */
GRP_fileClose, /* fileClose() method */
GRP_stat /* stat() method */
};

#endif /* defined PHYSFS_SUPPORTS_GRP */
@@ -355,7 +355,7 @@ static void HOG_enumerateFiles(dvoid *opaque, const char *dname,
} /* HOG_enumerateFiles */


static HOGentry *hog_find_entry(HOGinfo *info, const char *name)
static HOGentry *hog_find_entry(const HOGinfo *info, const char *name)
{
char *ptr = strchr(name, '.');
HOGentry *a = info->entries;
@@ -474,6 +474,27 @@ static int HOG_mkdir(dvoid *opaque, const char *name)
} /* HOG_mkdir */


static int HOG_stat(fvoid *opaque, const char *filename, int *exists,
PHYSFS_Stat *stat)
{
const HOGinfo *info = (const HOGinfo *) opaque;
const HOGentry *entry = hog_find_entry(info, filename);

*exists = (entry != 0);
if (!entry)
return 0;

stat->filesize = entry->size;
stat->filetype = PHYSFS_FILETYPE_REGULAR;
stat->modtime = info->last_mod_time;
stat->createtime = info->last_mod_time;
stat->accesstime = -1;
stat->readonly = 1;

return 0;
} /* HOG_stat */


const PHYSFS_ArchiveInfo __PHYSFS_ArchiveInfo_HOG =
{
"HOG",
@@ -505,7 +526,8 @@ const PHYSFS_Archiver __PHYSFS_Archiver_HOG =
HOG_tell, /* tell() method */
HOG_seek, /* seek() method */
HOG_fileLength, /* fileLength() method */
HOG_fileClose /* fileClose() method */
HOG_fileClose, /* fileClose() method */
HOG_stat /* stat() method */
};

#endif /* defined PHYSFS_SUPPORTS_HOG */
@@ -207,7 +207,7 @@ static void lzma_file_swap(void *_a, PHYSFS_uint32 one, PHYSFS_uint32 two)
/*
* Find entry 'name' in 'archive'
*/
static LZMAfile * lzma_find_file(LZMAarchive *archive, const char *name)
static LZMAfile * lzma_find_file(const LZMAarchive *archive, const char *name)
{
LZMAfile *file = bsearch(name, archive->files, archive->db.Database.NumFiles, sizeof(*archive->files), lzma_file_cmp_stdlib); /* FIXME: Should become __PHYSFS_search!!! */

@@ -695,6 +695,42 @@ static int LZMA_mkdir(dvoid *opaque, const char *name)
BAIL_MACRO(ERR_NOT_SUPPORTED, 0);
} /* LZMA_mkdir */

static int LZMA_stat(fvoid *opaque, const char *filename, int *exists,
PHYSFS_Stat *stat)
{
const LZMAarchive *archive = (const LZMAarchive *) opaque;
const LZMAfile *file = lzma_find_file(archive, filename);

*exists = (file != 0);
if (!file)
return 0;

if(file->item->IsDirectory)
{
stat->filesize = 0;
stat->filetype = PHYSFS_FILETYPE_DIRECTORY;
} /* if */
else
{
stat->filesize = (PHYSFS_sint64) file->item->Size;
stat->filetype = PHYSFS_FILETYPE_REGULAR;
} /* else */

/* !!! FIXME: the 0's should be -1's? */
if (file->item->IsLastWriteTimeDefined)
stat->modtime = lzma_filetime_to_unix_timestamp(&file->item->LastWriteTime);
else
stat->modtime = 0;

/* real create and accesstype are currently not in the lzma SDK */
stat->createtime = stat->modtime;
stat->accesstime = 0;

stat->readonly = 1; /* 7zips are always read only */

return 0;
} /* LZMA_stat */


const PHYSFS_ArchiveInfo __PHYSFS_ArchiveInfo_LZMA =
{
@@ -727,7 +763,8 @@ const PHYSFS_Archiver __PHYSFS_Archiver_LZMA =
LZMA_tell, /* tell() method */
LZMA_seek, /* seek() method */
LZMA_fileLength, /* fileLength() method */
LZMA_fileClose /* fileClose() method */
LZMA_fileClose, /* fileClose() method */
LZMA_stat /* stat() method */
};

#endif /* defined PHYSFS_SUPPORTS_7Z */
@@ -312,7 +312,7 @@ static void MVL_enumerateFiles(dvoid *opaque, const char *dname,
} /* MVL_enumerateFiles */


static MVLentry *mvl_find_entry(MVLinfo *info, const char *name)
static MVLentry *mvl_find_entry(const MVLinfo *info, const char *name)
{
char *ptr = strchr(name, '.');
MVLentry *a = info->entries;
@@ -431,6 +431,27 @@ static int MVL_mkdir(dvoid *opaque, const char *name)
} /* MVL_mkdir */


static int MVL_stat(fvoid *opaque, const char *filename, int *exists,
PHYSFS_Stat *stat)
{
const MVLinfo *info = (const MVLinfo *) opaque;
const MVLentry *entry = mvl_find_entry(info, filename);

*exists = (entry != 0);
if (!entry)
return 0;

stat->filesize = entry->size;
stat->filetype = PHYSFS_FILETYPE_REGULAR;
stat->modtime = info->last_mod_time;
stat->createtime = info->last_mod_time;
stat->accesstime = 0;
stat->readonly = 1;

return 0;
} /* MVL_stat */


const PHYSFS_ArchiveInfo __PHYSFS_ArchiveInfo_MVL =
{
"MVL",
@@ -462,7 +483,8 @@ const PHYSFS_Archiver __PHYSFS_Archiver_MVL =
MVL_tell, /* tell() method */
MVL_seek, /* seek() method */
MVL_fileLength, /* fileLength() method */
MVL_fileClose /* fileClose() method */
MVL_fileClose, /* fileClose() method */
MVL_stat /* stat() method */
};

#endif /* defined PHYSFS_SUPPORTS_MVL */
@@ -445,7 +445,8 @@ static void QPAK_enumerateFiles(dvoid *opaque, const char *dname,
* notation. Directories don't have QPAKentries associated with them, but
* (*isDir) will be set to non-zero if a dir was hit.
*/
static QPAKentry *qpak_find_entry(QPAKinfo *info, const char *path, int *isDir)
static QPAKentry *qpak_find_entry(const QPAKinfo *info, const char *path,
int *isDir)
{
QPAKentry *a = info->entries;
PHYSFS_sint32 pathlen = strlen(path);
@@ -590,6 +591,37 @@ static int QPAK_mkdir(dvoid *opaque, const char *name)
} /* QPAK_mkdir */


static int QPAK_stat(fvoid *opaque, const char *filename, int *exists,
PHYSFS_Stat *stat)
{
int isDir = 0;
const QPAKinfo *info = (const QPAKinfo *) opaque;
const QPAKentry *entry = qpak_find_entry(info, filename, &isDir);

*exists = ((isDir) || (entry != NULL));
if (!exists)
return 0;

if (isDir)
{
stat->filetype = PHYSFS_FILETYPE_DIRECTORY;
stat->filesize = 0;
} /* if */
else
{
stat->filetype = PHYSFS_FILETYPE_REGULAR;
stat->filesize = entry->size;
} /* else */

stat->modtime = info->last_mod_time;
stat->createtime = info->last_mod_time;
stat->accesstime = 0;
stat->readonly = 1;

return 0;
} /* QPAK_stat */


const PHYSFS_ArchiveInfo __PHYSFS_ArchiveInfo_QPAK =
{
"PAK",
@@ -621,7 +653,8 @@ const PHYSFS_Archiver __PHYSFS_Archiver_QPAK =
QPAK_tell, /* tell() method */
QPAK_seek, /* seek() method */
QPAK_fileLength, /* fileLength() method */
QPAK_fileClose /* fileClose() method */
QPAK_fileClose, /* fileClose() method */
QPAK_stat /* stat() method */
};

#endif /* defined PHYSFS_SUPPORTS_QPAK */
@@ -361,7 +361,7 @@ static void WAD_enumerateFiles(dvoid *opaque, const char *dname,
} /* WAD_enumerateFiles */


static WADentry *wad_find_entry(WADinfo *info, const char *name)
static WADentry *wad_find_entry(const WADinfo *info, const char *name)
{
WADentry *a = info->entries;
PHYSFS_sint32 lo = 0;
@@ -494,6 +494,27 @@ static int WAD_mkdir(dvoid *opaque, const char *name)
} /* WAD_mkdir */


static int WAD_stat(fvoid *opaque, const char *filename, int *exists,
PHYSFS_Stat *stat)
{
const WADinfo *info = (const WADinfo *) opaque;
const WADentry *entry = wad_find_entry(info, filename);

*exists = (entry != 0);
if (!entry)
return 0;

stat->filesize = entry->size;
stat->filetype = PHYSFS_FILETYPE_REGULAR;
stat->accesstime = 0;
stat->modtime = ((WADinfo *) opaque)->last_mod_time;
stat->createtime = ((WADinfo *) opaque)->last_mod_time;
stat->readonly = 1; /* WADs are always readonly */

return 0;
} /* WAD_stat */


const PHYSFS_ArchiveInfo __PHYSFS_ArchiveInfo_WAD =
{
"WAD",
@@ -525,7 +546,8 @@ const PHYSFS_Archiver __PHYSFS_Archiver_WAD =
WAD_tell, /* tell() method */
WAD_seek, /* seek() method */
WAD_fileLength, /* fileLength() method */
WAD_fileClose /* fileClose() method */
WAD_fileClose, /* fileClose() method */
WAD_stat /* stat() method */
};

#endif /* defined PHYSFS_SUPPORTS_WAD */

0 comments on commit f1cd4d8

Please sign in to comment.