diff --git a/src/common/filesystem.c b/src/common/filesystem.c index b791ae58..8cc52464 100644 --- a/src/common/filesystem.c +++ b/src/common/filesystem.c @@ -1253,51 +1253,18 @@ FS_AddGameDirectory(const char *dir) void FS_AddHomeAsGameDirectory(char *dir) { + char *home; char gdir[MAX_OSPATH]; - int len; - -#ifdef _WIN32 - char *cur; - char *old; - char *profile = getenv("USERPROFILE"); + size_t len; - if (!profile) + home = Sys_GetHomeDir(); + + if (home == NULL) { return; } - cur = old = profile; - - /* Replace backslashes by slashes */ - if (strstr(cur, "\\") != NULL) - { - while (cur != NULL) - { - if ((cur - old) > 1) - { - *cur = '/'; - - } - - old = cur; - cur = strchr(old + 1, '\\'); - } - } - - len = snprintf(gdir, sizeof(gdir), "%s%s%s/", profile, - "/Documents/YamagiQ2/", dir); -#else - char *homedir = getenv("HOME"); - - if (!homedir) - { - return; - } - - len = snprintf(gdir, sizeof(gdir), "%s/.yq2/%s/", homedir, dir); -#endif - - + len = snprintf(gdir, sizeof(gdir), "%s%s/", home, dir); FS_CreatePath(gdir); if ((len > 0) && (len < sizeof(gdir)) && (gdir[len-1] == '/')) diff --git a/src/common/header/common.h b/src/common/header/common.h index 0a11ab65..1e414c39 100644 --- a/src/common/header/common.h +++ b/src/common/header/common.h @@ -55,6 +55,12 @@ #define CPUSTRING "Unknown" #endif +#ifdef _WIN32 +#define CFGDIR "YamagiQ2" +#else +#define CFGDIR ".yq2" +#endif + /* ================================================================== */ typedef struct sizebuf_s @@ -741,6 +747,7 @@ void Sys_ConsoleOutput (char *string); void Sys_SendKeyEvents (void); void Sys_Error (char *error, ...); void Sys_Quit (void); +char *Sys_GetHomeDir(void); /* CLIENT / SERVER SYSTEMS */ diff --git a/src/unix/system.c b/src/unix/system.c index 3910e7a1..1ddc5c01 100644 --- a/src/unix/system.c +++ b/src/unix/system.c @@ -501,3 +501,22 @@ Sys_SendKeyEvents ( void ) /* grab frame time */ sys_frame_time = Sys_Milliseconds(); } + +char * +Sys_GetHomeDir(void) +{ + static char gdir[MAX_OSPATH]; + char *home; + + home = getenv("HOME"); + + if (!home) + { + return NULL; + } + + snprintf(gdir, sizeof(gdir), "%s/%s/", home, CFGDIR); + + return gdir; +} + diff --git a/src/windows/system.c b/src/windows/system.c index 25a45124..1f1ec9b7 100644 --- a/src/windows/system.c +++ b/src/windows/system.c @@ -32,6 +32,7 @@ #include #include #include +#include #include "../common/header/common.h" #include "header/conproc.h" @@ -606,6 +607,39 @@ Sys_GetCurrentDirectory(void) return dir; } +char * +Sys_GetHomeDir(void) +{ + char *old; + char *cur; + static char gdir[MAX_OSPATH]; + TCHAR profile[MAX_OSPATH]; + + SHGetFolderPath(NULL, CSIDL_PERSONAL, NULL, 0, profile); + + /* Replace backslashes by slashes */ + cur = old = profile; + + if (strstr(cur, "\\") != NULL) + { + while (cur != NULL) + { + if ((cur - old) > 1) + { + *cur = '/'; + + } + + old = cur; + cur = strchr(old + 1, '\\'); + } + } + + snprintf(gdir, sizeof(gdir), "%s/%s/", profile, CFGDIR); + + return gdir; +} + /* ======================================================================= */ /*