Mercurial > trustbridge
comparison cinst/mozilla.c @ 194:d4e97c9b199f
Use %APPDATA% as config bse dir on windows. Much simpler.
author | Sascha Wilde <wilde@intevation.de> |
---|---|
date | Wed, 26 Mar 2014 11:25:03 +0100 |
parents | bea93c8651b7 |
children | 90cf655a4112 |
comparison
equal
deleted
inserted
replaced
181:bea93c8651b7 | 194:d4e97c9b199f |
---|---|
77 * ORed together. | 77 * ORed together. |
78 */ | 78 */ |
79 int return_code = 0; | 79 int return_code = 0; |
80 | 80 |
81 /** | 81 /** |
82 * @brief Return users home path, on windows including drive letter | 82 * @brief Return configuration base directory. |
83 * @returns a pointer to a string containing the home path, it should | 83 * @returns A pointer to a string containing the path to the base |
84 * be freed by the caller. | 84 * directory holding the configuration directories for e.g. mozilla |
85 * and thunderbird. | |
85 */ | 86 */ |
86 static char * | 87 static char * |
87 get_home() | 88 get_conf_basedir() |
88 { | 89 { |
89 char *home, *homevar, *fqhome; | 90 char *cdir, *envvar; |
90 char *homedrive = NULL; | 91 |
91 | |
92 size_t len; | |
93 if (LINUX) | 92 if (LINUX) |
94 homevar = "HOME"; | 93 envvar = "HOME" ; |
95 else | 94 else |
96 homevar = "HOMEPATH"; | 95 envvar = "APPDATA"; |
97 | 96 |
98 if ((home = getenv(homevar)) == NULL) | 97 if ((cdir = getenv(envvar)) != NULL) |
99 { | 98 return cdir; |
100 DEBUGFPRINT("DEBUG: FATAL! No HOME in environment.\n"); | 99 else |
100 { | |
101 DEBUGFPRINT("DEBUG: FATAL! No %s in environment.\n", envvar); | |
101 exit(ERR_MOZ_HOMELESS); | 102 exit(ERR_MOZ_HOMELESS); |
102 } | 103 } |
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 } | 104 } |
121 | 105 |
122 /** | 106 /** |
123 * @brief Get a list of all mozilla profile directories | 107 * @brief Get a list of all mozilla profile directories |
124 * | 108 * |
215 char path[LINEBUFLEN]; | 199 char path[LINEBUFLEN]; |
216 char *fqpath; | 200 char *fqpath; |
217 char *mozdirname; | 201 char *mozdirname; |
218 DIR *mozdir; | 202 DIR *mozdir; |
219 struct dirent *mozdirent; | 203 struct dirent *mozdirent; |
220 char *home = get_home(); | 204 char *confbase = get_conf_basedir(); |
221 | 205 |
222 if (LINUX) | 206 if (LINUX) |
223 { | 207 { |
224 mozdirname = ".mozilla"; | 208 mozdirname = ".mozilla"; |
225 } | 209 } |
226 else | 210 else |
227 { | 211 { |
228 mozdirname = "AppData/Roaming/Mozilla"; | 212 mozdirname = "Mozilla"; |
229 } | 213 } |
230 | 214 |
231 snprintf(path, LINEBUFLEN, "%s/%s", home, mozdirname); | 215 snprintf(path, LINEBUFLEN, "%s/%s", |
216 confbase, | |
217 mozdirname); | |
232 if ((mozdir = opendir(path)) != NULL) | 218 if ((mozdir = opendir(path)) != NULL) |
233 { | 219 { |
234 while ((mozdirent = readdir(mozdir)) != NULL) | 220 while ((mozdirent = readdir(mozdir)) != NULL) |
235 { | 221 { |
236 snprintf(path, LINEBUFLEN, "%s/%s/%s", | 222 snprintf(path, LINEBUFLEN, "%s/%s/%s", |
237 home, | 223 confbase, |
238 mozdirname, | 224 mozdirname, |
239 mozdirent->d_name); | 225 mozdirent->d_name); |
240 if (port_isdir(path)) | 226 if (port_isdir(path)) |
241 { | 227 { |
242 snprintf(path, LINEBUFLEN, "%s/%s/%s/%s", | 228 snprintf(path, LINEBUFLEN, "%s/%s/%s/%s", |
243 home, | 229 confbase, |
244 mozdirname, | 230 mozdirname, |
245 mozdirent->d_name, | 231 mozdirent->d_name, |
246 "profiles.ini"); | 232 "profiles.ini"); |
247 DEBUGFPRINT("DEBUG: checking for %s...\n", path); | 233 DEBUGFPRINT("DEBUG: checking for %s...\n", path); |
248 if ((fqpath = port_realpath(path)) != NULL) | 234 if ((fqpath = port_realpath(path)) != NULL) |
255 } | 241 } |
256 closedir(mozdir); | 242 closedir(mozdir); |
257 } | 243 } |
258 else | 244 else |
259 { | 245 { |
260 DEBUGFPRINT("DEBUG: Could not open %s/%s\n", home, mozdirname); | 246 DEBUGFPRINT("DEBUG: Could not open %s/%s\n", confbase, mozdirname); |
261 exit(WARN_MOZ_NO_PROFILES); | 247 exit(WARN_MOZ_NO_PROFILES); |
262 } | 248 } |
263 return inis; | 249 return inis; |
264 } | 250 } |
265 | 251 |