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