mirror of
https://github.com/DarkPlacesEngine/gmqcc.git
synced 2024-11-28 06:32:44 +00:00
Fixes to the PAK utility.
This commit is contained in:
parent
86df8c8a78
commit
1fa9fbb94b
1 changed files with 28 additions and 9 deletions
33
pak.c
33
pak.c
|
@ -95,6 +95,7 @@ static void pak_tree_build(const char *entry) {
|
||||||
char *directory;
|
char *directory;
|
||||||
char *elements[28];
|
char *elements[28];
|
||||||
char *pathsplit;
|
char *pathsplit;
|
||||||
|
char *token;
|
||||||
|
|
||||||
size_t itr;
|
size_t itr;
|
||||||
size_t jtr;
|
size_t jtr;
|
||||||
|
@ -102,8 +103,14 @@ static void pak_tree_build(const char *entry) {
|
||||||
pathsplit = mem_a(56);
|
pathsplit = mem_a(56);
|
||||||
directory = mem_a(56);
|
directory = mem_a(56);
|
||||||
|
|
||||||
|
memset(pathsplit, 0, 56);
|
||||||
|
memset(directory, 0, 56);
|
||||||
|
|
||||||
strncpy(directory, entry, 56);
|
strncpy(directory, entry, 56);
|
||||||
for (itr = 0; (elements[itr] = pak_tree_sep(&directory, "/")); itr++);
|
for (itr = 0; (token = strsep(&directory, "/")) != NULL; itr++) {
|
||||||
|
elements[itr] = token;
|
||||||
|
}
|
||||||
|
|
||||||
for (jtr = 0; jtr < itr - 1; jtr++) {
|
for (jtr = 0; jtr < itr - 1; jtr++) {
|
||||||
strcat(pathsplit, elements[jtr]);
|
strcat(pathsplit, elements[jtr]);
|
||||||
strcat(pathsplit, "/");
|
strcat(pathsplit, "/");
|
||||||
|
@ -137,16 +144,16 @@ pak_file_t *pak_open_read(const char *file) {
|
||||||
pak->directories = NULL;
|
pak->directories = NULL;
|
||||||
pak->insert = false; /* read doesn't allow insert */
|
pak->insert = false; /* read doesn't allow insert */
|
||||||
|
|
||||||
memset (&(pak->header), 0, sizeof(pak_header_t));
|
memset (&pak->header, 0, sizeof(pak_header_t));
|
||||||
file_read (&(pak->header), 1, sizeof(pak_header_t), pak->handle);
|
file_read (&pak->header, sizeof(pak_header_t), 1, pak->handle);
|
||||||
util_endianswap(&(pak->header), 1, sizeof(pak_header_t));
|
util_endianswap(&pak->header, 1, sizeof(pak_header_t));
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Every PAK file has "PACK" stored as little endian data in the
|
* Every PAK file has "PACK" stored as little endian data in the
|
||||||
* header. If this data cannot compare (as checked here), it's
|
* header. If this data cannot compare (as checked here), it's
|
||||||
* probably not a PAK file.
|
* probably not a PAK file.
|
||||||
*/
|
*/
|
||||||
if (!(memcmp(&(pak->header.magic), (const void*)"PACK", sizeof(uint32_t)))) {
|
if ((memcmp(&(pak->header.magic), (const void*)"PACK", sizeof(uint32_t)))) {
|
||||||
file_close(pak->handle);
|
file_close(pak->handle);
|
||||||
mem_d (pak);
|
mem_d (pak);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -164,8 +171,8 @@ pak_file_t *pak_open_read(const char *file) {
|
||||||
*/
|
*/
|
||||||
for (itr = 0; itr < pak->header.dirlen / 64; itr++) {
|
for (itr = 0; itr < pak->header.dirlen / 64; itr++) {
|
||||||
pak_directory_t dir;
|
pak_directory_t dir;
|
||||||
file_read (&dir, 1, sizeof(pak_directory_t), pak->handle);
|
file_read (&dir, sizeof(pak_directory_t), 1, pak->handle);
|
||||||
util_endianswap(&dir, 1, sizeof(pak_directory_t));
|
/*util_endianswap(&dir, 1, sizeof(pak_directory_t));*/
|
||||||
|
|
||||||
vec_push(pak->directories, dir);
|
vec_push(pak->directories, dir);
|
||||||
}
|
}
|
||||||
|
@ -409,3 +416,15 @@ bool pak_close(pak_file_t *pak) {
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* test extraction */
|
||||||
|
#if 0
|
||||||
|
int main() {
|
||||||
|
pak_file_t *pak = pak_open_read("pak0.pak");
|
||||||
|
if (!pak) abort();
|
||||||
|
|
||||||
|
pak_extract_all(pak);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue