From 60c518022d73fd3962e32dcaef1d48e50c173967 Mon Sep 17 00:00:00 2001 From: Kovensky Date: Fri, 5 Feb 2010 01:09:25 -0300 Subject: [PATCH] Use SHGetSpecialFolderPath instead of %appdata% This is the Right Thing(tm). Cosmetics. --- get_path.c | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/get_path.c b/get_path.c index f903fcfe29..18cedb1874 100644 --- a/get_path.c +++ b/get_path.c @@ -18,15 +18,15 @@ #include #include #include -#elif defined(__MINGW32__) -#include -#include -#include -#elif defined(__CYGWIN__) +#elif defined(_WIN32) +#define _WIN32_IE 0x0400 #include +#include #include #include +#if defined(__CYGWIN__) #include +#endif #elif defined(__OS2__) #define INCL_DOS #include @@ -58,16 +58,14 @@ char *get_path(const char *filename){ { int i,imax=0; struct _stat statBuffer; - char exedir[MAX_PATH]; - char config_path[MAX_PATH]; - char *appdata = getenv("appdata"); - if (appdata && strcmp(appdata, "")) { - strncpy(exedir, appdata, MAX_PATH); - exedir[MAX_PATH-1] = '\0'; + char exedir[4096], config_path[4096], appdata[4096]; + if (SHGetSpecialFolderPathA(NULL, appdata, CSIDL_APPDATA, 1)) { + strncpy(exedir, appdata, strlen(appdata)); } else { - GetModuleFileNameA(NULL, exedir, MAX_PATH); + GetModuleFileNameA(NULL, exedir, 4096); } - for (i=0; i< strlen(exedir); i++) + int len = strlen(exedir); + for (i=0; i< len; i++) if (exedir[i] =='\\') exedir[i]='/'; @@ -75,8 +73,9 @@ char *get_path(const char *filename){ int stat_res; if ((stat_res = stat(config_path, &statBuffer)) < 0 || !(statBuffer.st_mode & S_IFDIR)) { - GetModuleFileNameA(NULL, exedir, MAX_PATH); - for (i=0; i< strlen(exedir); i++) + GetModuleFileNameA(NULL, exedir, 4096); + len = strlen(exedir); + for (i=0; i< len; i++) if (exedir[i] =='\\') {exedir[i]='/'; imax=i;} exedir[imax]='\0'; -- 2.11.4.GIT