changeset 650:98f5d15d5ec4

Improve and fix XDG support.
author Matti Hamalainen <ccr@tnsp.org>
date Mon, 26 Jan 2015 06:44:25 +0200
parents a190b618100a
children e862edb65b9d
files main.c
diffstat 1 files changed, 17 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/main.c	Mon Jan 26 06:44:05 2015 +0200
+++ b/main.c	Mon Jan 26 06:44:25 2015 +0200
@@ -24,9 +24,14 @@
 #  define SET_LOG_DIR        "NNChat Log Files"
 #  define SET_DIR_SEPARATOR  '\\'
 #else
-#define SET_CONFIG_FILE    ".nnchat"
-#define SET_LOG_DIR        "nnlogs"
-#define SET_DIR_SEPARATOR  '/'
+#  define SET_DIR_SEPARATOR  '/'
+#  define SET_LOG_DIR        "nnlogs"
+#  if defined(USE_XDG)
+#    define SET_XDG_CONFIG_DIR "nnchat"
+#    define SET_CONFIG_FILE    "config"
+#  else
+#    define SET_CONFIG_FILE    ".nnchat"
+#  endif
 #endif
 
 #define SET_PROFILE_PREFIX "http://www.newbienudes.com/profile/%s/"
@@ -1802,22 +1807,19 @@
 
 BOOL nn_log_open(nn_window_t *win)
 {
-    char *path = NULL;
+    char *path = NULL, *plt;
 #ifndef __WIN32
     int logFd = -1;
 #endif
 
-    if (!optLogEnable)
+    if (!optLogEnable || optLogPath == NULL)
         return FALSE;
 
-    if (optLogPath != NULL)
-    {
-        char *lt = strrchr(optLogPath, SET_DIR_SEPARATOR);
-        if (lt == NULL || lt[1] != 0)
-            path = th_strdup_printf("%s%c", optLogPath, SET_DIR_SEPARATOR);
-        else
-            path = th_strdup(optLogPath);
-    }
+    plt = strrchr(optLogPath, SET_DIR_SEPARATOR);
+    if (plt == NULL || plt[1] != 0)
+        path = th_strdup_printf("%s%c", optLogPath, SET_DIR_SEPARATOR);
+    else
+        path = th_strdup(optLogPath);
 
     if (win->id == NULL)
     {
@@ -2080,10 +2082,10 @@
 
         // If XDG is enabled, try the environment variable first
         if (xdgConfigDir != NULL && strcmp(xdgConfigDir, ""))
-            setConfigDir = th_strdup_printf("%s/nnchat/", xdgConfigDir);
+            setConfigDir = th_strdup_printf("%s/%s/", xdgConfigDir, SET_XDG_CONFIG_DIR);
         else
             // Nope, try the obvious alternative
-            setConfigDir = th_strdup_printf("%s/.config/nnchat/", setHomeDir);
+            setConfigDir = th_strdup_printf("%s/.config/%s/", setHomeDir, SET_XDG_CONFIG_DIR);
 #else
         setHomeDir = th_strdup(getenv("HOME"));
         setConfigDir = th_strdup(setHomeDir);