-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi Martin,

GWEN_Directory_GetHomeDirectory() auf Windows liefert momentan immer
GetWindowsDirectory() zurück, also "C:\Windows" oder "C:\WINNT". Da das
inzwischen mit gnucash und aqbanking aber echt akut wird, sollte hier
nun ein echtes *userspezifisches* home-Directory verwendet werden und
nicht mehr das systemweite windows-Directory.

In glib gibt es eine ähnliche Funktion g_get_home_dir(); die
Implementation von dort hab ich mal abgeschrieben und ich würde
vorschlagen, diese zu übernehmen. Es wird also getenv("HOME") genommen;
bei Nichtverfügbarkeit dann stattdessen getenv("USERPROFILE"); wenn
immer noch nicht verfügbar, als fallback das bisherige WindowsDirectory.

Patch hängt an. Bist du einverstanden?

Gruß

Christian
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2.1 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iQCVAwUBRcxW1mXAi+BfhivFAQJppwP+JoqLDFht2HtFYz7SWljfO3B1TNtLmya6
Y6BwFRQuMsJyY5GtIuIT/RrbtgF2ERADyh17rcbDkYI4TDRcn8W4WqK9nXi3GFex
L4xMG+eoS2t9zUHN2PG+Tyivhn57kx4ymnLjVWL3yc88Xd1IF2d6zn7r/qVkzpLH
gqkmF279Vzs=
=7Efp
-----END PGP SIGNATURE-----
Index: src/os/windows/directory.c
===================================================================
--- src/os/windows/directory.c  (revision 1145)
+++ src/os/windows/directory.c  (working copy)
@@ -159,15 +159,70 @@
 }
 
 
+/** Returns TRUE (nonzero) if the given path is an absolute one. */
+static int path_is_absolute(const char *path)
+{
+  return path && 
+    ( (path[0] == '\\') ||
+      (path[0] == '/') ||
+      ( (strlen(path) > 2) && (path[1] == ':') ) );
+}
 
 int GWEN_Directory_GetHomeDirectory(char *buffer, unsigned int size){
   int rv;
+  char *home_dir;
 
-  rv=GetWindowsDirectory(buffer, size);
-  if (rv==0) {
-    DBG_INFO(GWEN_LOGDOMAIN, "Error on GetWindowsDirectory");
-    return -1;
-  }
+  /* Taken from
+     http://svn.gnome.org/viewcvs/glib/trunk/glib/gutils.c, see
+     the lookup of the g_home_dir variable in
+     g_get_any_init_do(). */
+
+  /* We check $HOME first for Win32, though it is a last resort for Unix
+   * where we prefer the results of getpwuid().
+   */
+  home_dir = getenv ("HOME");
+
+  /* Only believe HOME if it is an absolute path and exists */
+  if (home_dir)
+    {
+      if (!(path_is_absolute (home_dir)
+           /* && g_file_test (home_dir, G_FILE_TEST_IS_DIR) */ 
+           ))
+       {
+         home_dir = NULL;
+       }
+    }
+  
+  if (!home_dir)
+    {
+      /* USERPROFILE is probably the closest equivalent to $HOME? */
+      if (getenv ("USERPROFILE") != NULL)
+       home_dir = getenv ("USERPROFILE");
+    }
+
+  /* Did we find any home_dir? Copy it to buffer. */
+  if (home_dir)
+    {
+      char *p;
+
+      rv = strlen (home_dir);
+      strncpy (buffer, home_dir, size);
+      
+      /* In case HOME is Unix-style (it happens), convert it to
+       * Windows style.
+       */
+      while ((p = strchr (buffer, '/')) != NULL)
+       *p = '\\';
+    }
+  else
+    {
+      rv=GetWindowsDirectory(buffer, size);
+      if (rv==0) {
+       DBG_INFO(GWEN_LOGDOMAIN, "Error on GetWindowsDirectory");
+       return -1;
+      }
+    }
+
   if (rv>=size) {
     DBG_INFO(GWEN_LOGDOMAIN, "Buffer too small");
     return -1;
-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier.
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Aqbanking-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/aqbanking-devel

Reply via email to