| 506 | VAR(zipcachemaxsize, 0, 512, 1024); // load zip files smaller than 512K straight into RAM |
| 507 | |
| 508 | void addzipmod(char *name) |
| 509 | { |
| 510 | const char *pname = fixzipname(name); |
| 511 | if(!pname) |
| 512 | { |
| 513 | conoutf("addzipmod: illegal filename %s", name); |
| 514 | return; |
| 515 | } |
| 516 | ziparchive *exists = findzip(name); |
| 517 | if(exists) |
| 518 | { // already added zip |
| 519 | archives.removeobj(exists); |
| 520 | archives.add(exists); // sort to the end of the list |
| 521 | rebuildzipfilehashtable(); |
| 522 | return; |
| 523 | } |
| 524 | ziparchive *arch = new ziparchive; |
| 525 | arch->name = newstring(name); |
| 526 | if(!(arch->data = openfile(pname, "rb"))) |
| 527 | { |
| 528 | conoutf("could not open file %s", pname); |
| 529 | delete arch; |
| 530 | return; |
| 531 | } |
| 532 | int zipsize = arch->data->size(); |
| 533 | if(zipsize > 0 && zipsize < zipcachemaxsize * 1024) |
| 534 | { |
| 535 | uchar *buf = new uchar[zipsize]; |
| 536 | if(arch->data->read(buf, zipsize) != zipsize) |
| 537 | { |
| 538 | conoutf("could not cache file %s", pname); |
| 539 | delete[] buf; |
| 540 | delete arch; |
| 541 | return; |
| 542 | } |
| 543 | delete arch->data; |
| 544 | arch->data = openmemfile(buf, zipsize, NULL); |
| 545 | } |
| 546 | zipdirectoryheader h; |
| 547 | if(!findzipdirectory(arch->data, h) || !readzipdirectory(arch->data, h.entries, h.offset, h.size, arch->files)) |
| 548 | { |
| 549 | conoutf("could not read directory in zip %s", pname); |
| 550 | delete arch; |
| 551 | return; |
| 552 | } |
| 553 | mountzip(*arch, NULL, NULL, !strncmp(behindpath(name), "###", 3)); |
| 554 | archives.add(arch); |
| 555 | rebuildzipfilehashtable(); |
| 556 | DEBUGCODE(clientlogf("added zipmod %s, %d bytes, %d files", pname, zipsize, arch->files.length())); |
| 557 | } |
| 558 | COMMAND(addzipmod, "s"); |
| 559 | |
| 560 | void zipmodremove(char *name) |
nothing calls this directly
no test coverage detected