Skip to content

Commit

Permalink
fix TAR not loading
Browse files Browse the repository at this point in the history
  • Loading branch information
Jon Daniel committed Aug 1, 2023
1 parent 0f54b25 commit 3be85fe
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 27 deletions.
9 changes: 5 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -126,15 +126,16 @@ if(NOT PHYSFS_ARCHIVE_WAD)
add_definitions(-DPHYSFS_SUPPORTS_WAD=0)
endif()

option(PHYSFS_ARCHIVE_TAR "Enable POSIX TAR / Chasm: The Rift [Demo] Remastered csm.bin support" TRUE)
if(NOT PHYSFS_ARCHIVE_TAR)
add_definitions(-DPHYSFS_SUPPORTS_TAR=0)
endif()

option(PHYSFS_ARCHIVE_CSM "Enable Chasm: The Rift CSM.BIN support" TRUE)
if(NOT PHYSFS_ARCHIVE_CSM)
add_definitions(-DPHYSFS_SUPPORTS_CSM=0)
endif()

option(PHYSFS_ARCHIVE_TAR "Enable POSIX TAR / Chasm: The Rift [Demo] Remastered csm.bin support" TRUE)
if(NOT PHYSFS_ARCHIVE_TAR)
add_definitions(-DPHYSFS_SUPPORTS_TAR=0)
endif()

option(PHYSFS_ARCHIVE_HOG "Enable Descent I/II HOG support" TRUE)
if(NOT PHYSFS_ARCHIVE_HOG)
Expand Down
32 changes: 14 additions & 18 deletions src/physfs_archiver_tar.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,18 @@
#if PHYSFS_SUPPORTS_TAR
#include "physfs_tar.h"

static bool TAR_loadEntries(PHYSFS_Io *io, void *arc)
static int TAR_loadEntries(PHYSFS_Io *io, void *arc)
{
union block zero_block;
union block current_block;
union block zero_block = { 0 };
union block current_block = { 0 };
PHYSFS_uint64 count = 0;
bool long_name = false;

memset(zero_block.buffer, 0, sizeof(BLOCKSIZE));
memset(current_block.buffer, 0, sizeof(BLOCKSIZE));

/* read header block until zero-only terminated block */
for(; __PHYSFS_readAll(io, current_block.buffer, BLOCKSIZE); count++)
for(; __PHYSFS_readAll(io, current_block.buffer, BLOCKSIZE) != 0; count++)
{
if( memcmp(current_block.buffer, zero_block.buffer, BLOCKSIZE) == 0 )
return true;
return 1;

/* verify magic */
switch(TAR_magic(&current_block))
Expand All @@ -49,35 +46,34 @@ static bool TAR_loadEntries(PHYSFS_Io *io, void *arc)
}
}

return false;
return 0;
}

static void *TAR_openArchive(PHYSFS_Io *io, const char *name,
int forWriting, int *claimed)
{
void *unpkarc = NULL;
union block first;
enum archive_format format;
char buf[BLOCKSIZE] = { '\0' };

assert(io != NULL); /* shouldn't ever happen. */

BAIL_IF(forWriting, PHYSFS_ERR_READ_ONLY, NULL);
BAIL_IF_ERRPASS(!__PHYSFS_readAll(io, buf, sizeof (buf)), NULL);
if ((memcmp(&buf[TMAGOFF], TMAGIC, TMAGLEN - 1) != 0) != 0)
BAIL(PHYSFS_ERR_UNSUPPORTED, NULL);

BAIL_IF_ERRPASS(!__PHYSFS_readAll(io, first.buffer, BLOCKSIZE), NULL);
format = TAR_magic(&first);
io->seek(io, 0);
*claimed = format == DEFAULT_FORMAT ? 0 : 1;
*claimed = 1;

unpkarc = UNPK_openArchive(io, 0, 1);
BAIL_IF_ERRPASS(!io->seek(io, 0), 0);
unpkarc = UNPK_openArchive(io, 1, 0);
BAIL_IF_ERRPASS(!unpkarc, NULL);

if (!TAR_loadEntries(io, unpkarc))
if (TAR_loadEntries(io, unpkarc) == 0)
{
UNPK_abandonArchive(unpkarc);
return NULL;
} /* if */


return unpkarc;
} /* TAR_openArchive */

Expand Down
8 changes: 4 additions & 4 deletions src/physfs_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ extern const PHYSFS_Archiver __PHYSFS_Archiver_QPAK;
extern const PHYSFS_Archiver __PHYSFS_Archiver_HOG;
extern const PHYSFS_Archiver __PHYSFS_Archiver_MVL;
extern const PHYSFS_Archiver __PHYSFS_Archiver_WAD;
extern const PHYSFS_Archiver __PHYSFS_Archiver_CSM;
extern const PHYSFS_Archiver __PHYSFS_Archiver_TAR;
extern const PHYSFS_Archiver __PHYSFS_Archiver_CSM;
extern const PHYSFS_Archiver __PHYSFS_Archiver_SLB;
extern const PHYSFS_Archiver __PHYSFS_Archiver_ISO9660;
extern const PHYSFS_Archiver __PHYSFS_Archiver_VDF;
Expand Down Expand Up @@ -202,12 +202,12 @@ void __PHYSFS_smallFree(void *ptr);
#ifndef PHYSFS_SUPPORTS_WAD
#define PHYSFS_SUPPORTS_WAD PHYSFS_SUPPORTS_DEFAULT
#endif
#ifndef PHYSFS_SUPPORTS_CSM
#define PHYSFS_SUPPORTS_CSM PHYSFS_SUPPORTS_DEFAULT
#endif
#ifndef PHYSFS_SUPPORTS_TAR
#define PHYSFS_SUPPORTS_TAR PHYSFS_SUPPORTS_DEFAULT
#endif
#ifndef PHYSFS_SUPPORTS_CSM
#define PHYSFS_SUPPORTS_CSM PHYSFS_SUPPORTS_DEFAULT
#endif
#ifndef PHYSFS_SUPPORTS_QPAK
#define PHYSFS_SUPPORTS_QPAK PHYSFS_SUPPORTS_DEFAULT
#endif
Expand Down
2 changes: 1 addition & 1 deletion src/physfs_tar.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#define TMAGIC "ustar" /* ustar and a null */
#define OLDGNU_MAGIC "ustar " /* 7 chars and a null */
#define TMAGLEN 6

#define TMAGOFF 257
#define TVERSION "00" /* 00 and no null */
#define TVERSLEN 2

Expand Down

0 comments on commit 3be85fe

Please sign in to comment.