| 627 | const char *desctxt = "desc.txt", *previewjpg = "preview.jpg", *modrev = "revision_"; // special files in zip containing description or preview |
| 628 | |
| 629 | void zipmodgetdesc(char *name) // open zip, read desc.txt and mount preview picture |
| 630 | { |
| 631 | const char *pname = fixzipname(name); |
| 632 | stream *f = pname ? openfile(pname, "rb") : NULL, *zf = NULL; |
| 633 | vector<const char *> files; |
| 634 | vector<char> res; |
| 635 | void *mz = zipmanualopen(f, files); |
| 636 | string tmp; |
| 637 | if(!f || !mz) conoutf("failed to read/open zip file %s", pname); |
| 638 | else |
| 639 | { |
| 640 | loopv(files) |
| 641 | { |
| 642 | if(!strcmp(files[i], desctxt)) |
| 643 | { |
| 644 | if((zf = zipmanualstream(mz, i))) loopk(11) |
| 645 | { |
| 646 | zf->getline(tmp, MAXSTRLEN / 2); |
| 647 | filtertext(tmp, tmp, FTXT__ZIPDESC); |
| 648 | if(*tmp) cvecprintf(res, "%s\n", escapestring(tmp)); |
| 649 | else break; |
| 650 | } |
| 651 | } |
| 652 | else if(!strcmp(files[i], previewjpg)) |
| 653 | { |
| 654 | vector<uchar> *v = new vector<uchar>; |
| 655 | zf = openvecfile(v); |
| 656 | int got = zipmanualread(mz, i, zf, 128 * 1024); // max. file size for preview.jpg is 128k |
| 657 | formatstring(tmp)("packages/modpreviews/%s.jpg", name); |
| 658 | addmemfile(tmp, v->getbuf(), got); |
| 659 | if(got == 128 * 1024) conoutf("\f3preview.jpg in zip file %s exceeds maximum file size: file truncated", pname); |
| 660 | } |
| 661 | DELETEP(zf); |
| 662 | } |
| 663 | zipmanualclose(mz); |
| 664 | } |
| 665 | resultcharvector(res, -1); |
| 666 | } |
| 667 | COMMAND(zipmodgetdesc, "s"); |
| 668 | |
| 669 | void zipmodgetfiles(char *name) // open zip, read list of files |
nothing calls this directly
no test coverage detected