2001-07-09 02:49:41 +02:00
|
|
|
/*
|
|
|
|
* GRP support routines for PhysicsFS.
|
|
|
|
*
|
|
|
|
* This driver handles BUILD engine archives ("groupfiles"). This format
|
|
|
|
* (but not this driver) was put together by Ken Silverman.
|
|
|
|
*
|
|
|
|
* The format is simple enough. In Ken's words:
|
|
|
|
*
|
|
|
|
* What's the .GRP file format?
|
|
|
|
*
|
|
|
|
* The ".grp" file format is just a collection of a lot of files stored
|
|
|
|
* into 1 big one. I tried to make the format as simple as possible: The
|
|
|
|
* first 12 bytes contains my name, "KenSilverman". The next 4 bytes is
|
|
|
|
* the number of files that were compacted into the group file. Then for
|
|
|
|
* each file, there is a 16 byte structure, where the first 12 bytes are
|
|
|
|
* the filename, and the last 4 bytes are the file's size. The rest of
|
|
|
|
* the group file is just the raw data packed one after the other in the
|
|
|
|
* same order as the list of files.
|
|
|
|
*
|
|
|
|
* (That info is from http://www.advsys.net/ken/build.htm ...)
|
|
|
|
*
|
2007-03-11 11:10:28 +01:00
|
|
|
* Please see the file LICENSE.txt in the source's root directory.
|
2001-07-09 02:49:41 +02:00
|
|
|
*
|
|
|
|
* This file written by Ryan C. Gordon.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define __PHYSICSFS_INTERNAL__
|
|
|
|
#include "physfs_internal.h"
|
|
|
|
|
2012-03-23 05:52:32 +01:00
|
|
|
#if PHYSFS_SUPPORTS_GRP
|
|
|
|
|
2017-07-16 10:39:14 +02:00
|
|
|
static int grpLoadEntries(PHYSFS_Io *io, const PHYSFS_uint32 count, void *arc)
|
2001-07-09 02:49:41 +02:00
|
|
|
{
|
2017-07-16 10:39:14 +02:00
|
|
|
PHYSFS_uint32 location = 16 + (16 * count); /* past sig+metadata. */
|
|
|
|
PHYSFS_uint32 i;
|
2002-07-23 09:48:43 +02:00
|
|
|
|
2017-07-16 10:39:14 +02:00
|
|
|
for (i = 0; i < count; i++)
|
2002-07-23 09:48:43 +02:00
|
|
|
{
|
2017-07-16 10:39:14 +02:00
|
|
|
char *ptr;
|
|
|
|
char name[13];
|
|
|
|
PHYSFS_uint32 size;
|
|
|
|
BAIL_IF_ERRPASS(!__PHYSFS_readAll(io, name, 12), 0);
|
|
|
|
BAIL_IF_ERRPASS(!__PHYSFS_readAll(io, &size, 4), 0);
|
|
|
|
|
|
|
|
name[12] = '\0'; /* name isn't null-terminated in file. */
|
|
|
|
if ((ptr = strchr(name, ' ')) != NULL)
|
2002-07-23 09:48:43 +02:00
|
|
|
*ptr = '\0'; /* trim extra spaces. */
|
|
|
|
|
2017-07-16 10:39:14 +02:00
|
|
|
size = PHYSFS_swapULE32(size);
|
|
|
|
BAIL_IF_ERRPASS(!UNPK_addEntry(arc, name, 0, location, size), 0);
|
2002-07-23 09:48:43 +02:00
|
|
|
|
2017-07-16 10:39:14 +02:00
|
|
|
location += size;
|
|
|
|
} /* for */
|
2010-09-06 08:50:29 +02:00
|
|
|
|
2017-07-16 10:39:14 +02:00
|
|
|
return 1;
|
2010-09-06 08:50:29 +02:00
|
|
|
} /* grpLoadEntries */
|
2002-07-23 09:48:43 +02:00
|
|
|
|
|
|
|
|
2010-08-30 09:01:57 +02:00
|
|
|
static void *GRP_openArchive(PHYSFS_Io *io, const char *name, int forWriting)
|
2002-07-23 09:48:43 +02:00
|
|
|
{
|
2010-08-30 09:01:57 +02:00
|
|
|
PHYSFS_uint8 buf[12];
|
2012-03-09 10:50:27 +01:00
|
|
|
PHYSFS_uint32 count = 0;
|
2017-07-16 10:39:14 +02:00
|
|
|
void *unpkarc = NULL;
|
2010-08-30 09:01:57 +02:00
|
|
|
|
|
|
|
assert(io != NULL); /* shouldn't ever happen. */
|
2001-07-09 02:49:41 +02:00
|
|
|
|
2017-07-06 17:51:41 +02:00
|
|
|
BAIL_IF(forWriting, PHYSFS_ERR_READ_ONLY, NULL);
|
2001-07-09 02:49:41 +02:00
|
|
|
|
2017-07-06 17:51:41 +02:00
|
|
|
BAIL_IF_ERRPASS(!__PHYSFS_readAll(io, buf, sizeof (buf)), NULL);
|
2010-08-30 09:01:57 +02:00
|
|
|
if (memcmp(buf, "KenSilverman", sizeof (buf)) != 0)
|
2017-07-06 17:51:41 +02:00
|
|
|
BAIL(PHYSFS_ERR_UNSUPPORTED, NULL);
|
2002-03-25 09:13:06 +01:00
|
|
|
|
2017-07-06 17:51:41 +02:00
|
|
|
BAIL_IF_ERRPASS(!__PHYSFS_readAll(io, &count, sizeof(count)), NULL);
|
2012-03-09 10:50:27 +01:00
|
|
|
count = PHYSFS_swapULE32(count);
|
2002-03-25 09:13:06 +01:00
|
|
|
|
2017-07-16 10:39:14 +02:00
|
|
|
unpkarc = UNPK_openArchive(io, count);
|
|
|
|
BAIL_IF_ERRPASS(!unpkarc, NULL);
|
|
|
|
|
|
|
|
if (!grpLoadEntries(io, count, unpkarc))
|
|
|
|
{
|
|
|
|
UNPK_closeArchive(unpkarc);
|
|
|
|
return NULL;
|
|
|
|
} /* if */
|
|
|
|
|
|
|
|
return unpkarc;
|
2001-07-09 02:49:41 +02:00
|
|
|
} /* GRP_openArchive */
|
|
|
|
|
|
|
|
|
2004-09-29 08:18:04 +02:00
|
|
|
const PHYSFS_Archiver __PHYSFS_Archiver_GRP =
|
|
|
|
{
|
2012-11-28 07:36:13 +01:00
|
|
|
CURRENT_PHYSFS_ARCHIVER_API_VERSION,
|
2012-03-25 23:17:56 +02:00
|
|
|
{
|
|
|
|
"GRP",
|
|
|
|
"Build engine Groupfile format",
|
|
|
|
"Ryan C. Gordon <icculus@icculus.org>",
|
2016-02-25 08:51:28 +01:00
|
|
|
"https://icculus.org/physfs/",
|
2012-11-30 06:04:52 +01:00
|
|
|
0, /* supportsSymlinks */
|
2012-03-25 23:17:56 +02:00
|
|
|
},
|
2012-11-30 20:06:21 +01:00
|
|
|
GRP_openArchive,
|
|
|
|
UNPK_enumerateFiles,
|
|
|
|
UNPK_openRead,
|
|
|
|
UNPK_openWrite,
|
|
|
|
UNPK_openAppend,
|
|
|
|
UNPK_remove,
|
|
|
|
UNPK_mkdir,
|
2012-11-30 20:09:56 +01:00
|
|
|
UNPK_stat,
|
|
|
|
UNPK_closeArchive
|
2004-09-29 08:18:04 +02:00
|
|
|
};
|
|
|
|
|
2002-05-10 11:25:25 +02:00
|
|
|
#endif /* defined PHYSFS_SUPPORTS_GRP */
|
|
|
|
|
2012-11-27 06:12:39 +01:00
|
|
|
/* end of archiver_grp.c ... */
|
2001-07-09 02:49:41 +02:00
|
|
|
|