X-Git-Url: https://git.xonotic.org/?p=xonotic%2Fgmqcc.git;a=blobdiff_plain;f=pak.c;h=bbe532225dea867790d774d49d026ba5e8bc4d31;hp=c7974b51fb95da033777350de45a35f890e3af7a;hb=fe14d1b056935d726cca09b2c0f2607c831244ef;hpb=033cf7c7d397c3fdc23a1448b0068000219efef6 diff --git a/pak.c b/pak.c index c7974b5..bbe5322 100644 --- a/pak.c +++ b/pak.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2013 + * Copyright (C) 2013, 2014 * Dale Weiler * * Permission is hereby granted, free of charge, to any person obtaining a copy of @@ -24,7 +24,6 @@ #include #include "gmqcc.h" -#include "platform.h" /* * The PAK format uses a FOURCC concept for storing the magic ident within @@ -99,14 +98,14 @@ static void pak_tree_build(const char *entry) { memset(pathsplit, 0, 56); - platform_strncpy(directory, entry, 56); + util_strncpy(directory, entry, 56); for (itr = 0; (token = pak_tree_sep(&directory, "/")) != NULL; itr++) { elements[itr] = token; } for (jtr = 0; jtr < itr - 1; jtr++) { - platform_strcat(pathsplit, elements[jtr]); - platform_strcat(pathsplit, "/"); + util_strcat(pathsplit, elements[jtr]); + util_strcat(pathsplit, "/"); if (fs_dir_make(pathsplit)) { mem_d(pathsplit); @@ -146,7 +145,10 @@ static pak_file_t *pak_open_read(const char *file) { memset (&pak->header, 0, sizeof(pak_header_t)); fs_file_read (&pak->header, sizeof(pak_header_t), 1, pak->handle); - util_endianswap(&pak->header, 1, sizeof(pak_header_t)); + + util_endianswap(&pak->header.magic, 1, sizeof(pak->header.magic)); + util_endianswap(&pak->header.diroff, 1, sizeof(pak->header.diroff)); + util_endianswap(&pak->header.dirlen, 1, sizeof(pak->header.dirlen)); /* * Every PAK file has "PACK" stored as FOURCC data in the @@ -163,7 +165,7 @@ static pak_file_t *pak_open_read(const char *file) { * Time to read in the directory handles and prepare the directories * vector. We're going to be reading some the file inwards soon. */ - fs_file_seek(pak->handle, pak->header.diroff, SEEK_SET); + fs_file_seek(pak->handle, pak->header.diroff, FS_FILE_SEEK_SET); /* * Read in all directories from the PAK file. These are considered @@ -172,7 +174,10 @@ static pak_file_t *pak_open_read(const char *file) { for (itr = 0; itr < pak->header.dirlen / 64; itr++) { pak_directory_t dir; fs_file_read (&dir, sizeof(pak_directory_t), 1, pak->handle); - util_endianswap(&dir, 1, sizeof(pak_directory_t)); + + /* Don't translate name - it's just an array of bytes. */ + util_endianswap(&dir.pos, 1, sizeof(dir.pos)); + util_endianswap(&dir.len, 1, sizeof(dir.len)); vec_push(pak->directories, dir); } @@ -296,7 +301,7 @@ static bool pak_extract_one(pak_file_t *pak, const char *file, const char *outdi mem_d(local); /* read */ - if (fs_file_seek (pak->handle, dir->pos, SEEK_SET) != 0) + if (fs_file_seek (pak->handle, dir->pos, FS_FILE_SEEK_SET) != 0) goto err; fs_file_read (dat, 1, dir->len, pak->handle); @@ -352,9 +357,9 @@ static bool pak_insert_one(pak_file_t *pak, const char *file) { * the directory entry, and the actual contents of the file * to the PAK file itself. */ - if (fs_file_seek(fp, 0, SEEK_END) != 0 || ((len = fs_file_tell(fp)) < 0)) + if (fs_file_seek(fp, 0, FS_FILE_SEEK_END) != 0 || ((len = fs_file_tell(fp)) < 0)) goto err; - if (fs_file_seek(fp, 0, SEEK_SET) != 0) + if (fs_file_seek(fp, 0, FS_FILE_SEEK_SET) != 0) goto err; dir.len = len; @@ -367,7 +372,7 @@ static bool pak_insert_one(pak_file_t *pak, const char *file) { if (strlen(file) >= 56) goto err; - platform_strncpy(dir.name, file, strlen(file)); + util_strncpy(dir.name, file, strlen(file)); /* * Allocate some memory for loading in the data that will be @@ -439,18 +444,17 @@ static bool pak_close(pak_file_t *pak) { pak->header.diroff = tell; /* patch header */ - if (fs_file_seek (pak->handle, 0, SEEK_SET) != 0) + if (fs_file_seek (pak->handle, 0, FS_FILE_SEEK_SET) != 0) goto err; fs_file_write(&(pak->header), sizeof(pak_header_t), 1, pak->handle); /* write directories */ - if (fs_file_seek (pak->handle, pak->header.diroff, SEEK_SET) != 0) + if (fs_file_seek (pak->handle, pak->header.diroff, FS_FILE_SEEK_SET) != 0) goto err; - for (itr = 0; itr < vec_size(pak->directories); itr++) { + for (itr = 0; itr < vec_size(pak->directories); itr++) fs_file_write(&(pak->directories[itr]), sizeof(pak_directory_t), 1, pak->handle); - } } vec_free (pak->directories); @@ -497,6 +501,7 @@ static bool parsecmd(const char *optname, int *argc_, char ***argv_, char **out, return true; } +#include int main(int argc, char **argv) { bool extract = true; char *redirout = (char*)stdout;