comparison nnchat.c @ 154:e8f67e344aaf

Get correct directory for saving configuration under Windows.
author Matti Hamalainen <ccr@tnsp.org>
date Wed, 03 Nov 2010 00:03:20 +0200
parents f1684884fd56
children 0720ca51673e
comparison
equal deleted inserted replaced
153:f1684884fd56 154:e8f67e344aaf
10 #include <string.h> 10 #include <string.h>
11 #include <errno.h> 11 #include <errno.h>
12 #ifdef __WIN32 12 #ifdef __WIN32
13 /* Undefine because both windows.h and curses.h #define it */ 13 /* Undefine because both windows.h and curses.h #define it */
14 #undef MOUSE_MOVED 14 #undef MOUSE_MOVED
15 #include <shlwapi.h>
15 #else 16 #else
16 #include <sys/wait.h> 17 #include <sys/wait.h>
17 #endif 18 #endif
18 #include <curses.h> 19 #include <curses.h>
19 20
803 fd_set sockfds; 804 fd_set sockfds;
804 char *tmpStr; 805 char *tmpStr;
805 nn_editbuf_t *editBuf = nn_editbuf_new(SET_BUFSIZE); 806 nn_editbuf_t *editBuf = nn_editbuf_new(SET_BUFSIZE);
806 nn_editbuf_t *histBuf[SET_MAX_HISTORY+2]; 807 nn_editbuf_t *histBuf[SET_MAX_HISTORY+2];
807 int histPos = 0, histMax = 0; 808 int histPos = 0, histMax = 0;
809
810 cfgitem_t *tmpcfg;
811 char *homeDir = NULL;
808 812
809 memset(histBuf, 0, sizeof(histBuf)); 813 memset(histBuf, 0, sizeof(histBuf));
810 814
811 /* Initialize */ 815 /* Initialize */
812 th_init("NNChat", "Newbie Nudes chat client", "0.8.1", 816 th_init("NNChat", "Newbie Nudes chat client", "0.8.1",
813 "Written and designed by Anonymous Finnish Guy (C) 2008-2010", 817 "Written and designed by Anonymous Finnish Guy (C) 2008-2010",
814 "This software is freeware, use and distribute as you wish."); 818 "This software is freeware, use and distribute as you wish.");
815 th_verbosityLevel = 0; 819 th_verbosityLevel = 0;
816 820
817 /* Read config */ 821 /* Read config */
818 {
819 cfgitem_t *tmpcfg;
820 FILE *cfgfile;
821 char *homeDir;
822
823 #ifdef __WIN32
824
825 #else
826 homeDir = getenv("HOME");
827 #endif
828
829 if (homeDir != NULL)
830 setConfigFile = th_strdup_printf("%s" SET_DIR_SEPARATOR "%s", homeDir, SET_CONFIG_FILE);
831 else
832 setConfigFile = th_strdup(SET_CONFIG_FILE);
833
834 THMSG(0, "Reading configuration from '%s'.\n", setConfigFile);
835
836 tmpcfg = NULL; 822 tmpcfg = NULL;
837 th_cfg_add_comment(&tmpcfg, "General settings"); 823 th_cfg_add_comment(&tmpcfg, "General settings");
838 th_cfg_add_string(&tmpcfg, "username", &optUserName, NULL); 824 th_cfg_add_string(&tmpcfg, "username", &optUserName, NULL);
839 th_cfg_add_string(&tmpcfg, "password", &optPassword, NULL); 825 th_cfg_add_string(&tmpcfg, "password", &optPassword, NULL);
840 th_cfg_add_comment(&tmpcfg, "Default color as a hex-triplet"); 826 th_cfg_add_comment(&tmpcfg, "Default color as a hex-triplet");
851 th_cfg_add_string(&tmpcfg, "host", &optServer, optServer); 837 th_cfg_add_string(&tmpcfg, "host", &optServer, optServer);
852 th_cfg_add_comment(&tmpcfg, "Default port to connect to (8002 = public room, 8003 = passion pit, 8005 = members only)"); 838 th_cfg_add_comment(&tmpcfg, "Default port to connect to (8002 = public room, 8003 = passion pit, 8005 = members only)");
853 th_cfg_add_int(&tmpcfg, "port", &optPort, optPort); 839 th_cfg_add_int(&tmpcfg, "port", &optPort, optPort);
854 th_cfg_add_section(&cfg, "server", tmpcfg); 840 th_cfg_add_section(&cfg, "server", tmpcfg);
855 841
856 if ((cfgfile = fopen(setConfigFile, "r")) != NULL) 842 #ifdef __WIN32
857 th_cfg_read(cfgfile, setConfigFile, cfg); 843 {
844 char tmpPath[MAX_PATH];
845 if (SHGetFolderPath(NULL, CSIDL_APPDATA | CSIDL_FLAG_CREATE, NULL, 0, tmpPath) == S_OK)
846 homeDir = th_strdup(tmpPath);
847 }
848 #else
849 homeDir = getenv("HOME");
850 #endif
851
852 if (homeDir != NULL) {
853 FILE *cfgfile;
854 setConfigFile = th_strdup_printf("%s" SET_DIR_SEPARATOR "%s", homeDir, SET_CONFIG_FILE);
855
856 THMSG(0, "Reading configuration from '%s'.\n", setConfigFile);
857
858 if ((cfgfile = fopen(setConfigFile, "r")) != NULL)
859 th_cfg_read(cfgfile, setConfigFile, cfg);
858 } 860 }
859 861
860 setBrowser = getenv("BROWSER"); 862 setBrowser = getenv("BROWSER");
861 if (setBrowser == NULL) 863 if (setBrowser == NULL)
862 setBrowser = "firefox"; 864 setBrowser = "firefox";