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

Function getfiledesc

source/src/worldio.cpp:1177–1225  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1175});
1176
1177char *getfiledesc(const char *dir, const char *name, const char *ext) // extract demo and map descriptions
1178{
1179 if(!dir || !name || !ext) return NULL;
1180 defformatstring(fn)("%s/%s.%s", dir, name, ext);
1181 path(fn);
1182 string text, demodescalias;
1183 if(!strcmp(ext, "dmo"))
1184 {
1185 stream *f = opengzfile(fn, "rb");
1186 if(!f) return NULL;
1187 demoheader hdr;
1188 if(f->read(&hdr, sizeof(demoheader))!=sizeof(demoheader) || memcmp(hdr.magic, DEMO_MAGIC, sizeof(hdr.magic))) { delete f; return NULL; }
1189 delete f;
1190 lilswap(&hdr.version, 1);
1191 lilswap(&hdr.protocol, 1);
1192 const char *tag = "(incompatible file) ";
1193 if(hdr.version == DEMO_VERSION)
1194 {
1195 if(hdr.protocol == PROTOCOL_VERSION) tag = "";
1196 else if(hdr.protocol == -PROTOCOL_VERSION) tag = "(recorded on modded server) ";
1197 }
1198 formatstring(text)("%s%s", tag, hdr.desc);
1199 text[DHDR_DESCCHARS - 1] = '\0';
1200 formatstring(demodescalias)("demodesc_%s", name);
1201 const char *customdesc = getalias(demodescalias);
1202 if(customdesc)
1203 {
1204 int textlen = strlen(text);
1205 concatformatstring(text, " \n\f4(Description: \f0%s\f4)", customdesc);
1206 ASSERT(MAXSTRLEN > 2 * DHDR_DESCCHARS);
1207 text[textlen + DHDR_DESCCHARS - 1] = '\0';
1208 }
1209 return newstring(text);
1210 }
1211 else if(!strcmp(ext, "cgz"))
1212 {
1213 stream *f = opengzfile(fn, "rb");
1214 if(!f) return NULL;
1215 header hdr;
1216 if(f->read(&hdr, sizeof(header))!=sizeof(header) || (strncmp(hdr.head, "CUBE", 4) && strncmp(hdr.head, "ACMP",4))) { delete f; return NULL; }
1217 delete f;
1218 lilswap(&hdr.version, 1);
1219 filtertext(hdr.maptitle, hdr.maptitle, FTXT__MAPMSG, 127);
1220 formatstring(text)("%s%s", (hdr.version>MAPVERSION) ? "(incompatible file) " : "", hdr.maptitle);
1221 text[DHDR_DESCCHARS - 1] = '\0';
1222 return newstring(text);
1223 }
1224 return NULL;
1225}
1226
1227void enumfiles(char *dir, char *ext)
1228{

Callers 2

renderMethod · 0.85
loopvFunction · 0.85

Calls 8

pathFunction · 0.85
opengzfileFunction · 0.85
lilswapFunction · 0.85
getaliasFunction · 0.85
concatformatstringFunction · 0.85
newstringFunction · 0.85
filtertextFunction · 0.85
readMethod · 0.45

Tested by

no test coverage detected