# HG changeset patch # User Sascha Wilde # Date 1395766616 -3600 # Node ID bea93c8651b7dc0fec47388c034c931388c17fe5 # Parent 344b8a79ad2ef6f8bb1908edf7e592a5e7770d5a# Parent 8fafd0fc21734fb3757f9d56955656f754ec8b33 Merged diff -r 8fafd0fc2173 -r bea93c8651b7 cinst/mozilla.c --- a/cinst/mozilla.c Tue Mar 25 17:28:55 2014 +0100 +++ b/cinst/mozilla.c Tue Mar 25 17:56:56 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; } } @@ -151,7 +192,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; @@ -173,58 +214,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; }