MCPcopy Index your code
hub / github.com/assaultcube/AC / gettexturelist

Function gettexturelist

source/src/texture.cpp:871–921  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

869COMMAND(guidetoggle, "");
870
871void gettexturelist(char *_filter, char *_exclude, char *_exts) // create a list of texture paths and filenames
872{
873 vector<char *> filter, exclude, exts, files;
874 vector<int> filter_n, exclude_n, exts_n;
875 explodelist(_filter, filter); // path has to start with one of these
876 explodelist(_exclude, exclude); // path may not start with one of these
877 explodelist(_exts, exts); // file needs to have one of those extensions (or ".jpg" by default)
878 if(!exts.length()) exts.add(newstring(".jpg"));
879 loopv(filter) filter_n.add((int) strlen(filter[i]));
880 loopv(exclude) exclude_n.add((int) strlen(exclude[i]));
881 loopv(exts) exts_n.add((int) strlen(exts[i]));
882 listfilesrecursive("packages/textures", files);
883 files.sort(stringsort);
884 loopvrev(files) if(files.inrange(i + 1) && !strcmp(files[i], files[i + 1])) delstring(files.remove(i + 1)); // remove doubles
885 int pn = strlen("packages/textures/");
886 loopvrev(files)
887 {
888 bool filtered = filter.length() == 0, excluded = false, extmatch = false;
889 if(!strncmp(files[i], "packages/textures/", pn))
890 {
891 const char *s = files[i] + pn;
892 loopvj(filter) if(!strncmp(s, filter[j], filter_n[j])) filtered = true;
893 loopvj(exclude) if(!strncmp(s, exclude[j], exclude_n[j])) excluded = true;
894 int n = strlen(s);
895 loopvj(exts) if(n > exts_n[j] && !strcmp(s + n - exts_n[j], exts[j])) extmatch = true;
896 }
897 if(!extmatch || !filtered || excluded) delstring(files.remove(i));
898 }
899 vector<char> res;
900 bool cutprefix = filter.length() == 1;
901 bool cutext = exts.length() == 1 && exts[0][0] != '.';
902 loopv(files)
903 {
904 char *f = files[i] + pn;
905 const char *p = parentdir(f), *b = behindpath(f);
906 cvecprintf(res, "\"%s\" \"%s\"", p, b); // always add columns for path (without "packages/textures/") and filename
907 if(cutprefix) cvecprintf(res, " \"%s\"", int(strlen(p)) > filter_n[0] ? p + filter_n[0] : ""); // if there's exactly one filter string, add column with that string omitted
908 if(cutext)
909 {
910 int n = strlen(b);
911 if(n > exts_n[0]) ((char *)b)[n - exts_n[0]] = '\0';
912 cvecprintf(res, " \"%s\"", b); // if there's only one allowed extension and it does not start with '.', add column of filenames without extension
913 }
914 res.add('\n');
915 }
916 filter.deletearrays();
917 exclude.deletearrays();
918 exts.deletearrays();
919 files.deletearrays();
920 resultcharvector(res, -1);
921}
922COMMAND(gettexturelist, "sss");
923
924void textureslotusagemapmodels(int *used)

Callers

nothing calls this directly

Calls 13

explodelistFunction · 0.85
newstringFunction · 0.85
listfilesrecursiveFunction · 0.85
delstringFunction · 0.85
resultcharvectorFunction · 0.85
sortMethod · 0.80
inrangeMethod · 0.80
deletearraysMethod · 0.80
loopvFunction · 0.70
loopvrevFunction · 0.70
lengthMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected