Mercurial > hg > nnchat
comparison main.c @ 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 | d6792ccefe2f |
children | a190b618100a |
comparison
equal
deleted
inserted
replaced
647:ff94100cfc7c | 648:a9d25e083f44 |
---|---|
1993 BOOL argsOK, colorSet = FALSE; | 1993 BOOL argsOK, colorSet = FALSE; |
1994 th_conn_t *conn = NULL; | 1994 th_conn_t *conn = NULL; |
1995 nn_editbuf_t *editBuf = nn_editbuf_new(NN_TMPBUF_SIZE); | 1995 nn_editbuf_t *editBuf = nn_editbuf_new(NN_TMPBUF_SIZE); |
1996 nn_editstate_t editState; | 1996 nn_editstate_t editState; |
1997 th_cfgitem_t *tmpcfg; | 1997 th_cfgitem_t *tmpcfg; |
1998 char *setHomeDir = NULL, *setProxyURI = NULL; | 1998 char *setHomeDir = NULL, *setConfigDir = NULL, *setProxyURI = NULL; |
1999 | 1999 |
2000 memset(editHistBuf, 0, sizeof(editHistBuf)); | 2000 memset(editHistBuf, 0, sizeof(editHistBuf)); |
2001 clearEditState(&editState); | 2001 clearEditState(&editState); |
2002 | 2002 |
2003 // Initialize | 2003 // Initialize |
2071 char tmpPath[MAX_PATH]; | 2071 char tmpPath[MAX_PATH]; |
2072 if (SHGetFolderPath(NULL, CSIDL_APPDATA | CSIDL_FLAG_CREATE, NULL, 0, tmpPath) == S_OK) | 2072 if (SHGetFolderPath(NULL, CSIDL_APPDATA | CSIDL_FLAG_CREATE, NULL, 0, tmpPath) == S_OK) |
2073 setHomeDir = th_strdup(tmpPath); | 2073 setHomeDir = th_strdup(tmpPath); |
2074 | 2074 |
2075 CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE); | 2075 CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE); |
2076 setConfigDir = th_strdup(setHomeDir); | |
2076 #elif defined(USE_XDG) | 2077 #elif defined(USE_XDG) |
2077 char *xdgConfigDir = getenv("XDG_CONFIG_HOME"); | 2078 const char *xdgConfigDir = getenv("XDG_CONFIG_HOME"); |
2079 setHomeDir = th_strdup(getenv("HOME")); | |
2078 | 2080 |
2079 // If XDG is enabled, try the environment variable first | 2081 // If XDG is enabled, try the environment variable first |
2080 if (xdgConfigDir != NULL) | 2082 if (xdgConfigDir != NULL && strcmp(xdgConfigDir, "")) |
2081 setHomeDir = th_strdup(xdgConfigDir); | 2083 setConfigDir = th_strdup_printf("%s/nnchat/", xdgConfigDir); |
2082 else | 2084 else |
2083 // Nope, try the obvious alternative | 2085 // Nope, try the obvious alternative |
2084 setHomeDir = th_strdup_printf("%s/.config", getenv("HOME")); | 2086 setConfigDir = th_strdup_printf("%s/.config/nnchat/", setHomeDir); |
2085 #else | 2087 #else |
2086 setHomeDir = th_strdup(getenv("HOME")); | 2088 setHomeDir = th_strdup(getenv("HOME")); |
2089 setConfigDir = th_strdup(setHomeDir); | |
2087 #endif | 2090 #endif |
2088 } | 2091 } |
2089 | 2092 |
2090 if (setHomeDir != NULL) | 2093 if (setConfigDir != NULL) |
2091 { | 2094 { |
2092 th_ioctx_t ctx; | 2095 th_ioctx_t ctx; |
2093 setConfigFile = th_strdup_printf("%s%c%s", setHomeDir, SET_DIR_SEPARATOR, SET_CONFIG_FILE); | 2096 setConfigFile = th_strdup_printf("%s%c%s", setConfigDir, SET_DIR_SEPARATOR, SET_CONFIG_FILE); |
2094 | 2097 |
2095 THMSG(0, "Reading configuration from '%s'.\n", setConfigFile); | 2098 THMSG(0, "Reading configuration from '%s'.\n", setConfigFile); |
2096 | 2099 |
2097 if (th_ioctx_open(&ctx, setConfigFile, "r", nn_ioctx_errfunc, nn_ioctx_msgfunc)) | 2100 if (th_ioctx_open(&ctx, setConfigFile, "r", nn_ioctx_errfunc, nn_ioctx_msgfunc)) |
2098 { | 2101 { |
2108 | 2111 |
2109 setBrowser = getenv("BROWSER"); | 2112 setBrowser = getenv("BROWSER"); |
2110 if (setBrowser == NULL) | 2113 if (setBrowser == NULL) |
2111 setBrowser = "firefox"; | 2114 setBrowser = "firefox"; |
2112 | 2115 |
2113 if (optLogPath == NULL) | 2116 if (optLogPath == NULL && setHomeDir != NULL) |
2114 { | 2117 { |
2115 optLogPath = th_strdup_printf("%s%c%s%c", | 2118 optLogPath = th_strdup_printf("%s%c%s%c", |
2116 setHomeDir, SET_DIR_SEPARATOR, SET_LOG_DIR, SET_DIR_SEPARATOR); | 2119 setHomeDir, SET_DIR_SEPARATOR, SET_LOG_DIR, SET_DIR_SEPARATOR); |
2117 } | 2120 } |
2118 | 2121 |
2389 th_free(tmp); | 2392 th_free(tmp); |
2390 } | 2393 } |
2391 | 2394 |
2392 th_cfg_free(cfg); | 2395 th_cfg_free(cfg); |
2393 th_free(setHomeDir); | 2396 th_free(setHomeDir); |
2397 th_free(setConfigDir); | |
2394 th_llist_free_func(setIdleMessages, th_free); | 2398 th_llist_free_func(setIdleMessages, th_free); |
2395 nn_userhash_free(nnUsers); | 2399 nn_userhash_free(nnUsers); |
2396 nn_editbuf_free(editBuf); | 2400 nn_editbuf_free(editBuf); |
2397 | 2401 |
2398 for (index = 0; index <= SET_MAX_HISTORY; index++) | 2402 for (index = 0; index <= SET_MAX_HISTORY; index++) |