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

Last change on this file since 2309 was 2309, checked in by sjboddie, 23 years ago

Removed the "/cgi-bin" from local library urls as it was only there to
make us unix people feel better and caused unnecessary complications.

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