From 15bea2c4a9f1161712bb381351a6b83ffb90f8d8 Mon Sep 17 00:00:00 2001 From: Pixel Date: Thu, 6 Aug 2009 18:49:37 -0700 Subject: Adding the mpqlib_update_hash_entry functions. --- mpq-bios.c | 29 +++++++++++++++++++++++++++-- mpq-bios.h | 8 +++++--- 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/mpq-bios.c b/mpq-bios.c index 93c0623..eeba42a 100644 --- a/mpq-bios.c +++ b/mpq-bios.c @@ -490,14 +490,29 @@ int mpqlib_add_hash_entry_by_name(struct mpq_archive_t * mpq_a, const char * nam return mpqlib_add_hash_entry_by_hash(mpq_a, h, hA, hB, language, platform, entry); } -int mpqlib_find_hash_entry_by_name(struct mpq_archive_t * mpq_a, const char * name, uint16_t language, uint16_t platform) { +int mpqlib_update_hash_entry_by_hash(struct mpq_archive_t * mpq_a, uint32_t h, uint32_t hA, uint32_t hB, uint16_t language, uint16_t platform, int entry) { + if (!mpq_a->for_write) { + __mpqlib_errno = MPQLIB_ERROR_READONLY; + return -1; + } + + hash_t * hash = mpqlib_locate_hash_entry(mpq_a, h, hA, hB, language, platform); + + if (hash) { + hash->file_block_index = entry; + return 0; + } + return -1; +} + +int mpqlib_update_hash_entry_by_name(struct mpq_archive_t * mpq_a, const char * name, uint16_t language, uint16_t platform, int entry) { uint32_t h, hA, hB; h = mpqlib_hash_filename(name); hA = mpqlib_hashA_filename(name); hB = mpqlib_hashB_filename(name); - return mpqlib_find_hash_entry_by_hash(mpq_a, h, hA, hB, language, platform); + return mpqlib_update_hash_entry_by_hash(mpq_a, h, hA, hB, language, platform, entry); } int mpqlib_find_hash_entry_by_hash(struct mpq_archive_t * mpq_a, uint32_t h, uint32_t hA, uint32_t hB, uint16_t language, uint16_t platform) { @@ -509,6 +524,16 @@ int mpqlib_find_hash_entry_by_hash(struct mpq_archive_t * mpq_a, uint32_t h, uin return -1; } +int mpqlib_find_hash_entry_by_name(struct mpq_archive_t * mpq_a, const char * name, uint16_t language, uint16_t platform) { + uint32_t h, hA, hB; + + h = mpqlib_hash_filename(name); + hA = mpqlib_hashA_filename(name); + hB = mpqlib_hashB_filename(name); + + return mpqlib_find_hash_entry_by_hash(mpq_a, h, hA, hB, language, platform); +} + uint64_t mpqlib_ioctl(struct mpq_archive_t * mpq_a, enum mpqlib_ioctl_t command, ...) { __mpqlib_errno = MPQLIB_ERROR_NO_ERROR; int r = 0; diff --git a/mpq-bios.h b/mpq-bios.h index 5444469..4113062 100644 --- a/mpq-bios.h +++ b/mpq-bios.h @@ -41,10 +41,12 @@ struct mpq_archive_t * mpqlib_open_archive_for_writing(const char * fname); struct mpq_archive_t * mpqlib_reopen_archive(int fd); void mpqlib_printtables(struct mpq_archive_t *); void mpqlib_close_archive(struct mpq_archive_t *); -int mpqlib_find_hash_entry_by_name(struct mpq_archive_t *, const char * name, uint16_t language, uint16_t platform); -int mpqlib_find_hash_entry_by_hash(struct mpq_archive_t *, uint32_t h, uint32_t hA, uint32_t hB, uint16_t language, uint16_t platform); -int mpqlib_add_hash_entry_by_name(struct mpq_archive_t *, const char * name, uint16_t language, uint16_t platform, int entry); +int mpqlib_update_hash_entry_by_hash(struct mpq_archive_t * mpq_a, uint32_t h, uint32_t hA, uint32_t hB, uint16_t language, uint16_t platform, int entry); +int mpqlib_update_hash_entry_by_name(struct mpq_archive_t * mpq_a, const char * name, uint16_t language, uint16_t platform, int entry); int mpqlib_add_hash_entry_by_hash(struct mpq_archive_t *, uint32_t h, uint32_t hA, uint32_t hB, uint16_t language, uint16_t, int entry); +int mpqlib_add_hash_entry_by_name(struct mpq_archive_t *, const char * name, uint16_t language, uint16_t platform, int entry); +int mpqlib_find_hash_entry_by_hash(struct mpq_archive_t *, uint32_t h, uint32_t hA, uint32_t hB, uint16_t language, uint16_t platform); +int mpqlib_find_hash_entry_by_name(struct mpq_archive_t *, const char * name, uint16_t language, uint16_t platform); uint64_t mpqlib_ioctl(struct mpq_archive_t *, enum mpqlib_ioctl_t command, ...); #ifdef __cplusplus -- cgit v1.2.3