]>
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 | ||
8507f105 DD |
21 | static char *cvsid = "\n%%% $Id$\n"; |
22 | ||
23c9e63c DD |
23 | #include "win32.h" |
24 | ||
25 | #include <stdio.h> | |
b11b49f3 | 26 | #include <stdlib.h> |
23c9e63c DD |
27 | #include <stdarg.h> |
28 | ||
29 | #include "ini.h" | |
30 | #include "resource.h" | |
31 | #include "concat.h" | |
32 | #include "state.h" | |
33 | #include "geturl.h" | |
34 | #include "dialog.h" | |
35 | #include "msg.h" | |
36 | #include "mkdir.h" | |
89b1a15b | 37 | #include "log.h" |
13d27274 | 38 | #include "version.h" |
a351e48c | 39 | #include "mount.h" |
23c9e63c DD |
40 | |
41 | unsigned int setup_timestamp = 0; | |
13d27274 | 42 | char *setup_version = 0; |
23c9e63c DD |
43 | |
44 | extern "C" int yyparse (); | |
b11b49f3 DD |
45 | /*extern int yydebug;*/ |
46 | ||
47 | static char *error_buf = 0; | |
48 | static int error_count = 0; | |
23c9e63c DD |
49 | |
50 | void | |
51 | do_ini (HINSTANCE h) | |
52 | { | |
53 | char *ini_file = get_url_to_string (concat (MIRROR_SITE, "/setup.ini", 0)); | |
b11b49f3 | 54 | dismiss_url_status_dialog (); |
23c9e63c DD |
55 | |
56 | if (!ini_file) | |
b5b282c4 DD |
57 | { |
58 | note (IDS_SETUPINI_MISSING, MIRROR_SITE); | |
59 | next_dialog = IDD_SITE; | |
60 | return; | |
61 | } | |
23c9e63c | 62 | |
13d27274 DD |
63 | package = 0; |
64 | npackages = 0; | |
65 | setup_timestamp = 0; | |
66 | setup_version = 0; | |
67 | ||
23c9e63c DD |
68 | ini_init (ini_file); |
69 | ||
70 | setup_timestamp = 0; | |
b11b49f3 DD |
71 | /*yydebug = 1;*/ |
72 | ||
73 | if (yyparse () || error_count > 0) | |
74 | { | |
75 | if (error_count == 1) | |
76 | MessageBox (0, error_buf, "Parse Error", 0); | |
77 | else | |
78 | MessageBox (0, error_buf, "Parse Errors", 0); | |
79 | } | |
dd3f7f9b DD |
80 | else |
81 | { | |
82 | /* save known-good setup.ini locally */ | |
83 | FILE *inif = fopen ("setup.ini", "wb"); | |
84 | if (inif) | |
85 | { | |
86 | fwrite (ini_file, 1, strlen (ini_file), inif); | |
87 | fclose (inif); | |
88 | } | |
89 | } | |
23c9e63c | 90 | |
04d6e06b | 91 | if (root_dir) |
23c9e63c | 92 | { |
a351e48c | 93 | mkdir_p (1, cygpath ("/etc/setup", 0)); |
04d6e06b DD |
94 | |
95 | unsigned int old_timestamp = 0; | |
a351e48c | 96 | FILE *ots = fopen (cygpath ("/etc/setup/timestamp", 0), "rt"); |
04d6e06b | 97 | if (ots) |
23c9e63c | 98 | { |
04d6e06b DD |
99 | fscanf (ots, "%u", &old_timestamp); |
100 | fclose (ots); | |
101 | if (old_timestamp && setup_timestamp | |
102 | && (old_timestamp > setup_timestamp)) | |
103 | { | |
104 | int yn = yesno (IDS_OLD_SETUPINI); | |
105 | if (yn == IDNO) | |
89b1a15b | 106 | exit_setup (1); |
04d6e06b | 107 | } |
23c9e63c | 108 | } |
04d6e06b | 109 | if (setup_timestamp) |
23c9e63c | 110 | { |
a351e48c | 111 | FILE *nts = fopen (cygpath ("/etc/setup/timestamp", 0), "wt"); |
04d6e06b DD |
112 | if (nts) |
113 | { | |
114 | fprintf (nts, "%u", setup_timestamp); | |
115 | fclose (nts); | |
116 | } | |
23c9e63c DD |
117 | } |
118 | } | |
119 | ||
13d27274 DD |
120 | msg ("setup_version is %s, our_version is %s", setup_version?:"(null)", version); |
121 | if (setup_version) | |
122 | { | |
123 | char *ini_version = canonicalize_version (setup_version); | |
124 | char *our_version = canonicalize_version (version); | |
125 | if (strcmp (our_version, ini_version) < 0) | |
126 | note (IDS_OLD_SETUP_VERSION, version, setup_version); | |
127 | } | |
128 | ||
713bbe5f | 129 | next_dialog = IDD_CHOOSE; |
23c9e63c DD |
130 | } |
131 | ||
b11b49f3 DD |
132 | extern int yylineno; |
133 | ||
134 | extern "C" int yyerror (char *s, ...) | |
23c9e63c | 135 | { |
b11b49f3 DD |
136 | char buf[1000]; |
137 | int len; | |
138 | sprintf (buf, "setup.ini line %d: ", yylineno); | |
139 | va_list args; | |
140 | va_start (args, s); | |
141 | vsprintf (buf + strlen (buf), s, args); | |
142 | OutputDebugString (buf); | |
143 | if (error_buf) | |
144 | { | |
145 | strcat (error_buf, "\n"); | |
146 | len = strlen (error_buf) + strlen (buf) + 5; | |
147 | error_buf = (char *) realloc (error_buf, len); | |
148 | strcat (error_buf, buf); | |
149 | } | |
150 | else | |
151 | { | |
152 | len = strlen (buf) + 5; | |
153 | error_buf = (char *) malloc (len); | |
154 | strcpy (error_buf, buf); | |
155 | } | |
156 | error_count++; | |
23c9e63c DD |
157 | } |
158 | ||
1fd6d0a2 | 159 | extern "C" int fprintf (FILE *f, const char *s, ...); |
23c9e63c | 160 | |
b11b49f3 DD |
161 | static char stderrbuf[1000]; |
162 | ||
23c9e63c | 163 | int |
1fd6d0a2 | 164 | fprintf (FILE *f, const char *fmt, ...) |
23c9e63c DD |
165 | { |
166 | char buf[1000]; | |
167 | int rv; | |
168 | va_list args; | |
169 | va_start (args, fmt); | |
170 | if (f == stderr) | |
171 | { | |
172 | rv = vsprintf (buf, fmt, args); | |
b11b49f3 DD |
173 | strcat (stderrbuf, buf); |
174 | if (char *nl = strchr (stderrbuf, '\n')) | |
175 | { | |
176 | *nl = 0; | |
177 | /*OutputDebugString (stderrbuf);*/ | |
178 | MessageBox (0, buf, "Cygwin Setup", 0); | |
179 | stderrbuf[0] = 0; | |
180 | } | |
42bf5b92 | 181 | |
23c9e63c DD |
182 | } |
183 | else | |
184 | { | |
185 | rv = vfprintf (f, fmt, args); | |
186 | } | |
187 | return rv; | |
188 | } |