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
=
46 #include "filemanip.h"
48 #include "io_stream.h"
54 #include "IniDBBuilderPackage.h"
57 extern ThreeBarProgressPage Progress
;
59 unsigned int setup_timestamp
= 0;
62 extern int yyparse ();
63 /*extern int yydebug;*/
65 static char *error_buf
= 0;
66 static int error_count
= 0;
70 static IniDBBuilder
*findBuilder
;
72 static const char *ini_filename
;
75 find_routine (char *path
, unsigned int fsize
)
77 const char *setup_ini
= trail (path
, "\\setup.ini");
79 if (setup_ini
== NULL
)
82 io_stream
*ini_file
= io_stream::open (String ("file://") + path
, "rb");
85 note (NULL
, IDS_SETUPINI_MISSING
, (String ("file://") + path
).cstr_oneuse());
89 log (LOG_BABBLE
, String ("Found ini file - file://") + local_dir
+ "/" + path
);
91 unsigned pathprefix_len
= setup_ini
- path
;
92 /* Copy leading part of path to temporary buffer and unescape it */
94 char path_prefix
[pathprefix_len
+ 1];
95 strncpy (path_prefix
, path
, pathprefix_len
);
96 path_prefix
[pathprefix_len
] = '\0';
97 String mirror
= rfc1738_unescape_part (path_prefix
);
102 if (yyparse () || error_count
> 0)
103 MessageBox (0, error_buf
, error_count
== 1 ? "Parse Error" : "Parse Errors", 0);
111 if (findBuilder
->timestamp
> setup_timestamp
)
113 setup_timestamp
= findBuilder
->timestamp
;
114 setup_version
= findBuilder
->version
;
119 do_local_ini (HWND owner
)
122 findBuilder
= new IniDBBuilderPackage
;
123 find (local_dir
, find_routine
);
130 do_remote_ini (HWND owner
)
132 size_t ini_count
= 0;
133 IniDBBuilderPackage
*aBuilder
= new IniDBBuilderPackage
;
135 for (size_t n
= 1; n
<= site_list
.number (); n
++)
137 io_stream
*compressed_ini_file
=
138 get_url_to_membuf (site_list
[n
]->url
+ "/setup.bz2", owner
);
139 io_stream
*ini_file
= 0;
140 if (!compressed_ini_file
)
141 ini_file
= get_url_to_membuf (site_list
[n
]->url
+ "/setup.ini", owner
);
144 ini_file
= compress::decompress (compressed_ini_file
);
149 note (owner
, IDS_SETUPINI_MISSING
, site_list
[n
]->url
.cstr_oneuse());
153 aBuilder
->parse_mirror
= site_list
[n
]->url
;
154 ini_init (ini_file
, aBuilder
);
158 if (yyparse () || error_count
> 0)
159 MessageBox (0, error_buf
,
160 error_count
== 1 ? "Parse Error" : "Parse Errors", 0);
163 /* save known-good setup.ini locally */
164 String
const fp
= String ("file://") + local_dir
+ "/" +
165 rfc1738_escape_part (site_list
[n
]->url
) +
167 io_stream::mkpath_p (PATH_TO_FILE
, fp
);
168 io_stream
*inistream
= io_stream::open (fp
, "wb");
169 if (inistream
&& !ini_file
->seek (0, IO_SEEK_SET
))
171 if (io_stream::copy (ini_file
, inistream
))
172 io_stream::remove (fp
.cstr_oneuse());
177 if (aBuilder
->timestamp
> setup_timestamp
)
179 setup_timestamp
= aBuilder
->timestamp
;
180 setup_version
= aBuilder
->version
;
183 delete compressed_ini_file
;
190 do_ini_thread (HINSTANCE h
, HWND owner
)
192 size_t ini_count
= 0;
193 if (source
== IDC_SOURCE_CWD
)
194 ini_count
= do_local_ini (owner
);
196 ini_count
= do_remote_ini (owner
);
200 next_dialog
= source
== IDC_SOURCE_CWD
? IDD_S_FROM_CWD
: IDD_SITE
;
204 if (get_root_dir ().cstr_oneuse())
206 io_stream::mkpath_p (PATH_TO_DIR
, "cygfile:///etc/setup");
208 unsigned int old_timestamp
= 0;
210 io_stream::open ("cygfile:///etc/setup/timestamp", "rt");
214 memset (temp
, '\0', 20);
215 if (ots
->read (temp
, 19))
216 sscanf (temp
, "%u", &old_timestamp
);
218 if (old_timestamp
&& setup_timestamp
219 && (old_timestamp
> setup_timestamp
))
221 int yn
= yesno (owner
, IDS_OLD_SETUPINI
);
223 LogSingleton::GetInstance().exit (1);
229 io_stream::open ("cygfile:///etc/setup/timestamp", "wt");
233 sprintf (temp
, "%u", setup_timestamp
);
234 nts
->write (temp
, strlen (temp
));
240 msg ("setup_version is %s, our_version is %s", setup_version
.size() ?
241 setup_version
.cstr_oneuse() : "(null)",
243 if (setup_version
.size())
245 String ini_version
= canonicalize_version (setup_version
);
246 String our_version
= canonicalize_version (version
);
247 // XXX useversion < operator
248 if (our_version
.compare (ini_version
) < 0)
249 note (owner
, IDS_OLD_SETUP_VERSION
, version
, setup_version
.cstr_oneuse());
252 next_dialog
= IDD_CHOOSE
;
256 do_ini_thread_reflector(void* p
)
259 context
= (HANDLE
*)p
;
261 do_ini_thread((HINSTANCE
)context
[0], (HWND
)context
[1]);
263 // Tell the progress page that we're done downloading
264 Progress
.PostMessage(WM_APP_SETUP_INI_DOWNLOAD_COMPLETE
, 0, next_dialog
);
269 static HANDLE context
[2];
272 do_ini (HINSTANCE h
, HWND owner
)
278 CreateThread (NULL
, 0, do_ini_thread_reflector
, context
, 0, &threadID
);
286 yyerror (String
const &s
)
288 char buf
[MAX_PATH
+ 1000];
290 sprintf (buf
, "%s line %d: ", ini_filename
, yylineno
- yybol ());
291 sprintf (buf
+ strlen (buf
), s
.cstr_oneuse());
292 OutputDebugString (buf
);
295 strcat (error_buf
, "\n");
296 len
= strlen (error_buf
) + strlen (buf
) + 5;
297 error_buf
= (char *) realloc (error_buf
, len
);
298 strcat (error_buf
, buf
);
302 len
= strlen (buf
) + 5;
303 error_buf
= (char *) malloc (len
);
304 strcpy (error_buf
, buf
);
307 /* TODO: is return 0 correct? */
311 extern "C" int fprintf (FILE * f
, const char *s
, ...);
313 static char stderrbuf
[1000];
316 fprintf (FILE * f
, const char *fmt
, ...)
321 va_start (args
, fmt
);
324 rv
= vsprintf (buf
, fmt
, args
);
325 strcat (stderrbuf
, buf
);
326 if (char *nl
= strchr (stderrbuf
, '\n'))
329 /*OutputDebugString (stderrbuf); */
330 MessageBox (0, buf
, "Cygwin Setup", 0);
337 rv
= vfprintf (f
, fmt
, args
);