2 * Copyright (c) 2000, Red Hat, Inc.
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.
9 * A copy of the GNU General Public License can be found at
12 * Written by DJ Delorie <dj@cygnus.com>
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. */
22 static const char *cvsid
=
47 #include "io_stream.h"
50 extern ThreeBarProgressPage Progress
;
52 unsigned int setup_timestamp
= 0;
53 char *setup_version
= 0;
55 extern int yyparse ();
56 /*extern int yydebug;*/
58 static char *error_buf
= 0;
59 static int error_count
= 0;
64 find_routine (char *path
, unsigned int fsize
)
66 if (!strstr (path
, "setup.ini") )
68 io_stream
*ini_file
= io_stream::open (concat ("file://", local_dir
,"/", path
, 0), "rb");
71 note (NULL
, IDS_SETUPINI_MISSING
, path
);
75 /* FIXME: only use most recent copy */
79 ini_init (ini_file
, concat ("file://", local_dir
,"/", path
, 0));
83 if (yyparse () || error_count
> 0)
84 MessageBox (0, error_buf
, error_count
== 1 ? "Parse Error" : "Parse Errors", 0);
90 do_local_ini (HWND owner
)
93 find (local_dir
, find_routine
);
98 do_remote_ini (HWND owner
)
100 size_t ini_count
= 0;
102 for (size_t n
= 1; n
<= site_list
.number (); n
++)
104 io_stream
*ini_file
=
105 get_url_to_membuf (concat (site_list
[n
]->url
, "/setup.ini", 0), owner
);
109 note (owner
, IDS_SETUPINI_MISSING
, site_list
[n
]->url
);
113 /* FIXME: only use most recent copy */
117 ini_init (ini_file
, site_list
[n
]->url
);
121 if (yyparse () || error_count
> 0)
122 MessageBox (0, error_buf
,
123 error_count
== 1 ? "Parse Error" : "Parse Errors", 0);
126 /* save known-good setup.ini locally */
127 char const *fp
= concat ("file://", local_dir
, "/",
128 rfc1738_escape_part (site_list
[n
]->url
),
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
))
134 if (io_stream::copy (ini_file
, inistream
))
135 io_stream::remove (fp
);
147 do_ini_thread (HINSTANCE h
, HWND owner
)
149 size_t ini_count
= 0;
150 if (source
== IDC_SOURCE_CWD
)
151 ini_count
= do_local_ini (owner
);
153 ini_count
= do_remote_ini (owner
);
157 next_dialog
= source
== IDC_SOURCE_CWD
? IDD_S_FROM_CWD
: IDD_SITE
;
163 io_stream::mkpath_p (PATH_TO_DIR
, "cygfile:///etc/setup");
165 unsigned int old_timestamp
= 0;
167 io_stream::open ("cygfile:///etc/setup/timestamp", "rt");
171 memset (temp
, '\0', 20);
172 if (ots
->read (temp
, 19))
173 sscanf (temp
, "%u", &old_timestamp
);
175 if (old_timestamp
&& setup_timestamp
176 && (old_timestamp
> setup_timestamp
))
178 int yn
= yesno (owner
, IDS_OLD_SETUPINI
);
186 io_stream::open ("cygfile:///etc/setup/timestamp", "wt");
190 sprintf (temp
, "%u", setup_timestamp
);
191 nts
->write (temp
, strlen (temp
));
197 msg ("setup_version is %s, our_version is %s", setup_version
? : "(null)",
201 char *ini_version
= canonicalize_version (setup_version
);
202 char *our_version
= canonicalize_version (version
);
203 if (strcmp (our_version
, ini_version
) < 0)
204 note (owner
, IDS_OLD_SETUP_VERSION
, version
, setup_version
);
207 next_dialog
= IDD_CHOOSER
;
211 do_ini_thread_reflector(void* p
)
214 context
= (HANDLE
*)p
;
216 do_ini_thread((HINSTANCE
)context
[0], (HWND
)context
[1]);
218 // Tell the progress page that we're done downloading
219 Progress
.PostMessage(WM_APP_SETUP_INI_DOWNLOAD_COMPLETE
, 0, next_dialog
);
224 static HANDLE context
[2];
227 do_ini (HINSTANCE h
, HWND owner
)
232 _beginthread(do_ini_thread_reflector
, 0, context
);
239 yyerror (char *s
, ...)
243 sprintf (buf
, "setup.ini line %d: ", yylineno
);
246 vsprintf (buf
+ strlen (buf
), s
, args
);
247 OutputDebugString (buf
);
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
);
257 len
= strlen (buf
) + 5;
258 error_buf
= (char *) malloc (len
);
259 strcpy (error_buf
, buf
);
262 /* TODO: is return 0 correct? */
266 extern "C" int fprintf (FILE * f
, const char *s
, ...);
268 static char stderrbuf
[1000];
271 fprintf (FILE * f
, const char *fmt
, ...)
276 va_start (args
, fmt
);
279 rv
= vsprintf (buf
, fmt
, args
);
280 strcat (stderrbuf
, buf
);
281 if (char *nl
= strchr (stderrbuf
, '\n'))
284 /*OutputDebugString (stderrbuf); */
285 MessageBox (0, buf
, "Cygwin Setup", 0);
292 rv
= vfprintf (f
, fmt
, args
);