Mercurial > trustbridge
comparison cinst/mozilla.c @ 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 |
comparison
equal
deleted
inserted
replaced
177:c92297bcda8f | 180:344b8a79ad2e |
---|---|
75 * error code on fatal errors and to and warning code on non-fatal | 75 * error code on fatal errors and to and warning code on non-fatal |
76 * errors. In case of mor than one warning the warning codes will be | 76 * errors. In case of mor than one warning the warning codes will be |
77 * ORed together. | 77 * ORed together. |
78 */ | 78 */ |
79 int return_code = 0; | 79 int return_code = 0; |
80 | |
81 /** | |
82 * @brief Return users home path, on windows including drive letter | |
83 * @returns a pointer to a string containing the home path, it should | |
84 * be freed by the caller. | |
85 */ | |
86 static char * | |
87 get_home() | |
88 { | |
89 char *home, *homevar, *fqhome; | |
90 char *homedrive = NULL; | |
91 | |
92 size_t len; | |
93 if (LINUX) | |
94 homevar = "HOME"; | |
95 else | |
96 homevar = "HOMEPATH"; | |
97 | |
98 if ((home = getenv(homevar)) == NULL) | |
99 { | |
100 DEBUGFPRINT("DEBUG: FATAL! No HOME in environment.\n"); | |
101 exit(ERR_MOZ_HOMELESS); | |
102 } | |
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 } | |
80 | 121 |
81 /** | 122 /** |
82 * @brief Get a list of all mozilla profile directories | 123 * @brief Get a list of all mozilla profile directories |
83 * | 124 * |
84 * Read the profiles.ini and extract all profile paths from that. | 125 * Read the profiles.ini and extract all profile paths from that. |
130 snprintf(path, LINEBUFLEN, "%s/%s", inifile_dirname, value); | 171 snprintf(path, LINEBUFLEN, "%s/%s", inifile_dirname, value); |
131 else | 172 else |
132 strncpy(path, value, LINEBUFLEN); | 173 strncpy(path, value, LINEBUFLEN); |
133 if ((fqpath = port_realpath(path)) != NULL) | 174 if ((fqpath = port_realpath(path)) != NULL) |
134 { | 175 { |
135 DEBUGFPRINT("DEBUG: Found profile path: '%s'\n", fqpath) | 176 DEBUGFPRINT("DEBUG: Found profile path: '%s'\n", fqpath); |
136 strv_append(&dirs, fqpath, strlen(fqpath)); | 177 strv_append(&dirs, fqpath, strlen(fqpath)); |
137 free (fqpath); | 178 free (fqpath); |
138 } | 179 } |
139 else | 180 else |
140 { | 181 { |
141 DEBUGFPRINT("DEBUG: WARN! Non existent profile path: '%s'\n", path) | 182 DEBUGFPRINT("DEBUG: WARN! Non existent profile path: '%s'\n", path); |
142 return_code |= WARN_MOZ_PROFILE_DOES_NOT_EXIST; | 183 return_code |= WARN_MOZ_PROFILE_DOES_NOT_EXIST; |
143 } | 184 } |
144 } | 185 } |
145 else if (str_equal(key, "IsRelative") && | 186 else if (str_equal(key, "IsRelative") && |
146 str_starts_with(value, "1")) | 187 str_starts_with(value, "1")) |
148 } | 189 } |
149 } | 190 } |
150 } | 191 } |
151 else | 192 else |
152 { | 193 { |
153 DEBUGFPRINT("DEBUG: WARN! Could not open ini file: '%s'\n", inifile_name) | 194 DEBUGFPRINT("DEBUG: WARN! Could not open ini file: '%s'\n", inifile_name); |
154 return_code |= WARN_MOZ_FAILED_TO_OPEN_INI; | 195 return_code |= WARN_MOZ_FAILED_TO_OPEN_INI; |
155 } | 196 } |
156 return dirs; | 197 return dirs; |
157 } | 198 } |
158 | 199 |
170 get_profile_inis () | 211 get_profile_inis () |
171 { | 212 { |
172 char **inis = NULL; | 213 char **inis = NULL; |
173 char path[LINEBUFLEN]; | 214 char path[LINEBUFLEN]; |
174 char *fqpath; | 215 char *fqpath; |
216 char *mozdirname; | |
175 DIR *mozdir; | 217 DIR *mozdir; |
176 struct dirent *mozdirent; | 218 struct dirent *mozdirent; |
219 char *home = get_home(); | |
177 | 220 |
178 if (LINUX) | 221 if (LINUX) |
179 { | 222 { |
180 /* Search in $HOME/.mozilla */ | 223 mozdirname = ".mozilla"; |
181 char *home; | 224 } |
182 | 225 else |
183 if ((home = getenv("HOME")) == NULL) | 226 { |
227 mozdirname = "AppData/Roaming/Mozilla"; | |
228 } | |
229 | |
230 snprintf(path, LINEBUFLEN, "%s/%s", home, mozdirname); | |
231 if ((mozdir = opendir(path)) != NULL) | |
232 { | |
233 while ((mozdirent = readdir(mozdir)) != NULL) | |
184 { | 234 { |
185 DEBUGFPRINT("DEBUG: FATAL! No HOME in environment.\n") | 235 snprintf(path, LINEBUFLEN, "%s/%s/%s", |
186 exit(ERR_MOZ_HOMELESS); | 236 home, |
187 } | 237 mozdirname, |
188 | 238 mozdirent->d_name); |
189 snprintf(path, LINEBUFLEN, "%s/%s", home, "/.mozilla"); | 239 if (port_isdir(path)) |
190 if ((mozdir = opendir(path)) != NULL) | |
191 { | |
192 while ((mozdirent = readdir(mozdir)) != NULL) | |
193 { | 240 { |
194 snprintf(path, LINEBUFLEN, "%s/%s/%s", | 241 snprintf(path, LINEBUFLEN, "%s/%s/%s/%s", |
195 home, | 242 home, |
196 "/.mozilla", | 243 mozdirname, |
197 mozdirent->d_name); | 244 mozdirent->d_name, |
198 if (port_isdir(path)) | 245 "profiles.ini"); |
246 DEBUGFPRINT("DEBUG: checking for %s...\n", path); | |
247 if ((fqpath = port_realpath(path)) != NULL) | |
199 { | 248 { |
200 snprintf(path, LINEBUFLEN, "%s/%s/%s/%s", | 249 strv_append(&inis, fqpath, strlen(fqpath)); |
201 home, | 250 DEBUGFPRINT("DEBUG: Found mozilla ini file: '%s'\n", fqpath); |
202 "/.mozilla", | 251 free(fqpath); |
203 mozdirent->d_name, | |
204 "profiles.ini"); | |
205 DEBUGFPRINT("DEBUG: checking for %s...\n", path); | |
206 if ((fqpath = port_realpath(path)) != NULL) | |
207 { | |
208 strv_append(&inis, fqpath, strlen(fqpath)); | |
209 DEBUGFPRINT("DEBUG: Found mozilla ini file: '%s'\n", fqpath); | |
210 free(fqpath); | |
211 } | |
212 } | 252 } |
213 } | 253 } |
214 closedir(mozdir); | |
215 } | 254 } |
216 else | 255 closedir(mozdir); |
217 { | 256 } |
218 DEBUGFPRINT("DEBUG: Could not open %s/.mozilla\n", home) | 257 else |
219 exit(WARN_MOZ_NO_PROFILES); | 258 { |
220 } | 259 DEBUGFPRINT("DEBUG: Could not open %s/%s\n", home, mozdirname); |
221 } | 260 exit(WARN_MOZ_NO_PROFILES); |
222 else | |
223 { | |
224 /* Windows */ | |
225 fprintf(stderr, "Windows not yet supported"); | |
226 abort(); | |
227 } | 261 } |
228 return inis; | 262 return inis; |
229 } | 263 } |
230 | 264 |
231 | 265 |