Mercurial > hg > dmlib
comparison tools/packed.c @ 2479:c1cae47cd410
Rename DMPackEntry::length to csize (compressed size).
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Mon, 27 Apr 2020 21:33:29 +0300 |
parents | d18fd4866650 |
children | c7a0913e1032 |
comparison
equal
deleted
inserted
replaced
2478:0d13de7edb30 | 2479:c1cae47cd410 |
---|---|
213 strncpy(node->filename, src->filename, DMRES_NAME_LEN); | 213 strncpy(node->filename, src->filename, DMRES_NAME_LEN); |
214 node->filename[DMRES_NAME_LEN] = 0; | 214 node->filename[DMRES_NAME_LEN] = 0; |
215 | 215 |
216 node->size = src->size; | 216 node->size = src->size; |
217 node->offset = src->offset; | 217 node->offset = src->offset; |
218 node->length = src->length; | 218 node->csize = src->csize; |
219 node->flags = src->flags; | 219 node->flags = src->flags; |
220 | 220 |
221 return node; | 221 return node; |
222 } | 222 } |
223 | 223 |
242 sizeof(hdr.dirEntries) + sizeof(hdr.dirOffset); | 242 sizeof(hdr.dirEntries) + sizeof(hdr.dirOffset); |
243 | 243 |
244 for (node = pack->entries; node != NULL; node = node->next) | 244 for (node = pack->entries; node != NULL; node = node->next) |
245 { | 245 { |
246 hdr.dirEntries++; | 246 hdr.dirEntries++; |
247 hdr.dirOffset += node->length; | 247 hdr.dirOffset += node->csize; |
248 } | 248 } |
249 | 249 |
250 dmMsg(1, "%d entries in PACK, dir at offset 0x%08" DM_PRIx64 ".\n", | 250 dmMsg(1, "%d entries in PACK, dir at offset 0x%08" DM_PRIx64 ".\n", |
251 hdr.dirEntries, hdr.dirOffset); | 251 hdr.dirEntries, hdr.dirOffset); |
252 | 252 |
267 for (node = pack->entries; node != NULL; node = node->next) | 267 for (node = pack->entries; node != NULL; node = node->next) |
268 { | 268 { |
269 // Write one entry | 269 // Write one entry |
270 if (!dm_fwrite_str(pack->file, node->filename, DMRES_NAME_LEN) || | 270 if (!dm_fwrite_str(pack->file, node->filename, DMRES_NAME_LEN) || |
271 !dm_fwrite_le64(pack->file, node->offset) || | 271 !dm_fwrite_le64(pack->file, node->offset) || |
272 !dm_fwrite_le32(pack->file, node->length) || | 272 !dm_fwrite_le32(pack->file, node->csize) || |
273 !dm_fwrite_le32(pack->file, node->size) || | 273 !dm_fwrite_le32(pack->file, node->size) || |
274 !dm_fwrite_le32(pack->file, node->flags)) | 274 !dm_fwrite_le32(pack->file, node->flags)) |
275 return DMERR_FWRITE; | 275 return DMERR_FWRITE; |
276 } | 276 } |
277 | 277 |
324 // Compute starting offset | 324 // Compute starting offset |
325 outSize = 0; | 325 outSize = 0; |
326 startOffs = sizeof(DMPackFileHeader); | 326 startOffs = sizeof(DMPackFileHeader); |
327 for (node = pack->entries; node != NULL; node = node->next) | 327 for (node = pack->entries; node != NULL; node = node->next) |
328 { | 328 { |
329 startOffs += node->length; | 329 startOffs += node->csize; |
330 } | 330 } |
331 | 331 |
332 // Seek to the position | 332 // Seek to the position |
333 if (fseeko(pack->file, startOffs, SEEK_SET) != 0) | 333 if (fseeko(pack->file, startOffs, SEEK_SET) != 0) |
334 return DMERR_INVALID; | 334 return DMERR_INVALID; |
402 // Create directory entry | 402 // Create directory entry |
403 strncpy(entry.filename, filename, DMRES_NAME_LEN); | 403 strncpy(entry.filename, filename, DMRES_NAME_LEN); |
404 entry.filename[DMRES_NAME_LEN] = 0; | 404 entry.filename[DMRES_NAME_LEN] = 0; |
405 entry.offset = startOffs; | 405 entry.offset = startOffs; |
406 entry.size = zstr.total_in; | 406 entry.size = zstr.total_in; |
407 entry.length = outSize; | 407 entry.csize = outSize; |
408 entry.flags = flags | (compress ? DMF_COMPRESSED : 0); | 408 entry.flags = flags | (compress ? DMF_COMPRESSED : 0); |
409 | 409 |
410 // Add directory entry | 410 // Add directory entry |
411 if ((*ppEntry = dmPackEntryCopy(&entry)) == NULL) | 411 if ((*ppEntry = dmPackEntryCopy(&entry)) == NULL) |
412 { | 412 { |
475 goto out; | 475 goto out; |
476 } | 476 } |
477 zinit = TRUE; | 477 zinit = TRUE; |
478 } | 478 } |
479 | 479 |
480 remaining = entry->length; | 480 remaining = entry->csize; |
481 zret = Z_OK; | 481 zret = Z_OK; |
482 while (remaining > 0 && zret == Z_OK) | 482 while (remaining > 0 && zret == Z_OK) |
483 { | 483 { |
484 size_t needed = remaining > SET_TMPBUF_SIZE ? SET_TMPBUF_SIZE : remaining; | 484 size_t needed = remaining > SET_TMPBUF_SIZE ? SET_TMPBUF_SIZE : remaining; |
485 zstr.avail_in = fread(inBuffer, sizeof(Uint8), needed, pack->file); | 485 zstr.avail_in = fread(inBuffer, sizeof(Uint8), needed, pack->file); |
719 } | 719 } |
720 else | 720 else |
721 { | 721 { |
722 dmPrint(1, "%-32s ['%s', s=%d, c=%d, o=%" DM_PRId64 ", f=0x%04x]\n", | 722 dmPrint(1, "%-32s ['%s', s=%d, c=%d, o=%" DM_PRId64 ", f=0x%04x]\n", |
723 srcFilenames[i], node->filename, | 723 srcFilenames[i], node->filename, |
724 node->size, node->length, node->offset, node->flags); | 724 node->size, node->csize, node->offset, node->flags); |
725 } | 725 } |
726 } | 726 } |
727 | 727 |
728 dmMsg(2, "w=%d\n", dmPackWrite(pack)); | 728 dmMsg(2, "w=%d\n", dmPackWrite(pack)); |
729 dmMsg(2, "c=%d\n", dmPackClose(pack)); | 729 dmMsg(2, "c=%d\n", dmPackClose(pack)); |
766 match = TRUE; | 766 match = TRUE; |
767 | 767 |
768 if (match) | 768 if (match) |
769 { | 769 { |
770 dmPrint(0, "%-32s | %8d | %8d | %08" DM_PRIx64 " | %04x\n", | 770 dmPrint(0, "%-32s | %8d | %8d | %08" DM_PRIx64 " | %04x\n", |
771 node->filename, node->size, node->length, | 771 node->filename, node->size, node->csize, |
772 node->offset, node->flags); | 772 node->offset, node->flags); |
773 } | 773 } |
774 } | 774 } |
775 | 775 |
776 dmMsg(2, "c=%d\n", dmPackClose(pack)); | 776 dmMsg(2, "c=%d\n", dmPackClose(pack)); |
819 // Mark as done | 819 // Mark as done |
820 node->privFlags |= PACK_EXTRACTED; | 820 node->privFlags |= PACK_EXTRACTED; |
821 | 821 |
822 // Print one entry | 822 // Print one entry |
823 dmPrint(0, "Extracting: %-32s [siz=%d, cmp=%d, offs=0x%08" DM_PRIx64 ", flags=0x%04x]\n", | 823 dmPrint(0, "Extracting: %-32s [siz=%d, cmp=%d, offs=0x%08" DM_PRIx64 ", flags=0x%04x]\n", |
824 node->filename, node->size, node->length, | 824 node->filename, node->size, node->csize, |
825 node->offset, node->flags); | 825 node->offset, node->flags); |
826 | 826 |
827 dmPackExtractFile(pack, node, optDoCompress); | 827 dmPackExtractFile(pack, node, optDoCompress); |
828 } | 828 } |
829 } | 829 } |