]>
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" | |
35 | #include "concat.h" | |
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 RC |
49 | #include "threebar.h" |
50 | extern ThreeBarProgressPage Progress; | |
51 | ||
23c9e63c | 52 | unsigned int setup_timestamp = 0; |
13d27274 | 53 | char *setup_version = 0; |
23c9e63c | 54 | |
0af2d779 | 55 | extern int yyparse (); |
b11b49f3 DD |
56 | /*extern int yydebug;*/ |
57 | ||
58 | static char *error_buf = 0; | |
59 | static int error_count = 0; | |
23c9e63c | 60 | |
de6a1a64 | 61 | static int local_ini; |
23c9e63c | 62 | |
de6a1a64 RC |
63 | static void |
64 | find_routine (char *path, unsigned int fsize) | |
65 | { | |
858f100d | 66 | if (!strstr (path, "setup.ini") ) |
de6a1a64 RC |
67 | return; |
68 | io_stream *ini_file = io_stream::open (concat ("file://", local_dir,"/", path, 0), "rb"); | |
23c9e63c | 69 | if (!ini_file) |
b5b282c4 | 70 | { |
ab57ceaa | 71 | note (NULL, IDS_SETUPINI_MISSING, path); |
de6a1a64 | 72 | return; |
b5b282c4 | 73 | } |
23c9e63c | 74 | |
de6a1a64 | 75 | /* FIXME: only use most recent copy */ |
13d27274 DD |
76 | setup_timestamp = 0; |
77 | setup_version = 0; | |
78 | ||
de6a1a64 | 79 | ini_init (ini_file, concat ("file://", local_dir,"/", path, 0)); |
23c9e63c | 80 | |
b24c88b3 | 81 | /*yydebug = 1; */ |
b11b49f3 DD |
82 | |
83 | if (yyparse () || error_count > 0) | |
341988b9 | 84 | MessageBox (0, error_buf, error_count == 1 ? "Parse Error" : "Parse Errors", 0); |
dd3f7f9b | 85 | else |
de6a1a64 RC |
86 | local_ini++; |
87 | } | |
88 | ||
89 | static int | |
ab57ceaa | 90 | do_local_ini (HWND owner) |
de6a1a64 RC |
91 | { |
92 | local_ini = 0; | |
93 | find (local_dir, find_routine); | |
94 | return local_ini; | |
95 | } | |
96 | ||
97 | static int | |
ab57ceaa | 98 | do_remote_ini (HWND owner) |
de6a1a64 RC |
99 | { |
100 | size_t ini_count = 0; | |
ab57ceaa | 101 | |
de6a1a64 | 102 | for (size_t n = 1; n <= site_list.number (); n++) |
dd3f7f9b | 103 | { |
de6a1a64 | 104 | io_stream *ini_file = |
ab57ceaa | 105 | get_url_to_membuf (concat (site_list[n]->url, "/setup.ini", 0), owner); |
de6a1a64 RC |
106 | |
107 | if (!ini_file) | |
108 | { | |
ab57ceaa | 109 | note (owner, IDS_SETUPINI_MISSING, site_list[n]->url); |
de6a1a64 RC |
110 | continue; |
111 | } | |
112 | ||
113 | /* FIXME: only use most recent copy */ | |
114 | setup_timestamp = 0; | |
115 | setup_version = 0; | |
116 | ||
117 | ini_init (ini_file, site_list[n]->url); | |
118 | ||
119 | /*yydebug = 1; */ | |
120 | ||
121 | if (yyparse () || error_count > 0) | |
122 | MessageBox (0, error_buf, | |
123 | error_count == 1 ? "Parse Error" : "Parse Errors", 0); | |
124 | else | |
125 | { | |
126 | /* save known-good setup.ini locally */ | |
127 | char const *fp = concat ("file://", local_dir, "/", | |
128 | rfc1738_escape_part (site_list[n]->url), | |
129 | "/setup.ini", 0); | |
130 | io_stream::mkpath_p (PATH_TO_FILE, fp); | |
131 | io_stream *inistream = io_stream::open (fp, "wb"); | |
132 | if (inistream && !ini_file->seek (0, IO_SEEK_SET)) | |
133 | { | |
134 | if (io_stream::copy (ini_file, inistream)) | |
135 | io_stream::remove (fp); | |
136 | delete ini_file; | |
137 | delete inistream; | |
138 | } | |
139 | free ((void *) fp); | |
140 | ini_count++; | |
dd3f7f9b DD |
141 | } |
142 | } | |
de6a1a64 RC |
143 | return ini_count; |
144 | } | |
145 | ||
ab57ceaa RC |
146 | static void |
147 | do_ini_thread (HINSTANCE h, HWND owner) | |
de6a1a64 RC |
148 | { |
149 | size_t ini_count = 0; | |
150 | if (source == IDC_SOURCE_CWD) | |
ab57ceaa | 151 | ini_count = do_local_ini (owner); |
de6a1a64 | 152 | else |
ab57ceaa | 153 | ini_count = do_remote_ini (owner); |
de6a1a64 RC |
154 | |
155 | if (ini_count == 0) | |
156 | { | |
157 | next_dialog = source == IDC_SOURCE_CWD ? IDD_S_FROM_CWD : IDD_SITE; | |
158 | return; | |
159 | } | |
23c9e63c | 160 | |
85b43844 | 161 | if (get_root_dir ()) |
23c9e63c | 162 | { |
b24c88b3 | 163 | io_stream::mkpath_p (PATH_TO_DIR, "cygfile:///etc/setup"); |
04d6e06b DD |
164 | |
165 | unsigned int old_timestamp = 0; | |
b24c88b3 RC |
166 | io_stream *ots = |
167 | io_stream::open ("cygfile:///etc/setup/timestamp", "rt"); | |
04d6e06b | 168 | if (ots) |
23c9e63c | 169 | { |
b24c88b3 RC |
170 | char temp[20]; |
171 | memset (temp, '\0', 20); | |
172 | if (ots->read (temp, 19)) | |
173 | sscanf (temp, "%u", &old_timestamp); | |
174 | delete ots; | |
04d6e06b DD |
175 | if (old_timestamp && setup_timestamp |
176 | && (old_timestamp > setup_timestamp)) | |
177 | { | |
ab57ceaa | 178 | int yn = yesno (owner, IDS_OLD_SETUPINI); |
04d6e06b | 179 | if (yn == IDNO) |
89b1a15b | 180 | exit_setup (1); |
04d6e06b | 181 | } |
23c9e63c | 182 | } |
04d6e06b | 183 | if (setup_timestamp) |
23c9e63c | 184 | { |
b24c88b3 RC |
185 | io_stream *nts = |
186 | io_stream::open ("cygfile:///etc/setup/timestamp", "wt"); | |
04d6e06b DD |
187 | if (nts) |
188 | { | |
b24c88b3 RC |
189 | char temp[20]; |
190 | sprintf (temp, "%u", setup_timestamp); | |
191 | nts->write (temp, strlen (temp)); | |
192 | delete nts; | |
04d6e06b | 193 | } |
23c9e63c DD |
194 | } |
195 | } | |
196 | ||
b24c88b3 RC |
197 | msg ("setup_version is %s, our_version is %s", setup_version ? : "(null)", |
198 | version); | |
13d27274 DD |
199 | if (setup_version) |
200 | { | |
201 | char *ini_version = canonicalize_version (setup_version); | |
202 | char *our_version = canonicalize_version (version); | |
203 | if (strcmp (our_version, ini_version) < 0) | |
ab57ceaa | 204 | note (owner, IDS_OLD_SETUP_VERSION, version, setup_version); |
13d27274 DD |
205 | } |
206 | ||
ab57ceaa | 207 | next_dialog = IDD_CHOOSER; |
23c9e63c DD |
208 | } |
209 | ||
ab57ceaa RC |
210 | static void |
211 | do_ini_thread_reflector(void* p) | |
212 | { | |
213 | HANDLE *context; | |
214 | context = (HANDLE*)p; | |
215 | ||
216 | do_ini_thread((HINSTANCE)context[0], (HWND)context[1]); | |
217 | ||
218 | // Tell the progress page that we're done downloading | |
219 | Progress.PostMessage(WM_APP_SETUP_INI_DOWNLOAD_COMPLETE, 0, next_dialog); | |
220 | ||
221 | _endthread(); | |
222 | } | |
223 | ||
224 | static HANDLE context[2]; | |
225 | ||
226 | void | |
227 | do_ini (HINSTANCE h, HWND owner) | |
228 | { | |
229 | context[0] = h; | |
230 | context[1] = owner; | |
231 | ||
232 | _beginthread(do_ini_thread_reflector, 0, context); | |
233 | } | |
234 | ||
235 | ||
b11b49f3 DD |
236 | extern int yylineno; |
237 | ||
b24c88b3 RC |
238 | extern "C" int |
239 | yyerror (char *s, ...) | |
23c9e63c | 240 | { |
b11b49f3 DD |
241 | char buf[1000]; |
242 | int len; | |
243 | sprintf (buf, "setup.ini line %d: ", yylineno); | |
244 | va_list args; | |
245 | va_start (args, s); | |
246 | vsprintf (buf + strlen (buf), s, args); | |
247 | OutputDebugString (buf); | |
248 | if (error_buf) | |
249 | { | |
250 | strcat (error_buf, "\n"); | |
251 | len = strlen (error_buf) + strlen (buf) + 5; | |
252 | error_buf = (char *) realloc (error_buf, len); | |
253 | strcat (error_buf, buf); | |
254 | } | |
255 | else | |
256 | { | |
257 | len = strlen (buf) + 5; | |
258 | error_buf = (char *) malloc (len); | |
259 | strcpy (error_buf, buf); | |
260 | } | |
261 | error_count++; | |
b24c88b3 RC |
262 | /* TODO: is return 0 correct? */ |
263 | return 0; | |
23c9e63c DD |
264 | } |
265 | ||
b24c88b3 | 266 | extern "C" int fprintf (FILE * f, const char *s, ...); |
23c9e63c | 267 | |
b11b49f3 DD |
268 | static char stderrbuf[1000]; |
269 | ||
23c9e63c | 270 | int |
b24c88b3 | 271 | fprintf (FILE * f, const char *fmt, ...) |
23c9e63c DD |
272 | { |
273 | char buf[1000]; | |
274 | int rv; | |
275 | va_list args; | |
276 | va_start (args, fmt); | |
277 | if (f == stderr) | |
278 | { | |
279 | rv = vsprintf (buf, fmt, args); | |
b11b49f3 DD |
280 | strcat (stderrbuf, buf); |
281 | if (char *nl = strchr (stderrbuf, '\n')) | |
282 | { | |
283 | *nl = 0; | |
b24c88b3 | 284 | /*OutputDebugString (stderrbuf); */ |
b11b49f3 DD |
285 | MessageBox (0, buf, "Cygwin Setup", 0); |
286 | stderrbuf[0] = 0; | |
287 | } | |
42bf5b92 | 288 | |
23c9e63c DD |
289 | } |
290 | else | |
291 | { | |
292 | rv = vfprintf (f, fmt, args); | |
293 | } | |
294 | return rv; | |
295 | } |