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

Last change on this file since 15852 was 15625, checked in by mdewsnip, 16 years ago

(Adding new DB support) Replaced a bunch of "gdbmhome" with "dbhome".

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 26.5 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_dbhome;
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_dbhome);
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_dbhome.empty())
324 write_ini_line(fout, "gdbmhome", (*here).second.gsdl_dbhome);
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_dbhome = 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 dbhome
478 } else if (key == "gsdlhome") {
479 gsdl_gsdlhome = value;
480 gsdl_dbhome = value;
481
482 } else if (key == "gdbmhome") {
483 gsdl_dbhome = value;
484 }
485 } else {
486
487 // gsdlhome must occur in file before dbhome
488 if (key == "gsdlhome") {
489 gsdl_collectinfo[section].gsdl_gsdlhome = value;
490 gsdl_collectinfo[section].gsdl_dbhome = value;
491 } else if (key == "gdbmhome") {
492 gsdl_collectinfo[section].gsdl_dbhome = 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_dbhome);
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_dbhome);
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_LOCALHOST,
593 BM_GETCHECK, 0, 0) == 1) return ARM_LOCALHOST;
594 if (SendDlgItemMessage(hwndDlg, ID_ARM_127_0_0_1,
595 BM_GETCHECK, 0, 0) == 1) return ARM_127_0_0_1;
596 return ARM_NAME;
597}
598
599static void set_address_resolution_field (HWND hwndDlg,
600 int address_res_method) {
601 // update the radio buttons
602 SendDlgItemMessage(hwndDlg, ID_ARM_NAME, BM_SETCHECK,
603 (address_res_method == ARM_NAME) ? BST_CHECKED : BST_UNCHECKED, 0);
604 SendDlgItemMessage(hwndDlg, ID_ARM_IP, BM_SETCHECK,
605 (address_res_method == ARM_IP) ? BST_CHECKED : BST_UNCHECKED, 0);
606 SendDlgItemMessage(hwndDlg, ID_ARM_LOCALHOST, BM_SETCHECK,
607 (address_res_method == ARM_LOCALHOST) ? BST_CHECKED : BST_UNCHECKED, 0);
608 SendDlgItemMessage(hwndDlg, ID_ARM_127_0_0_1, BM_SETCHECK,
609 (address_res_method == ARM_127_0_0_1) ? BST_CHECKED : BST_UNCHECKED, 0);
610
611}
612
613static void read_dialog_fields (HWND hwndDlg) {
614 int res; BOOL bres;
615
616 // port number
617 gsdl_port_num = GetDlgItemInt(hwndDlg, SERVER_PORT_EDIT_BOX, &bres, 0);
618 if (!bres) gsdl_port_num = 80;
619
620 // whether to enter the library automatically on startup
621 res = SendDlgItemMessage(hwndDlg, ID_AUTO_ENTER_LIBRARY, BM_GETCHECK, 0, 0);
622 gsdl_auto_enter = (res == 1);
623
624 // which browser to use
625 gsdl_browser = read_dialog_browser_field (hwndDlg);
626
627 // find out where the browser exe lives
628 read_browser_exe_field (hwndDlg, gsdl_browser_exe, MAX_FILENAME_SIZE);
629
630 // which address resolution method
631 gsdl_address_resolution_method = read_address_resolution_field(hwndDlg);
632}
633
634
635
636
637static BOOL CALLBACK dialog_proc(HWND hwndDlg, UINT uMsg,
638 WPARAM wParam,LPARAM lParam) {
639 int wNotifyCode = HIWORD(wParam);
640 int wID = LOWORD(wParam);
641 char *filefilter = "Program Files (*.exe)\0*.exe\0All Files (*.*)\0*.*\0\0";
642 OPENFILENAME fname;
643 char filename[MAX_FILENAME_SIZE];
644
645 switch (uMsg) {
646 case WM_INITDIALOG:
647 // set current values
648 SetDlgItemInt(hwndDlg, SERVER_PORT_EDIT_BOX, gsdl_port_num, FALSE);
649 SendDlgItemMessage(hwndDlg, ID_AUTO_ENTER_LIBRARY, BM_SETCHECK,
650 gsdl_auto_enter ? 1 : 0, 0);
651 set_dialog_browser_field (hwndDlg, gsdl_browser, gsdl_browser_exe);
652 set_address_resolution_field(hwndDlg, gsdl_address_resolution_method);
653 dialog_update_enables(hwndDlg);
654
655 // make sure that the default browser, netscape and internet explorer
656 // radio buttons are only enabled if they could be found
657 if (default_browser_exe[0] == '\0')
658 EnableWindow (GetDlgItem (hwndDlg, ID_RADIO_DEFAULT), FALSE);
659 if (netscape_exe[0] == '\0')
660 EnableWindow (GetDlgItem (hwndDlg, ID_RADIO_NETSCAPE), FALSE);
661 if (iexplore_exe[0] == '\0')
662 EnableWindow (GetDlgItem (hwndDlg, ID_RADIO_IE), FALSE);
663
664 return 1;
665
666 case WM_COMMAND:
667 if (wNotifyCode == BN_CLICKED) {
668 switch (wID) {
669 case ID_CANCEL_BUTTON:
670 EndDialog(hwndDlg, 0);
671 return 1;
672
673 case ID_OK_BUTTON:
674 // check to make sure we can find the browser
675 filename[0] = '\0';
676 read_browser_exe_field (hwndDlg, filename, MAX_FILENAME_SIZE);
677 if (check_program_exe (filename)) {
678 // the file exists
679 // if netscape is needed, make sure the browser is netscape
680 _strlwr(filename);
681 if (!gsdl_netscapeneeded || strstr (filename, "netscape.exe") != NULL) {
682 // everything is ok
683 read_dialog_fields(hwndDlg);
684 EndDialog(hwndDlg, 1);
685
686 } else {
687 // message: must use netscape with this version
688 MessageBox(hwndDlg,
689 "You are using this software on a machine which\n"
690 "currently does not have a working TCP/IP network layer.\n"
691 "To allow the Greenstone Digital Library software to use\n"
692 "its own TCP/IP network layer you must use a Netscape\n"
693 "web browser.",
694 "Greenstone Digital Library Software",
695 MB_OK|MB_APPLMODAL);
696 }
697 } else {
698 // message: the file did not exist
699 MessageBox(hwndDlg,
700 "Could not find the selected browser. You must have a\n"
701 "web browser installed to use the Greenstone Digital\n"
702 "Library software.",
703 "Greenstone Digital Library Software",
704 MB_OK|MB_APPLMODAL);
705 }
706 return 1;
707
708 case ID_RADIO_DEFAULT:
709 set_dialog_browser_field (hwndDlg, GS_DEFAULT, NULL);
710 dialog_update_enables(hwndDlg);
711 return 1;
712
713 case ID_RADIO_NETSCAPE:
714 set_dialog_browser_field (hwndDlg, GS_NETSCAPE, NULL);
715 dialog_update_enables(hwndDlg);
716 return 1;
717
718 case ID_RADIO_IE:
719 set_dialog_browser_field (hwndDlg, GS_IEXPLORE, NULL);
720 dialog_update_enables(hwndDlg);
721 return 1;
722
723 case ID_RADIO_OTHER:
724 set_dialog_browser_field (hwndDlg, GS_OTHER, NULL);
725 dialog_update_enables(hwndDlg);
726 return 1;
727
728 case ID_BROWSE_BUTTON:
729 filename[0] = '\0';
730 memset(&fname, 0, sizeof(OPENFILENAME));
731 fname.lStructSize = sizeof(OPENFILENAME);
732 fname.hwndOwner = hwndDlg;
733 fname.hInstance = NULL;
734 fname.lpstrFilter = filefilter;
735 fname.lpstrCustomFilter = NULL;
736 fname.nMaxCustFilter = 0;
737 fname.nFilterIndex = 1;
738 fname.lpstrFile = filename;
739 fname.nMaxFile = MAX_FILENAME_SIZE-1;
740 fname.lpstrFileTitle = NULL;
741 fname.nMaxFileTitle = 0;
742 fname.lpstrInitialDir = NULL;
743 fname.lpstrTitle = "Choose Web Browser";
744 fname.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
745
746 if(GetOpenFileName(&fname)) {
747 set_dialog_browser_field (hwndDlg, GS_OTHER, filename);
748 dialog_update_enables(hwndDlg);
749 }
750 return 1;
751
752 case ID_ARM_NAME:
753 set_address_resolution_field (hwndDlg, ARM_NAME);
754 dialog_update_enables(hwndDlg);
755 return 1;
756 case ID_ARM_IP:
757 set_address_resolution_field (hwndDlg, ARM_IP);
758 dialog_update_enables(hwndDlg);
759 return 1;
760 case ID_ARM_LOCALHOST:
761 set_address_resolution_field (hwndDlg, ARM_LOCALHOST);
762 dialog_update_enables(hwndDlg);
763 return 1;
764 case ID_ARM_127_0_0_1:
765 set_address_resolution_field (hwndDlg, ARM_127_0_0_1);
766 dialog_update_enables(hwndDlg);
767 return 1;
768
769 }
770 }
771 return 0;
772
773 case WM_CLOSE:
774 case WM_DESTROY:
775 EndDialog(hwndDlg, 0);
776 return 1;
777 }
778
779 return 0;
780}
781
782static void dialog_debug_update_enables (HWND hwndDlg) {
783 int res;
784
785 // if they want a log of program use allow them to
786 // edit its filename
787 res = SendDlgItemMessage(hwndDlg, LOG_CHECK, BM_GETCHECK,0,0);
788 SendDlgItemMessage(hwndDlg, LOG_NAME_BOX, WM_ENABLE, (res == 1), 0);
789}
790
791
792static void read_dialog_debug_fields (HWND hwndDlg) {
793 int res;
794
795 // whether to log program use
796 res = SendDlgItemMessage(hwndDlg, LOG_CHECK, BM_GETCHECK,0,0);
797 gsdl_keep_log = (res == 1);
798
799 // log filename
800 res = SendDlgItemMessage(hwndDlg, LOG_NAME_BOX, EM_GETMODIFY,0,0);
801 if (res != 0) {
802 res = GetDlgItemText(hwndDlg, LOG_NAME_BOX, gsdl_log_name, MAX_FILENAME_SIZE);
803 }
804
805 // whether to display log information on console
806 res = SendDlgItemMessage(hwndDlg, CONSOLE_CHECK, BM_GETCHECK,0,0);
807 gsdl_show_console = (res == 1);
808}
809
810
811static BOOL CALLBACK dialog_debug_proc(HWND hwndDlg, UINT uMsg,
812 WPARAM wParam,LPARAM lParam) {
813 int wNotifyCode = HIWORD(wParam);
814 int wID = LOWORD(wParam);
815
816 switch (uMsg) {
817 case WM_INITDIALOG:
818 // set current values
819 SendDlgItemMessage(hwndDlg, LOG_CHECK, BM_SETCHECK,
820 gsdl_keep_log ? 1 : 0, 0);
821 SetDlgItemText(hwndDlg, LOG_NAME_BOX, gsdl_log_name);
822 SendDlgItemMessage(hwndDlg, CONSOLE_CHECK, BM_SETCHECK,
823 gsdl_show_console ? 1 : 0, 0);
824 dialog_debug_update_enables(hwndDlg);
825 return 1;
826
827 case WM_COMMAND:
828 if (wNotifyCode == BN_CLICKED) {
829 switch (wID) {
830 case ID_CANCEL_BUTTON:
831 EndDialog(hwndDlg, 0);
832 return 1;
833
834 case ID_OK_BUTTON:
835 read_dialog_debug_fields(hwndDlg);
836 EndDialog(hwndDlg, 1);
837 return 1;
838
839 case LOG_CHECK:
840 dialog_debug_update_enables(hwndDlg);
841 return 1;
842 }
843 }
844 return 0;
845
846 case WM_CLOSE:
847 case WM_DESTROY:
848 EndDialog(hwndDlg, 0);
849 return 1;
850 }
851
852 return 0;
853}
854
855
856void Settings_Dialog(HWND window, int netscapeneeded)
857{
858 int old_gsdl_show_console = gsdl_show_console;
859 int old_gsdl_port_num = gsdl_port_num;
860
861 int res = 0;
862
863 gsdl_netscapeneeded = netscapeneeded;
864
865 if ((GetAsyncKeyState(VK_CONTROL) & 0x8000) &&
866 (GetAsyncKeyState(VkKeyScan('d')) & 0x8000)) {
867 // control-D was pressed, display debug settings
868 // dialog box
869 res = DialogBox (NULL, MAKEINTRESOURCE(COMMS_DIALOG_DEBUG),
870 window, (DLGPROC)dialog_debug_proc);
871
872 if (res == 1) {
873 // only update if exited via the OK button
874 if (gsdl_keep_log) open_log_file();
875 else close_log_file();
876
877 // turn the console on/off if we need to
878 if (gsdl_show_console != old_gsdl_show_console) {
879 if (gsdl_show_console) activate_console ();
880 else deactivate_console ();
881 }
882 }
883
884 } else {
885 // display normal settings dialog box
886
887 // make sure everything is up-to-date
888 gsdl_check_browser_settings (netscapeneeded);
889
890 res = DialogBox (NULL, MAKEINTRESOURCE(COMMS_DIALOG2),
891 window, (DLGPROC)dialog_proc);
892
893 if (res == 1) {
894 // only update if exited via the OK button
895 if (gsdl_port_num != old_gsdl_port_num) {
896 EndHTTPServer();
897 StartHTTPServer(window);
898 }
899 }
900 }
901
902 // save the settings if we exited via the ok button
903 if (res == 1) {
904 write_settings(gsdl_url);
905 // reset httpprefix in case port number was changed
906 // configure_httpprefix ();
907 }
908}
Note: See TracBrowser for help on using the repository browser.