Mercurial > trustbridge
comparison cinst/mozilla.c @ 201:45f6b62f91e7
merged.
author | Raimund Renkert <rrenkert@intevation.de> |
---|---|
date | Wed, 26 Mar 2014 13:30:33 +0100 |
parents | 5d380b662198 |
children | d29997e09177 |
comparison
equal
deleted
inserted
replaced
200:fe424c5fc875 | 201:45f6b62f91e7 |
---|---|
59 #include <errorcodes.h> | 59 #include <errorcodes.h> |
60 #include <portpath.h> | 60 #include <portpath.h> |
61 #include <strhelp.h> | 61 #include <strhelp.h> |
62 | 62 |
63 #ifndef _WIN32 | 63 #ifndef _WIN32 |
64 #define CONFDIRS ".mozilla", ".thunderbird" | |
64 #define LINUX 1 | 65 #define LINUX 1 |
65 #else | 66 #else |
67 #define CONFDIRS "Mozilla", "Thunderbird" | |
66 #define LINUX 0 | 68 #define LINUX 0 |
67 #endif | 69 #endif |
68 | 70 |
69 #define LINEBUFLEN 1000 | 71 #define LINEBUFLEN 1000 |
70 | 72 |
77 * ORed together. | 79 * ORed together. |
78 */ | 80 */ |
79 int return_code = 0; | 81 int return_code = 0; |
80 | 82 |
81 /** | 83 /** |
82 * @brief Return users home path, on windows including drive letter | 84 * @brief Return configuration base directory. |
83 * @returns a pointer to a string containing the home path, it should | 85 * @returns A pointer to a string containing the path to the base |
84 * be freed by the caller. | 86 * directory holding the configuration directories for e.g. mozilla |
87 * and thunderbird. | |
85 */ | 88 */ |
86 static char * | 89 static char * |
87 get_home() | 90 get_conf_basedir() |
88 { | 91 { |
89 char *home, *homevar, *fqhome; | 92 char *cdir, *envvar; |
90 char *homedrive = NULL; | 93 |
91 | |
92 size_t len; | |
93 if (LINUX) | 94 if (LINUX) |
94 homevar = "HOME"; | 95 envvar = "HOME" ; |
95 else | 96 else |
96 homevar = "HOMEPATH"; | 97 envvar = "APPDATA"; |
97 | 98 |
98 if ((home = getenv(homevar)) == NULL) | 99 if ((cdir = getenv(envvar)) != NULL) |
99 { | 100 return cdir; |
100 DEBUGFPRINT("DEBUG: FATAL! No HOME in environment.\n"); | 101 else |
102 { | |
103 DEBUGFPRINT("DEBUG: FATAL! No %s in environment.\n", envvar); | |
101 exit(ERR_MOZ_HOMELESS); | 104 exit(ERR_MOZ_HOMELESS); |
102 } | 105 } |
103 | |
104 len = strlen(home); | |
105 if (!LINUX) | |
106 homedrive = getenv("HOMEDRIVE"); | |
107 | |
108 if (homedrive != NULL) | |
109 len += strlen(homedrive); | |
110 | |
111 len++; /* Room for \0 */ | |
112 fqhome = xmalloc(len); | |
113 | |
114 if (homedrive == NULL) | |
115 snprintf(fqhome, len, "%s", home); | |
116 else | |
117 snprintf(fqhome, len, "%s%s", homedrive, home); | |
118 | |
119 return fqhome; | |
120 } | 106 } |
121 | 107 |
122 /** | 108 /** |
123 * @brief Get a list of all mozilla profile directories | 109 * @brief Get a list of all mozilla profile directories |
124 * | 110 * |
212 get_profile_inis () | 198 get_profile_inis () |
213 { | 199 { |
214 char **inis = NULL; | 200 char **inis = NULL; |
215 char path[LINEBUFLEN]; | 201 char path[LINEBUFLEN]; |
216 char *fqpath; | 202 char *fqpath; |
217 char *mozdirname; | |
218 DIR *mozdir; | 203 DIR *mozdir; |
219 struct dirent *mozdirent; | 204 struct dirent *mozdirent; |
220 char *home = get_home(); | 205 char *confbase = get_conf_basedir(); |
221 | 206 const char *confdirs[] = { CONFDIRS, NULL }; |
222 if (LINUX) | 207 |
223 { | 208 for (int i=0; confdirs[i] != NULL; i++) |
224 mozdirname = ".mozilla"; | 209 { |
225 } | 210 snprintf(path, LINEBUFLEN, "%s/%s", |
226 else | 211 confbase, |
227 { | 212 confdirs[i]); |
228 mozdirname = "AppData/Roaming/Mozilla"; | 213 if ((mozdir = opendir(path)) != NULL) |
229 } | |
230 | |
231 snprintf(path, LINEBUFLEN, "%s/%s", home, mozdirname); | |
232 if ((mozdir = opendir(path)) != NULL) | |
233 { | |
234 while ((mozdirent = readdir(mozdir)) != NULL) | |
235 { | 214 { |
236 snprintf(path, LINEBUFLEN, "%s/%s/%s", | 215 while ((mozdirent = readdir(mozdir)) != NULL) |
237 home, | |
238 mozdirname, | |
239 mozdirent->d_name); | |
240 if (port_isdir(path)) | |
241 { | 216 { |
242 snprintf(path, LINEBUFLEN, "%s/%s/%s/%s", | 217 snprintf(path, LINEBUFLEN, "%s/%s/%s", |
243 home, | 218 confbase, |
244 mozdirname, | 219 confdirs[i], |
245 mozdirent->d_name, | 220 mozdirent->d_name); |
246 "profiles.ini"); | 221 if (port_isdir(path) |
247 DEBUGFPRINT("DEBUG: checking for %s...\n", path); | 222 && (strcmp(mozdirent->d_name, "..") != 0)) |
248 if ((fqpath = port_realpath(path)) != NULL) | |
249 { | 223 { |
250 strv_append(&inis, fqpath, strlen(fqpath)); | 224 snprintf(path, LINEBUFLEN, "%s/%s/%s/%s", |
251 DEBUGFPRINT("DEBUG: Found mozilla ini file: '%s'\n", fqpath); | 225 confbase, |
252 free(fqpath); | 226 confdirs[i], |
227 mozdirent->d_name, | |
228 "profiles.ini"); | |
229 DEBUGFPRINT("DEBUG: checking for %s...\n", path); | |
230 if ((fqpath = port_realpath(path)) != NULL) | |
231 { | |
232 strv_append(&inis, fqpath, strlen(fqpath)); | |
233 DEBUGFPRINT("DEBUG: Found mozilla ini file: '%s'\n", fqpath); | |
234 free(fqpath); | |
235 } | |
253 } | 236 } |
254 } | 237 } |
238 closedir(mozdir); | |
255 } | 239 } |
256 closedir(mozdir); | 240 else |
257 } | 241 { |
258 else | 242 DEBUGFPRINT("DEBUG: Could not open %s/%s\n", confbase, confdirs[i]); |
259 { | 243 } |
260 DEBUGFPRINT("DEBUG: Could not open %s/%s\n", home, mozdirname); | 244 } |
245 if (inis == NULL) | |
246 { | |
247 DEBUGFPRINT("DEBUG: No ini files found - will do nothing!\n"); | |
261 exit(WARN_MOZ_NO_PROFILES); | 248 exit(WARN_MOZ_NO_PROFILES); |
262 } | 249 } |
263 return inis; | 250 return inis; |
264 } | 251 } |
265 | 252 |
275 { | 262 { |
276 pdirs = | 263 pdirs = |
277 get_profile_dirs(mozinis[y++]); | 264 get_profile_dirs(mozinis[y++]); |
278 if (pdirs != NULL) | 265 if (pdirs != NULL) |
279 { | 266 { |
267 x = 0; | |
280 while (pdirs[x] != NULL) | 268 while (pdirs[x] != NULL) |
281 puts(pdirs[x++]); | 269 puts(pdirs[x++]); |
282 strv_free(pdirs); | 270 strv_free(pdirs); |
283 } | 271 } |
284 } | 272 } |