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

Last change on this file since 611 was 611, checked in by sjboddie, 25 years ago

initial commit of windows server code

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