changeset 180:344b8a79ad2e

Implemented detection profile paths for Windows Vista/7.
author Sascha Wilde <wilde@intevation.de>
date Tue, 25 Mar 2014 17:51:24 +0100
parents c92297bcda8f
children bea93c8651b7
files cinst/mozilla.c
diffstat 1 files changed, 81 insertions(+), 47 deletions(-) [+]
line wrap: on
line diff
--- a/cinst/mozilla.c	Tue Mar 25 16:48:18 2014 +0100
+++ b/cinst/mozilla.c	Tue Mar 25 17:51:24 2014 +0100
@@ -79,6 +79,47 @@
 int return_code = 0;
 
 /**
+ * @brief Return users home path, on windows including drive letter
+ * @returns a pointer to a string containing the home path, it should
+ * be freed by the caller.
+ */
+static char *
+get_home()
+{
+  char *home, *homevar, *fqhome;
+  char *homedrive = NULL;
+
+  size_t len;
+  if (LINUX)
+    homevar = "HOME";
+  else
+    homevar = "HOMEPATH";
+
+  if ((home = getenv(homevar)) == NULL)
+    {
+      DEBUGFPRINT("DEBUG: FATAL!  No HOME in environment.\n");
+      exit(ERR_MOZ_HOMELESS);
+    }
+
+  len = strlen(home);
+  if (!LINUX)
+    homedrive = getenv("HOMEDRIVE");
+
+  if (homedrive != NULL)
+    len += strlen(homedrive);
+
+  len++;                        /* Room for \0 */
+  fqhome = xmalloc(len);
+
+  if (homedrive == NULL)
+    snprintf(fqhome, len, "%s", home);
+  else
+    snprintf(fqhome, len, "%s%s", homedrive, home);
+
+  return fqhome;
+}
+
+/**
  * @brief Get a list of all mozilla profile directories
  *
  * Read the profiles.ini and extract all profile paths from that.
@@ -132,13 +173,13 @@
                     strncpy(path, value, LINEBUFLEN);
                   if ((fqpath = port_realpath(path)) != NULL)
                     {
-                      DEBUGFPRINT("DEBUG: Found profile path: '%s'\n", fqpath)
+                      DEBUGFPRINT("DEBUG: Found profile path: '%s'\n", fqpath);
                       strv_append(&dirs, fqpath, strlen(fqpath));
                       free (fqpath);
                     }
                   else
                     {
-                      DEBUGFPRINT("DEBUG: WARN!  Non existent profile path: '%s'\n", path)
+                      DEBUGFPRINT("DEBUG: WARN!  Non existent profile path: '%s'\n", path);
                       return_code |= WARN_MOZ_PROFILE_DOES_NOT_EXIST;
                     }
                 }
@@ -150,7 +191,7 @@
     }
   else
     {
-      DEBUGFPRINT("DEBUG: WARN!  Could not open ini file: '%s'\n", inifile_name)
+      DEBUGFPRINT("DEBUG: WARN!  Could not open ini file: '%s'\n", inifile_name);
       return_code |= WARN_MOZ_FAILED_TO_OPEN_INI;
     }
   return dirs;
@@ -172,58 +213,51 @@
   char **inis = NULL;
   char path[LINEBUFLEN];
   char *fqpath;
+  char *mozdirname;
   DIR *mozdir;
   struct dirent *mozdirent;
+  char *home = get_home();
 
   if (LINUX)
     {
-      /* Search in $HOME/.mozilla */
-      char *home;
-
-      if ((home = getenv("HOME")) == NULL)
-        {
-          DEBUGFPRINT("DEBUG: FATAL!  No HOME in environment.\n")
-            exit(ERR_MOZ_HOMELESS);
-        }
-
-      snprintf(path, LINEBUFLEN, "%s/%s", home, "/.mozilla");
-      if ((mozdir = opendir(path)) != NULL)
-        {
-          while ((mozdirent = readdir(mozdir)) != NULL)
-            {
-              snprintf(path, LINEBUFLEN, "%s/%s/%s",
-                       home,
-                       "/.mozilla",
-                       mozdirent->d_name);
-              if (port_isdir(path))
-                {
-                  snprintf(path, LINEBUFLEN, "%s/%s/%s/%s",
-                           home,
-                           "/.mozilla",
-                           mozdirent->d_name,
-                           "profiles.ini");
-                  DEBUGFPRINT("DEBUG: checking for %s...\n", path);
-                  if ((fqpath = port_realpath(path)) != NULL)
-                    {
-                      strv_append(&inis, fqpath, strlen(fqpath));
-                      DEBUGFPRINT("DEBUG: Found mozilla ini file: '%s'\n", fqpath);
-                      free(fqpath);
-                    }
-                }
-            }
-          closedir(mozdir);
-        }
-      else
-        {
-          DEBUGFPRINT("DEBUG: Could not open %s/.mozilla\n", home)
-            exit(WARN_MOZ_NO_PROFILES);
-        }
+      mozdirname = ".mozilla";
     }
   else
     {
-      /* Windows */
-      fprintf(stderr, "Windows not yet supported");
-      abort();
+      mozdirname = "AppData/Roaming/Mozilla";
+    }
+
+  snprintf(path, LINEBUFLEN, "%s/%s", home, mozdirname);
+  if ((mozdir = opendir(path)) != NULL)
+    {
+      while ((mozdirent = readdir(mozdir)) != NULL)
+        {
+          snprintf(path, LINEBUFLEN, "%s/%s/%s",
+                   home,
+                   mozdirname,
+                   mozdirent->d_name);
+          if (port_isdir(path))
+            {
+              snprintf(path, LINEBUFLEN, "%s/%s/%s/%s",
+                       home,
+                       mozdirname,
+                       mozdirent->d_name,
+                       "profiles.ini");
+              DEBUGFPRINT("DEBUG: checking for %s...\n", path);
+              if ((fqpath = port_realpath(path)) != NULL)
+                {
+                  strv_append(&inis, fqpath, strlen(fqpath));
+                  DEBUGFPRINT("DEBUG: Found mozilla ini file: '%s'\n", fqpath);
+                  free(fqpath);
+                }
+            }
+        }
+      closedir(mozdir);
+    }
+  else
+    {
+      DEBUGFPRINT("DEBUG: Could not open %s/%s\n", home, mozdirname);
+      exit(WARN_MOZ_NO_PROFILES);
     }
   return inis;
 }

http://wald.intevation.org/projects/trustbridge/