comparison main.c @ 616:1ffacd20b88b

Clean up the #ifdef mess around homedir handling a bit.
author Matti Hamalainen <ccr@tnsp.org>
date Wed, 21 May 2014 19:10:02 +0300
parents 2cd71b7c1e8e
children ada20f599490
comparison
equal deleted inserted replaced
615:399ce077b2a0 616:1ffacd20b88b
2001 th_cfg_add_string(&tmpcfg, "extension", &optLogExtension, optLogExtension); 2001 th_cfg_add_string(&tmpcfg, "extension", &optLogExtension, optLogExtension);
2002 2002
2003 th_cfg_add_section(&cfg, "logging", tmpcfg); 2003 th_cfg_add_section(&cfg, "logging", tmpcfg);
2004 2004
2005 // Get home directory path 2005 // Get home directory path
2006 #ifdef __WIN32 2006 {
2007 { 2007 #if defined(__WIN32)
2008 char tmpPath[MAX_PATH]; 2008 char tmpPath[MAX_PATH];
2009 if (SHGetFolderPath(NULL, CSIDL_APPDATA | CSIDL_FLAG_CREATE, NULL, 0, tmpPath) == S_OK) 2009 if (SHGetFolderPath(NULL, CSIDL_APPDATA | CSIDL_FLAG_CREATE, NULL, 0, tmpPath) == S_OK)
2010 setHomeDir = th_strdup(tmpPath); 2010 setHomeDir = th_strdup(tmpPath);
2011 2011
2012 CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE); 2012 CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE);
2013 } 2013 #elif defined(USE_XDG)
2014 #else 2014 char *xdgConfigDir = getenv("XDG_CONFIG_HOME");
2015 { 2015
2016 char *xdgConfigDir = getenv("XDG_CONFIG_HOME"),
2017 *userHomeDir = getenv("HOME");
2018
2019 #ifdef USE_XDG
2020 // If XDG is enabled, try the environment variable first 2016 // If XDG is enabled, try the environment variable first
2021 if (xdgConfigDir != NULL) 2017 if (xdgConfigDir != NULL)
2022 setHomeDir = th_strdup(xdgConfigDir); 2018 setHomeDir = th_strdup(xdgConfigDir);
2023 else 2019 else
2024 // Nope, try the obvious alternative 2020 // Nope, try the obvious alternative
2025 setHomeDir = th_strdup_printf("%s/.config", userHomeDir); 2021 setHomeDir = th_strdup_printf("%s/.config", getenv("HOME"));
2026 #else 2022 #else
2027 setHomeDir = th_strdup(userHomeDir); 2023 setHomeDir = th_strdup(getenv("HOME"));
2028 #endif 2024 #endif
2029 } 2025 }
2030 #endif
2031 2026
2032 if (setHomeDir != NULL) 2027 if (setHomeDir != NULL)
2033 { 2028 {
2034 th_ioctx_t ctx; 2029 th_ioctx_t ctx;
2035 setConfigFile = th_strdup_printf("%s%c%s", setHomeDir, SET_DIR_SEPARATOR, SET_CONFIG_FILE); 2030 setConfigFile = th_strdup_printf("%s%c%s", setHomeDir, SET_DIR_SEPARATOR, SET_CONFIG_FILE);