MCPcopy Create free account
hub / github.com/ddnet/ddnet / FindDataDirectory

Method FindDataDirectory

src/engine/shared/storage.cpp:279–350  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

277 }
278
279 void FindDataDirectory(const char *pArgv0)
280 {
281 // 1) use data-dir in PWD if present
282 if(fs_is_dir("data/mapres"))
283 {
284 str_copy(m_aDatadir, "data");
285 return;
286 }
287
288#if defined(DATA_DIR)
289 // 2) use compiled-in data-dir if present
290 if(fs_is_dir(DATA_DIR "/mapres"))
291 {
292 str_copy(m_aDatadir, DATA_DIR, sizeof(m_aDatadir));
293 return;
294 }
295#endif
296
297 // 3) check for usable path in argv[0]
298 {
299#ifdef CONF_PLATFORM_HAIKU
300 pArgv0 = realpath(pArgv0, NULL);
301#endif
302 unsigned int Pos = ~0U;
303 for(unsigned i = 0; pArgv0[i]; i++)
304 if(pArgv0[i] == '/' || pArgv0[i] == '\\')
305 Pos = i;
306
307 if(Pos < IO_MAX_PATH_LENGTH)
308 {
309 char aBuf[IO_MAX_PATH_LENGTH];
310 char aDir[IO_MAX_PATH_LENGTH];
311 str_copy(aDir, pArgv0, Pos + 1);
312 str_format(aBuf, sizeof(aBuf), "%s/data/mapres", aDir);
313 if(fs_is_dir(aBuf))
314 {
315 str_format(m_aDatadir, sizeof(m_aDatadir), "%s/data", aDir);
316 return;
317 }
318 }
319 }
320#ifdef CONF_PLATFORM_HAIKU
321 free((void *)pArgv0);
322#endif
323
324#if defined(CONF_FAMILY_UNIX)
325 // 4) check for all default locations
326 {
327 const char *apDirs[] = {
328 "/usr/share/ddnet",
329 "/usr/share/games/ddnet",
330 "/usr/local/share/ddnet",
331 "/usr/local/share/games/ddnet",
332 "/usr/pkg/share/ddnet",
333 "/usr/pkg/share/games/ddnet",
334 "/opt/ddnet"};
335
336 for(const char *pDir : apDirs)

Callers 1

CreateTempStorageFunction · 0.80

Calls 3

fs_is_dirFunction · 0.85
str_formatFunction · 0.85
str_copyFunction · 0.50

Tested by

no test coverage detected