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

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

The old windows local library gsdl.ini file is now called gsdlsite.cfg
to tie in more closely with the web library.

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 22.0 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, "\\gsdlsite.cfg");
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, "\\gsdlsite.cfg");
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 (key.empty()) continue;
379 if (value.empty()) {
380 // should be a section title
381 section = key;
382 // remove square brackets
383 section.erase (section.begin());
384 section.erase (section.end()-1);
385
386 } else {
387
388 cstr_value = value.getcstr ();
389
390 if (section == "gsdl") {
391
392 if (key == "enterlib") {
393 gsdl_enterlib = value;
394
395 // 'logfilename' should occur in the configuration file
396 // before 'keeplog'
397 } else if (key == "logfilename") {
398 strcpy (gsdl_log_name, cstr_value);
399
400 } else if (key == "keeplog") {
401 gsdl_keep_log = value.getint();
402 if (gsdl_keep_log) open_log_file();
403
404 } else if (key == "consolelog") {
405 if (value.getint()) activate_console();
406 else deactivate_console();
407
408 } else if (key == "portnumber") {
409 gsdl_port_num = value.getint();
410
411 } else if (key == "autoenter") {
412 gsdl_auto_enter = value.getint();
413
414 } else if (key == "browser") {
415 gsdl_browser = value.getint();
416
417 } else if (key == "browserexe") {
418 strcpy (gsdl_browser_exe, cstr_value);
419
420 } else if (key == "collections") {
421 gsdl_collections = value;
422
423 // gsdlhome must occur in file before gdbmhome
424 } else if (key == "gsdlhome") {
425 gsdl_gsdlhome = value;
426 gsdl_gdbmhome = value;
427
428 } else if (key == "gdbmhome") {
429 gsdl_gdbmhome = value;
430 }
431 } else {
432
433 // gsdlhome must occur in file before gdbmhome
434 if (key == "gsdlhome") {
435 gsdl_collectinfo[section].gsdl_gsdlhome = value;
436 gsdl_collectinfo[section].gsdl_gdbmhome = value;
437 } else if (key == "gdbmhome") {
438 gsdl_collectinfo[section].gsdl_gdbmhome = value;
439 }
440 }
441 delete cstr_value;
442 }
443 }
444 conf.close();
445 }
446
447 // check the homes to make sure they don't contain
448 // extra slashes at the end
449 remove_end_slashes (gsdl_gsdlhome);
450 remove_end_slashes (gsdl_gdbmhome);
451 colinfo_tmap::iterator here = gsdl_collectinfo.begin();
452 colinfo_tmap::iterator end = gsdl_collectinfo.end();
453 while (here != end) {
454 remove_end_slashes ((*here).second.gsdl_gsdlhome);
455 remove_end_slashes ((*here).second.gsdl_gdbmhome);
456 here ++;
457 }
458
459 // check the browser settings
460 check_browser_settings (gsdl_browser, gsdl_browser_exe, netscapeneeded);
461}
462
463void gsdl_check_browser_settings (int netscapeneeded) {
464 check_installed_browsers (netscapeneeded);
465 check_browser_settings (gsdl_browser, gsdl_browser_exe, netscapeneeded);
466}
467
468
469static void dialog_update_enables (HWND hwndDlg) {
470 int res;
471
472 // if they want to use another browser, they should be able
473 // edit its filename
474 res = SendDlgItemMessage(hwndDlg, ID_RADIO_OTHER, BM_GETCHECK,0,0);
475 SendDlgItemMessage(hwndDlg, ID_OTHER_NAME, WM_ENABLE, (res == 1), 0);
476}
477
478
479static int read_dialog_browser_field (HWND hwndDlg) {
480 if (SendDlgItemMessage(hwndDlg, ID_RADIO_NETSCAPE,
481 BM_GETCHECK, 0, 0) == 1) return GS_NETSCAPE;
482 if (SendDlgItemMessage(hwndDlg, ID_RADIO_IE,
483 BM_GETCHECK, 0, 0) == 1) return GS_IEXPLORE;
484 if (SendDlgItemMessage(hwndDlg, ID_RADIO_OTHER,
485 BM_GETCHECK, 0, 0) == 1) return GS_OTHER;
486 return GS_NETSCAPE;
487}
488
489
490
491static void set_dialog_browser_field (HWND hwndDlg, int browser, char *othername) {
492 // if we are trying to set the browser to netscape or
493 // internet explorer and we can't find them, set the browser
494 // to 'other'
495 if ((browser == GS_NETSCAPE) && (netscape_exe[0] == '\0'))
496 browser = GS_IEXPLORE;
497 if ((browser == GS_IEXPLORE) && (iexplore_exe[0] == '\0')) {
498 if (netscape_exe[0] != '\0') browser = GS_NETSCAPE;
499 else browser = GS_OTHER;
500 }
501
502 // update the radio buttons
503 SendDlgItemMessage(hwndDlg, ID_RADIO_NETSCAPE, BM_SETCHECK,
504 (browser == GS_NETSCAPE) ? BST_CHECKED : BST_UNCHECKED, 0);
505 SendDlgItemMessage(hwndDlg, ID_RADIO_IE, BM_SETCHECK,
506 (browser == GS_IEXPLORE) ? BST_CHECKED : BST_UNCHECKED, 0);
507 SendDlgItemMessage(hwndDlg, ID_RADIO_OTHER, BM_SETCHECK,
508 (browser == GS_OTHER) ? BST_CHECKED : BST_UNCHECKED, 0);
509
510 // update the other name field
511 if (browser == GS_NETSCAPE) {
512 SetDlgItemText(hwndDlg, ID_OTHER_NAME, netscape_exe);
513 } else if (browser == GS_IEXPLORE) {
514 SetDlgItemText(hwndDlg, ID_OTHER_NAME, iexplore_exe);
515 } else if (othername != NULL) {
516 SetDlgItemText(hwndDlg, ID_OTHER_NAME, othername);
517 }
518}
519
520
521static void read_browser_exe_field (HWND hwndDlg, char *filename, int maxsize) {
522 filename[0] = '\0';
523 GetDlgItemText(hwndDlg, ID_OTHER_NAME, filename, maxsize);
524}
525
526
527static void read_dialog_fields (HWND hwndDlg) {
528 int res; BOOL bres;
529
530 // port number
531 gsdl_port_num = GetDlgItemInt(hwndDlg, SERVER_PORT_EDIT_BOX, &bres, 0);
532 if (!bres) gsdl_port_num = 80;
533
534 // whether to enter the library automatically on startup
535 res = SendDlgItemMessage(hwndDlg, ID_AUTO_ENTER_LIBRARY, BM_GETCHECK, 0, 0);
536 gsdl_auto_enter = (res == 1);
537
538 // which browser to use
539 gsdl_browser = read_dialog_browser_field (hwndDlg);
540
541 // find out where the browser exe lives
542 read_browser_exe_field (hwndDlg, gsdl_browser_exe, MAX_FILENAME_SIZE);
543}
544
545
546
547
548static BOOL CALLBACK dialog_proc(HWND hwndDlg, UINT uMsg,
549 WPARAM wParam,LPARAM lParam) {
550 int wNotifyCode = HIWORD(wParam);
551 int wID = LOWORD(wParam);
552 char *filefilter = "Program Files (*.exe)\0*.exe\0All Files (*.*)\0*.*\0\0";
553 OPENFILENAME fname;
554 char filename[MAX_FILENAME_SIZE];
555
556 switch (uMsg) {
557 case WM_INITDIALOG:
558 // set current values
559 SetDlgItemInt(hwndDlg, SERVER_PORT_EDIT_BOX, gsdl_port_num, FALSE);
560 SendDlgItemMessage(hwndDlg, ID_AUTO_ENTER_LIBRARY, BM_SETCHECK,
561 gsdl_auto_enter ? 1 : 0, 0);
562 set_dialog_browser_field (hwndDlg, gsdl_browser, gsdl_browser_exe);
563 dialog_update_enables(hwndDlg);
564
565 // make sure that the netscape and internet explorer
566 // radio buttons are only enabled if they could be found
567 if (netscape_exe[0] == '\0')
568 EnableWindow (GetDlgItem (hwndDlg, ID_RADIO_NETSCAPE), FALSE);
569 if (iexplore_exe[0] == '\0')
570 EnableWindow (GetDlgItem (hwndDlg, ID_RADIO_IE), FALSE);
571
572 return 1;
573
574 case WM_COMMAND:
575 if (wNotifyCode == BN_CLICKED) {
576 switch (wID) {
577 case ID_CANCEL_BUTTON:
578 EndDialog(hwndDlg, 0);
579 return 1;
580
581 case ID_OK_BUTTON:
582 // check to make sure we can find the browser
583 filename[0] = '\0';
584 read_browser_exe_field (hwndDlg, filename, MAX_FILENAME_SIZE);
585 if (check_program_exe (filename)) {
586 // the file exists
587 // if netscape is needed, make sure the browser is netscape
588 _strlwr(filename);
589 if (!gsdl_netscapeneeded || strstr (filename, "netscape.exe") != NULL) {
590 // everything is ok
591 read_dialog_fields(hwndDlg);
592 EndDialog(hwndDlg, 1);
593
594 } else {
595 // message: must use netscape with this version
596 MessageBox(hwndDlg,
597 "You are using this software on a machine which\n"
598 "currently does not have a working TCP/IP network layer.\n"
599 "To allow the Greenstone Digital Library software to use\n"
600 "its own TCP/IP network layer you must use a Netscape\n"
601 "browser. If you do not have Netscape installed, please\n"
602 "choose 'Install Netscape 4.05' from the 'Files' menu.",
603 "Greenstone Digital Library Software",
604 MB_OK|MB_APPLMODAL);
605 }
606 } else {
607 // message: the file did not exist
608 MessageBox(hwndDlg,
609 "Could not find the selected browser. If you do not\n"
610 "have a browser installed, please choose\n"
611 "'Install Netscape 4.05' from the 'Files' menu.",
612 "Greenstone Digital Library Software",
613 MB_OK|MB_APPLMODAL);
614 }
615 return 1;
616
617 case ID_RADIO_NETSCAPE:
618 set_dialog_browser_field (hwndDlg, GS_NETSCAPE, NULL);
619 dialog_update_enables(hwndDlg);
620 return 1;
621
622 case ID_RADIO_IE:
623 set_dialog_browser_field (hwndDlg, GS_IEXPLORE, NULL);
624 dialog_update_enables(hwndDlg);
625 return 1;
626
627 case ID_RADIO_OTHER:
628 set_dialog_browser_field (hwndDlg, GS_OTHER, NULL);
629 dialog_update_enables(hwndDlg);
630 return 1;
631
632 case ID_BROWSE_BUTTON:
633 filename[0] = '\0';
634 memset(&fname, 0, sizeof(OPENFILENAME));
635 fname.lStructSize = sizeof(OPENFILENAME);
636 fname.hwndOwner = hwndDlg;
637 fname.hInstance = NULL;
638 fname.lpstrFilter = filefilter;
639 fname.lpstrCustomFilter = NULL;
640 fname.nMaxCustFilter = 0;
641 fname.nFilterIndex = 1;
642 fname.lpstrFile = filename;
643 fname.nMaxFile = MAX_FILENAME_SIZE-1;
644 fname.lpstrFileTitle = NULL;
645 fname.nMaxFileTitle = 0;
646 fname.lpstrInitialDir = NULL;
647 fname.lpstrTitle = "Choose Web Browser";
648 fname.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
649
650 if(GetOpenFileName(&fname)) {
651 set_dialog_browser_field (hwndDlg, GS_OTHER, filename);
652 dialog_update_enables(hwndDlg);
653 }
654 return 1;
655 }
656 }
657 return 0;
658
659 case WM_CLOSE:
660 case WM_DESTROY:
661 EndDialog(hwndDlg, 0);
662 return 1;
663 }
664
665 return 0;
666}
667
668static void dialog_debug_update_enables (HWND hwndDlg) {
669 int res;
670
671 // if they want a log of program use allow them to
672 // edit its filename
673 res = SendDlgItemMessage(hwndDlg, LOG_CHECK, BM_GETCHECK,0,0);
674 SendDlgItemMessage(hwndDlg, LOG_NAME_BOX, WM_ENABLE, (res == 1), 0);
675}
676
677
678static void read_dialog_debug_fields (HWND hwndDlg) {
679 int res;
680
681 // whether to log program use
682 res = SendDlgItemMessage(hwndDlg, LOG_CHECK, BM_GETCHECK,0,0);
683 gsdl_keep_log = (res == 1);
684
685 // log filename
686 res = SendDlgItemMessage(hwndDlg, LOG_NAME_BOX, EM_GETMODIFY,0,0);
687 if (res != 0) {
688 res = GetDlgItemText(hwndDlg, LOG_NAME_BOX, gsdl_log_name, MAX_FILENAME_SIZE);
689 }
690
691 // whether to display log information on console
692 res = SendDlgItemMessage(hwndDlg, CONSOLE_CHECK, BM_GETCHECK,0,0);
693 gsdl_show_console = (res == 1);
694}
695
696
697static BOOL CALLBACK dialog_debug_proc(HWND hwndDlg, UINT uMsg,
698 WPARAM wParam,LPARAM lParam) {
699 int wNotifyCode = HIWORD(wParam);
700 int wID = LOWORD(wParam);
701
702 switch (uMsg) {
703 case WM_INITDIALOG:
704 // set current values
705 SendDlgItemMessage(hwndDlg, LOG_CHECK, BM_SETCHECK,
706 gsdl_keep_log ? 1 : 0, 0);
707 SetDlgItemText(hwndDlg, LOG_NAME_BOX, gsdl_log_name);
708 SendDlgItemMessage(hwndDlg, CONSOLE_CHECK, BM_SETCHECK,
709 gsdl_show_console ? 1 : 0, 0);
710 dialog_debug_update_enables(hwndDlg);
711 return 1;
712
713 case WM_COMMAND:
714 if (wNotifyCode == BN_CLICKED) {
715 switch (wID) {
716 case ID_CANCEL_BUTTON:
717 EndDialog(hwndDlg, 0);
718 return 1;
719
720 case ID_OK_BUTTON:
721 read_dialog_debug_fields(hwndDlg);
722 EndDialog(hwndDlg, 1);
723 return 1;
724
725 case LOG_CHECK:
726 dialog_debug_update_enables(hwndDlg);
727 return 1;
728 }
729 }
730 return 0;
731
732 case WM_CLOSE:
733 case WM_DESTROY:
734 EndDialog(hwndDlg, 0);
735 return 1;
736 }
737
738 return 0;
739}
740
741
742void Settings_Dialog(HWND window, int netscapeneeded)
743{
744 int old_gsdl_show_console = gsdl_show_console;
745 int old_gsdl_port_num = gsdl_port_num;
746
747 int res = 0;
748
749 gsdl_netscapeneeded = netscapeneeded;
750
751 if ((GetAsyncKeyState(VK_CONTROL) & 0x8000) &&
752 (GetAsyncKeyState(VkKeyScan('d')) & 0x8000)) {
753 // control-D was pressed, display debug settings
754 // dialog box
755 res = DialogBox (NULL, MAKEINTRESOURCE(COMMS_DIALOG_DEBUG),
756 window, (DLGPROC)dialog_debug_proc);
757
758 if (res == 1) {
759 // only update if exited via the OK button
760 if (gsdl_keep_log) open_log_file();
761 else close_log_file();
762
763 // turn the console on/off if we need to
764 if (gsdl_show_console != old_gsdl_show_console) {
765 if (gsdl_show_console) activate_console ();
766 else deactivate_console ();
767 }
768 }
769
770 } else {
771 // display normal settings dialog box
772
773 // make sure everything is up-to-date
774 gsdl_check_browser_settings (netscapeneeded);
775
776 res = DialogBox (NULL, MAKEINTRESOURCE(COMMS_DIALOG2),
777 window, (DLGPROC)dialog_proc);
778
779 if (res == 1) {
780 // only update if exited via the OK button
781 if (gsdl_port_num != old_gsdl_port_num) {
782 EndHTTPServer();
783 StartHTTPServer(window);
784 }
785 }
786 }
787
788 // save the settings if we exited via the ok button
789 if (res == 1) {
790 write_settings();
791 // reset httpprefix in case port number was changed
792 // configure_httpprefix ();
793 }
794}
Note: See TracBrowser for help on using the repository browser.