diff os2/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 b6249d66404c
children 3eedfd4f7c5d
line wrap: on
line diff
--- a/os2/dw.c	Thu Nov 24 06:07:40 2011 +0000
+++ b/os2/dw.c	Fri Nov 25 17:36:59 2011 +0000
@@ -67,11 +67,12 @@
 
 HWND hwndApp = NULLHANDLE, hwndBubble = NULLHANDLE, hwndBubbleLast = NULLHANDLE, hwndEmph = NULLHANDLE;
 HWND hwndTrayServer = NULLHANDLE, hwndTaskBar = NULLHANDLE;
-;
+
 PRECORDCORE pCoreEmph = NULL;
 ULONG aulBuffer[4];
 HWND lasthcnr = 0, lastitem = 0, popup = 0, desktop;
 HMOD wpconfig = 0, pmprintf = 0;
+static char _dw_exec_dir[MAX_PATH+1] = {0};
 
 unsigned long _colors[] = {
    CLR_BLACK,
@@ -3985,8 +3986,22 @@
    APIRET rc;
    char objnamebuf[300] = "";
 
-   argc = argc; /* keep compiler happy */
-   argv = argv; /* keep compiler happy */
+   /* 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])
+      _getcwd(_dw_exec_dir, MAX_PATH);
+      
    if(newthread)
    {
       dwhab = WinInitialize(0);
@@ -11135,7 +11150,7 @@
  */
 char * API dw_user_dir(void)
 {
-   static char _user_dir[1024] = "";
+   static char _user_dir[MAX_PATH+1] = {0};
 
    if(!_user_dir[0])
    {
@@ -11150,6 +11165,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.