Skip to content

Commit

Permalink
thdat: don't special case th105
Browse files Browse the repository at this point in the history
  • Loading branch information
DankRank committed Sep 17, 2023
1 parent 750c9b5 commit 221027d
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 9 deletions.
9 changes: 3 additions & 6 deletions thdat/thdat.c
Original file line number Diff line number Diff line change
Expand Up @@ -274,12 +274,9 @@ thdat_create_wrapper(
free(entries_count);
// ...and then module->create, if this is th105 archive.
// This is because the list of entries comes first in th105 archives.
if (version == 105105 || version == 105 || version == 123) {
if (!thdat_init(state->thdat, error))
{
thdat_state_free(state);
exit(1);
}
if (!thdat_init(state->thdat, error)) {
thdat_state_free(state);
exit(1);
}

k = 0;
Expand Down
7 changes: 5 additions & 2 deletions thtk/thdat.c
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ thdat_new(
thdat->entry_count = 0;
thdat->entries = NULL;
thdat->offset = 0;
thdat->inited = 0;
return thdat;
}

Expand Down Expand Up @@ -153,10 +154,13 @@ thdat_init(
thdat_t* thdat,
thtk_error_t** error)
{
if (thdat->inited)
return 1;
if (!thdat->module->create(thdat, error)) {
thdat_free(thdat);
return 0;
}
thdat->inited = 1;
return 1;
}

Expand All @@ -178,10 +182,9 @@ thdat_create(
return NULL;
thdat->entry_count = entry_count;
thdat->entries = calloc(entry_count, sizeof(thdat_entry_t));
if (version != 105105 && version != 105 && version != 123) {
if (!(thdat->module->flags & THDAT_LATE_INIT))
if (!thdat_init(thdat, error))
return NULL;
}
return thdat;
}

Expand Down
3 changes: 3 additions & 0 deletions thtk/thdat.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ struct thdat_t {
size_t entry_count;
thdat_entry_t* entries;
uint32_t offset;
int inited;
};

/* Strip path names. */
Expand All @@ -68,6 +69,8 @@ struct thdat_t {
#define THDAT_8_3 4
/* No compression (zsize is not used). */
#define THDAT_NO_COMPRESSION 8
/* thdat_init must be called _after_ setting the filenames. */
#define THDAT_LATE_INIT 16

struct thdat_module_t {
/* THDAT_ flags. */
Expand Down
2 changes: 1 addition & 1 deletion thtk/thdat105.c
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ const thdat_module_t archive_th75 = {
};

const thdat_module_t archive_th105 = {
THDAT_NO_COMPRESSION,
THDAT_NO_COMPRESSION|THDAT_LATE_INIT,
th105_open,
th105_create,
th105_close,
Expand Down

0 comments on commit 221027d

Please sign in to comment.