Skip to content

Commit

Permalink
Unix: Use de::Info to configure basedir and libdir
Browse files Browse the repository at this point in the history
The de::Info parser is utilized to read Unix-specific configuration
files /etc/doomsday/paths and ~/.doomsday/paths for overridden
base and library directories. For instance:

basedir: /opt/deng/share/
libdir: /opt/deng/lib/

This allows a packager to override the compile-time
DENG_BASE_DIR and DENG_LIBRARY_DIR without the user
needing to know about it.

Command line options (-basedir, -appdir, -libdir) still take precedence
over these.
  • Loading branch information
skyjake committed Apr 22, 2012
1 parent aeb6107 commit 1d7ff12
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 3 deletions.
12 changes: 9 additions & 3 deletions doomsday/engine/portable/src/library.c
Expand Up @@ -75,17 +75,23 @@ static void getBundlePath(char* path, size_t len)
return;
}

/*
#ifdef MACOSX
// This is the default location where bundles are.
dd_snprintf(path, len, "%s/Bundles", appDir);
#endif
*/

#ifdef UNIX
#ifdef DENG_LIBRARY_DIR
# ifdef DENG_LIBRARY_DIR
strncpy(path, DENG_LIBRARY_DIR, len);
#else
# else
// Assume they are in the cwd.
strncpy(path, appDir, len);
#endif
# endif

// Check Unix-specific config files.
DD_Unix_GetConfigValue("paths", "libdir", path, len);
#endif
}
#endif
Expand Down
9 changes: 9 additions & 0 deletions doomsday/engine/unix/include/dd_uinit.h
Expand Up @@ -53,6 +53,15 @@ extern application_t app;
boolean DD_Unix_Init(int argc, char** argv);
void DD_Shutdown(void);

/**
* @note This implementation re-parses the entire config file on each call, so
* it is not useful for performance-critical or high volume usage.
*
* @return @c true, if the found config value was written to @a dest, otherwise
* @c false.
*/
boolean DD_Unix_GetConfigValue(const char* configFile, const char* key, char* dest, size_t destLen);

#ifdef __cplusplus
}
#endif
Expand Down
44 changes: 44 additions & 0 deletions doomsday/engine/unix/src/dd_uinit.c
Expand Up @@ -310,6 +310,8 @@ static void determineGlobalPaths(application_t* app)
#else
strncpy(ddBasePath, DENG_BASE_DIR, FILENAME_T_MAXLEN);
#endif
// Also check the system config files.
DD_Unix_GetConfigValue("paths", "basedir", ddBasePath, FILENAME_T_MAXLEN);
}
Dir_CleanPath(ddBasePath, FILENAME_T_MAXLEN);
Dir_MakeAbsolutePath(ddBasePath, FILENAME_T_MAXLEN);
Expand Down Expand Up @@ -427,3 +429,45 @@ void DD_Shutdown(void)
Library_Shutdown();
DisplayMode_Shutdown();
}

boolean DD_Unix_GetConfigValue(const char* configFile, const char* key, char* dest, size_t destLen)
{
Info* info;
char buf[512];
ddstring_t* p;
boolean success = false;

// Maybe it is in the user's .doomsday dir.
p = Str_New();
Str_Appendf(p, "~/.doomsday/%s", configFile);
F_MakeAbsolute(p, p);
info = Info_NewFromFile(Str_Text(p));
if(info)
{
if(Info_FindValue(info, key, buf, sizeof(buf)))
{
strncpy(dest, buf, destLen);
success = true;
goto cleanup;
}
}

// Check for a config file for the library path.
Str_Clear(p);
Str_Appendf(p, "/etc/doomsday/%s", configFile);
info = Info_NewFromFile(Str_Text(p));
if(info)
{
if(Info_FindValue(info, key, buf, sizeof(buf)))
{
strncpy(dest, buf, destLen);
success = true;
goto cleanup;
}
}

cleanup:
Info_Delete(info);
Str_Delete(p);
return success;
}

0 comments on commit 1d7ff12

Please sign in to comment.