source: trunk/gsdl/src/w32server/settings.cpp@ 10648

Last change on this file since 10648 was 10648, checked in by mdewsnip, 19 years ago

Changed the default address resolution method to "1": get an IP, but don't resolve it to a name. Always using 127.0.0.1 didn't work in Fiji, unfortunately.

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