diff cinst/mozilla.c @ 985:1743895b39b8

(issue86) Install into default profile folders on windows.
author Andre Heinecke <andre.heinecke@intevation.de>
date Fri, 29 Aug 2014 17:13:30 +0200
parents b3695a3399de
children 66f6361fba1b
line wrap: on
line diff
--- a/cinst/mozilla.c	Fri Aug 29 17:12:35 2014 +0200
+++ b/cinst/mozilla.c	Fri Aug 29 17:13:30 2014 +0200
@@ -84,11 +84,13 @@
 #define NSSSHARED ".pki/nssdb"
 #define NSSSHARED_GLOBAL "/etc/pki/nssdb"
 #define TARGET_LINUX 1
+#define DIRSEP "/"
 #else
-#define MOZILLA_DEFAULTS 0
+#define MOZILLA_DEFAULTS "Mozilla Firefox\\browser\\defaults", "Mozilla Thunderbird\\defaults"
 #define CONFDIRS "Mozilla", "Thunderbird"
 #define NSSSHARED ""
 #define TARGET_LINUX 0
+#define DIRSEP "\\"
 #endif
 
 /**
@@ -318,16 +320,36 @@
 
   const char *confdirs[] = { MOZILLA_DEFAULTS, NULL };
 
+#ifdef _WIN32
+  char *program_files = get_program_files_folder();
+  if (!program_files)
+    {
+      ERRORPRINTF ("Failed to look up program files folder.\n");
+      return NULL;
+    }
+#endif
+
   for (int i=0; confdirs[i] != NULL; i++)
     {
-      char * realpath = port_realpath(confdirs[i]);
-      char * profile_dir = NULL;
+      char *realpath = NULL,
+           *profile_dir = NULL;
+#ifndef _WIN32
+      realpath = port_realpath(confdirs[i]);
+#else
+      /* As on linux we only respect the default installation directory
+         mozilla firefox and thunderbird change their registry key with
+         each version as the key includes the version number. It would
+         be error prone to search the system for every instance. So we
+         only check the default installation directories. */
+      xasprintf(&realpath, "%s" DIRSEP "%s", program_files, confdirs[i]);
+#endif
       if (realpath == NULL)
         {
           DEBUGPRINTF ("Did not find directory: '%s'\n", confdirs[i]);
           continue;
         }
-      xasprintf(&profile_dir, "%s/profile", realpath);
+      xasprintf(&profile_dir, "%s" DIRSEP "profile", realpath);
+      xfree(realpath);
       if (port_isdir(profile_dir))
         {
           DEBUGPRINTF("Found default directory: '%s'\n", profile_dir);
@@ -351,7 +373,7 @@
           else
             {
               /* Lets create it */
-              if (!port_mkdir(profile_dir))
+              if (!port_mkdir_p(profile_dir))
                 {
                   ERRORPRINTF ("Failed to create directory: '%s'\n", profile_dir);
                   xfree(profile_dir);
@@ -364,6 +386,7 @@
             }
         }
     }
+  xfree (program_files);
   return retval;
 }
 

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