static int wad_load_entries(const char *name, int forWriting, WADinfo *info) { void *fh = NULL; PHYSFS_uint32 fileCount; PHYSFS_uint32 directoryOffset; WADentry *entry; char lastDirectory[9]; lastDirectory[8] = 0; /* Make sure lastDirectory stays null-terminated. */ BAIL_IF_MACRO(!wad_open(name, forWriting, &fh, &fileCount,&directoryOffset), NULL, 0); info->entryCount = fileCount; info->entries = (WADentry *) allocator.Malloc(sizeof(WADentry)*fileCount); if (info->entries == NULL) { __PHYSFS_platformClose(fh); BAIL_MACRO(ERR_OUT_OF_MEMORY, 0); } /* if */ __PHYSFS_platformSeek(fh,directoryOffset); for (entry = info->entries; fileCount > 0; fileCount--, entry++) { if (__PHYSFS_platformRead(fh, &entry->startPos, 4, 1) != 1) { __PHYSFS_platformClose(fh); return 0; } /* if */ if (__PHYSFS_platformRead(fh, &entry->size, 4, 1) != 1) { __PHYSFS_platformClose(fh); return 0; } /* if */ if (__PHYSFS_platformRead(fh, &entry->name, 8, 1) != 1) { __PHYSFS_platformClose(fh); return 0; } /* if */ entry->name[8] = '\0'; /* name might not be null-terminated in file. */ entry->size = PHYSFS_swapULE32(entry->size); entry->startPos = PHYSFS_swapULE32(entry->startPos); } /* for */ __PHYSFS_platformClose(fh); __PHYSFS_sort(info->entries, info->entryCount, wad_entry_cmp, wad_entry_swap); return 1; } /* wad_load_entries */
static int hog_load_entries(const char *name, int forWriting, HOGinfo *info) { void *fh = NULL; PHYSFS_uint32 fileCount; HOGentry *entry; BAIL_IF_MACRO(!hog_open(name, forWriting, &fh, &fileCount), NULL, 0); info->entryCount = fileCount; info->entries = (HOGentry *) malloc(sizeof (HOGentry) * fileCount); if (info->entries == NULL) { __PHYSFS_platformClose(fh); BAIL_MACRO(ERR_OUT_OF_MEMORY, 0); } /* if */ for (entry = info->entries; fileCount > 0; fileCount--, entry++) { if (__PHYSFS_platformRead(fh, &entry->name, 13, 1) != 1) { __PHYSFS_platformClose(fh); return(0); } /* if */ if (__PHYSFS_platformRead(fh, &entry->size, 4, 1) != 1) { __PHYSFS_platformClose(fh); return(0); } /* if */ entry->size = PHYSFS_swapULE32(entry->size); entry->startPos = __PHYSFS_platformTell(fh); if (entry->startPos == -1) { __PHYSFS_platformClose(fh); return(0); } // Skip over entry if (!__PHYSFS_platformSeek(fh, entry->startPos + entry->size)) { __PHYSFS_platformClose(fh); return(0); } } /* for */ __PHYSFS_platformClose(fh); __PHYSFS_sort(info->entries, info->entryCount, hog_entry_cmp, hog_entry_swap); return(1); } /* hog_load_entries */
static int HHA_load_entries(const char *name, int forWriting, HHAinfo *info) { void *fh = NULL; PHYSFS_uint32 fileNameSize; PHYSFS_uint32 fileCount; HHAentry *entry; PHYSFS_uint32 buf[6]; BAIL_IF_MACRO(!hha_open(name, forWriting, &fh, &fileNameSize, &fileCount), NULL, 0); info->entryCount = fileCount; info->filenames = (char *) allocator.Malloc(fileNameSize); if (info->filenames == NULL) { __PHYSFS_platformClose(fh); BAIL_MACRO(ERR_OUT_OF_MEMORY, 0); } /* if */ info->entries = (HHAentry *) allocator.Malloc(sizeof(HHAentry)*fileCount); if (info->entries == NULL) { __PHYSFS_platformClose(fh); BAIL_MACRO(ERR_OUT_OF_MEMORY, 0); } /* if */ if (__PHYSFS_platformRead(fh, info->filenames, 1, fileNameSize) != fileNameSize) { __PHYSFS_platformClose(fh); return(0); } for (entry = info->entries; fileCount > 0; fileCount--, entry++) { if (__PHYSFS_platformRead(fh, buf, sizeof(PHYSFS_uint32), 6) != 6) { __PHYSFS_platformClose(fh); return(0); } /* if */ entry->dir = info->filenames + PHYSFS_swapULE32(buf[0]); entry->name = info->filenames + PHYSFS_swapULE32(buf[1]); entry->compress = PHYSFS_swapULE32(buf[2]); entry->offset = PHYSFS_swapULE32(buf[3]); entry->uncompressed_size = PHYSFS_swapULE32(buf[4]); entry->compressed_size = PHYSFS_swapULE32(buf[5]); } /* for */ __PHYSFS_platformClose(fh); __PHYSFS_sort(info->entries, info->entryCount, HHA_entry_cmp, HHA_entry_swap); return(1); } /* HHA_load_entries */
/* * Load metadata for all files */ static int lzma_files_init(LZMAarchive *archive) { PHYSFS_uint32 fileIndex = 0, numFiles = archive->db.Database.NumFiles; for (fileIndex = 0; fileIndex < numFiles; fileIndex++ ) { if (!lzma_file_init(archive, fileIndex)) { return 0; /* FALSE on failure */ } } /* for */ __PHYSFS_sort(archive->files, (size_t) numFiles, lzma_file_cmp, lzma_file_swap); return 1; } /* lzma_load_files */
PHYSFS_Dir *UNPK_openArchive(PHYSFS_Io *io, UNPKentry *e, const PHYSFS_uint32 num) { UNPKinfo *info = (UNPKinfo *) allocator.Malloc(sizeof (UNPKinfo)); if (info == NULL) { allocator.Free(e); BAIL_MACRO(PHYSFS_ERR_OUT_OF_MEMORY, NULL); } /* if */ __PHYSFS_sort(e, (size_t) num, entryCmp, entrySwap); info->io = io; info->entryCount = num; info->entries = e; return info; } /* UNPK_openArchive */
static int mvl_load_entries(const char *name, int forWriting, MVLinfo *info) { void *fh = NULL; PHYSFS_uint32 fileCount; PHYSFS_uint32 location = 8; /* sizeof sig. */ MVLentry *entry; BAIL_IF_MACRO(!mvl_open(name, forWriting, &fh, &fileCount), NULL, 0); info->entryCount = fileCount; info->entries = (MVLentry *) allocator.Malloc(sizeof(MVLentry)*fileCount); if (info->entries == NULL) { __PHYSFS_platformClose(fh); BAIL_MACRO(ERR_OUT_OF_MEMORY, 0); } /* if */ location += (17 * fileCount); for (entry = info->entries; fileCount > 0; fileCount--, entry++) { if (__PHYSFS_platformRead(fh, &entry->name, 13, 1) != 1) { __PHYSFS_platformClose(fh); return 0; } /* if */ if (__PHYSFS_platformRead(fh, &entry->size, 4, 1) != 1) { __PHYSFS_platformClose(fh); return 0; } /* if */ entry->size = PHYSFS_swapULE32(entry->size); entry->startPos = location; location += entry->size; } /* for */ __PHYSFS_platformClose(fh); __PHYSFS_sort(info->entries, info->entryCount, mvl_entry_cmp, mvl_entry_swap); return 1; } /* mvl_load_entries */