MCPcopy Create free account
hub / github.com/assaultcube/AC / addzipmod

Function addzipmod

source/src/zip.cpp:508–557  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

506VAR(zipcachemaxsize, 0, 512, 1024); // load zip files smaller than 512K straight into RAM
507
508void 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}
558COMMAND(addzipmod, "s");
559
560void zipmodremove(char *name)

Callers

nothing calls this directly

Calls 15

fixzipnameFunction · 0.85
findzipFunction · 0.85
rebuildzipfilehashtableFunction · 0.85
newstringFunction · 0.85
openfileFunction · 0.85
openmemfileFunction · 0.85
findzipdirectoryFunction · 0.85
readzipdirectoryFunction · 0.85
mountzipFunction · 0.85
behindpathFunction · 0.85
clientlogfFunction · 0.85
removeobjMethod · 0.80

Tested by

no test coverage detected