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