source: trunk/gsdl/src/library/settings.cpp@ 492

Last change on this file since 492 was 20, checked in by sjboddie, 26 years ago

Added w32server files to src/library

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