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