[2286] | 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 |
|
---|
[1203] | 28 | #include "text_t.h"
|
---|
[4642] | 29 | #include "fileutil.h"
|
---|
[1203] | 30 |
|
---|
[611] | 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"
|
---|
[902] | 44 | #include "cgiwrapper.h"
|
---|
[611] | 45 |
|
---|
| 46 | // library settings
|
---|
[902] | 47 | text_t gsdl_enterlib;
|
---|
| 48 | text_t gsdl_gsdlhome;
|
---|
[16310] | 49 | text_t gsdl_collecthome;
|
---|
[15625] | 50 | text_t gsdl_dbhome;
|
---|
[902] | 51 | text_t gsdl_collections;
|
---|
| 52 | colinfo_tmap gsdl_collectinfo;
|
---|
[611] | 53 |
|
---|
[902] | 54 | char gsdl_staticpages[MAX_FILENAME_SIZE];
|
---|
[611] | 55 |
|
---|
| 56 | // debug settings
|
---|
[902] | 57 | char gsdl_log_name[MAX_FILENAME_SIZE] = "c:\\gsdl.log";
|
---|
| 58 | int gsdl_keep_log = 0;
|
---|
| 59 | int gsdl_show_console = 0;
|
---|
[611] | 60 |
|
---|
| 61 | // general settings
|
---|
[902] | 62 | int gsdl_port_num = 80;
|
---|
| 63 | int gsdl_auto_enter = 0;
|
---|
[10224] | 64 | int gsdl_browser = GS_DEFAULT;
|
---|
[902] | 65 | char gsdl_browser_exe[MAX_FILENAME_SIZE] = "";
|
---|
[4292] | 66 | text_t gsdl_url;
|
---|
[4642] | 67 | text_t gsdl_conffile;
|
---|
[4339] | 68 | int gsdl_start_browser = 1;
|
---|
[10648] | 69 | int gsdl_address_resolution_method = 1; // Get an IP, but don't resolve to a name
|
---|
[611] | 70 |
|
---|
| 71 | // private data
|
---|
| 72 |
|
---|
| 73 | // pathnames of the latest installed versions of netscape and
|
---|
| 74 | // internet explorer
|
---|
| 75 | static char netscape_exe[MAX_FILENAME_SIZE]="";
|
---|
| 76 | static char iexplore_exe[MAX_FILENAME_SIZE]="";
|
---|
| 77 |
|
---|
| 78 | // pathname of the default browser
|
---|
| 79 | static char default_browser_exe[MAX_FILENAME_SIZE]="";
|
---|
| 80 |
|
---|
| 81 | // whether netscape is needed (used in the settings dialog box)
|
---|
[902] | 82 | static int gsdl_netscapeneeded = 0;
|
---|
[611] | 83 |
|
---|
| 84 | static void remove_end_slashes(char *str) {
|
---|
[902] | 85 | int len = strlen (str);
|
---|
| 86 | while ((len > 0) && ((str[len-1] == '\\') || (str[len-1] == '/'))) {
|
---|
[9598] | 87 | --len;
|
---|
[902] | 88 | }
|
---|
| 89 | str[len] = '\0';
|
---|
[611] | 90 | }
|
---|
| 91 |
|
---|
[902] | 92 | static void remove_end_slashes (text_t &str) {
|
---|
| 93 | char *cstr = str.getcstr();
|
---|
| 94 | remove_end_slashes (cstr);
|
---|
| 95 | str = cstr;
|
---|
[9636] | 96 | delete []cstr;
|
---|
[902] | 97 | }
|
---|
[611] | 98 |
|
---|
| 99 | // returns 1 if successful, 0 otherwise
|
---|
| 100 | // checks for a file's existence
|
---|
| 101 | static int check_program_exe (char *path) {
|
---|
[902] | 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;
|
---|
[611] | 113 | }
|
---|
| 114 |
|
---|
| 115 |
|
---|
| 116 | // returns 1 if successful, 0 otherwise
|
---|
| 117 | static int get_default_browser_path (char *providedhtmltype, char *path, int maxsize) {
|
---|
[902] | 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) {
|
---|
[611] | 142 | // strip all excess stuff off the command
|
---|
[902] | 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];
|
---|
[9598] | 156 | ++len;
|
---|
[902] | 157 | }
|
---|
| 158 | } else {
|
---|
| 159 | if (path[i] == endchar) break;
|
---|
| 160 | path[len] = path[i];
|
---|
[9598] | 161 | ++len;
|
---|
[902] | 162 | }
|
---|
[9598] | 163 | ++i;
|
---|
[611] | 164 | }
|
---|
[902] | 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;
|
---|
[611] | 180 | }
|
---|
| 181 |
|
---|
| 182 |
|
---|
| 183 | // returns 1 if successful, 0 otherwise
|
---|
| 184 | // note that appname should include .exe (e.g. netscape.exe)
|
---|
| 185 | static int registry_get_app_paths (char *appname, char *path, int maxsize) {
|
---|
[902] | 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;
|
---|
[611] | 204 | }
|
---|
| 205 |
|
---|
| 206 | static void check_installed_browsers (int netscapeneeded) {
|
---|
[902] | 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")) {
|
---|
[611] | 225 | netscape_exe[0] = '\0';
|
---|
[902] | 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")) {
|
---|
[611] | 257 | iexplore_exe[0] = '\0';
|
---|
[902] | 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 | }
|
---|
[611] | 272 | }
|
---|
| 273 |
|
---|
[4292] | 274 | void write_settings (const text_t url) {
|
---|
[902] | 275 |
|
---|
[4642] | 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);
|
---|
[9636] | 283 | delete []conffile_c;
|
---|
[902] | 284 | if (fout) {
|
---|
| 285 |
|
---|
| 286 | outconvertclass text_t2ascii;
|
---|
[611] | 287 |
|
---|
[902] | 288 | // top (gsdl) level stuff
|
---|
| 289 | fout << "[gsdl]\n";
|
---|
[4292] | 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 |
|
---|
[902] | 301 | write_ini_line(fout, "enterlib", gsdl_enterlib);
|
---|
| 302 | write_ini_line(fout, "gsdlhome", gsdl_gsdlhome);
|
---|
[16310] | 303 | write_ini_line(fout, "collecthome", gsdl_collecthome);
|
---|
[15625] | 304 | write_ini_line(fout, "gdbmhome", gsdl_dbhome);
|
---|
[902] | 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);
|
---|
[4339] | 315 | write_ini_line(fout, "start_browser", text_t(gsdl_start_browser));
|
---|
[10231] | 316 | write_ini_line(fout, "address_resolution_method", text_t(gsdl_address_resolution_method));
|
---|
| 317 |
|
---|
[902] | 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);
|
---|
[16310] | 325 | if (!(*here).second.gsdl_collecthome.empty())
|
---|
| 326 | write_ini_line(fout, "collecthome", (*here).second.gsdl_collecthome);
|
---|
[15625] | 327 | if (!(*here).second.gsdl_dbhome.empty())
|
---|
| 328 | write_ini_line(fout, "gdbmhome", (*here).second.gsdl_dbhome);
|
---|
[902] | 329 |
|
---|
[9598] | 330 | ++here;
|
---|
[902] | 331 | }
|
---|
| 332 | fout.close();
|
---|
| 333 | }
|
---|
[611] | 334 | }
|
---|
| 335 |
|
---|
| 336 |
|
---|
| 337 | // browser_compare assumes that check_exe is in lowercase
|
---|
| 338 | static int browser_compare (char *browser_exe_path, char *check_exe) {
|
---|
[902] | 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);
|
---|
[611] | 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
|
---|
| 349 | static void check_browser_settings (int &browser, char *browser_exe,
|
---|
[902] | 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
|
---|
[9526] | 366 | if (browser == GS_DEFAULT) {
|
---|
| 367 | strcpy (browser_exe, default_browser_exe);
|
---|
| 368 | } else if (browser == GS_NETSCAPE) {
|
---|
[902] | 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 | }
|
---|
[611] | 382 | }
|
---|
| 383 |
|
---|
| 384 |
|
---|
| 385 | static void revert_defaults (int netscapeneeded) {
|
---|
[902] | 386 | find_location();
|
---|
| 387 |
|
---|
| 388 | // library settings
|
---|
[2343] | 389 | gsdl_enterlib = "/gsdl";
|
---|
[902] | 390 | gsdl_gsdlhome = data_location;
|
---|
[16310] | 391 | gsdl_collecthome = filename_cat(data_location,"collect");
|
---|
[15625] | 392 | gsdl_dbhome = data_location;
|
---|
[902] | 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;
|
---|
[4339] | 402 | gsdl_start_browser = 1;
|
---|
| 403 |
|
---|
[902] | 404 | check_installed_browsers (netscapeneeded);
|
---|
[10224] | 405 | gsdl_browser = GS_DEFAULT;
|
---|
[902] | 406 | strcpy (gsdl_browser_exe, default_browser_exe);
|
---|
| 407 | check_browser_settings (gsdl_browser, gsdl_browser_exe, netscapeneeded);
|
---|
[611] | 408 | }
|
---|
| 409 |
|
---|
| 410 | void read_settings (int netscapeneeded) {
|
---|
[902] | 411 |
|
---|
[4642] | 412 | if (gsdl_conffile.empty()) {
|
---|
| 413 | find_location();
|
---|
| 414 | gsdl_conffile = filename_cat(data_location, "gsdlsite.cfg");
|
---|
| 415 | }
|
---|
[902] | 416 |
|
---|
| 417 | // set up defaults
|
---|
| 418 | revert_defaults (netscapeneeded);
|
---|
| 419 |
|
---|
| 420 | text_t key, value, section;
|
---|
| 421 | char *cstr_value;
|
---|
[4642] | 422 | char *conffile_c = gsdl_conffile.getcstr();
|
---|
[1203] | 423 | #if defined (GSDL_USE_IOS_H)
|
---|
[4642] | 424 | ifstream conf (conffile_c, ios::nocreate);
|
---|
[1203] | 425 | #else
|
---|
[4642] | 426 | ifstream conf (conffile_c);
|
---|
[1203] | 427 | #endif
|
---|
[9636] | 428 | delete []conffile_c;
|
---|
[902] | 429 | if (conf) {
|
---|
| 430 | while (read_ini_line(conf, key, value) >= 0) {
|
---|
[1739] | 431 | if (key.empty()) continue;
|
---|
[902] | 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);
|
---|
[611] | 438 |
|
---|
[902] | 439 | } else {
|
---|
[611] | 440 |
|
---|
[902] | 441 | cstr_value = value.getcstr ();
|
---|
| 442 |
|
---|
| 443 | if (section == "gsdl") {
|
---|
[611] | 444 |
|
---|
[902] | 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();
|
---|
[4339] | 466 |
|
---|
| 467 | } else if (key == "start_browser") {
|
---|
| 468 | gsdl_start_browser = value.getint();
|
---|
[902] | 469 |
|
---|
| 470 | } else if (key == "browser") {
|
---|
| 471 | gsdl_browser = value.getint();
|
---|
| 472 |
|
---|
| 473 | } else if (key == "browserexe") {
|
---|
| 474 | strcpy (gsdl_browser_exe, cstr_value);
|
---|
[611] | 475 |
|
---|
[10231] | 476 | } else if (key == "address_resolution_method") {
|
---|
| 477 | gsdl_address_resolution_method = value.getint();
|
---|
| 478 |
|
---|
[902] | 479 | } else if (key == "collections") {
|
---|
| 480 | gsdl_collections = value;
|
---|
[16310] | 481 | }
|
---|
[15625] | 482 | // gsdlhome must occur in file before dbhome
|
---|
[16310] | 483 | else if (key == "gsdlhome") {
|
---|
[902] | 484 | gsdl_gsdlhome = value;
|
---|
[16310] | 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") {
|
---|
[15625] | 492 | gsdl_dbhome = value;
|
---|
[902] | 493 | }
|
---|
| 494 | } else {
|
---|
| 495 |
|
---|
[15625] | 496 | // gsdlhome must occur in file before dbhome
|
---|
[902] | 497 | if (key == "gsdlhome") {
|
---|
| 498 | gsdl_collectinfo[section].gsdl_gsdlhome = value;
|
---|
[17987] | 499 | gsdl_collectinfo[section].gsdl_collecthome = filename_cat(value,"collect");
|
---|
[15625] | 500 | gsdl_collectinfo[section].gsdl_dbhome = value;
|
---|
[16310] | 501 | }
|
---|
| 502 | else if (key == "collecthome") {
|
---|
| 503 | gsdl_collectinfo[section].gsdl_collecthome = value;
|
---|
| 504 | }
|
---|
| 505 | else if (key == "gdbmhome") {
|
---|
[15625] | 506 | gsdl_collectinfo[section].gsdl_dbhome = value;
|
---|
[902] | 507 | }
|
---|
[611] | 508 | }
|
---|
[9636] | 509 | delete []cstr_value;
|
---|
[902] | 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);
|
---|
[16310] | 518 | remove_end_slashes (gsdl_collecthome);
|
---|
[15625] | 519 | remove_end_slashes (gsdl_dbhome);
|
---|
[902] | 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);
|
---|
[16310] | 524 | remove_end_slashes ((*here).second.gsdl_collecthome);
|
---|
[15625] | 525 | remove_end_slashes ((*here).second.gsdl_dbhome);
|
---|
[9598] | 526 | ++here;
|
---|
[902] | 527 | }
|
---|
[611] | 528 |
|
---|
[902] | 529 | // check the browser settings
|
---|
| 530 | check_browser_settings (gsdl_browser, gsdl_browser_exe, netscapeneeded);
|
---|
[611] | 531 | }
|
---|
| 532 |
|
---|
[902] | 533 | void gsdl_check_browser_settings (int netscapeneeded) {
|
---|
| 534 | check_installed_browsers (netscapeneeded);
|
---|
| 535 | check_browser_settings (gsdl_browser, gsdl_browser_exe, netscapeneeded);
|
---|
[611] | 536 | }
|
---|
| 537 |
|
---|
| 538 |
|
---|
| 539 | static void dialog_update_enables (HWND hwndDlg) {
|
---|
[902] | 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);
|
---|
[611] | 546 | }
|
---|
| 547 |
|
---|
| 548 |
|
---|
| 549 | static int read_dialog_browser_field (HWND hwndDlg) {
|
---|
[9526] | 550 | if (SendDlgItemMessage(hwndDlg, ID_RADIO_DEFAULT,
|
---|
| 551 | BM_GETCHECK, 0, 0) == 1) return GS_DEFAULT;
|
---|
[902] | 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;
|
---|
[611] | 559 | }
|
---|
| 560 |
|
---|
| 561 |
|
---|
| 562 | static void set_dialog_browser_field (HWND hwndDlg, int browser, char *othername) {
|
---|
[9526] | 563 | // if we are trying to set the browser to default, netscape or
|
---|
[902] | 564 | // internet explorer and we can't find them, set the browser
|
---|
| 565 | // to 'other'
|
---|
[9526] | 566 | if ((browser == GS_DEFAULT) && (default_browser_exe[0] == '\0'))
|
---|
| 567 | browser = GS_NETSCAPE;
|
---|
[902] | 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
|
---|
[9526] | 576 | SendDlgItemMessage(hwndDlg, ID_RADIO_DEFAULT, BM_SETCHECK,
|
---|
| 577 | (browser == GS_DEFAULT) ? BST_CHECKED : BST_UNCHECKED, 0);
|
---|
[902] | 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
|
---|
[9526] | 586 | if (browser == GS_DEFAULT) {
|
---|
| 587 | SetDlgItemText(hwndDlg, ID_OTHER_NAME, default_browser_exe);
|
---|
| 588 | } else if (browser == GS_NETSCAPE) {
|
---|
[902] | 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 | }
|
---|
[611] | 595 | }
|
---|
| 596 |
|
---|
| 597 |
|
---|
| 598 | static void read_browser_exe_field (HWND hwndDlg, char *filename, int maxsize) {
|
---|
[902] | 599 | filename[0] = '\0';
|
---|
| 600 | GetDlgItemText(hwndDlg, ID_OTHER_NAME, filename, maxsize);
|
---|
[611] | 601 | }
|
---|
| 602 |
|
---|
[11096] | 603 | static 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;
|
---|
[11319] | 608 | if (SendDlgItemMessage(hwndDlg, ID_ARM_LOCALHOST,
|
---|
| 609 | BM_GETCHECK, 0, 0) == 1) return ARM_LOCALHOST;
|
---|
[11096] | 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 | }
|
---|
[611] | 614 |
|
---|
[11096] | 615 | static 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);
|
---|
[11319] | 622 | SendDlgItemMessage(hwndDlg, ID_ARM_LOCALHOST, BM_SETCHECK,
|
---|
| 623 | (address_res_method == ARM_LOCALHOST) ? BST_CHECKED : BST_UNCHECKED, 0);
|
---|
[11096] | 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 |
|
---|
[611] | 629 | static void read_dialog_fields (HWND hwndDlg) {
|
---|
[902] | 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);
|
---|
[11096] | 645 |
|
---|
| 646 | // which address resolution method
|
---|
| 647 | gsdl_address_resolution_method = read_address_resolution_field(hwndDlg);
|
---|
[611] | 648 | }
|
---|
| 649 |
|
---|
| 650 |
|
---|
| 651 |
|
---|
| 652 |
|
---|
| 653 | static BOOL CALLBACK dialog_proc(HWND hwndDlg, UINT uMsg,
|
---|
[902] | 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);
|
---|
[11096] | 668 | set_address_resolution_field(hwndDlg, gsdl_address_resolution_method);
|
---|
[902] | 669 | dialog_update_enables(hwndDlg);
|
---|
| 670 |
|
---|
[9526] | 671 | // make sure that the default browser, netscape and internet explorer
|
---|
[902] | 672 | // radio buttons are only enabled if they could be found
|
---|
[9526] | 673 | if (default_browser_exe[0] == '\0')
|
---|
| 674 | EnableWindow (GetDlgItem (hwndDlg, ID_RADIO_DEFAULT), FALSE);
|
---|
[902] | 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"
|
---|
[2345] | 709 | "web browser.",
|
---|
[902] | 710 | "Greenstone Digital Library Software",
|
---|
| 711 | MB_OK|MB_APPLMODAL);
|
---|
| 712 | }
|
---|
| 713 | } else {
|
---|
| 714 | // message: the file did not exist
|
---|
| 715 | MessageBox(hwndDlg,
|
---|
[2345] | 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.",
|
---|
[902] | 719 | "Greenstone Digital Library Software",
|
---|
| 720 | MB_OK|MB_APPLMODAL);
|
---|
[611] | 721 | }
|
---|
[902] | 722 | return 1;
|
---|
[9526] | 723 |
|
---|
| 724 | case ID_RADIO_DEFAULT:
|
---|
| 725 | set_dialog_browser_field (hwndDlg, GS_DEFAULT, NULL);
|
---|
| 726 | dialog_update_enables(hwndDlg);
|
---|
| 727 | return 1;
|
---|
[902] | 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;
|
---|
[11096] | 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;
|
---|
[11319] | 776 | case ID_ARM_LOCALHOST:
|
---|
| 777 | set_address_resolution_field (hwndDlg, ARM_LOCALHOST);
|
---|
| 778 | dialog_update_enables(hwndDlg);
|
---|
| 779 | return 1;
|
---|
[11096] | 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 |
|
---|
[902] | 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;
|
---|
[611] | 796 | }
|
---|
| 797 |
|
---|
| 798 | static void dialog_debug_update_enables (HWND hwndDlg) {
|
---|
[902] | 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);
|
---|
[611] | 805 | }
|
---|
| 806 |
|
---|
| 807 |
|
---|
| 808 | static void read_dialog_debug_fields (HWND hwndDlg) {
|
---|
[902] | 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);
|
---|
[611] | 824 | }
|
---|
| 825 |
|
---|
| 826 |
|
---|
| 827 | static BOOL CALLBACK dialog_debug_proc(HWND hwndDlg, UINT uMsg,
|
---|
[902] | 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;
|
---|
[611] | 869 | }
|
---|
| 870 |
|
---|
| 871 |
|
---|
| 872 | void Settings_Dialog(HWND window, int netscapeneeded)
|
---|
| 873 | {
|
---|
[902] | 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);
|
---|
[611] | 908 |
|
---|
[902] | 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) {
|
---|
[4292] | 920 | write_settings(gsdl_url);
|
---|
[902] | 921 | // reset httpprefix in case port number was changed
|
---|
| 922 | // configure_httpprefix ();
|
---|
| 923 | }
|
---|
[611] | 924 | }
|
---|