| 1 | /* |
| 2 | * Descent 3 |
| 3 | * Copyright (C) 2024 Parallax Software |
| 4 | * |
| 5 | * This program is free software: you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation, either version 3 of the License, or |
| 8 | * (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 | |
| 18 | --- HISTORICAL COMMENTS FOLLOW --- |
| 19 | |
| 20 | * $Logfile: /DescentIII/Main/Cfile/hog.cpp $ |
| 21 | * $Revision: 20 $ |
| 22 | * $Date: 8/06/99 4:29p $ |
| 23 | * $Author: Samir $ |
| 24 | * |
| 25 | * |
| 26 | * |
| 27 | * $Log: /DescentIII/Main/Cfile/hog.cpp $ |
| 28 | * |
| 29 | * 20 8/06/99 4:29p Samir |
| 30 | * added function to read record information for a hog file entry. needed |
| 31 | * from mn3edit. |
| 32 | * |
| 33 | * 19 7/28/99 3:35p Kevin |
| 34 | * Mac! |
| 35 | * |
| 36 | * 18 5/10/99 10:25p Ardussi |
| 37 | * changes to compile on Mac |
| 38 | * |
| 39 | * 17 4/15/99 9:19p Jeff |
| 40 | * Changes for Linux version |
| 41 | * |
| 42 | * 16 2/16/99 2:08p Nate |
| 43 | * Made CreateNewHogFile() a bit friendlier |
| 44 | * |
| 45 | * 15 1/13/99 6:39a Jeff |
| 46 | * fixed some case-sensitive #includes |
| 47 | * |
| 48 | * 13 10/15/98 2:52p Nate |
| 49 | * Fixed FileCopy() by changing free() to mem_free() |
| 50 | * |
| 51 | * 12 10/08/98 4:23p Kevin |
| 52 | * Changed code to comply with memory library usage. Always use mem_malloc |
| 53 | * , mem_free and mem_strdup |
| 54 | * |
| 55 | * 11 8/16/98 4:23p Nate |
| 56 | * Added CreateNewHogFile() |
| 57 | * |
| 58 | * 10 8/14/98 4:38p Nate |
| 59 | * Fixed a few minor bugs and added better error reporting |
| 60 | * |
| 61 | * 9 8/14/98 1:01p Nate |
| 62 | * Added better error reporting for the HogEditor |
| 63 | * |
| 64 | * 8 7/27/98 9:48a Nate |
| 65 | * Fixed hog file header filling |
| 66 | * |
| 67 | * 7 7/24/98 6:39p Nate |
| 68 | * fixed hog bugs. |
| 69 | * |
| 70 | * 6 7/20/98 3:34p Nate |
| 71 | * Fixed up Hog file stuff |
| 72 | * |
| 73 | * 5 7/13/98 6:20p Nate |
| 74 | * Fixed ReadHogEntry() and WriteHogEntry() |
| 75 | * |
| 76 | * 4 7/13/98 2:18p Nate |
| 77 | * |
| 78 | * 3 4/01/98 7:03p Samir |
| 79 | * modified some cfile stuff. |
| 80 | * |
| 81 | * 2 3/31/98 6:13p Samir |
| 82 | * new hogfile format. |
| 83 | * |
| 84 | * 1 3/31/98 6:08p Samir |
| 85 | * |
| 86 | * |
| 87 | * $NoKeywords: $ |
| 88 | */ |
| 89 | |
| 90 | #include <cstring> |
| 91 | |
| 92 | #include "byteswap.h" |
| 93 | #include "hogfile.h" |
| 94 | |
| 95 | /* |
| 96 | HOG FILE FORMAT v2.0 |
| 97 | |
| 98 | HOG_TAG_STR [strlen()] |
| 99 | NFILES [int32] |
| 100 | HDRINFO [HOG_HDR_SIZE] |
| 101 | FILE_TABLE [sizeof(FILE_ENTRY) * NFILES] |
| 102 | FILE 0 [filelen(FILE 0)] |
| 103 | FILE 1 [filelen(FILE 1)] |
| 104 | . |
| 105 | . |
| 106 | . |
| 107 | FILE NFILES-1 [filelen(NFILES -1)] |
| 108 | */ |
| 109 | |
| 110 | bool ReadHogHeader(FILE *fp, tHogHeader *header) { |
| 111 | if (fread(&header->magic, HOG_TAG_LEN, 1, fp) != HOG_TAG_LEN && strncmp(header->magic, HOG_TAG_STR, 4) != 0 ) |
| 112 | return false; |
| 113 | |
| 114 | if (fread(&header->nfiles, sizeof(header->nfiles), 1, fp) != 1) |
| 115 | return false; |
| 116 | header->nfiles = INTEL_INT(header->nfiles); |
| 117 | |
| 118 | if (fread(&header->file_data_offset, sizeof(header->file_data_offset), 1, fp) != 1) |
| 119 | return false; |
| 120 | header->file_data_offset = INTEL_INT(header->file_data_offset); |
| 121 | |
| 122 | return true; |
| 123 | } |
| 124 | |
| 125 | bool ReadHogEntry(FILE *fp, tHogFileEntry *entry) { |
| 126 | if (fread(entry->name, sizeof(char), HOG_FILENAME_LEN, fp) != HOG_FILENAME_LEN) |
| 127 | return false; |
| 128 | if (fread(&entry->flags, sizeof(entry->flags), 1, fp) != 1) |
| 129 | return false; |
| 130 | entry->flags = INTEL_INT(entry->flags); |
| 131 | |
| 132 | if (fread(&entry->len, sizeof(entry->len), 1, fp) != 1) |
| 133 | return false; |
| 134 | entry->len = INTEL_INT(entry->len); |
| 135 | |
| 136 | if (fread(&entry->timestamp, sizeof(entry->timestamp), 1, fp) != 1) |
| 137 | return false; |
| 138 | entry->timestamp = INTEL_INT(entry->timestamp); |
| 139 | |
| 140 | return true; |
| 141 | } |