source: main/tags/2.51-jcdl/gsdl/src/w32server/settings.cpp@ 25382

Last change on this file since 25382 was 4642, checked in by sjboddie, 21 years ago

Added command line arguments to server.exe so the GLI can tell it to use
an alternative config file.

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