DirTrees and unpacked archives shouldn't demand a count of entries for init.
This commit is contained in:
parent
32ed71db48
commit
d3ac612b61
|
@ -183,11 +183,11 @@ static int szipLoadEntry(SZIPinfo *info, const PHYSFS_uint32 idx)
|
||||||
|
|
||||||
static int szipLoadEntries(SZIPinfo *info)
|
static int szipLoadEntries(SZIPinfo *info)
|
||||||
{
|
{
|
||||||
const PHYSFS_uint32 count = info->db.NumFiles;
|
|
||||||
int retval = 0;
|
int retval = 0;
|
||||||
|
|
||||||
if (__PHYSFS_DirTreeInit(&info->tree, count, sizeof (SZIPentry)))
|
if (__PHYSFS_DirTreeInit(&info->tree, sizeof (SZIPentry)))
|
||||||
{
|
{
|
||||||
|
const PHYSFS_uint32 count = info->db.NumFiles;
|
||||||
PHYSFS_uint32 i;
|
PHYSFS_uint32 i;
|
||||||
for (i = 0; i < count; i++)
|
for (i = 0; i < count; i++)
|
||||||
BAIL_IF_ERRPASS(!szipLoadEntry(info, i), 0);
|
BAIL_IF_ERRPASS(!szipLoadEntry(info, i), 0);
|
||||||
|
|
|
@ -73,7 +73,7 @@ static void *GRP_openArchive(PHYSFS_Io *io, const char *name, int forWriting)
|
||||||
BAIL_IF_ERRPASS(!__PHYSFS_readAll(io, &count, sizeof(count)), NULL);
|
BAIL_IF_ERRPASS(!__PHYSFS_readAll(io, &count, sizeof(count)), NULL);
|
||||||
count = PHYSFS_swapULE32(count);
|
count = PHYSFS_swapULE32(count);
|
||||||
|
|
||||||
unpkarc = UNPK_openArchive(io, count);
|
unpkarc = UNPK_openArchive(io);
|
||||||
BAIL_IF_ERRPASS(!unpkarc, NULL);
|
BAIL_IF_ERRPASS(!unpkarc, NULL);
|
||||||
|
|
||||||
if (!grpLoadEntries(io, count, unpkarc))
|
if (!grpLoadEntries(io, count, unpkarc))
|
||||||
|
|
|
@ -72,7 +72,7 @@ static void *HOG_openArchive(PHYSFS_Io *io, const char *name, int forWriting)
|
||||||
BAIL_IF_ERRPASS(!__PHYSFS_readAll(io, buf, 3), NULL);
|
BAIL_IF_ERRPASS(!__PHYSFS_readAll(io, buf, 3), NULL);
|
||||||
BAIL_IF(memcmp(buf, "DHF", 3) != 0, PHYSFS_ERR_UNSUPPORTED, NULL);
|
BAIL_IF(memcmp(buf, "DHF", 3) != 0, PHYSFS_ERR_UNSUPPORTED, NULL);
|
||||||
|
|
||||||
unpkarc = UNPK_openArchive(io, count);
|
unpkarc = UNPK_openArchive(io);
|
||||||
BAIL_IF_ERRPASS(!unpkarc, NULL);
|
BAIL_IF_ERRPASS(!unpkarc, NULL);
|
||||||
|
|
||||||
if (!hogLoadEntries(io, unpkarc))
|
if (!hogLoadEntries(io, unpkarc))
|
||||||
|
|
|
@ -67,7 +67,7 @@ static void *MVL_openArchive(PHYSFS_Io *io, const char *name, int forWriting)
|
||||||
|
|
||||||
count = PHYSFS_swapULE32(count);
|
count = PHYSFS_swapULE32(count);
|
||||||
|
|
||||||
unpkarc = UNPK_openArchive(io, count);
|
unpkarc = UNPK_openArchive(io);
|
||||||
BAIL_IF_ERRPASS(!unpkarc, NULL);
|
BAIL_IF_ERRPASS(!unpkarc, NULL);
|
||||||
|
|
||||||
if (!mvlLoadEntries(io, count, unpkarc))
|
if (!mvlLoadEntries(io, count, unpkarc))
|
||||||
|
|
|
@ -83,7 +83,7 @@ static void *QPAK_openArchive(PHYSFS_Io *io, const char *name, int forWriting)
|
||||||
|
|
||||||
BAIL_IF_ERRPASS(!io->seek(io, pos), NULL);
|
BAIL_IF_ERRPASS(!io->seek(io, pos), NULL);
|
||||||
|
|
||||||
unpkarc = UNPK_openArchive(io, count);
|
unpkarc = UNPK_openArchive(io);
|
||||||
BAIL_IF_ERRPASS(!unpkarc, NULL);
|
BAIL_IF_ERRPASS(!unpkarc, NULL);
|
||||||
|
|
||||||
if (!qpakLoadEntries(io, count, unpkarc))
|
if (!qpakLoadEntries(io, count, unpkarc))
|
||||||
|
|
|
@ -93,7 +93,7 @@ static void *SLB_openArchive(PHYSFS_Io *io, const char *name, int forWriting)
|
||||||
/* seek to the table of contents */
|
/* seek to the table of contents */
|
||||||
BAIL_IF_ERRPASS(!io->seek(io, tocPos), NULL);
|
BAIL_IF_ERRPASS(!io->seek(io, tocPos), NULL);
|
||||||
|
|
||||||
unpkarc = UNPK_openArchive(io, count);
|
unpkarc = UNPK_openArchive(io);
|
||||||
BAIL_IF_ERRPASS(!unpkarc, NULL);
|
BAIL_IF_ERRPASS(!unpkarc, NULL);
|
||||||
|
|
||||||
if (!slbLoadEntries(io, count, unpkarc))
|
if (!slbLoadEntries(io, count, unpkarc))
|
||||||
|
|
|
@ -271,12 +271,12 @@ void *UNPK_addEntry(void *opaque, char *name, const int isdir,
|
||||||
} /* UNPK_addEntry */
|
} /* UNPK_addEntry */
|
||||||
|
|
||||||
|
|
||||||
void *UNPK_openArchive(PHYSFS_Io *io, const PHYSFS_uint64 entry_count)
|
void *UNPK_openArchive(PHYSFS_Io *io)
|
||||||
{
|
{
|
||||||
UNPKinfo *info = (UNPKinfo *) allocator.Malloc(sizeof (UNPKinfo));
|
UNPKinfo *info = (UNPKinfo *) allocator.Malloc(sizeof (UNPKinfo));
|
||||||
BAIL_IF(!info, PHYSFS_ERR_OUT_OF_MEMORY, NULL);
|
BAIL_IF(!info, PHYSFS_ERR_OUT_OF_MEMORY, NULL);
|
||||||
|
|
||||||
if (!__PHYSFS_DirTreeInit(&info->tree, entry_count, sizeof (UNPKentry)))
|
if (!__PHYSFS_DirTreeInit(&info->tree, sizeof (UNPKentry)))
|
||||||
{
|
{
|
||||||
allocator.Free(info);
|
allocator.Free(info);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
|
@ -92,7 +92,7 @@ static void *WAD_openArchive(PHYSFS_Io *io, const char *name, int forWriting)
|
||||||
|
|
||||||
BAIL_IF_ERRPASS(!io->seek(io, directoryOffset), 0);
|
BAIL_IF_ERRPASS(!io->seek(io, directoryOffset), 0);
|
||||||
|
|
||||||
unpkarc = UNPK_openArchive(io, count);
|
unpkarc = UNPK_openArchive(io);
|
||||||
BAIL_IF_ERRPASS(!unpkarc, NULL);
|
BAIL_IF_ERRPASS(!unpkarc, NULL);
|
||||||
|
|
||||||
if (!wadLoadEntries(io, count, unpkarc))
|
if (!wadLoadEntries(io, count, unpkarc))
|
||||||
|
|
|
@ -1472,7 +1472,7 @@ static void *ZIP_openArchive(PHYSFS_Io *io, const char *name, int forWriting)
|
||||||
|
|
||||||
if (!zip_parse_end_of_central_dir(info, &dstart, &cdir_ofs, &count))
|
if (!zip_parse_end_of_central_dir(info, &dstart, &cdir_ofs, &count))
|
||||||
goto ZIP_openarchive_failed;
|
goto ZIP_openarchive_failed;
|
||||||
else if (!__PHYSFS_DirTreeInit(&info->tree, count, sizeof (ZIPentry)))
|
else if (!__PHYSFS_DirTreeInit(&info->tree, sizeof (ZIPentry)))
|
||||||
goto ZIP_openarchive_failed;
|
goto ZIP_openarchive_failed;
|
||||||
|
|
||||||
root = (ZIPentry *) info->tree.root;
|
root = (ZIPentry *) info->tree.root;
|
||||||
|
|
|
@ -3008,9 +3008,7 @@ static void setDefaultAllocator(void)
|
||||||
} /* setDefaultAllocator */
|
} /* setDefaultAllocator */
|
||||||
|
|
||||||
|
|
||||||
int __PHYSFS_DirTreeInit(__PHYSFS_DirTree *dt,
|
int __PHYSFS_DirTreeInit(__PHYSFS_DirTree *dt, const size_t entrylen)
|
||||||
const PHYSFS_uint64 entry_count,
|
|
||||||
const size_t entrylen)
|
|
||||||
{
|
{
|
||||||
static char rootpath[2] = { '/', '\0' };
|
static char rootpath[2] = { '/', '\0' };
|
||||||
size_t alloclen;
|
size_t alloclen;
|
||||||
|
@ -3024,7 +3022,7 @@ int __PHYSFS_DirTreeInit(__PHYSFS_DirTree *dt,
|
||||||
memset(dt->root, '\0', entrylen);
|
memset(dt->root, '\0', entrylen);
|
||||||
dt->root->name = rootpath;
|
dt->root->name = rootpath;
|
||||||
dt->root->isdir = 1;
|
dt->root->isdir = 1;
|
||||||
dt->hashBuckets = (size_t) (entry_count / 5);
|
dt->hashBuckets = 64;
|
||||||
if (!dt->hashBuckets)
|
if (!dt->hashBuckets)
|
||||||
dt->hashBuckets = 1;
|
dt->hashBuckets = 1;
|
||||||
dt->entrylen = entrylen;
|
dt->entrylen = entrylen;
|
||||||
|
|
|
@ -343,7 +343,7 @@ int __PHYSFS_readAll(PHYSFS_Io *io, void *buf, const PHYSFS_uint64 len);
|
||||||
/* These are shared between some archivers. */
|
/* These are shared between some archivers. */
|
||||||
|
|
||||||
void UNPK_closeArchive(void *opaque);
|
void UNPK_closeArchive(void *opaque);
|
||||||
void *UNPK_openArchive(PHYSFS_Io *io, const PHYSFS_uint64 entry_count);
|
void *UNPK_openArchive(PHYSFS_Io *io);
|
||||||
void *UNPK_addEntry(void *opaque, char *name, const int isdir,
|
void *UNPK_addEntry(void *opaque, char *name, const int isdir,
|
||||||
const PHYSFS_uint64 pos, const PHYSFS_uint64 len);
|
const PHYSFS_uint64 pos, const PHYSFS_uint64 len);
|
||||||
PHYSFS_Io *UNPK_openRead(void *opaque, const char *name);
|
PHYSFS_Io *UNPK_openRead(void *opaque, const char *name);
|
||||||
|
@ -377,9 +377,7 @@ typedef struct __PHYSFS_DirTree
|
||||||
} __PHYSFS_DirTree;
|
} __PHYSFS_DirTree;
|
||||||
|
|
||||||
|
|
||||||
int __PHYSFS_DirTreeInit(__PHYSFS_DirTree *dt,
|
int __PHYSFS_DirTreeInit(__PHYSFS_DirTree *dt, const size_t entrylen);
|
||||||
const PHYSFS_uint64 entry_count,
|
|
||||||
const size_t entrylen);
|
|
||||||
void *__PHYSFS_DirTreeAdd(__PHYSFS_DirTree *dt, char *name, const int isdir);
|
void *__PHYSFS_DirTreeAdd(__PHYSFS_DirTree *dt, char *name, const int isdir);
|
||||||
void *__PHYSFS_DirTreeFind(__PHYSFS_DirTree *dt, const char *path);
|
void *__PHYSFS_DirTreeFind(__PHYSFS_DirTree *dt, const char *path);
|
||||||
void __PHYSFS_DirTreeEnumerateFiles(void *opaque, const char *dname,
|
void __PHYSFS_DirTreeEnumerateFiles(void *opaque, const char *dname,
|
||||||
|
|
Loading…
Reference in New Issue