comparison main.c @ 512:93c8ba1ef55f

Support XDG specification.
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 05 Jun 2012 19:56:57 +0300
parents 291e3caa91a0
children ef5a2aa8382b
comparison
equal deleted inserted replaced
511:291e3caa91a0 512:93c8ba1ef55f
1361 th_cfg_add_bool(&tmpcfg, "enable", &optLogEnable, optLogEnable); 1361 th_cfg_add_bool(&tmpcfg, "enable", &optLogEnable, optLogEnable);
1362 th_cfg_add_comment(&tmpcfg, "Log filename format"); 1362 th_cfg_add_comment(&tmpcfg, "Log filename format");
1363 th_cfg_add_string(&tmpcfg, "filename", &optLogFilename, optLogFilename); 1363 th_cfg_add_string(&tmpcfg, "filename", &optLogFilename, optLogFilename);
1364 th_cfg_add_section(&cfg, "logging", tmpcfg); 1364 th_cfg_add_section(&cfg, "logging", tmpcfg);
1365 1365
1366 // Get home directory path
1366 #ifdef __WIN32 1367 #ifdef __WIN32
1367 { 1368 {
1368 char tmpPath[MAX_PATH]; 1369 char tmpPath[MAX_PATH];
1369 if (SHGetFolderPath(NULL, CSIDL_APPDATA | CSIDL_FLAG_CREATE, NULL, 0, tmpPath) == S_OK) 1370 if (SHGetFolderPath(NULL, CSIDL_APPDATA | CSIDL_FLAG_CREATE, NULL, 0, tmpPath) == S_OK)
1370 setHomeDir = th_strdup(tmpPath); 1371 setHomeDir = th_strdup(tmpPath);
1371 1372
1372 CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE); 1373 CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE);
1373 } 1374 }
1374 #else 1375 #else
1375 setHomeDir = th_strdup(getenv("HOME")); 1376 {
1377 char *xdgConfigDir = getenv("XDG_CONFIG_HOME"),
1378 *userHomeDir = getenv("HOME");
1379 #ifdef USE_XDG
1380 if (xdgConfigDir != NULL)
1381 setHomeDir = th_strdup(xdgConfigDir);
1382 else
1383 setHomeDir = th_strdup_printf("%s/.config", userHomeDir);
1384 #else
1385 setHomeDir = th_strdup(userHomeDir);
1386 #endif
1387 }
1376 #endif 1388 #endif
1377 1389
1378 if (setHomeDir != NULL) 1390 if (setHomeDir != NULL)
1379 { 1391 {
1380 FILE *cfgfile; 1392 FILE *cfgfile;