Mercurial > hg > nnchat
changeset 648:a9d25e083f44
Separate home dir and config dir functionality.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Mon, 26 Jan 2015 05:22:12 +0200 |
parents | ff94100cfc7c |
children | a190b618100a |
files | main.c |
diffstat | 1 files changed, 12 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/main.c Fri Jan 09 20:37:15 2015 +0200 +++ b/main.c Mon Jan 26 05:22:12 2015 +0200 @@ -1995,7 +1995,7 @@ nn_editbuf_t *editBuf = nn_editbuf_new(NN_TMPBUF_SIZE); nn_editstate_t editState; th_cfgitem_t *tmpcfg; - char *setHomeDir = NULL, *setProxyURI = NULL; + char *setHomeDir = NULL, *setConfigDir = NULL, *setProxyURI = NULL; memset(editHistBuf, 0, sizeof(editHistBuf)); clearEditState(&editState); @@ -2073,24 +2073,27 @@ setHomeDir = th_strdup(tmpPath); CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE); + setConfigDir = th_strdup(setHomeDir); #elif defined(USE_XDG) - char *xdgConfigDir = getenv("XDG_CONFIG_HOME"); + const char *xdgConfigDir = getenv("XDG_CONFIG_HOME"); + setHomeDir = th_strdup(getenv("HOME")); // If XDG is enabled, try the environment variable first - if (xdgConfigDir != NULL) - setHomeDir = th_strdup(xdgConfigDir); + if (xdgConfigDir != NULL && strcmp(xdgConfigDir, "")) + setConfigDir = th_strdup_printf("%s/nnchat/", xdgConfigDir); else // Nope, try the obvious alternative - setHomeDir = th_strdup_printf("%s/.config", getenv("HOME")); + setConfigDir = th_strdup_printf("%s/.config/nnchat/", setHomeDir); #else setHomeDir = th_strdup(getenv("HOME")); + setConfigDir = th_strdup(setHomeDir); #endif } - if (setHomeDir != NULL) + if (setConfigDir != NULL) { th_ioctx_t ctx; - setConfigFile = th_strdup_printf("%s%c%s", setHomeDir, SET_DIR_SEPARATOR, SET_CONFIG_FILE); + setConfigFile = th_strdup_printf("%s%c%s", setConfigDir, SET_DIR_SEPARATOR, SET_CONFIG_FILE); THMSG(0, "Reading configuration from '%s'.\n", setConfigFile); @@ -2110,7 +2113,7 @@ if (setBrowser == NULL) setBrowser = "firefox"; - if (optLogPath == NULL) + if (optLogPath == NULL && setHomeDir != NULL) { optLogPath = th_strdup_printf("%s%c%s%c", setHomeDir, SET_DIR_SEPARATOR, SET_LOG_DIR, SET_DIR_SEPARATOR); @@ -2391,6 +2394,7 @@ th_cfg_free(cfg); th_free(setHomeDir); + th_free(setConfigDir); th_llist_free_func(setIdleMessages, th_free); nn_userhash_free(nnUsers); nn_editbuf_free(editBuf);