1 | #if defined(GSDL_USE_OBJECTSPACE)
|
---|
2 | # include <ospace\std\fstream>
|
---|
3 | #elif defined(GSDL_USE_IOS_H)
|
---|
4 | # include <fstream.h>
|
---|
5 | #else
|
---|
6 | # include <fstream>
|
---|
7 | #endif
|
---|
8 |
|
---|
9 | #include <windows.h>
|
---|
10 | #include "httpsrv.h"
|
---|
11 | #include "settings.h"
|
---|
12 | #include "locate.h"
|
---|
13 | #include "resource.h"
|
---|
14 | #include "cgiwrapper.h"
|
---|
15 |
|
---|
16 | // library settings
|
---|
17 | text_t gsdl_enterlib;
|
---|
18 | text_t gsdl_gsdlhome;
|
---|
19 | text_t gsdl_gdbmhome;
|
---|
20 | text_t gsdl_collections;
|
---|
21 | colinfo_tmap gsdl_collectinfo;
|
---|
22 |
|
---|
23 | char gsdl_staticpages[MAX_FILENAME_SIZE];
|
---|
24 |
|
---|
25 | // debug settings
|
---|
26 | char gsdl_log_name[MAX_FILENAME_SIZE] = "c:\\gsdl.log";
|
---|
27 | int gsdl_keep_log = 0;
|
---|
28 | int gsdl_show_console = 0;
|
---|
29 |
|
---|
30 | // general settings
|
---|
31 | int gsdl_port_num = 80;
|
---|
32 | int gsdl_auto_enter = 0;
|
---|
33 | int gsdl_browser = GS_NETSCAPE;
|
---|
34 | char gsdl_browser_exe[MAX_FILENAME_SIZE] = "";
|
---|
35 |
|
---|
36 |
|
---|
37 | // private data
|
---|
38 |
|
---|
39 | // pathnames of the latest installed versions of netscape and
|
---|
40 | // internet explorer
|
---|
41 | static char netscape_exe[MAX_FILENAME_SIZE]="";
|
---|
42 | static char iexplore_exe[MAX_FILENAME_SIZE]="";
|
---|
43 |
|
---|
44 | // pathname of the default browser
|
---|
45 | static char default_browser_exe[MAX_FILENAME_SIZE]="";
|
---|
46 |
|
---|
47 | // whether netscape is needed (used in the settings dialog box)
|
---|
48 | static int gsdl_netscapeneeded = 0;
|
---|
49 |
|
---|
50 | static void remove_end_slashes(char *str) {
|
---|
51 | int len = strlen (str);
|
---|
52 | while ((len > 0) && ((str[len-1] == '\\') || (str[len-1] == '/'))) {
|
---|
53 | len --;
|
---|
54 | }
|
---|
55 | str[len] = '\0';
|
---|
56 | }
|
---|
57 |
|
---|
58 | static void remove_end_slashes (text_t &str) {
|
---|
59 | char *cstr = str.getcstr();
|
---|
60 | remove_end_slashes (cstr);
|
---|
61 | str = cstr;
|
---|
62 | delete cstr;
|
---|
63 | }
|
---|
64 |
|
---|
65 | // returns 1 if successful, 0 otherwise
|
---|
66 | // checks for a file's existence
|
---|
67 | static int check_program_exe (char *path) {
|
---|
68 | UINT curerrormode;
|
---|
69 | OFSTRUCT reOpenBuff;
|
---|
70 | int retvalue = 0;
|
---|
71 |
|
---|
72 | reOpenBuff.cBytes = sizeof (OFSTRUCT);
|
---|
73 |
|
---|
74 | curerrormode = SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOOPENFILEERRORBOX);
|
---|
75 | if (OpenFile(path, &reOpenBuff, OF_EXIST) != HFILE_ERROR) retvalue = 1;
|
---|
76 | SetErrorMode(curerrormode);
|
---|
77 |
|
---|
78 | return retvalue;
|
---|
79 | }
|
---|
80 |
|
---|
81 |
|
---|
82 | // returns 1 if successful, 0 otherwise
|
---|
83 | static int get_default_browser_path (char *providedhtmltype, char *path, int maxsize) {
|
---|
84 | HKEY hk1, hk2;
|
---|
85 | char htmltype[256];
|
---|
86 | long size;
|
---|
87 | int retval = 0;
|
---|
88 |
|
---|
89 | htmltype[0] = '\0';
|
---|
90 | path[0] = '\0';
|
---|
91 |
|
---|
92 | // try and get information about the default browser from the
|
---|
93 | // registry
|
---|
94 |
|
---|
95 | if (providedhtmltype != NULL) strcpy (htmltype, providedhtmltype);
|
---|
96 |
|
---|
97 | else if (RegOpenKey(HKEY_CLASSES_ROOT, ".htm", &hk1) == ERROR_SUCCESS) {
|
---|
98 | size = 256;
|
---|
99 | RegQueryValue(hk1, NULL, htmltype, &size);
|
---|
100 | RegCloseKey(hk1);
|
---|
101 | }
|
---|
102 |
|
---|
103 | if (RegOpenKey(HKEY_CLASSES_ROOT, htmltype, &hk1) == ERROR_SUCCESS) {
|
---|
104 | if (RegOpenKey(hk1, "shell\\open", &hk2) == ERROR_SUCCESS) {
|
---|
105 | // look for the command to start the browser
|
---|
106 | size = maxsize;
|
---|
107 | if (RegQueryValue(hk2,"command",path,&size) == ERROR_SUCCESS) {
|
---|
108 | // strip all excess stuff off the command
|
---|
109 | char endchar = ' ';
|
---|
110 | int i = 0, len = 0;
|
---|
111 | int state = 0; // 0=strip initial white-space and quotes, 1=grab path
|
---|
112 | while (path[i] != '\0') {
|
---|
113 | if (state == 0) {
|
---|
114 | if (path[i] == ' ') {
|
---|
115 | // do nothing
|
---|
116 | } else if (path[i] == '"') {
|
---|
117 | endchar = '"';
|
---|
118 | state = 1;
|
---|
119 | } else {
|
---|
120 | state = 1;
|
---|
121 | path[len] = path[i];
|
---|
122 | len++;
|
---|
123 | }
|
---|
124 | } else {
|
---|
125 | if (path[i] == endchar) break;
|
---|
126 | path[len] = path[i];
|
---|
127 | len++;
|
---|
128 | }
|
---|
129 | i++;
|
---|
130 | }
|
---|
131 | path[len] = '\0';
|
---|
132 |
|
---|
133 | // check the resulting pathname
|
---|
134 | if (check_program_exe (path)) {
|
---|
135 | retval = 1; // succeeded
|
---|
136 | } else {
|
---|
137 | path[0] = '\0'; // failed (must have been deleted or something...)
|
---|
138 | }
|
---|
139 | }
|
---|
140 | RegCloseKey(hk2);
|
---|
141 | }
|
---|
142 | RegCloseKey(hk1);
|
---|
143 | }
|
---|
144 |
|
---|
145 | return retval;
|
---|
146 | }
|
---|
147 |
|
---|
148 |
|
---|
149 | // returns 1 if successful, 0 otherwise
|
---|
150 | // note that appname should include .exe (e.g. netscape.exe)
|
---|
151 | static int registry_get_app_paths (char *appname, char *path, int maxsize) {
|
---|
152 | HKEY hk1;
|
---|
153 | long size;
|
---|
154 | int retval = 0;
|
---|
155 |
|
---|
156 | path[0] = '\0';
|
---|
157 |
|
---|
158 | if (RegOpenKey(HKEY_LOCAL_MACHINE,
|
---|
159 | "Software\\Microsoft\\Windows\\CurrentVersion\\App Paths",
|
---|
160 | &hk1) == ERROR_SUCCESS) {
|
---|
161 | size = maxsize;
|
---|
162 | if (RegQueryValue (hk1, appname, path, &size) == ERROR_SUCCESS &&
|
---|
163 | check_program_exe (path));
|
---|
164 | retval = 1;
|
---|
165 |
|
---|
166 | RegCloseKey(hk1);
|
---|
167 | }
|
---|
168 |
|
---|
169 | return retval;
|
---|
170 | }
|
---|
171 |
|
---|
172 | static void check_installed_browsers (int netscapeneeded) {
|
---|
173 | netscape_exe[0] = '\0';
|
---|
174 | iexplore_exe[0] = '\0';
|
---|
175 | default_browser_exe[0] = '\0';
|
---|
176 |
|
---|
177 | // update the default browser information (if netscape isn't needed)
|
---|
178 | if (!netscapeneeded) {
|
---|
179 | get_default_browser_path (NULL, default_browser_exe, MAX_FILENAME_SIZE);
|
---|
180 | _strlwr (default_browser_exe);
|
---|
181 | }
|
---|
182 |
|
---|
183 | // look for netscape
|
---|
184 |
|
---|
185 | // first look for netscape in the registry
|
---|
186 | if (!registry_get_app_paths("netscape.exe", netscape_exe, MAX_FILENAME_SIZE)) {
|
---|
187 | // next look for "NetscapeMarkup"
|
---|
188 | if (get_default_browser_path ("NetscapeMarkup", netscape_exe, MAX_FILENAME_SIZE)) {
|
---|
189 | _strlwr (netscape_exe);
|
---|
190 | if (!strstr (netscape_exe, "netscape.exe")) {
|
---|
191 | netscape_exe[0] = '\0';
|
---|
192 |
|
---|
193 | // next look for \netscape\netscape.exe
|
---|
194 |
|
---|
195 | // get drive letter of the windows directory
|
---|
196 | GetWindowsDirectory(netscape_exe, MAX_FILENAME_SIZE);
|
---|
197 | netscape_exe[1] = '\0';
|
---|
198 | strcat (netscape_exe, ":\\netscape\\netscape.exe");
|
---|
199 |
|
---|
200 | if (!check_program_exe (netscape_exe)) {
|
---|
201 | // lastly look for \netscape\program\netscape.exe
|
---|
202 | netscape_exe[1] = '\0';
|
---|
203 | strcat (netscape_exe, ":\\netscape\\program\\netscape.exe");
|
---|
204 |
|
---|
205 | }
|
---|
206 | }
|
---|
207 | }
|
---|
208 | }
|
---|
209 | _strlwr (netscape_exe);
|
---|
210 | if ((strlen (netscape_exe) > 0) && !check_program_exe (netscape_exe)) {
|
---|
211 | netscape_exe[0] = '\0'; // couldn't find netscape
|
---|
212 | }
|
---|
213 |
|
---|
214 | // look for internet explorer (if netscape isn't needed)
|
---|
215 |
|
---|
216 | // first look for iexplore in the registry
|
---|
217 | if (!netscapeneeded && !registry_get_app_paths("iexplore.exe",
|
---|
218 | iexplore_exe, MAX_FILENAME_SIZE)) {
|
---|
219 | // next look for "htmlfile"
|
---|
220 | if (get_default_browser_path ("htmlfile", iexplore_exe, MAX_FILENAME_SIZE)) {
|
---|
221 | _strlwr (iexplore_exe);
|
---|
222 | if (!strstr (iexplore_exe, "iexplore.exe")) {
|
---|
223 | iexplore_exe[0] = '\0';
|
---|
224 |
|
---|
225 | // next look for \iexplore\iexplore.exe
|
---|
226 |
|
---|
227 | // get drive letter of the windows directory
|
---|
228 | GetWindowsDirectory(iexplore_exe, MAX_FILENAME_SIZE);
|
---|
229 | iexplore_exe[1] = '\0';
|
---|
230 | strcat (iexplore_exe, ":\\iexplore\\iexplore.exe");
|
---|
231 | }
|
---|
232 | }
|
---|
233 | }
|
---|
234 | _strlwr (iexplore_exe);
|
---|
235 | if ((strlen (iexplore_exe) > 0) && !check_program_exe (iexplore_exe)) {
|
---|
236 | iexplore_exe[0] = '\0'; // couldn't find internet explorer
|
---|
237 | }
|
---|
238 | }
|
---|
239 |
|
---|
240 | void write_settings () {
|
---|
241 | char conffile[MAX_FILENAME_SIZE];
|
---|
242 |
|
---|
243 | strcpy (conffile, data_location);
|
---|
244 | remove_end_slashes (conffile);
|
---|
245 | strcat (conffile, "\\gsdl.ini");
|
---|
246 |
|
---|
247 | ofstream fout (conffile);
|
---|
248 | if (fout) {
|
---|
249 |
|
---|
250 | outconvertclass text_t2ascii;
|
---|
251 |
|
---|
252 | // top (gsdl) level stuff
|
---|
253 | fout << "[gsdl]\n";
|
---|
254 | write_ini_line(fout, "enterlib", gsdl_enterlib);
|
---|
255 | write_ini_line(fout, "gsdlhome", gsdl_gsdlhome);
|
---|
256 | write_ini_line(fout, "gdbmhome", gsdl_gdbmhome);
|
---|
257 |
|
---|
258 | write_ini_line(fout, "logfilename", gsdl_log_name);
|
---|
259 | write_ini_line(fout, "keeplog", text_t(gsdl_keep_log));
|
---|
260 | write_ini_line(fout, "consolelog", text_t(gsdl_show_console));
|
---|
261 |
|
---|
262 | write_ini_line(fout, "portnumber", text_t(gsdl_port_num));
|
---|
263 | write_ini_line(fout, "autoenter", text_t(gsdl_auto_enter));
|
---|
264 | write_ini_line(fout, "browser", text_t(gsdl_browser));
|
---|
265 | write_ini_line(fout, "browserexe", gsdl_browser_exe);
|
---|
266 | write_ini_line(fout, "collections", gsdl_collections);
|
---|
267 |
|
---|
268 | // collection levels
|
---|
269 | colinfo_tmap::iterator here = gsdl_collectinfo.begin();
|
---|
270 | colinfo_tmap::iterator end = gsdl_collectinfo.end();
|
---|
271 | while (here != end) {
|
---|
272 | fout << text_t2ascii << "[" << (*here).first << "]\n";
|
---|
273 | if (!(*here).second.gsdl_gsdlhome.empty())
|
---|
274 | write_ini_line(fout, "gsdlhome", (*here).second.gsdl_gsdlhome);
|
---|
275 | if (!(*here).second.gsdl_gdbmhome.empty())
|
---|
276 | write_ini_line(fout, "gdbmhome", (*here).second.gsdl_gdbmhome);
|
---|
277 |
|
---|
278 | here ++;
|
---|
279 | }
|
---|
280 | fout.close();
|
---|
281 | }
|
---|
282 | }
|
---|
283 |
|
---|
284 |
|
---|
285 | // browser_compare assumes that check_exe is in lowercase
|
---|
286 | static int browser_compare (char *browser_exe_path, char *check_exe) {
|
---|
287 | char tmp_exe[MAX_FILENAME_SIZE];
|
---|
288 | strcpy (tmp_exe, browser_exe_path);
|
---|
289 | _strlwr (tmp_exe);
|
---|
290 | return (strstr (tmp_exe, check_exe) != NULL);
|
---|
291 | }
|
---|
292 |
|
---|
293 | // This function assumes that check_installed_browsers
|
---|
294 | // has been recently called
|
---|
295 | // It also assumes that browser_exe is large
|
---|
296 | // enough to receive any path names to any browser
|
---|
297 | static void check_browser_settings (int &browser, char *browser_exe,
|
---|
298 | int netscapeneeded) {
|
---|
299 |
|
---|
300 | // sort out which browser to use
|
---|
301 | if ((browser == GS_NETSCAPE) && (netscape_exe[0] == '\0'))
|
---|
302 | browser = GS_IEXPLORE;
|
---|
303 | if ((browser == GS_IEXPLORE) && (netscapeneeded || (iexplore_exe[0] == '\0'))) {
|
---|
304 | if (netscape_exe[0] != '\0') browser = GS_NETSCAPE;
|
---|
305 | else browser = GS_OTHER;
|
---|
306 | }
|
---|
307 | if ((browser == GS_OTHER) && netscapeneeded &&
|
---|
308 | !browser_compare (browser_exe, "netscape.exe") && (netscape_exe[0] != '\0')) {
|
---|
309 | // this other browser isn't netscape and netscape is available
|
---|
310 | browser = GS_NETSCAPE;
|
---|
311 | }
|
---|
312 |
|
---|
313 |
|
---|
314 | // get the browser's executable
|
---|
315 | if (browser == GS_NETSCAPE) {
|
---|
316 | strcpy (browser_exe, netscape_exe);
|
---|
317 | } else if (browser == GS_IEXPLORE) {
|
---|
318 | strcpy (browser_exe, iexplore_exe);
|
---|
319 | } else {
|
---|
320 | browser = GS_OTHER;
|
---|
321 |
|
---|
322 | // if the browser should be netscape then check to
|
---|
323 | // make sure it is
|
---|
324 | if (netscapeneeded && !browser_compare (browser_exe, "netscape.exe")) {
|
---|
325 | // not netscape, set to no browser
|
---|
326 | browser_exe[0] = '\0';
|
---|
327 | }
|
---|
328 | }
|
---|
329 | }
|
---|
330 |
|
---|
331 |
|
---|
332 | static void revert_defaults (int netscapeneeded) {
|
---|
333 | find_location();
|
---|
334 |
|
---|
335 | // library settings
|
---|
336 | gsdl_enterlib = "/cgi-bin/gw";
|
---|
337 | gsdl_gsdlhome = data_location;
|
---|
338 | gsdl_gdbmhome = data_location;
|
---|
339 |
|
---|
340 | // debug settings
|
---|
341 | gsdl_keep_log = 0;
|
---|
342 | strcpy (gsdl_log_name, "c:\\gsdl.log");
|
---|
343 | gsdl_show_console = 0;
|
---|
344 |
|
---|
345 | // general settings
|
---|
346 | gsdl_port_num = 80;
|
---|
347 | gsdl_auto_enter = 0;
|
---|
348 |
|
---|
349 | check_installed_browsers (netscapeneeded);
|
---|
350 | gsdl_browser = GS_NETSCAPE;
|
---|
351 | strcpy (gsdl_browser_exe, default_browser_exe);
|
---|
352 | check_browser_settings (gsdl_browser, gsdl_browser_exe, netscapeneeded);
|
---|
353 | }
|
---|
354 |
|
---|
355 | void read_settings (int netscapeneeded) {
|
---|
356 | char conffile[MAX_FILENAME_SIZE];
|
---|
357 |
|
---|
358 | find_location();
|
---|
359 |
|
---|
360 | strcpy (conffile, data_location);
|
---|
361 | remove_end_slashes (conffile);
|
---|
362 | strcat (conffile, "\\gsdl.ini");
|
---|
363 |
|
---|
364 | // set up defaults
|
---|
365 | revert_defaults (netscapeneeded);
|
---|
366 |
|
---|
367 | text_t key, value, section;
|
---|
368 | char *cstr_value;
|
---|
369 | ifstream conf (conffile, ios::nocreate);
|
---|
370 | if (conf) {
|
---|
371 | while (read_ini_line(conf, key, value) >= 0) {
|
---|
372 | if (value.empty()) {
|
---|
373 | // should be a section title
|
---|
374 | section = key;
|
---|
375 | // remove square brackets
|
---|
376 | section.erase (section.begin());
|
---|
377 | section.erase (section.end()-1);
|
---|
378 |
|
---|
379 | } else {
|
---|
380 |
|
---|
381 | cstr_value = value.getcstr ();
|
---|
382 |
|
---|
383 | if (section == "gsdl") {
|
---|
384 |
|
---|
385 | if (key == "enterlib") {
|
---|
386 | gsdl_enterlib = value;
|
---|
387 |
|
---|
388 | // 'logfilename' should occur in the configuration file
|
---|
389 | // before 'keeplog'
|
---|
390 | } else if (key == "logfilename") {
|
---|
391 | strcpy (gsdl_log_name, cstr_value);
|
---|
392 |
|
---|
393 | } else if (key == "keeplog") {
|
---|
394 | gsdl_keep_log = value.getint();
|
---|
395 | if (gsdl_keep_log) open_log_file();
|
---|
396 |
|
---|
397 | } else if (key == "consolelog") {
|
---|
398 | if (value.getint()) activate_console();
|
---|
399 | else deactivate_console();
|
---|
400 |
|
---|
401 | } else if (key == "portnumber") {
|
---|
402 | gsdl_port_num = value.getint();
|
---|
403 |
|
---|
404 | } else if (key == "autoenter") {
|
---|
405 | gsdl_auto_enter = value.getint();
|
---|
406 |
|
---|
407 | } else if (key == "browser") {
|
---|
408 | gsdl_browser = value.getint();
|
---|
409 |
|
---|
410 | } else if (key == "browserexe") {
|
---|
411 | strcpy (gsdl_browser_exe, cstr_value);
|
---|
412 |
|
---|
413 | } else if (key == "collections") {
|
---|
414 | gsdl_collections = value;
|
---|
415 |
|
---|
416 | // gsdlhome must occur in file before gdbmhome
|
---|
417 | } else if (key == "gsdlhome") {
|
---|
418 | gsdl_gsdlhome = value;
|
---|
419 | gsdl_gdbmhome = value;
|
---|
420 |
|
---|
421 | } else if (key == "gdbmhome") {
|
---|
422 | gsdl_gdbmhome = value;
|
---|
423 | }
|
---|
424 | } else {
|
---|
425 |
|
---|
426 | // gsdlhome must occur in file before gdbmhome
|
---|
427 | if (key == "gsdlhome") {
|
---|
428 | gsdl_collectinfo[section].gsdl_gsdlhome = value;
|
---|
429 | gsdl_collectinfo[section].gsdl_gdbmhome = value;
|
---|
430 | } else if (key == "gdbmhome") {
|
---|
431 | gsdl_collectinfo[section].gsdl_gdbmhome = value;
|
---|
432 | }
|
---|
433 | }
|
---|
434 | delete cstr_value;
|
---|
435 | }
|
---|
436 | }
|
---|
437 | conf.close();
|
---|
438 | }
|
---|
439 |
|
---|
440 | // check the homes to make sure they don't contain
|
---|
441 | // extra slashes at the end
|
---|
442 | remove_end_slashes (gsdl_gsdlhome);
|
---|
443 | remove_end_slashes (gsdl_gdbmhome);
|
---|
444 | colinfo_tmap::iterator here = gsdl_collectinfo.begin();
|
---|
445 | colinfo_tmap::iterator end = gsdl_collectinfo.end();
|
---|
446 | while (here != end) {
|
---|
447 | remove_end_slashes ((*here).second.gsdl_gsdlhome);
|
---|
448 | remove_end_slashes ((*here).second.gsdl_gdbmhome);
|
---|
449 | here ++;
|
---|
450 | }
|
---|
451 |
|
---|
452 | // check the browser settings
|
---|
453 | check_browser_settings (gsdl_browser, gsdl_browser_exe, netscapeneeded);
|
---|
454 | }
|
---|
455 |
|
---|
456 | void gsdl_check_browser_settings (int netscapeneeded) {
|
---|
457 | check_installed_browsers (netscapeneeded);
|
---|
458 | check_browser_settings (gsdl_browser, gsdl_browser_exe, netscapeneeded);
|
---|
459 | }
|
---|
460 |
|
---|
461 |
|
---|
462 | static void dialog_update_enables (HWND hwndDlg) {
|
---|
463 | int res;
|
---|
464 |
|
---|
465 | // if they want to use another browser, they should be able
|
---|
466 | // edit its filename
|
---|
467 | res = SendDlgItemMessage(hwndDlg, ID_RADIO_OTHER, BM_GETCHECK,0,0);
|
---|
468 | SendDlgItemMessage(hwndDlg, ID_OTHER_NAME, WM_ENABLE, (res == 1), 0);
|
---|
469 | }
|
---|
470 |
|
---|
471 |
|
---|
472 | static int read_dialog_browser_field (HWND hwndDlg) {
|
---|
473 | if (SendDlgItemMessage(hwndDlg, ID_RADIO_NETSCAPE,
|
---|
474 | BM_GETCHECK, 0, 0) == 1) return GS_NETSCAPE;
|
---|
475 | if (SendDlgItemMessage(hwndDlg, ID_RADIO_IE,
|
---|
476 | BM_GETCHECK, 0, 0) == 1) return GS_IEXPLORE;
|
---|
477 | if (SendDlgItemMessage(hwndDlg, ID_RADIO_OTHER,
|
---|
478 | BM_GETCHECK, 0, 0) == 1) return GS_OTHER;
|
---|
479 | return GS_NETSCAPE;
|
---|
480 | }
|
---|
481 |
|
---|
482 |
|
---|
483 |
|
---|
484 | static void set_dialog_browser_field (HWND hwndDlg, int browser, char *othername) {
|
---|
485 | // if we are trying to set the browser to netscape or
|
---|
486 | // internet explorer and we can't find them, set the browser
|
---|
487 | // to 'other'
|
---|
488 | if ((browser == GS_NETSCAPE) && (netscape_exe[0] == '\0'))
|
---|
489 | browser = GS_IEXPLORE;
|
---|
490 | if ((browser == GS_IEXPLORE) && (iexplore_exe[0] == '\0')) {
|
---|
491 | if (netscape_exe[0] != '\0') browser = GS_NETSCAPE;
|
---|
492 | else browser = GS_OTHER;
|
---|
493 | }
|
---|
494 |
|
---|
495 | // update the radio buttons
|
---|
496 | SendDlgItemMessage(hwndDlg, ID_RADIO_NETSCAPE, BM_SETCHECK,
|
---|
497 | (browser == GS_NETSCAPE) ? BST_CHECKED : BST_UNCHECKED, 0);
|
---|
498 | SendDlgItemMessage(hwndDlg, ID_RADIO_IE, BM_SETCHECK,
|
---|
499 | (browser == GS_IEXPLORE) ? BST_CHECKED : BST_UNCHECKED, 0);
|
---|
500 | SendDlgItemMessage(hwndDlg, ID_RADIO_OTHER, BM_SETCHECK,
|
---|
501 | (browser == GS_OTHER) ? BST_CHECKED : BST_UNCHECKED, 0);
|
---|
502 |
|
---|
503 | // update the other name field
|
---|
504 | if (browser == GS_NETSCAPE) {
|
---|
505 | SetDlgItemText(hwndDlg, ID_OTHER_NAME, netscape_exe);
|
---|
506 | } else if (browser == GS_IEXPLORE) {
|
---|
507 | SetDlgItemText(hwndDlg, ID_OTHER_NAME, iexplore_exe);
|
---|
508 | } else if (othername != NULL) {
|
---|
509 | SetDlgItemText(hwndDlg, ID_OTHER_NAME, othername);
|
---|
510 | }
|
---|
511 | }
|
---|
512 |
|
---|
513 |
|
---|
514 | static void read_browser_exe_field (HWND hwndDlg, char *filename, int maxsize) {
|
---|
515 | filename[0] = '\0';
|
---|
516 | GetDlgItemText(hwndDlg, ID_OTHER_NAME, filename, maxsize);
|
---|
517 | }
|
---|
518 |
|
---|
519 |
|
---|
520 | static void read_dialog_fields (HWND hwndDlg) {
|
---|
521 | int res; BOOL bres;
|
---|
522 |
|
---|
523 | // port number
|
---|
524 | gsdl_port_num = GetDlgItemInt(hwndDlg, SERVER_PORT_EDIT_BOX, &bres, 0);
|
---|
525 | if (!bres) gsdl_port_num = 80;
|
---|
526 |
|
---|
527 | // whether to enter the library automatically on startup
|
---|
528 | res = SendDlgItemMessage(hwndDlg, ID_AUTO_ENTER_LIBRARY, BM_GETCHECK, 0, 0);
|
---|
529 | gsdl_auto_enter = (res == 1);
|
---|
530 |
|
---|
531 | // which browser to use
|
---|
532 | gsdl_browser = read_dialog_browser_field (hwndDlg);
|
---|
533 |
|
---|
534 | // find out where the browser exe lives
|
---|
535 | read_browser_exe_field (hwndDlg, gsdl_browser_exe, MAX_FILENAME_SIZE);
|
---|
536 | }
|
---|
537 |
|
---|
538 |
|
---|
539 |
|
---|
540 |
|
---|
541 | static BOOL CALLBACK dialog_proc(HWND hwndDlg, UINT uMsg,
|
---|
542 | WPARAM wParam,LPARAM lParam) {
|
---|
543 | int wNotifyCode = HIWORD(wParam);
|
---|
544 | int wID = LOWORD(wParam);
|
---|
545 | char *filefilter = "Program Files (*.exe)\0*.exe\0All Files (*.*)\0*.*\0\0";
|
---|
546 | OPENFILENAME fname;
|
---|
547 | char filename[MAX_FILENAME_SIZE];
|
---|
548 |
|
---|
549 | switch (uMsg) {
|
---|
550 | case WM_INITDIALOG:
|
---|
551 | // set current values
|
---|
552 | SetDlgItemInt(hwndDlg, SERVER_PORT_EDIT_BOX, gsdl_port_num, FALSE);
|
---|
553 | SendDlgItemMessage(hwndDlg, ID_AUTO_ENTER_LIBRARY, BM_SETCHECK,
|
---|
554 | gsdl_auto_enter ? 1 : 0, 0);
|
---|
555 | set_dialog_browser_field (hwndDlg, gsdl_browser, gsdl_browser_exe);
|
---|
556 | dialog_update_enables(hwndDlg);
|
---|
557 |
|
---|
558 | // make sure that the netscape and internet explorer
|
---|
559 | // radio buttons are only enabled if they could be found
|
---|
560 | if (netscape_exe[0] == '\0')
|
---|
561 | EnableWindow (GetDlgItem (hwndDlg, ID_RADIO_NETSCAPE), FALSE);
|
---|
562 | if (iexplore_exe[0] == '\0')
|
---|
563 | EnableWindow (GetDlgItem (hwndDlg, ID_RADIO_IE), FALSE);
|
---|
564 |
|
---|
565 | return 1;
|
---|
566 |
|
---|
567 | case WM_COMMAND:
|
---|
568 | if (wNotifyCode == BN_CLICKED) {
|
---|
569 | switch (wID) {
|
---|
570 | case ID_CANCEL_BUTTON:
|
---|
571 | EndDialog(hwndDlg, 0);
|
---|
572 | return 1;
|
---|
573 |
|
---|
574 | case ID_OK_BUTTON:
|
---|
575 | // check to make sure we can find the browser
|
---|
576 | filename[0] = '\0';
|
---|
577 | read_browser_exe_field (hwndDlg, filename, MAX_FILENAME_SIZE);
|
---|
578 | if (check_program_exe (filename)) {
|
---|
579 | // the file exists
|
---|
580 | // if netscape is needed, make sure the browser is netscape
|
---|
581 | _strlwr(filename);
|
---|
582 | if (!gsdl_netscapeneeded || strstr (filename, "netscape.exe") != NULL) {
|
---|
583 | // everything is ok
|
---|
584 | read_dialog_fields(hwndDlg);
|
---|
585 | EndDialog(hwndDlg, 1);
|
---|
586 |
|
---|
587 | } else {
|
---|
588 | // message: must use netscape with this version
|
---|
589 | MessageBox(hwndDlg,
|
---|
590 | "You are using this software on a machine which\n"
|
---|
591 | "currently does not have a working TCP/IP network layer.\n"
|
---|
592 | "To allow the Greenstone Digital Library software to use\n"
|
---|
593 | "its own TCP/IP network layer you must use a Netscape\n"
|
---|
594 | "browser. If you do not have Netscape installed, please\n"
|
---|
595 | "choose 'Install Netscape 4.05' from the 'Files' menu.",
|
---|
596 | "Greenstone Digital Library Software",
|
---|
597 | MB_OK|MB_APPLMODAL);
|
---|
598 | }
|
---|
599 | } else {
|
---|
600 | // message: the file did not exist
|
---|
601 | MessageBox(hwndDlg,
|
---|
602 | "Could not find the selected browser. If you do not\n"
|
---|
603 | "have a browser installed, please choose\n"
|
---|
604 | "'Install Netscape 4.05' from the 'Files' menu.",
|
---|
605 | "Greenstone Digital Library Software",
|
---|
606 | MB_OK|MB_APPLMODAL);
|
---|
607 | }
|
---|
608 | return 1;
|
---|
609 |
|
---|
610 | case ID_RADIO_NETSCAPE:
|
---|
611 | set_dialog_browser_field (hwndDlg, GS_NETSCAPE, NULL);
|
---|
612 | dialog_update_enables(hwndDlg);
|
---|
613 | return 1;
|
---|
614 |
|
---|
615 | case ID_RADIO_IE:
|
---|
616 | set_dialog_browser_field (hwndDlg, GS_IEXPLORE, NULL);
|
---|
617 | dialog_update_enables(hwndDlg);
|
---|
618 | return 1;
|
---|
619 |
|
---|
620 | case ID_RADIO_OTHER:
|
---|
621 | set_dialog_browser_field (hwndDlg, GS_OTHER, NULL);
|
---|
622 | dialog_update_enables(hwndDlg);
|
---|
623 | return 1;
|
---|
624 |
|
---|
625 | case ID_BROWSE_BUTTON:
|
---|
626 | filename[0] = '\0';
|
---|
627 | memset(&fname, 0, sizeof(OPENFILENAME));
|
---|
628 | fname.lStructSize = sizeof(OPENFILENAME);
|
---|
629 | fname.hwndOwner = hwndDlg;
|
---|
630 | fname.hInstance = NULL;
|
---|
631 | fname.lpstrFilter = filefilter;
|
---|
632 | fname.lpstrCustomFilter = NULL;
|
---|
633 | fname.nMaxCustFilter = 0;
|
---|
634 | fname.nFilterIndex = 1;
|
---|
635 | fname.lpstrFile = filename;
|
---|
636 | fname.nMaxFile = MAX_FILENAME_SIZE-1;
|
---|
637 | fname.lpstrFileTitle = NULL;
|
---|
638 | fname.nMaxFileTitle = 0;
|
---|
639 | fname.lpstrInitialDir = NULL;
|
---|
640 | fname.lpstrTitle = "Choose Web Browser";
|
---|
641 | fname.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
|
---|
642 |
|
---|
643 | if(GetOpenFileName(&fname)) {
|
---|
644 | set_dialog_browser_field (hwndDlg, GS_OTHER, filename);
|
---|
645 | dialog_update_enables(hwndDlg);
|
---|
646 | }
|
---|
647 | return 1;
|
---|
648 | }
|
---|
649 | }
|
---|
650 | return 0;
|
---|
651 |
|
---|
652 | case WM_CLOSE:
|
---|
653 | case WM_DESTROY:
|
---|
654 | EndDialog(hwndDlg, 0);
|
---|
655 | return 1;
|
---|
656 | }
|
---|
657 |
|
---|
658 | return 0;
|
---|
659 | }
|
---|
660 |
|
---|
661 | static void dialog_debug_update_enables (HWND hwndDlg) {
|
---|
662 | int res;
|
---|
663 |
|
---|
664 | // if they want a log of program use allow them to
|
---|
665 | // edit its filename
|
---|
666 | res = SendDlgItemMessage(hwndDlg, LOG_CHECK, BM_GETCHECK,0,0);
|
---|
667 | SendDlgItemMessage(hwndDlg, LOG_NAME_BOX, WM_ENABLE, (res == 1), 0);
|
---|
668 | }
|
---|
669 |
|
---|
670 |
|
---|
671 | static void read_dialog_debug_fields (HWND hwndDlg) {
|
---|
672 | int res;
|
---|
673 |
|
---|
674 | // whether to log program use
|
---|
675 | res = SendDlgItemMessage(hwndDlg, LOG_CHECK, BM_GETCHECK,0,0);
|
---|
676 | gsdl_keep_log = (res == 1);
|
---|
677 |
|
---|
678 | // log filename
|
---|
679 | res = SendDlgItemMessage(hwndDlg, LOG_NAME_BOX, EM_GETMODIFY,0,0);
|
---|
680 | if (res != 0) {
|
---|
681 | res = GetDlgItemText(hwndDlg, LOG_NAME_BOX, gsdl_log_name, MAX_FILENAME_SIZE);
|
---|
682 | }
|
---|
683 |
|
---|
684 | // whether to display log information on console
|
---|
685 | res = SendDlgItemMessage(hwndDlg, CONSOLE_CHECK, BM_GETCHECK,0,0);
|
---|
686 | gsdl_show_console = (res == 1);
|
---|
687 | }
|
---|
688 |
|
---|
689 |
|
---|
690 | static BOOL CALLBACK dialog_debug_proc(HWND hwndDlg, UINT uMsg,
|
---|
691 | WPARAM wParam,LPARAM lParam) {
|
---|
692 | int wNotifyCode = HIWORD(wParam);
|
---|
693 | int wID = LOWORD(wParam);
|
---|
694 |
|
---|
695 | switch (uMsg) {
|
---|
696 | case WM_INITDIALOG:
|
---|
697 | // set current values
|
---|
698 | SendDlgItemMessage(hwndDlg, LOG_CHECK, BM_SETCHECK,
|
---|
699 | gsdl_keep_log ? 1 : 0, 0);
|
---|
700 | SetDlgItemText(hwndDlg, LOG_NAME_BOX, gsdl_log_name);
|
---|
701 | SendDlgItemMessage(hwndDlg, CONSOLE_CHECK, BM_SETCHECK,
|
---|
702 | gsdl_show_console ? 1 : 0, 0);
|
---|
703 | dialog_debug_update_enables(hwndDlg);
|
---|
704 | return 1;
|
---|
705 |
|
---|
706 | case WM_COMMAND:
|
---|
707 | if (wNotifyCode == BN_CLICKED) {
|
---|
708 | switch (wID) {
|
---|
709 | case ID_CANCEL_BUTTON:
|
---|
710 | EndDialog(hwndDlg, 0);
|
---|
711 | return 1;
|
---|
712 |
|
---|
713 | case ID_OK_BUTTON:
|
---|
714 | read_dialog_debug_fields(hwndDlg);
|
---|
715 | EndDialog(hwndDlg, 1);
|
---|
716 | return 1;
|
---|
717 |
|
---|
718 | case LOG_CHECK:
|
---|
719 | dialog_debug_update_enables(hwndDlg);
|
---|
720 | return 1;
|
---|
721 | }
|
---|
722 | }
|
---|
723 | return 0;
|
---|
724 |
|
---|
725 | case WM_CLOSE:
|
---|
726 | case WM_DESTROY:
|
---|
727 | EndDialog(hwndDlg, 0);
|
---|
728 | return 1;
|
---|
729 | }
|
---|
730 |
|
---|
731 | return 0;
|
---|
732 | }
|
---|
733 |
|
---|
734 |
|
---|
735 | void Settings_Dialog(HWND window, int netscapeneeded)
|
---|
736 | {
|
---|
737 | int old_gsdl_show_console = gsdl_show_console;
|
---|
738 | int old_gsdl_port_num = gsdl_port_num;
|
---|
739 |
|
---|
740 | int res = 0;
|
---|
741 |
|
---|
742 | gsdl_netscapeneeded = netscapeneeded;
|
---|
743 |
|
---|
744 | if ((GetAsyncKeyState(VK_CONTROL) & 0x8000) &&
|
---|
745 | (GetAsyncKeyState(VkKeyScan('d')) & 0x8000)) {
|
---|
746 | // control-D was pressed, display debug settings
|
---|
747 | // dialog box
|
---|
748 | res = DialogBox (NULL, MAKEINTRESOURCE(COMMS_DIALOG_DEBUG),
|
---|
749 | window, (DLGPROC)dialog_debug_proc);
|
---|
750 |
|
---|
751 | if (res == 1) {
|
---|
752 | // only update if exited via the OK button
|
---|
753 | if (gsdl_keep_log) open_log_file();
|
---|
754 | else close_log_file();
|
---|
755 |
|
---|
756 | // turn the console on/off if we need to
|
---|
757 | if (gsdl_show_console != old_gsdl_show_console) {
|
---|
758 | if (gsdl_show_console) activate_console ();
|
---|
759 | else deactivate_console ();
|
---|
760 | }
|
---|
761 | }
|
---|
762 |
|
---|
763 | } else {
|
---|
764 | // display normal settings dialog box
|
---|
765 |
|
---|
766 | // make sure everything is up-to-date
|
---|
767 | gsdl_check_browser_settings (netscapeneeded);
|
---|
768 |
|
---|
769 | res = DialogBox (NULL, MAKEINTRESOURCE(COMMS_DIALOG2),
|
---|
770 | window, (DLGPROC)dialog_proc);
|
---|
771 |
|
---|
772 | if (res == 1) {
|
---|
773 | // only update if exited via the OK button
|
---|
774 | if (gsdl_port_num != old_gsdl_port_num) {
|
---|
775 | EndHTTPServer();
|
---|
776 | StartHTTPServer(window);
|
---|
777 | }
|
---|
778 | }
|
---|
779 | }
|
---|
780 |
|
---|
781 | // save the settings if we exited via the ok button
|
---|
782 | if (res == 1) {
|
---|
783 | write_settings();
|
---|
784 | // reset httpprefix in case port number was changed
|
---|
785 | // configure_httpprefix ();
|
---|
786 | }
|
---|
787 | }
|
---|