]>
Commit | Line | Data |
---|---|---|
23c9e63c DD |
1 | /* |
2 | * Copyright (c) 2000, Red Hat, Inc. | |
3 | * | |
4 | * This program is free software; you can redistribute it and/or modify | |
5 | * it under the terms of the GNU General Public License as published by | |
6 | * the Free Software Foundation; either version 2 of the License, or | |
7 | * (at your option) any later version. | |
8 | * | |
9 | * A copy of the GNU General Public License can be found at | |
10 | * http://www.gnu.org/ | |
11 | * | |
12 | * Written by DJ Delorie <dj@cygnus.com> | |
13 | * | |
14 | */ | |
15 | ||
16 | /* The purpose of this file is to get and parse the setup.ini file | |
17 | from the mirror site. A few support routines for the bison and | |
18 | flex parsers are provided also. We check to see if this setup.ini | |
19 | is older than the one we used last time, and if so, warn the user. */ | |
20 | ||
b24c88b3 RC |
21 | #if 0 |
22 | static const char *cvsid = | |
23 | "\n%%% $Id$\n"; | |
24 | #endif | |
8507f105 | 25 | |
23c9e63c DD |
26 | #include "win32.h" |
27 | ||
28 | #include <stdio.h> | |
b11b49f3 | 29 | #include <stdlib.h> |
23c9e63c | 30 | #include <stdarg.h> |
ab57ceaa | 31 | #include <process.h> |
23c9e63c DD |
32 | |
33 | #include "ini.h" | |
34 | #include "resource.h" | |
3c054baf | 35 | #include "String++.h" |
23c9e63c DD |
36 | #include "state.h" |
37 | #include "geturl.h" | |
38 | #include "dialog.h" | |
39 | #include "msg.h" | |
89b1a15b | 40 | #include "log.h" |
13d27274 | 41 | #include "version.h" |
a351e48c | 42 | #include "mount.h" |
de6a1a64 RC |
43 | #include "site.h" |
44 | #include "rfc1738.h" | |
45 | #include "find.h" | |
23c9e63c | 46 | |
b24c88b3 RC |
47 | #include "io_stream.h" |
48 | ||
ab57ceaa | 49 | #include "threebar.h" |
58ee6135 RC |
50 | |
51 | #include "rfc1738.h" | |
b92028a4 | 52 | |
076654e7 | 53 | #include "IniDBBuilderPackage.h" |
b92028a4 | 54 | |
ab57ceaa RC |
55 | extern ThreeBarProgressPage Progress; |
56 | ||
23c9e63c | 57 | unsigned int setup_timestamp = 0; |
b92028a4 | 58 | String setup_version; |
23c9e63c | 59 | |
0af2d779 | 60 | extern int yyparse (); |
b11b49f3 DD |
61 | /*extern int yydebug;*/ |
62 | ||
63 | static char *error_buf = 0; | |
64 | static int error_count = 0; | |
23c9e63c | 65 | |
de6a1a64 | 66 | static int local_ini; |
23c9e63c | 67 | |
076654e7 RC |
68 | static IniDBBuilder *findBuilder; |
69 | ||
de6a1a64 RC |
70 | static void |
71 | find_routine (char *path, unsigned int fsize) | |
72 | { | |
858f100d | 73 | if (!strstr (path, "setup.ini") ) |
de6a1a64 | 74 | return; |
1ac649ed RC |
75 | io_stream *ini_file = io_stream::open (String ("file://") + local_dir + "/" + |
76 | path, "rb"); | |
23c9e63c | 77 | if (!ini_file) |
b5b282c4 | 78 | { |
1ac649ed RC |
79 | note (NULL, IDS_SETUPINI_MISSING, (String ("file://") + local_dir + "/" + |
80 | path).cstr_oneuse()); | |
de6a1a64 | 81 | return; |
b5b282c4 | 82 | } |
3c054baf RC |
83 | else |
84 | log (LOG_BABBLE, String ("Found ini file - file://") + local_dir + "/" + path); | |
23c9e63c | 85 | |
58ee6135 RC |
86 | /* Attempt to unescape the string */ |
87 | path[strlen(path) -10] = '\0'; | |
88 | String mirror = rfc1738_unescape_part (path); | |
076654e7 RC |
89 | findBuilder->parse_mirror = mirror; |
90 | ini_init (ini_file, findBuilder); | |
23c9e63c | 91 | |
b24c88b3 | 92 | /*yydebug = 1; */ |
b11b49f3 DD |
93 | |
94 | if (yyparse () || error_count > 0) | |
341988b9 | 95 | MessageBox (0, error_buf, error_count == 1 ? "Parse Error" : "Parse Errors", 0); |
dd3f7f9b | 96 | else |
de6a1a64 | 97 | local_ini++; |
076654e7 | 98 | if (findBuilder->timestamp > setup_timestamp) |
b92028a4 | 99 | { |
076654e7 RC |
100 | setup_timestamp = findBuilder->timestamp; |
101 | setup_version = findBuilder->version; | |
b92028a4 | 102 | } |
de6a1a64 RC |
103 | } |
104 | ||
105 | static int | |
ab57ceaa | 106 | do_local_ini (HWND owner) |
de6a1a64 RC |
107 | { |
108 | local_ini = 0; | |
076654e7 | 109 | findBuilder = new IniDBBuilderPackage; |
de6a1a64 | 110 | find (local_dir, find_routine); |
076654e7 RC |
111 | delete findBuilder; |
112 | findBuilder = 0; | |
de6a1a64 RC |
113 | return local_ini; |
114 | } | |
115 | ||
116 | static int | |
ab57ceaa | 117 | do_remote_ini (HWND owner) |
de6a1a64 RC |
118 | { |
119 | size_t ini_count = 0; | |
076654e7 | 120 | IniDBBuilderPackage *aBuilder = new IniDBBuilderPackage; |
ab57ceaa | 121 | |
de6a1a64 | 122 | for (size_t n = 1; n <= site_list.number (); n++) |
dd3f7f9b | 123 | { |
de6a1a64 | 124 | io_stream *ini_file = |
3c054baf | 125 | get_url_to_membuf (site_list[n]->url + "/setup.ini", owner); |
de6a1a64 RC |
126 | |
127 | if (!ini_file) | |
128 | { | |
3c054baf | 129 | note (owner, IDS_SETUPINI_MISSING, site_list[n]->url.cstr_oneuse()); |
de6a1a64 RC |
130 | continue; |
131 | } | |
132 | ||
076654e7 RC |
133 | aBuilder->parse_mirror = site_list[n]->url; |
134 | ini_init (ini_file, aBuilder); | |
de6a1a64 RC |
135 | |
136 | /*yydebug = 1; */ | |
137 | ||
138 | if (yyparse () || error_count > 0) | |
139 | MessageBox (0, error_buf, | |
140 | error_count == 1 ? "Parse Error" : "Parse Errors", 0); | |
141 | else | |
142 | { | |
143 | /* save known-good setup.ini locally */ | |
3c054baf RC |
144 | String const fp = String ("file://") + local_dir + "/" + |
145 | rfc1738_escape_part (site_list[n]->url) + | |
146 | "/setup.ini"; | |
de6a1a64 RC |
147 | io_stream::mkpath_p (PATH_TO_FILE, fp); |
148 | io_stream *inistream = io_stream::open (fp, "wb"); | |
149 | if (inistream && !ini_file->seek (0, IO_SEEK_SET)) | |
150 | { | |
151 | if (io_stream::copy (ini_file, inistream)) | |
3c054baf | 152 | io_stream::remove (fp.cstr_oneuse()); |
de6a1a64 RC |
153 | delete ini_file; |
154 | delete inistream; | |
155 | } | |
5e0464a1 | 156 | ++ini_count; |
dd3f7f9b | 157 | } |
076654e7 | 158 | if (aBuilder->timestamp > setup_timestamp) |
b92028a4 | 159 | { |
076654e7 RC |
160 | setup_timestamp = aBuilder->timestamp; |
161 | setup_version = aBuilder->version; | |
b92028a4 | 162 | } |
dd3f7f9b | 163 | } |
076654e7 | 164 | delete aBuilder; |
de6a1a64 RC |
165 | return ini_count; |
166 | } | |
167 | ||
ab57ceaa RC |
168 | static void |
169 | do_ini_thread (HINSTANCE h, HWND owner) | |
de6a1a64 RC |
170 | { |
171 | size_t ini_count = 0; | |
172 | if (source == IDC_SOURCE_CWD) | |
ab57ceaa | 173 | ini_count = do_local_ini (owner); |
de6a1a64 | 174 | else |
ab57ceaa | 175 | ini_count = do_remote_ini (owner); |
de6a1a64 RC |
176 | |
177 | if (ini_count == 0) | |
178 | { | |
179 | next_dialog = source == IDC_SOURCE_CWD ? IDD_S_FROM_CWD : IDD_SITE; | |
180 | return; | |
181 | } | |
23c9e63c | 182 | |
3c054baf | 183 | if (get_root_dir ().cstr_oneuse()) |
23c9e63c | 184 | { |
b24c88b3 | 185 | io_stream::mkpath_p (PATH_TO_DIR, "cygfile:///etc/setup"); |
04d6e06b DD |
186 | |
187 | unsigned int old_timestamp = 0; | |
b24c88b3 RC |
188 | io_stream *ots = |
189 | io_stream::open ("cygfile:///etc/setup/timestamp", "rt"); | |
04d6e06b | 190 | if (ots) |
23c9e63c | 191 | { |
b24c88b3 RC |
192 | char temp[20]; |
193 | memset (temp, '\0', 20); | |
194 | if (ots->read (temp, 19)) | |
195 | sscanf (temp, "%u", &old_timestamp); | |
196 | delete ots; | |
04d6e06b DD |
197 | if (old_timestamp && setup_timestamp |
198 | && (old_timestamp > setup_timestamp)) | |
199 | { | |
ab57ceaa | 200 | int yn = yesno (owner, IDS_OLD_SETUPINI); |
04d6e06b | 201 | if (yn == IDNO) |
9f4a0c62 | 202 | LogSingleton::GetInstance().exit (1); |
04d6e06b | 203 | } |
23c9e63c | 204 | } |
04d6e06b | 205 | if (setup_timestamp) |
23c9e63c | 206 | { |
b24c88b3 RC |
207 | io_stream *nts = |
208 | io_stream::open ("cygfile:///etc/setup/timestamp", "wt"); | |
04d6e06b DD |
209 | if (nts) |
210 | { | |
b24c88b3 RC |
211 | char temp[20]; |
212 | sprintf (temp, "%u", setup_timestamp); | |
213 | nts->write (temp, strlen (temp)); | |
214 | delete nts; | |
04d6e06b | 215 | } |
23c9e63c DD |
216 | } |
217 | } | |
218 | ||
b92028a4 RC |
219 | msg ("setup_version is %s, our_version is %s", setup_version.size() ? |
220 | setup_version.cstr_oneuse() : "(null)", | |
b24c88b3 | 221 | version); |
b92028a4 | 222 | if (setup_version.size()) |
13d27274 | 223 | { |
3c054baf RC |
224 | String ini_version = canonicalize_version (setup_version); |
225 | String our_version = canonicalize_version (version); | |
226 | // XXX useversion < operator | |
227 | if (our_version.compare (ini_version) < 0) | |
b92028a4 | 228 | note (owner, IDS_OLD_SETUP_VERSION, version, setup_version.cstr_oneuse()); |
13d27274 DD |
229 | } |
230 | ||
ab57ceaa | 231 | next_dialog = IDD_CHOOSER; |
23c9e63c DD |
232 | } |
233 | ||
45e01f23 | 234 | static DWORD WINAPI |
ab57ceaa RC |
235 | do_ini_thread_reflector(void* p) |
236 | { | |
237 | HANDLE *context; | |
238 | context = (HANDLE*)p; | |
239 | ||
240 | do_ini_thread((HINSTANCE)context[0], (HWND)context[1]); | |
241 | ||
242 | // Tell the progress page that we're done downloading | |
243 | Progress.PostMessage(WM_APP_SETUP_INI_DOWNLOAD_COMPLETE, 0, next_dialog); | |
244 | ||
45e01f23 | 245 | ExitThread(0); |
ab57ceaa RC |
246 | } |
247 | ||
248 | static HANDLE context[2]; | |
249 | ||
250 | void | |
251 | do_ini (HINSTANCE h, HWND owner) | |
252 | { | |
45e01f23 RC |
253 | context[0] = h; |
254 | context[1] = owner; | |
255 | ||
256 | DWORD threadID; | |
257 | CreateThread (NULL, 0, do_ini_thread_reflector, context, 0, &threadID); | |
ab57ceaa RC |
258 | } |
259 | ||
260 | ||
b11b49f3 DD |
261 | extern int yylineno; |
262 | ||
6391823e RC |
263 | extern int |
264 | yyerror (String const &s) | |
23c9e63c | 265 | { |
b11b49f3 DD |
266 | char buf[1000]; |
267 | int len; | |
268 | sprintf (buf, "setup.ini line %d: ", yylineno); | |
6391823e | 269 | sprintf (buf + strlen (buf), s.cstr_oneuse()); |
b11b49f3 DD |
270 | OutputDebugString (buf); |
271 | if (error_buf) | |
272 | { | |
273 | strcat (error_buf, "\n"); | |
274 | len = strlen (error_buf) + strlen (buf) + 5; | |
275 | error_buf = (char *) realloc (error_buf, len); | |
276 | strcat (error_buf, buf); | |
277 | } | |
278 | else | |
279 | { | |
280 | len = strlen (buf) + 5; | |
281 | error_buf = (char *) malloc (len); | |
282 | strcpy (error_buf, buf); | |
283 | } | |
284 | error_count++; | |
b24c88b3 RC |
285 | /* TODO: is return 0 correct? */ |
286 | return 0; | |
23c9e63c DD |
287 | } |
288 | ||
b24c88b3 | 289 | extern "C" int fprintf (FILE * f, const char *s, ...); |
23c9e63c | 290 | |
b11b49f3 DD |
291 | static char stderrbuf[1000]; |
292 | ||
23c9e63c | 293 | int |
b24c88b3 | 294 | fprintf (FILE * f, const char *fmt, ...) |
23c9e63c DD |
295 | { |
296 | char buf[1000]; | |
297 | int rv; | |
298 | va_list args; | |
299 | va_start (args, fmt); | |
300 | if (f == stderr) | |
301 | { | |
302 | rv = vsprintf (buf, fmt, args); | |
b11b49f3 DD |
303 | strcat (stderrbuf, buf); |
304 | if (char *nl = strchr (stderrbuf, '\n')) | |
305 | { | |
306 | *nl = 0; | |
b24c88b3 | 307 | /*OutputDebugString (stderrbuf); */ |
b11b49f3 DD |
308 | MessageBox (0, buf, "Cygwin Setup", 0); |
309 | stderrbuf[0] = 0; | |
310 | } | |
42bf5b92 | 311 | |
23c9e63c DD |
312 | } |
313 | else | |
314 | { | |
315 | rv = vfprintf (f, fmt, args); | |
316 | } | |
317 | return rv; | |
318 | } |