# HG changeset patch # User Matti Hamalainen # Date 1288735400 -7200 # Node ID e8f67e344aaf160321ee4ae4c6bd7afd1fbdfc0e # Parent f1684884fd56e7d6dd43cf6cbd8cf61e381d87bd Get correct directory for saving configuration under Windows. diff -r f1684884fd56 -r e8f67e344aaf nnchat.c --- a/nnchat.c Wed Nov 03 00:03:02 2010 +0200 +++ b/nnchat.c Wed Nov 03 00:03:20 2010 +0200 @@ -12,6 +12,7 @@ #ifdef __WIN32 /* Undefine because both windows.h and curses.h #define it */ #undef MOUSE_MOVED +#include #else #include #endif @@ -805,6 +806,9 @@ nn_editbuf_t *editBuf = nn_editbuf_new(SET_BUFSIZE); nn_editbuf_t *histBuf[SET_MAX_HISTORY+2]; int histPos = 0, histMax = 0; + + cfgitem_t *tmpcfg; + char *homeDir = NULL; memset(histBuf, 0, sizeof(histBuf)); @@ -815,24 +819,6 @@ th_verbosityLevel = 0; /* Read config */ - { - cfgitem_t *tmpcfg; - FILE *cfgfile; - char *homeDir; - -#ifdef __WIN32 - -#else - homeDir = getenv("HOME"); -#endif - - if (homeDir != NULL) - setConfigFile = th_strdup_printf("%s" SET_DIR_SEPARATOR "%s", homeDir, SET_CONFIG_FILE); - else - setConfigFile = th_strdup(SET_CONFIG_FILE); - - THMSG(0, "Reading configuration from '%s'.\n", setConfigFile); - tmpcfg = NULL; th_cfg_add_comment(&tmpcfg, "General settings"); th_cfg_add_string(&tmpcfg, "username", &optUserName, NULL); @@ -853,8 +839,24 @@ th_cfg_add_int(&tmpcfg, "port", &optPort, optPort); th_cfg_add_section(&cfg, "server", tmpcfg); - if ((cfgfile = fopen(setConfigFile, "r")) != NULL) - th_cfg_read(cfgfile, setConfigFile, cfg); +#ifdef __WIN32 + { + char tmpPath[MAX_PATH]; + if (SHGetFolderPath(NULL, CSIDL_APPDATA | CSIDL_FLAG_CREATE, NULL, 0, tmpPath) == S_OK) + homeDir = th_strdup(tmpPath); + } +#else + homeDir = getenv("HOME"); +#endif + + if (homeDir != NULL) { + FILE *cfgfile; + setConfigFile = th_strdup_printf("%s" SET_DIR_SEPARATOR "%s", homeDir, SET_CONFIG_FILE); + + THMSG(0, "Reading configuration from '%s'.\n", setConfigFile); + + if ((cfgfile = fopen(setConfigFile, "r")) != NULL) + th_cfg_read(cfgfile, setConfigFile, cfg); } setBrowser = getenv("BROWSER");