Ignore:
Timestamp:
2000-02-03T14:45:48+13:00 (24 years ago)
Author:
sjboddie
Message:

lots of stuff

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gsdl/src/w32server/settings.cpp

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