Ignore:
Timestamp:
2000-08-31T00:42:59+12:00 (24 years ago)
Author:
cs025
Message:

Updated sources with most of uninstall added

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gsinstaller/gsinstall.cpp

    r1397 r1475  
    2929
    3030bool            config_complete = false;
    31 // static char app_tmptext[100] = "George";
    3231
    3332typedef vector<dirSelector *> dirSelVector;
    3433
    35 class GSInstall
     34class GSInstall : public installManager
    3635{ private:
    37         configureFile   *   configFile;
    38         FilePath *          collectPath;
    39     FilePath *          installToPath;
    40     FilePath *          sourcePath;
    41     FilePath *          gsdlSourcePath;
    42     FilePath *          destinationPath;
    43     FilePath *          dataDestPath;
     36        configureFile   *   configFile;             // the installation configure file
     37
     38        FilePath *          collectPath;            // where the collection is currently installed
     39    FilePath *          installToPath;      // the first cut at a destination folder
     40    FilePath *          sourcePath;             // the root source folder
     41    FilePath *          gsdlSourcePath;     // the gsdl folder in the source area
     42    FilePath *          destinationPath;    // where the executables will be installed to
     43    FilePath *          dataDestPath;           // where the collection data files will go
     44
     45    bool                        installVolume;      // whether to install collection data
     46    bool                        installFullVolume;// whether to install all collection data
     47
     48    dirSelVector        selectedDirs;           // configuration objects
     49
     50    gsPlatform                  platform;           // platform information
     51    gsRegistry *                gsRegister;     // registry
     52    gsManifest *                manifest;           // manifest of files
     53    gsProgramManager  * progman;            // program manager connection
     54
     55    void                getSourcePath();
     56    void                getExistingInstall();
     57    public:
    4458    bool            installExe;
    45     bool                        installVolume;
    46     bool                        installFullVolume;
    47     gsPlatform          platform;
    48     unInstaller *       unInstall;
    49 
    50     dirSelVector        selectedDirs;
    51 
    52     gsRegistry *        gsRegister;
    53     gsManifest *        manifest;
    54 
    55     void                getSourcePath();
    56     public:
    57         GSInstall();
     59
     60        GSInstall(bool uninstall);
    5861    FilePath *  collectionPath();
    5962    FilePath *  installPath();
     
    6467    bool                installNetscape();
    6568    void                setDestination();
     69    void                setUninstall();
     70    void                uninstall();
    6671    void                setManifest();
    6772    void                addSelectedDir(dirSelector *selector);
     
    8792 * THe source path is also discovered.
    8893 */
    89 GSInstall::GSInstall()
    90 { gsPlatform    platform;
    91 
    92     // get the installation configuration file
     94GSInstall::GSInstall(bool uninstall)
     95    : installManager()
     96{ // get the installation configuration file
    9397    this->configFile    = new configureFile("install.cfg");
    9498
    95   // initialise the pointers that we test later this fn.
    96   this->unInstall       = NULL;
     99    // set up "default" installation bits
     100  this->installToPath   = new FilePath("C:\\GSDL");
     101    this->collectPath   = NULL;
     102  this->installExe  = true; // we must install the exe files
    97103
    98104    // don't attempt this with windows 3.1
    99   if (!platform.isWindows32s() || TRUE)
     105  if (!this->platform.isWindows32s())
    100106  { // get the registry
    101       this->gsRegister  = new gsRegistry(*this->configFile);
    102 
    103     // TODO: in windows 3.1 we can't use the register as it isn't fully/properly
     107      this->gsRegister  = new gsRegistry(*this, *this->configFile);
     108  }
     109  else
     110  { // TODO: in windows 3.1 we can't use the register as it isn't fully/properly
    104111      //       implemented; we must get the existing path information from elsewhere
    105     if (gsRegister->collectionInstalled())
    106       { // TODO: check if receptionist etc should be replaced or not
    107 
    108         // TODO: check build version of the volume
    109 
    110         // Get location of the library executable from the registry; this
    111         // is thence used to get the location of gsdl.ini etc.
    112         this->collectPath   = this->gsRegister->collectionPath();
    113         this->installToPath = this->collectPath;
    114 
    115         // TODO: if collectPath == NULL generate error
    116 
    117       // get uninstall information from destination location
    118       FilePath *uninstallPath   = new FilePath(this->collectPath->cString(), "uninstl.cfg");
    119       this->unInstall   = new unInstaller(uninstallPath->cString());
    120       delete uninstallPath;
    121 
    122       // we don't need to install the exe files
    123         this->installExe = false||true;
    124       }
    125     else
    126       { this->installToPath = new FilePath("C:\\GSDL");
    127             this->collectPath   = NULL;
    128         // we must install the exe files
    129           this->installExe  = true;
    130     }
    131   }
    132   else
    133   { // TODO: do windows 3.1 stuff here
    134     this->installToPath = new FilePath("C:\\GSDL");
    135     this->installExe = true;
    136     this->collectPath   = NULL;
    137   }
    138 
    139   if (this->unInstall   == NULL)
    140   { this->unInstall = new unInstaller("");
     112    this->gsRegister    = new gsRegistry(*this, *this->configFile);
    141113  }
    142114
     
    145117  this->installFullVolume   = true;
    146118
     119    // detect any existing installation; unnecessary in uninstall (it's the
     120  // "source" directory - see later
     121  if (uninstall == false)
     122  { this->getExistingInstall();
     123  }
     124
    147125  // get where we are installing from
    148126  this->getSourcePath();
    149127
    150   // get the manifest
    151   this->manifest = new gsManifest(*this->sourcePath);
     128  // if doing an uninstall we now know where the "uninstall" is
     129  if (uninstall == true)
     130  { this->collectPath   = this->sourcePath;
     131  }
     132
     133  // get the manifest and program manager objects
     134  if (uninstall)
     135  { this->manifest = new gsManifest(*this);
     136  }
     137  else
     138  { this->manifest = new gsManifest(*this, *this->sourcePath);
     139  }
     140  this->progman  = new gsProgramManager(*this);
    152141
    153142  // tell manifest the number of bits in the raw windows environment; this may
     
    165154  }
    166155*/
    167   // inform manifests of collection directory name
    168   char *buffer;
    169   this->configFile->get("CollectionDirName", &buffer);
    170   this->manifest->expandMacro("COLDIRNAME", buffer);
    171   delete buffer;
     156  // inform manifest of collection directory name
     157  string colDir;
     158  colDir = this->configFile->getString("CollectionDirName");
     159  if (colDir != "")
     160  { this->manifest->expandMacro("COLDIRNAME", colDir);
     161  }
     162}
     163
     164/**
     165 * Detect the presence of an existing installation
     166 */
     167void GSInstall::getExistingInstall()
     168{   if (!this->platform.isWindows32s())
     169    {   if (gsRegister->collectionInstalled())
     170      { // TODO: check if receptionist etc should be replaced or not
     171
     172        // TODO: check build version of the volume
     173
     174        // Get location of the library executable from the registry; this
     175        // is thence used to get the location of gsdl.ini etc.
     176        this->collectPath   = this->gsRegister->collectionPath();
     177      if (this->collectPath != "")
     178      { this->installToPath = this->collectPath;
     179
     180        // we don't need to install the exe files
     181            this->installExe = false;
     182      }
     183      }
     184  }
    172185}
    173186
     
    189202
    190203  // get the gsdl source path
    191   this->gsdlSourcePath  = new FilePath(this->sourcePath->cString(), "gsdl");
     204  this->gsdlSourcePath  = new FilePath(this->sourcePath->pathString(), "gsdl");
    192205  delete exePath;
    193206}
     
    199212 */
    200213bool GSInstall::copyFiles()
    201 {   FileVector *fileList;
    202 
    203   // ensure that we have got the required destination and that we can write there
     214{   // ensure that we have got the required destination and that we can write there
    204215  if (this->installExe)
    205216  { this->destinationPath->ensureWriteablePath();
     
    232243  // now move on to add key items
    233244    if (this->installExe)
    234   { FilePath *serverPath    = new FilePath((char *) this->destinationPath->cString(), "server.exe");
    235     char *exeKeyPath;
     245  { FilePath *serverPath    = new FilePath(this->destinationPath->pathString(), "server.exe");
     246    FilePath *setupPath     = new FilePath(this->destinationPath->pathString(), "gssetup.exe");
     247      FilePath *logPath = new FilePath(this->destinationPath->pathString(), "install.log");
     248    string exeKeyPath, uninstallCmd, uninstallKeyPath;
    236249    gsPlatform platform;
    237250
     
    240253                                                                        this->gsRegister->collectKeyId(),
    241254                                      "library",
    242                                       serverPath->cString());
     255                                      serverPath->pathString());
    243256
    244257    // This test is in fact for 9x or NT 4+; we're worried about the registry
     
    254267        this->gsRegister->storeKeyString(   HKEY_LOCAL_MACHINE,
    255268                                                                        exeKeyPath,
    256                                           NULL,
    257                                         serverPath->cString());
     269                                          "",
     270                                        serverPath->pathString());
    258271
    259272      // store path for this application
     
    261274                                                                        exeKeyPath,
    262275                                          "path",
    263                                         this->destinationPath->cString());
    264       // delete the windows 9x speciall app path key
    265             delete exeKeyPath;
    266 
    267       // TODO: set up uninstall option
     276                                        this->destinationPath->pathString());
     277
     278      // create uninstall command line
     279      uninstallCmd = setupPath->pathString() + " -u " + logPath->pathString();
     280      uninstallKeyPath = this->gsRegister->uninstallKeyId(this->configFile->getString("CollectionName"));
     281
     282      // ensure uninstall key exists
     283      this->gsRegister->ensureKeyExists(HKEY_LOCAL_MACHINE, uninstallKeyPath);
     284
     285      this->gsRegister->storeKeyString(HKEY_LOCAL_MACHINE, uninstallKeyPath,
     286                                                                        "DisplayName",
     287                                        this->configFile->getString("CollectionName"));
     288      this->gsRegister->storeKeyString(HKEY_LOCAL_MACHINE, uninstallKeyPath,
     289                                                                        "UninstallString", uninstallCmd);
    268290    }
     291    delete setupPath;
    269292    delete serverPath;
     293      delete logPath;
    270294  }
    271295
     
    280304 */
    281305void GSInstall::setDestination()
    282 {   this->destinationPath       = new FilePath(this->selectedDirs[0]->selectedPath());
     306{ // get configuration from the install wizard pages
     307    this->destinationPath       = new FilePath(this->selectedDirs[0]->selectedPath());
    283308    this->installFullVolume = this->selectedDirs[1]->getOption();
    284309  if (this->installFullVolume || true)  // NB: always take path from 2nd dialog
     
    287312  else
    288313  { this->dataDestPath  = this->destinationPath;
     314  }
     315
     316  // open the log for writing
     317  FilePath *logPath = new FilePath(this->destinationPath->pathString(), "install.log");
     318  this->openLog(logPath->pathString(), true);
     319  delete logPath;
     320}
     321
     322void GSInstall::setUninstall()
     323{
     324  // open the log for reading
     325  FilePath *logPath = new FilePath(this->collectPath->pathString(), "install.log");
     326  this->openLog(logPath->pathString(), false);
     327  delete logPath;
     328}
     329
     330void GSInstall::uninstall()
     331{ FilePath *iniPath;
     332    string      command;
     333  stringArray params;
     334
     335    this->manifest = new gsManifest(*this); // get a manifest manager
     336
     337  iniPath   = new FilePath(this->collectPath->pathString(), "gsdl.ini");
     338    gsProfile gsdlProfile(*this, iniPath->pathString());
     339
     340    while ((command = this->readCommand(params)) != "")
     341  { if (!this->manifest->undoAction(command, params))
     342    { if (!gsdlProfile.undoAction(command, params))
     343        { if (!this->gsRegister->undoAction(command, params))
     344        { if (!this->progman->undoAction(command, params))
     345            {
     346          }
     347        }
     348      }
     349    }
    289350  }
    290351}
     
    295356void GSInstall::setManifest()
    296357{   if (this->installExe)
    297     {   this->manifest->selectGroup("library", this->destinationPath->pathString());
     358    {   this->manifest->selectGroup("library", *this->destinationPath);
    298359  }
    299360  if (this->installFullVolume)
    300   { this->manifest->selectGroup("collection", this->dataDestPath->pathString());
     361  { this->manifest->selectGroup("collection", *this->dataDestPath);
    301362  }
    302363  else
    303   { this->manifest->selectGroup("database", this->dataDestPath->pathString());
     364  { this->manifest->selectGroup("database", *this->dataDestPath);
    304365  }
    305366}
     
    310371 */
    311372bool GSInstall::updateProgman()
    312 { gsProgramManager  progman;
    313     char *            groupName = NULL;
     373{ string groupName;
    314374
    315375  // if we managed to get a connection to the program manager (or explorer
    316376  // shell) then do the requisite updates
    317   if (progman.connect())
     377  if (this->progman->connect())
    318378  { // get group name from folders
    319     this->configFile->get("ProgramGroupName", &groupName);
    320       if (groupName == NULL)
     379    groupName = this->configFile->getString("ProgramGroupName");
     380      if (groupName == "")
    321381    {   // TODO: error handling
    322         progman.disconnect();
    323           delete groupName;
     382        this->progman->disconnect();
    324383        return false;
    325384      }
    326385
    327386      // add the group
    328         if (!progman.addProgramGroup(groupName))
    329       { progman.disconnect();
    330           delete groupName;
     387        if (!this->progman->addProgramGroup(groupName))
     388      { this->progman->disconnect();
    331389        return false;
    332390    }
    333391
    334392    // add a "server" icon
    335     FilePath libraryPath(this->destinationPath->cString(), "library.exe");
    336       if (!progman.addIcon(groupName, "Library (without nextwork support)", libraryPath.cString(), ""))
    337     { progman.disconnect();
    338           delete groupName;
    339         return false;
     393    FilePath libraryPath(this->destinationPath->pathString(), "library.exe");
     394      if (!this->progman->addIcon(groupName, "Library (without nextwork support)", libraryPath.pathString(), ""))
     395    { // assume that it may be there already
    340396      }
    341397
    342     // TODO: check for server existence
    343     FilePath serverPath(this->destinationPath->cString(), "server.exe");
    344       if (!progman.addIcon(groupName, "Server", serverPath.cString(), ""))
    345     {   progman.disconnect();
    346           delete groupName;
    347         return false;
     398    // check for server existence
     399    FilePath serverPath(this->destinationPath->pathString(), "server.exe");
     400    if (serverPath.exists())
     401    { if (!this->progman->addIcon(groupName, "Server", serverPath.pathString(), ""))
     402        {   // assume that it may be there already
     403      }
    348404      }
    349405
    350     FilePath readMePath(this->destinationPath->cString(), "readme.txt");
    351       if (!progman.addIcon(groupName, "ReadMe", readMePath.cString(), ""))
    352     {   progman.disconnect();
    353           delete groupName;
    354         return false;
     406    FilePath readMePath(this->destinationPath->pathString(), "readme.txt");
     407      if (!this->progman->addIcon(groupName, "ReadMe", readMePath.pathString(), ""))
     408    {
    355409      }
    356410
    357     FilePath supportPath(this->destinationPath->cString(), "support.html");
    358       if (!progman.addIcon(groupName, "Technical Support", supportPath.cString(), ""))
    359     {   progman.disconnect();
    360           delete groupName;
    361         return false;
     411    FilePath supportPath(this->destinationPath->pathString(), "support.html");
     412      if (!this->progman->addIcon(groupName, "Technical Support", supportPath.pathString(), ""))
     413    {
    362414      }
    363415
    364     // TODO: add uninstall support
    365 
    366     // dispose of group name
    367       delete groupName;
     416    // TODO: uninstall icon
     417    // FilePath uninstallPath(this->destinationPath->pathString(), "gssetup.exe");
    368418
    369419    // disconnect from program manager
    370     progman.disconnect();
     420    this->progman->disconnect();
    371421  }
    372422  return true;
     
    393443    {   exePath = this->collectPath;
    394444  }
    395   iniPath   = new FilePath((char *) exePath->cString(), "gsdl.ini");
     445  iniPath   = new FilePath(exePath->pathString(), "gsdl.ini");
    396446
    397447  // TODO: check if this 'if' structure is correct; suspect that it isn't quite
     
    401451  //       This all needs investigating
    402452  if (this->installVolume)
    403   { char volumeSectionName[100] = "\0";
    404     unsigned int space  = 99;
    405 
    406     // Manufacture the appropriate section name now; an equivalent string
     453  { // Manufacture the appropriate section name now; an equivalent string
    407454    // is also constructed
    408     this->configFile->concat("CollectionName", volumeSectionName, space);
    409     strcat(volumeSectionName, "#");
    410     space --;
    411     this->configFile->concat("CollectionVolume", volumeSectionName, space);
    412     string volumeSectionString(volumeSectionName);
     455    string volumeSectionString = this->configFile->getString("CollectionName") +
     456                                                             "#" + this->configFile->getString("CollectionVolume");
    413457
    414458    // if we're installing the full data for the collection, then take the
     
    423467
    424468    // create a profile object to write to the gsdl.ini file
    425     gsProfile gsdlProfile(iniPath->cString());
     469    gsProfile gsdlProfile(*this, iniPath->pathString());
    426470
    427471    // if installing the executable, add the database and greenstone home
     
    429473    if (this->installExe)
    430474    {   // set the correct exe entries in gsdl.ini (in the gsdl section)
    431             gsdlProfile.writeString("gsdl", "gsdlhome", dataPath->cString());
    432       gsdlProfile.writeString("gsdl", "gdbmhome", this->dataDestPath->cString());
    433 
    434       this->unInstall->record("gsdl", "profilewrite", 2, &gsdl_VLHOME,
    435                                                     &dataPath->pathString());
    436       this->unInstall->record("gsdl", "profilewrite", 2, &gsdl_DBHOME,
    437                                                     &this->dataDestPath->pathString());
     475            gsdlProfile.writeString("gsdl", "gsdlhome", dataPath->pathString());
     476      gsdlProfile.writeString("gsdl", "gdbmhome", this->dataDestPath->pathString());
    438477    }
    439478
     
    441480    if (this->installVolume)
    442481    { // note the collection in the general gsdl section; and add the undo item too
    443         gsdlProfile.ensureListMember("gsdl", gsdl_COLLIST.c_str(), volumeSectionName);
    444       this->unInstall->record("gsdl", "proflistensure", 2, &gsdl_COLLIST, &volumeSectionString);
     482        gsdlProfile.ensureListMember("gsdl", gsdl_COLLIST, volumeSectionString);
    445483
    446484      // note the volume data in its own section
    447         gsdlProfile.writeString(volumeSectionName, "gsdlhome", dataPath->cString());
    448         gsdlProfile.writeString(volumeSectionName, "gdbmhome", this->dataDestPath->cString());
    449         gsdlProfile.writeString(volumeSectionName, "staticpath", dataPath->cString());
    450 
    451       this->unInstall->record(volumeSectionName, "profilewrite", 2, &gsdl_VLHOME, &dataPath->pathString());
    452       this->unInstall->record(volumeSectionName, "profilewrite", 2, &gsdl_DBHOME, &this->dataDestPath->pathString());
    453       this->unInstall->record(volumeSectionName, "profilewrite", 2, &gsdl_STATIC, &dataPath->pathString());
     485        gsdlProfile.writeString(volumeSectionString, "gsdlhome", dataPath->pathString());
     486        gsdlProfile.writeString(volumeSectionString, "gdbmhome", this->dataDestPath->pathString());
     487        gsdlProfile.writeString(volumeSectionString, "staticpath", dataPath->pathString());
    454488    }
    455489  }
     
    462496
    463497bool GSInstall::installNetscape()
    464 {   FilePath    netscape32Path(this->sourcePath->cString(), "netscape\\n32e405.exe");
    465   FilePath  netscape16Path(this->sourcePath->cString(), "netscape\\n16e405.exe");
     498{   FilePath    netscape32Path(this->sourcePath->pathString(), "netscape\\n32e405.exe");
     499  FilePath  netscape16Path(this->sourcePath->pathString(), "netscape\\n16e405.exe");
    466500
    467501  launchApp launchNetscape(netscape32Path);
     
    580614
    581615        case PSN_KILLACTIVE:
    582         { // note the path from the dialog
     616        break;
     617
     618                case PSN_WIZNEXT:
     619          { // note the path from the dialog
    583620            dirSelector *selector = ((dirSelector *) GetWindowLong(Dialog, GWL_USERDATA));
    584621            selector->setPathFromEdit(GetDlgItem(Dialog, dirpath_PATH));
     
    586623            // create a new FilePath object to check on the proposed destination
    587624                    FilePath *path = new FilePath(selector->selectedPath());
     625
     626          // if the proposed destination doesn't exist, ask the user whether to
     627          // create it now.  TODO: actually create it if asked!
    588628          if (path->exists() == false)
    589629          { char buffer[128];
     
    600640          }
    601641          delete path;
    602         }
    603         break;
    604 
    605                 case PSN_WIZNEXT:
    606           { if (((LPNMHDR) lParam)->idFrom == 0)
    607             { // TODO: note a default here
    608             }
    609642          }
    610643        break;
     
    673706    pshead.nPages      = 2;
    674707    pshead.nStartPage  = 0;
    675     pshead.ppsp        = ppage;
     708  if (install.installExe == true)
     709  { pshead.ppsp          = ppage;
     710  }
     711  else // cheat as the executable etc. is already installed
     712  { pshead.ppsp          = &ppage[1];
     713  }
    676714    pshead.pfnCallback = GSInstall_wizardProc;
    677715
     
    705743  switch(Message)
    706744    { case WM_CREATE:
    707     {
     745    { ShowWindow(Window, SW_MAXIMIZE);
    708746    }
    709747    break;
     
    713751
    714752    case WM_USER:
    715     {   //dirSelector selector("Choose a Greenstone directory", "Select directory");
    716 
    717       //selector.requestPath(Window, "Select directory");
    718       GSInstall install;
    719       GSInstall_init_wizard(install);
    720       if (config_complete == false)
    721       { MessageBox(0, "Install cancelled", app_name, MB_OK);
    722             }
     753    { // uninstall action
     754        if (strstr(app_cmdLine, "-u") != NULL || true)
     755        { char *at = strstr(app_cmdLine, "-u");
     756        at += strlen("-u") + 1;
     757
     758                GSInstall install(true);
     759        install.setUninstall();
     760        install.uninstall();
     761      }
     762      // install wizard
    723763      else
    724       { install.setDestination();
    725         install.setManifest();
    726           install.copyFiles();
    727         install.updateProgman();
    728           install.updateRegistry();
    729         install.updateProfiles();
    730         install.installNetscape();
     764      { GSInstall install(false);
     765        GSInstall_init_wizard(install);
     766          if (config_complete == false)
     767        {   MessageBox(0, "Install cancelled", app_name, MB_OK);
     768                }
     769        else
     770          { // configure the installation
     771            install.setDestination();
     772            install.setManifest();
     773
     774            // perform installation
     775              install.copyFiles();
     776            install.updateProgman();
     777              install.updateRegistry();
     778            install.updateProfiles();
     779
     780            // do further actions
     781          install.installNetscape();
     782          }
    731783      }
    732784      DestroyWindow(Window);
Note: See TracChangeset for help on using the changeset viewer.