source: branches/New_Config_Format-branch/gsdl/src/w32server/settings.cpp@ 1279

Last change on this file since 1279 was 1279, checked in by sjboddie, 24 years ago

merged changes to trunk into New_Config_Format branch

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