Mercurial > dwindows
diff win/dw.c @ 1381:3ba4853d5b78
Initial attempt at dw_app_dir() for OS/2, Windows and Mac...
This function will return the best attempt at determining the application data directory for the current platform. The executable directory on OS/2 or Windows. The application bundle directory on Mac. The "share" folder at the same level as the binary (or /usr/local/share if that can't be determined) plus the binary name on Unix.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Fri, 25 Nov 2011 17:36:59 +0000 |
parents | cc66b6d4b74e |
children | 156e32814c83 |
line wrap: on
line diff
--- a/win/dw.c Thu Nov 24 06:07:40 2011 +0000 +++ b/win/dw.c Fri Nov 25 17:36:59 2011 +0000 @@ -143,7 +143,8 @@ * an alternate temporary directory if TMP is not set, so we get the value * of TEMP and store it here. */ -static char _dw_alternate_temp_dir[MAX_PATH+1]; +static char _dw_alternate_temp_dir[MAX_PATH+1] = {0}; +static char _dw_exec_dir[MAX_PATH+1] = {0}; int main(int argc, char *argv[]); @@ -3649,6 +3650,22 @@ struct GdiplusStartupInput si; #endif + /* Setup the private data directory */ + if(argc > 0 && argv[0]) + { + char *pos = strrchr(argv[0], '\\'); + + /* Just to be safe try the unix style */ + if(!pos) + pos = strrchr(argv[0], '/'); + + if(pos) + strncpy(_dw_exec_dir, argv[0], (size_t)(pos - argv[0])); + } + /* If that failed... just get the current directory */ + if(!_dw_exec_dir[0]) + GetCurrentDirectory(MAX_PATH, _dw_exec_dir); + /* Initialize our thread local storage */ _foreground = TlsAlloc(); _background = TlsAlloc(); @@ -10714,6 +10731,15 @@ } /* + * Returns a pointer to a static buffer which containes the + * private application data directory. + */ +char *dw_app_dir(void) +{ + return _dw_exec_dir; +} + +/* * Call a function from the window (widget)'s context. * Parameters: * handle: Window handle of the widget.