source: gsdl/trunk/runtime-src/src/w32server/settings.cpp@ 17987

Last change on this file since 17987 was 17987, checked in by kjdon, 15 years ago

fixed a typo: collecct

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