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

Last change on this file since 11143 was 11096, checked in by kjdon, 18 years ago

added in address resolution method selection to settings dialog

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