2003-07-21 02:27:09 +02:00
|
|
|
/*
|
|
|
|
* QPAK support routines for PhysicsFS.
|
|
|
|
*
|
|
|
|
* This archiver handles the archive format utilized by Quake 1 and 2.
|
2017-07-16 10:35:46 +02:00
|
|
|
* Quake3-based games use the PkZip/Info-Zip format (which our
|
2017-07-22 19:48:31 +02:00
|
|
|
* physfs_archiver_zip.c handles).
|
2003-07-21 02:27:09 +02:00
|
|
|
*
|
|
|
|
* ========================================================================
|
|
|
|
*
|
|
|
|
* This format info (in more detail) comes from:
|
2017-06-20 20:06:13 +02:00
|
|
|
* https://web.archive.org/web/20040209101748/http://debian.fmi.uni-sofia.bg/~sergei/cgsr/docs/pak.txt
|
2003-07-21 02:27:09 +02:00
|
|
|
*
|
|
|
|
* Quake PAK Format
|
|
|
|
*
|
|
|
|
* Header
|
|
|
|
* (4 bytes) signature = 'PACK'
|
|
|
|
* (4 bytes) directory offset
|
|
|
|
* (4 bytes) directory length
|
|
|
|
*
|
|
|
|
* Directory
|
|
|
|
* (56 bytes) file name
|
|
|
|
* (4 bytes) file position
|
|
|
|
* (4 bytes) file length
|
|
|
|
*
|
|
|
|
* ========================================================================
|
|
|
|
*
|
2007-03-11 11:10:28 +01:00
|
|
|
* Please see the file LICENSE.txt in the source's root directory.
|
2003-07-21 02:27:09 +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_QPAK
|
|
|
|
|
2012-03-23 07:45:38 +01:00
|
|
|
#define QPAK_SIG 0x4B434150 /* "PACK" in ASCII. */
|
2003-11-09 22:06:15 +01:00
|
|
|
|
2017-07-16 10:39:14 +02:00
|
|
|
static int qpakLoadEntries(PHYSFS_Io *io, const PHYSFS_uint32 count, void *arc)
|
2003-07-21 02:27:09 +02:00
|
|
|
{
|
2017-07-16 10:39:14 +02:00
|
|
|
PHYSFS_uint32 i;
|
|
|
|
for (i = 0; i < count; i++)
|
2003-07-21 02:27:09 +02:00
|
|
|
{
|
2017-07-16 10:39:14 +02:00
|
|
|
PHYSFS_uint32 size;
|
2017-07-22 18:47:32 +02:00
|
|
|
PHYSFS_uint32 pos;
|
2017-07-16 10:39:14 +02:00
|
|
|
char name[56];
|
|
|
|
BAIL_IF_ERRPASS(!__PHYSFS_readAll(io, name, 56), 0);
|
2017-07-22 18:47:32 +02:00
|
|
|
BAIL_IF_ERRPASS(!__PHYSFS_readAll(io, &pos, 4), 0);
|
2017-07-16 10:39:14 +02:00
|
|
|
BAIL_IF_ERRPASS(!__PHYSFS_readAll(io, &size, 4), 0);
|
|
|
|
size = PHYSFS_swapULE32(size);
|
2017-07-22 18:47:32 +02:00
|
|
|
pos = PHYSFS_swapULE32(pos);
|
|
|
|
BAIL_IF_ERRPASS(!UNPK_addEntry(arc, name, 0, -1, -1, pos, size), 0);
|
2003-07-21 02:27:09 +02:00
|
|
|
} /* for */
|
|
|
|
|
2017-07-16 10:39:14 +02:00
|
|
|
return 1;
|
2012-03-23 07:45:38 +01:00
|
|
|
} /* qpakLoadEntries */
|
2003-07-21 02:27:09 +02:00
|
|
|
|
|
|
|
|
2010-08-30 09:01:57 +02:00
|
|
|
static void *QPAK_openArchive(PHYSFS_Io *io, const char *name, int forWriting)
|
2003-07-21 02:27:09 +02:00
|
|
|
{
|
2010-08-30 09:01:57 +02:00
|
|
|
PHYSFS_uint32 val = 0;
|
|
|
|
PHYSFS_uint32 pos = 0;
|
|
|
|
PHYSFS_uint32 count = 0;
|
2017-07-16 10:39:14 +02:00
|
|
|
void *unpkarc;
|
2003-07-21 02:27:09 +02:00
|
|
|
|
2010-08-30 09:01:57 +02:00
|
|
|
assert(io != NULL); /* shouldn't ever happen. */
|
2003-07-21 02:27:09 +02:00
|
|
|
|
2017-07-06 17:51:41 +02:00
|
|
|
BAIL_IF(forWriting, PHYSFS_ERR_READ_ONLY, NULL);
|
2003-07-21 02:27:09 +02:00
|
|
|
|
2017-07-06 17:51:41 +02:00
|
|
|
BAIL_IF_ERRPASS(!__PHYSFS_readAll(io, &val, 4), NULL);
|
2012-03-20 20:38:12 +01:00
|
|
|
if (PHYSFS_swapULE32(val) != QPAK_SIG)
|
2017-07-06 17:51:41 +02:00
|
|
|
BAIL(PHYSFS_ERR_UNSUPPORTED, NULL);
|
2003-07-21 02:27:09 +02:00
|
|
|
|
2017-07-06 17:51:41 +02:00
|
|
|
BAIL_IF_ERRPASS(!__PHYSFS_readAll(io, &val, 4), NULL);
|
2010-08-30 09:01:57 +02:00
|
|
|
pos = PHYSFS_swapULE32(val); /* directory table offset. */
|
|
|
|
|
2017-07-06 17:51:41 +02:00
|
|
|
BAIL_IF_ERRPASS(!__PHYSFS_readAll(io, &val, 4), NULL);
|
2010-08-30 09:01:57 +02:00
|
|
|
count = PHYSFS_swapULE32(val);
|
2003-07-21 02:27:09 +02:00
|
|
|
|
2010-08-30 09:01:57 +02:00
|
|
|
/* corrupted archive? */
|
2017-07-06 17:51:41 +02:00
|
|
|
BAIL_IF((count % 64) != 0, PHYSFS_ERR_CORRUPT, NULL);
|
2010-08-30 09:01:57 +02:00
|
|
|
count /= 64;
|
|
|
|
|
2017-07-06 17:51:41 +02:00
|
|
|
BAIL_IF_ERRPASS(!io->seek(io, pos), NULL);
|
2010-08-30 09:01:57 +02:00
|
|
|
|
2017-07-21 19:54:42 +02:00
|
|
|
unpkarc = UNPK_openArchive(io);
|
2017-07-16 10:39:14 +02:00
|
|
|
BAIL_IF_ERRPASS(!unpkarc, NULL);
|
|
|
|
|
|
|
|
if (!qpakLoadEntries(io, count, unpkarc))
|
|
|
|
{
|
2017-07-22 01:01:41 +02:00
|
|
|
UNPK_abandonArchive(unpkarc);
|
2017-07-16 10:39:14 +02:00
|
|
|
return NULL;
|
|
|
|
} /* if */
|
|
|
|
|
|
|
|
return unpkarc;
|
2003-07-21 02:27:09 +02:00
|
|
|
} /* QPAK_openArchive */
|
|
|
|
|
|
|
|
|
2004-09-29 08:18:04 +02:00
|
|
|
const PHYSFS_Archiver __PHYSFS_Archiver_QPAK =
|
|
|
|
{
|
2012-11-28 07:36:13 +01:00
|
|
|
CURRENT_PHYSFS_ARCHIVER_API_VERSION,
|
2012-03-25 23:17:56 +02:00
|
|
|
{
|
|
|
|
"PAK",
|
|
|
|
"Quake I/II 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
|
|
|
QPAK_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
|
|
|
};
|
|
|
|
|
2003-07-21 02:27:09 +02:00
|
|
|
#endif /* defined PHYSFS_SUPPORTS_QPAK */
|
|
|
|
|
2017-07-22 19:19:57 +02:00
|
|
|
/* end of physfs_archiver_qpak.c ... */
|
2003-07-21 02:27:09 +02:00
|
|
|
|