Changeset 1475 for trunk


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

Updated sources with most of uninstall added

Location:
trunk/gsinstaller
Files:
23 edited

Legend:

Unmodified
Added
Removed
  • trunk/gsinstaller/FilePath.cpp

    r1397 r1475  
    103103  this->path = filePath;
    104104
    105   // if it didn't have a concluding divider, then add one
    106   if (this->path[filePath.length()-1] != divider)
     105  // if it didn't have a concluding divider, then add one; note that if
     106  // filePath is empty, we're not actually going to add any divider at
     107  // all
     108  if (filePath.length() > 0 &&
     109      this->path[filePath.length()-1] != divider)
    107110  { this->path.append(dividerStr);
    108111  }
  • trunk/gsinstaller/configFile.cpp

    r1397 r1475  
    4343  space -= strlen(configstr->item[loop].data);
    4444  return true;
     45}
     46
     47string configureFile::getString(string label)
     48{   for (int loop = 0; loop < configstr->count; loop ++)
     49    {   if (strcmp(configstr->item[loop].label, label.c_str()) == 0)
     50    { return configstr->item[loop].data;
     51    }
     52  }
     53  return "";
    4554}
    4655
     
    8897}
    8998
    90 bool configureFile::scan(char *block, unsigned int &pos)
     99/**
     100 * Scan one line of the configuration file
     101 */
     102bool configureFile::scan(char *block, unsigned int &pos, unsigned int length)
    91103{ int off = 0;
    92104    void *newstr;
    93105
     106  if (pos == length)
     107  { return true;
     108  }
     109
     110    // if it's a comment line, skip it straightaway
     111  if (block[pos] == '#')
     112  { while (block[pos] >= ' ')
     113    {   block ++;
     114    }
     115    while (block[pos] < ' ')
     116    {   block ++;
     117        if (block[pos-1] == '\0')
     118      { break;
     119      }
     120    }
     121    return true;
     122  }
     123
     124  // otherwise create a new struct to cope with the list of configuration items
    94125  newstr = realloc(configstr, sizeof(config_str) +
    95126                              sizeof(config_item) * configstr->count);
     
    101132  configstr = (config_str *) newstr;
    102133
    103   while (block[pos] != ':')
     134  // scan to the colon to get the label
     135  while (pos < length && block[pos] != ':')
    104136  { configstr->item[configstr->count].label[off] = block[pos];
    105137    off ++;
     
    108140  configstr->item[configstr->count].label[off] = '\0';
    109141
     142  // read until we get past any leading whitespace or tabs
    110143  off = 0;
    111   do
    112   { pos ++;
    113   } while (block[pos] <= ' ' && block[pos] != '\x0a' && block[pos] != '\x0d');
    114 
    115   while(block[pos] >= ' ')
     144  if (pos < length)
     145  { do
     146    {   pos ++;
     147    }
     148    while (block[pos] <= ' ' && block[pos] != '\x0a' && block[pos] != '\x0d');
     149  }
     150
     151  // read until we reach a "magic" character - this is where we read the value
     152  while(pos < length && block[pos] >= ' ')
    116153  { configstr->item[configstr->count].data[off] = block[pos];
    117154    pos ++;
     
    120157  configstr->item[configstr->count].data[off] = '\0';
    121158
    122   do
    123   { pos ++;
    124   }
    125     while (block[pos] <= ' ');
    126 
     159  // skip any magic characters
     160  if (pos < length)
     161  { do
     162    { pos ++;
     163    }
     164      while (block[pos] <= ' ' && pos < length);
     165  }
     166
     167  // remember that we've added to the list
    127168  configstr->count ++;
    128169  return true;
     
    190231    position    = 0;
    191232    while (position < length)
    192     { this->scan(block, position);
     233    { this->scan(block, position, length);
    193234    }
    194235
    195236    fclose(fhandle);
     237
     238      free(block);
     239
     240      this->valid = true;
    196241  }
    197242  else
    198243  { // No config file MessageBox(0, "oops", "oops", MB_OK);
    199   }
    200 
    201   free(block);
     244    this->valid = false;
     245  }
    202246//Acorn:  free(varval);
    203247
    204   this->valid = true;
    205248}
    206249
  • trunk/gsinstaller/configFile.h

    r1397 r1475  
    11#ifndef _CONFIG_H_
    22#define _CONFIG_H_
     3#include <string>
     4using namespace std;
     5
    36#include <stdio.h>
    47#include <string.h>
     
    2225    bool valid;
    2326
    24     bool scan(char *buffer, unsigned int &pos);
     27    bool scan(char *buffer, unsigned int &pos, unsigned int length);
    2528    public:
    2629    configureFile(char *name);
     
    2831    bool put(char *label, char *value);
    2932    bool concat(char *label, char *buffer, unsigned int &space);
     33    string getString(string label);
    3034    void get(char *label, char **to);
    3135    bool store(char *);
  • trunk/gsinstaller/copyProgress.cpp

    r1397 r1475  
    77
    88extern HINSTANCE app_instance;
     9extern gsInstall_getDesktopExt(int *x, int *y);
    910
    1011LRESULT CALLBACK copyProgressBar_windowProc(    HWND window, UINT message,
     
    8586void copyProgressBar::show()
    8687{ long params[2];
     88  int sx, sy, dx, dy;
    8789
    8890    params[0] = (long) this;
    8991  params[1] = (long) "Copying files....";
    9092  this->registerClass();
    91     this->progressParent    = CreateWindowEx(WS_EX_APPWINDOW, "CopyProgressBar", "GreenStone Installer", WS_VISIBLE,
    92                                                                          CW_USEDEFAULT, CW_USEDEFAULT, 200, 80, 0, (HMENU) 0,
    93                                          app_instance, (void *) params);
     93
     94  gsInstall_getDesktopExt(&sx, &sy);
     95
     96  dx = (sx - 200) >> 1;
     97  dy = (sy - 80) >> 1;
     98
     99    this->progressParent    = CreateWindowEx(   WS_EX_APPWINDOW, "CopyProgressBar",
     100                                                                                "GreenStone Installer", WS_VISIBLE,
     101                                                                                    dx, dy, 200, 80,
     102                                          0, (HMENU) 0,
     103                                                    app_instance, (void *) params);
    94104    this->progressBar   = CreateWindowEx(0, PROGRESS_CLASS, NULL, WS_CHILD | WS_VISIBLE,
    95                                                                          10, 30, 180, GetSystemMetrics(SM_CYVSCROLL), this->progressParent, (HMENU) 0,
     105                                                                         10, 30, 180, GetSystemMetrics(SM_CYVSCROLL),
     106                                     this->progressParent, (HMENU) 0,
    96107                                         app_instance, NULL);
    97108}
  • trunk/gsinstaller/fileCopier.cpp

    r1397 r1475  
    1414    this->sourceDir = from;
    1515  this->destDir     = to;
     16  this->dataSize    = 0;
    1617
    1718    FileVector::iterator here   = files.begin();
     
    4344 * Copy a particular file to its destination
    4445 */
    45 bool fileCopySet::copyFile(File *file, copyProgressBar &progressBar)
     46bool fileCopySet::copyFile(File *file, fileCopyMonitor *monitor, copyProgressBar &progressBar)
    4647{ unsigned long copied = 0;
    4748    unsigned long bytes_read, bytes_written;
     
    8990
    9091  // free destination filename text
     92  if (monitor != NULL)
     93  { monitor->copied(file->getFileName(), destination, false);
     94  }
    9195  delete destination;
    9296  return true;
     
    97101 *  destination
    98102 */
    99 void fileCopySet::copy(File *file, copyProgressBar &progressBar)
     103void fileCopySet::copy(File *file, fileCopyMonitor *monitor, copyProgressBar &progressBar)
    100104{ // just skip this file if it doesn't exist
    101105    if (file->exists() == false)
     
    116120    vector<File>::iterator end  = file->childEnd();
    117121    while (here != end)
    118     {   this->copy(here, progressBar);
     122    {   this->copy(here, monitor, progressBar);
    119123        here ++;
    120124    }
     125
     126      if (monitor != NULL)
     127    {   monitor->copied(file->getFileName(), thisDestDir, true);
     128    }
    121129
    122130    // delete constructed destination name
     
    126134  else
    127135  { // copy file itself
    128     this->copyFile(file, progressBar);
     136    this->copyFile(file, monitor, progressBar);
    129137  }
    130138  progressBar.done(file->getRawFileSize());
    131139}
    132140
    133 void fileCopySet::copy(copyProgressBar &progressBar)
     141void fileCopySet::copy(fileCopyMonitor *monitor, copyProgressBar &progressBar)
    134142{   FileVector::iterator here = fileList.begin();
    135143    FileVector::iterator end    = fileList.end();
    136144
    137145  while (here != end)
    138   { this->copy(here, progressBar);
     146  { this->copy(here, monitor, progressBar);
    139147    here ++;
    140148  }
     
    173181
    174182    // get destination root and use it to obtain space check information
    175     char buffer[120];
    176183        FilePath *destRoot = localSet[0].destDir.root();
    177     strcpy(buffer, destRoot->cString());
    178     MessageBox(0, buffer, "A", MB_OK);
    179184        DiskSpace space(destRoot->cString());
    180185
     
    230235}
    231236
    232 fileCopier::fileCopier(fileCopySetList &_list)
     237fileCopier::fileCopier(fileCopyMonitor *monitor, fileCopySetList &_list)
    233238{   this->list  = _list;
    234239  this->dataSize    = 0;
    235240  this->copied      = 0;
    236 }
    237 
    238 fileCopier::fileCopier()
     241  this->monitor     = monitor;
     242}
     243
     244fileCopier::fileCopier(fileCopyMonitor *monitor)
    239245{ this->dataSize    = 0;
    240246  this->copied      = 0;
     247  this->monitor     = monitor;
    241248}
    242249
     
    247254  this->progressBar.show();
    248255  while (here != end)
    249   { here->copy(this->progressBar);
     256  { here->copy(this->monitor, this->progressBar);
    250257    here ++;
    251258  }
  • trunk/gsinstaller/fileCopier.h

    r1397 r1475  
    44#include "copyProgress.h"
    55#include "diskSpace.h"
     6
     7class fileCopyMonitor
     8{   public:
     9        fileCopyMonitor() {};
     10        virtual void copied(string from, string to, bool isDir) = 0;
     11};
    612
    713class fileCopySet
     
    1723    unsigned long getOriginalSize();
    1824    unsigned long getCopiedSize(DiskSpace &space);
    19     bool copyFile(File *file, copyProgressBar &progressBar);
    20     void copy(File *file, copyProgressBar &progressBar);
    21     void copy(copyProgressBar &progressBar);
     25    bool copyFile(File *file, fileCopyMonitor *monitor, copyProgressBar &progressBar);
     26    void copy(File *file, fileCopyMonitor *monitor, copyProgressBar &progressBar);
     27    void copy(fileCopyMonitor *monitor, copyProgressBar &progressBar);
    2228};
    2329
     
    3036    unsigned long   copied;
    3137      copyProgressBar progressBar;
     38    fileCopyMonitor *monitor;
    3239    protected:
    3340  public:
    34     fileCopier::fileCopier(fileCopySetList &list);
    35     fileCopier::fileCopier();
     41    fileCopier::fileCopier(fileCopyMonitor *monitor, fileCopySetList &list);
     42    fileCopier::fileCopier(fileCopyMonitor *monitor);
    3643    void fileCopier::addSet(fileCopySet &set) { this->list.push_back(set); }
    3744    bool checkSpace();
  • trunk/gsinstaller/gsManifest.cpp

    r1397 r1475  
    11#include "gsManifest.h"
    2 #include "fileCopier.h"
    32
    43#include <string.h>
     
    76#include <windows.h>
    87
    9 gsManifest::gsManifest(FilePath &root)
     8gsManifest::gsManifest(installManager &manager)
     9  : installAgent(manager)
     10{   // do nothing!
     11}
     12
     13gsManifest::gsManifest(installManager &manager, FilePath &root)
     14  : installAgent(manager), fileCopyMonitor()
    1015{   this->getManifest(root);
    1116    this->expandGroups();
     
    8792    group = newgroup;
    8893  }
     94  // if it starts with a hash it's just a comment line; skip it
     95  else if (*line == '#')
     96  { // do nothing!
     97  }
     98  // an actual line of member items; read them in
    8999  else
    90100  { stringArray array;
     
    186196}
    187197
    188 void gsManifest::selectGroup(string &groupName, FilePath &destination)
     198void gsManifest::selectGroup(string groupName, FilePath &destination)
    189199{ stringArray &groupArray = this->manifests[groupName];
    190200
     
    193203}
    194204
     205/**
     206 * Copy the manifest
     207 */
    195208bool gsManifest::copy(FilePath *source)
    196 { fileCopier    copy;
     209{ fileCopier    copy(this);
    197210
    198211    pathStringArrayMap::iterator here = this->selected.begin();
    199212  pathStringArrayMap::iterator end  = this->selected.end();
    200213
     214  // add all the sets to copy to the manifest
    201215  while (here != end)
    202216  { FileVector *fileList;
     
    205219
    206220    // TODO: eliminate inefficiency; we're doing FilePath->string->FilePath in
    207     // effect between constructing the copy lists, and then the sets as far
     221    // effect between constructing the copy lists, and then the sets, as far
    208222    // as the destinations go
    209     fileList = this->selection(array);
     223    fileList = this->selection(*source, array);
    210224    fileCopySet copySet(*fileList, *source, path);
    211225    copy.addSet(copySet);
     
    214228  }
    215229
     230  // check that we've got enough space @ the destination(s)
    216231  if (!copy.checkSpace())
    217232  { return false;
    218233  }
     234
     235  // do the actual copying
    219236  copy.copy();
    220237  return true;
    221238}
    222239
    223 FileVector *gsManifest::selection(stringArray &array)
     240void gsManifest::copied(string from, string to, bool isDir)
     241{ if (isDir)
     242    {   this->logAction("Manifest.CreateDir", to);
     243    }
     244  else
     245  { this->logAction("Manifest.CopyFile", from, to);
     246  }
     247}
     248
     249void gsManifest::logAction(string actionName, string file)
     250{   manager->writeString(actionName);
     251    manager->writeSeparator();
     252  manager->writeString(file);
     253  manager->writeString("\n");
     254}
     255
     256void gsManifest::logAction(string actionName, string source, string dest)
     257{   manager->writeString(actionName);
     258    manager->writeSeparator();
     259  manager->writeString(source);
     260    manager->writeSeparator();
     261  manager->writeString(dest);
     262  manager->writeString("\n");
     263}
     264
     265bool gsManifest::undoAction(string actionName, stringArray &params)
     266{   if (actionName == "Manifest.CreateDir" || actionName == "CreateDir")
     267    {   RemoveDirectory(params[0].c_str());
     268      return true;
     269  }
     270  else if (actionName == "Manifest.CopyFile" || actionName == "CopyFile")
     271    {   DeleteFile(params[1].c_str());
     272    return true;
     273  }
     274  return false;
     275}
     276
     277FileVector *gsManifest::selection(FilePath &root, stringArray &array)
    224278{   FileVector *reply = new FileVector();
    225279
    226280  for (unsigned int i = 0; i < array.size(); i++)
    227   { File file(array[i]);
     281  { FilePath    fileName(root.pathString(), array[i]);
     282    File file(fileName.pathString());
    228283    reply->push_back(file);
    229284  }
     
    231286}
    232287
    233 FileVector *gsManifest::selection(FilePath &destination)
    234 {   return this->selection(this->selected[destination]);
    235 }
    236 
     288FileVector *gsManifest::selection(FilePath &source, FilePath &destination)
     289{   return this->selection(source, this->selected[destination]);
     290}
     291
  • trunk/gsinstaller/gsManifest.h

    r1397 r1475  
    66#include "File.h"
    77#include "FilePath.h"
     8#include "FileCopier.h"
    89#include "stringArray.h"
     10#include "uninstall.h"
    911
    1012typedef map<FilePath, stringArray, less<FilePath> > pathStringArrayMap;
    1113
    12 class gsManifest
     14class gsManifest : public installAgent, fileCopyMonitor
    1315{   private:
    1416    protected:
    1517        strArrayMap                 manifests;
    1618    pathStringArrayMap  selected;
     19
     20    bool getManifestLine(char *line, string &macro);
    1721  public:
    18     gsManifest(FilePath &path);
     22    gsManifest(installManager &manager, FilePath &path); // used for install
     23    gsManifest(installManager &manager); // used for uninstall
    1924    bool getManifest(FilePath &path);
    20     bool getManifestLine(char *line, string &macro);
     25    void logAction(string actionName, string file);
     26    void logAction(string actionName, string source, string dest);
     27    bool undoAction(string actionName, stringArray &params);
    2128    void expandGroupInstance(string parent, string child);
    2229    void expandGroup(string &group);
     
    2633    void clearSelection();
    2734    bool copy(FilePath *source);
    28     void selectGroup(string &groupName, FilePath &destination);
    29     FileVector *selection(stringArray &array);
    30     FileVector *selection(FilePath &destination);
     35    void selectGroup(string groupName, FilePath &destination);
     36    FileVector *selection(FilePath &source, stringArray &array);
     37    FileVector *selection(FilePath &source, FilePath &destination);
    3138    bool selectCheckSpace();
     39
     40    void copied(string from, string to, bool isDir); // from fileCopyMonitor
    3241};
    3342#endif;
  • trunk/gsinstaller/gsProfile.cpp

    r1397 r1475  
    22
    33#include <stdio.h>
    4 #include "stringArray.h"
    54
    6 gsProfile::gsProfile(const char *fileName)
     5gsProfile::gsProfile(installManager &manager, string fileName)
     6  : installAgent(manager)
    77{   this->fileName  = fileName;
    88}
    99
    10 bool gsProfile::ensureListMember(const char *sectionName, const char *listName,
    11                                                                     const char *listMember)
     10void gsProfile::logAction(string action, string sectionName, string item,
     11                                                    string value)
     12{ manager->writeString(action);
     13    manager->writeSeparator();
     14  manager->writeString(this->fileName);
     15  manager->writeSeparator();
     16  manager->writeString(sectionName);
     17  manager->writeSeparator();
     18  manager->writeString(item);
     19  manager->writeSeparator();
     20  manager->writeString(value);
     21  manager->writeString("\n");
     22}
     23
     24bool gsProfile::undoAction(string actionName, stringArray &params)
     25{   if (actionName == "ProfileAddListMember")
     26    {   this->removeListMember(params[0], params[1], params[2]);
     27    return true;
     28  }
     29  return false;
     30}
     31
     32bool gsProfile::ensureListMember(string sectionName, string listName,
     33                                                                    string listMember)
    1234{ char              buffer[256] = "\0";
    1335    stringArray *members;
     36  bool              reply = true;
    1437
    15     if (GetPrivateProfileString(sectionName, listName, "",
    16                                                         buffer, 256, this->fileName) <= 0)
     38    if (GetPrivateProfileString(sectionName.c_str(), listName.c_str(), "",
     39                                                        buffer, 256, this->fileName.c_str()) <= 0)
    1740  { buffer[0] = '\0';
    1841  }
     
    2245  { members->add(listMember);
    2346    members->writeToCString(buffer, ";", 256);
    24     delete members;
    25     return WritePrivateProfileString(sectionName, listName, buffer, this->fileName);
     47
     48    reply   = this->writeString(sectionName, listName, buffer);
     49    if (reply)
     50    {   this->logAction("ProfileAddListMember", sectionName, listName, listMember);
     51    }
    2652  }
    2753  delete members;
    28   return true;
     54  return reply;
    2955}
    3056
    31 bool gsProfile::addListMember(const char *sectionName, const char *listName, const char *listMember)
     57bool gsProfile::addListMember(string sectionName, string listName, string listMember)
    3258{ char buffer[256];
    3359  stringArray   *members;
    3460
    35     GetPrivateProfileString(sectionName, listName, "",
    36                                                     buffer, 256, this->fileName);
     61    GetPrivateProfileString(sectionName.c_str(), listName.c_str(), "",
     62                                                    buffer, 256, this->fileName.c_str());
    3763    // straightforward, unthinking, add
    3864  members   = new stringArray(buffer, ";");
     
    4066  members->writeToCString(buffer, ";", 256);
    4167  delete members;
    42   return WritePrivateProfileString(sectionName, listName, buffer, this->fileName);
     68  return this->writeString(sectionName, listName, buffer);
    4369}
    4470
    45 bool gsProfile::removeListMember(const char *sectionName, const char *listName, const char *listMember)
     71bool gsProfile::removeListMember(string sectionName, string listName, string listMember)
    4672{ char buffer[256];
    4773  stringArray   *members;
    4874
    49     GetPrivateProfileString(sectionName, listName, "",
    50                                                     buffer, 256, this->fileName);
     75    GetPrivateProfileString(sectionName.c_str(), listName.c_str(), "",
     76                                                    buffer, 256, this->fileName.c_str());
    5177    // straightforward, unthinking, removal - if it isn't there, we won't need to
    5278  // worry!
     
    5682  delete members;
    5783
    58   return WritePrivateProfileString(sectionName, listName, buffer, this->fileName);
     84  return this->writeString(sectionName, listName, buffer);
    5985}
    6086
    61 bool gsProfile::writeString(const char *sectionName, const char *itemName, const char *itemValue)
    62 {   if (!WritePrivateProfileString(sectionName, itemName, itemValue, this->fileName))
     87bool gsProfile::writeString(string sectionName, string itemName, string itemValue)
     88{   if (!WritePrivateProfileString( sectionName.c_str(), itemName.c_str(),
     89                                                                    itemValue.c_str(), this->fileName.c_str()))
    6390    { DWORD error = GetLastError();
    6491    char buffer[20];
  • trunk/gsinstaller/gsProfile.h

    r1397 r1475  
    11#ifndef _GSPROFILE_H_
    22#define _GSPROFILE_H_
     3#include <string>
     4using namespace std;
    35#include <windows.h>
    4 class gsProfile
     6
     7#include "uninstall.h"
     8#include "stringarray.h"
     9
     10class gsProfile : public installAgent
    511{
    612    private:
    7     const char *fileName;
     13    string fileName;
     14
     15    void logAction(string action, string sectionName, string item, string value);
    816  protected:
    917  public:
    10     gsProfile(const char *fileName);
    11     bool ensureListMember(const char *sectionName, const char *listName, const char *listMember);
    12     bool removeListMember(const char *sectionName, const char *listName, const char *listMember);
    13     bool addListMember(const char *sectionName, const char *listName, const char *listMember);
    14     bool writeString(const char *sectionName, const char *itemName, const char *itemValue);
     18    gsProfile(installManager &manager, string fileName);
     19    bool ensureListMember(string sectionName, string listName, string listMember);
     20    bool removeListMember(string sectionName, string listName, string listMember);
     21    bool addListMember(string sectionName, string listName, string listMember);
     22    bool writeString(string sectionName, string itemName, string itemValue);
     23    bool undoAction(string actionName, stringArray &params);
    1524};
    1625#endif
  • trunk/gsinstaller/gsProgman.cpp

    r1397 r1475  
    8080}
    8181
    82 gsProgramManager::gsProgramManager()
     82gsProgramManager::gsProgramManager(installManager &manager)
     83    : installAgent(manager)
    8384{   this->platform  = new gsPlatform();
    8485    this->connected = false;
     86}
     87
     88void gsProgramManager::logAction(string actionName, string group)
     89{   manager->writeString(actionName);
     90    manager->writeSeparator();
     91  manager->writeString(group);
     92    manager->writeString("\n");
     93}
     94
     95void gsProgramManager::logAction(string actionName, string group, string item, string parameter)
     96{   manager->writeString(actionName);
     97    manager->writeSeparator();
     98  manager->writeString(group);
     99    manager->writeSeparator();
     100  manager->writeString(item);
     101    manager->writeSeparator();
     102  manager->writeString(parameter);
     103    manager->writeString("\n");
     104}
     105
     106bool gsProgramManager::undoAction(string actionName, stringArray &params)
     107{ if (actionName == "ProgManCreateGroup")
     108    {   this->removeProgramGroup(params[0]);
     109    return true;
     110  }
     111  else if (actionName == "ProgManAddIcon")
     112  { this->removeIcon(params[0], params[1]);
     113    return true;
     114  }
     115  return false;
    85116}
    86117
     
    123154}
    124155
    125 bool gsProgramManager::addProgramGroup(const char *groupName)
     156bool gsProgramManager::addProgramGroup(string groupName)
    126157{   //CreateGroup(groupName);
    127158    char buffer[256];
     
    147178  else
    148179  { // add using program manager DDE
    149     sprintf(buffer, "[CreateGroup (%s)]", groupName);
     180    sprintf(buffer, "[CreateGroup (%s)]", groupName.c_str());
    150181    if (!DDEShellCommand(this->instance, buffer))
    151182    {   // flag error by returning false
     
    153184    }
    154185  }
     186
     187  this->logAction("ProgManCreateGroup", groupName);
    155188    return true;
    156189}
    157190
    158 bool gsProgramManager::addIcon( const char *groupName,              // group of the icon
    159                                                                 const char *iconName,                   // name of the icon
    160                                 const char *iconDestination,    // destination file of the icon
    161                                                             const char *description)            // the textual description
    162                                                                                             // of the icon (not usually displayed)
     191bool gsProgramManager::addIcon( string groupName,               // group of the icon
     192                                                                string iconName,                // name of the icon
     193                                string iconDestination, // destination file of the icon
     194                                                            string description)         // the textual description
     195                                                                                // of the icon (not usually displayed)
    163196{   bool                    reply = false;
    164197    char                    buffer[MAX_PATH];
     
    176209
    177210        SHGetPathFromIDList(pidl, buffer);
    178         fullPath    = new FilePath(4, buffer, groupName, iconName, "!.lnk");
     211        fullPath    = new FilePath(4, buffer, groupName.c_str(), iconName.c_str(), ".lnk");
    179212
    180213        // Get a pointer to the IShellLink interface.
     
    186219        // Set the path to the shortcut target, and add the
    187220        // description.
    188       psl->SetPath(iconDestination);
    189 
    190         psl->SetDescription(description);
     221      psl->SetPath(iconDestination.c_str());
     222
     223        psl->SetDescription(description.c_str());
    191224
    192225        // Query IShellLink for the IPersistFile interface for saving the
     
    214247    // ensure that the requisite group is active; the add icon command will
    215248    // use the active group.
    216     sprintf(buffer, "[ShowGroup(%s,5)]", groupName);
     249    sprintf(buffer, "[ShowGroup(%s,5)]", groupName.c_str());
    217250    if (!DDEShellCommand(this->instance, buffer))
    218251    { // TODO: articulate/determine possible errors; expand error handling
     
    221254
    222255    // and now add the item itself to the active (given) group
    223     sprintf(buffer, "[AddItem(%s,%s)]", iconDestination, iconName);
     256    sprintf(buffer, "[AddItem(%s,%s)]", iconDestination.c_str(), iconName.c_str());
    224257    if (!DDEShellCommand(this->instance, buffer))
    225258    {   // TODO: again work out what the problems could be
     
    228261    reply = true;
    229262  }
     263
     264  if (reply)
     265  { this->logAction("ProgManAddItem", groupName, iconName, iconDestination);
     266  }
    230267  return reply;
    231268}
    232269
    233 bool gsProgramManager::removeProgramGroup(const char *groupName)
     270bool gsProgramManager::removeProgramGroup(string groupName)
    234271{   //CreateGroup(groupName);
    235272    char buffer[256];
     
    255292  else
    256293  { // add using program manager DDE
    257     sprintf(buffer, "[DeleteGroup (%s)]", groupName);
     294    sprintf(buffer, "[DeleteGroup (%s)]", groupName.c_str());
    258295    if (!DDEShellCommand(this->instance, buffer))
    259296    {   // flag error by returning false
     
    264301}
    265302
    266 bool gsProgramManager::removeIcon(const char *groupName,                // group of the icon
    267                                                                     const char *iconName)                   // name of the icon
     303bool gsProgramManager::removeIcon(string groupName,             // group of the icon
     304                                                                    string iconName)                    // name of the icon
    268305{   bool                    reply = false;
    269306    char                    buffer[MAX_PATH];
     
    281318
    282319        SHGetPathFromIDList(pidl, buffer);
    283         fullPath    = new FilePath(4, buffer, groupName, iconName, "!.lnk");
     320        fullPath    = new FilePath(4, buffer, groupName.c_str(), iconName.c_str(), "!.lnk");
    284321
    285322    // TODO: delete file
     
    290327    // ensure that the requisite group is active; the add icon command will
    291328    // use the active group.
    292     sprintf(buffer, "[ShowGroup(%s,5)]", groupName);
     329    sprintf(buffer, "[ShowGroup(%s,5)]", groupName.c_str());
    293330    if (!DDEShellCommand(this->instance, buffer))
    294331    { // TODO: articulate/determine possible errors; expand error handling
     
    297334
    298335    // and now add the item itself to the active (given) group
    299     sprintf(buffer, "[DeleteItem(%s)]", iconName);
     336    sprintf(buffer, "[DeleteItem(%s)]", iconName.c_str());
    300337    if (!DDEShellCommand(this->instance, buffer))
    301338    {   // TODO: again work out what the problems could be
  • trunk/gsinstaller/gsProgman.h

    r1397 r1475  
    44
    55#include "gsPlatform.h"
     6#include "uninstall.h"
     7#include "stringArray.h"
    68
    7 class gsProgramManager
     9class gsProgramManager : public installAgent
    810{
    911    private:
     
    1113    DWORD               instance;
    1214    bool                connected;
     15
     16    void logAction(string actionName, string group);
     17    void logAction(string actionName, string group, string item, string parameter);
    1318  protected:
    1419  public:
    1520    // constructor
    16     gsProgramManager();
     21    gsProgramManager(installManager &manager);
    1722
    1823    // connect/disconnect activity
     
    2025    bool disconnect();
    2126
    22     bool addProgramGroup(const char *name);
    23     bool removeProgramGroup(const char *name);
    24     bool addIcon(   const char *groupName, const char *iconName, const char *iconDestination,
    25                                 const char *description);
    26     bool removeIcon(    const char *groupName, const char *iconName);
     27    bool addProgramGroup(string name);
     28    bool removeProgramGroup(string name);
     29    bool addIcon(   string groupName, string iconName, string iconDestination,
     30                                string description);
     31    bool removeIcon(    string groupName, string iconName);
     32
     33    bool undoAction(string actionName, stringArray &params);
    2734};
    2835#endif
  • trunk/gsinstaller/gsRegistry.cpp

    r1397 r1475  
    11#include "gsRegistry.h"
    22
    3 gsRegistry::gsRegistry(configureFile &configFile)
     3gsRegistry::gsRegistry(installManager &manager, configureFile &configFile)
     4  : installAgent(manager)
    45{ unsigned int space;
    56
    67    // Create string for volume key
    7     strcpy(volumeKey, "Software\\");
    8     space   = 255 - strlen(volumeKey);
    9 
    10     configFile.concat("CompanyName", volumeKey, space);
    11   strcat(volumeKey, "\\");
    12     configFile.concat("CollectionName", volumeKey, space);
    13   strcat(volumeKey, "\\");
    14     configFile.concat("CollectionVolume", volumeKey, space);
    15   strcat(volumeKey, "\\");
    16     configFile.concat("CollectionVersion", volumeKey, space);
     8    volumeKey = "Software\\" + configFile.getString("CompanyName") + "\\" +
     9                            configFile.getString("CollectionName") + "\\" +
     10                            configFile.getString("CollectionVolume") + "\\" +
     11                            configFile.getString("CollectionVersion");
    1712
    1813    // Create string for collection key
    19     strcpy(collectKey, "Software\\");
    20     space   = 255 - strlen(collectKey);
    21 
    22     configFile.concat("CompanyName", collectKey, space);
    23   strcat(collectKey, "\\");
    24     configFile.concat("CollectionName", collectKey, space);
    25   strcat(collectKey, "\\");
    26     configFile.concat("CollectionVersion", collectKey, space);
     14    collectKey = "Software\\" + configFile.getString("CompanyName") + "\\" +
     15                            configFile.getString("CollectionName") + "\\" +
     16                configFile.getString("CollectionVersion");
    2717}
    2818
    29 bool gsRegistry::ensureKeysExist()
    30 {   if (registry_ensureKeyExists(HKEY_LOCAL_MACHINE, this->collectKey) == false)
    31     {   return false;
     19bool gsRegistry::logAction(string action, HKEY base, string path, string item, string value)
     20{   manager->writeString(action);
     21    manager->writeSeparator();
     22  manager->writeString(path);
     23    if (item != "" || value != "")
     24  { manager->writeSeparator();
     25    if (item == "")
     26    {   manager->writeString("{Default}");
     27    }
     28    else
     29    {   manager->writeString(item);
     30    }
     31        manager->writeSeparator();
     32    manager->writeString(value);
    3233  }
    33   if (registry_ensureKeyExists(HKEY_LOCAL_MACHINE, this->volumeKey) == false)
    34   { return false;
     34  manager->writeString("\n");
     35}
     36
     37bool gsRegistry::undoAction(string actionName, stringArray &params)
     38{ if (actionName == "RegistryCreateKey")
     39    {   this->destroyKey(HKEY_LOCAL_MACHINE, params[0]);
     40  }
     41  else if (actionName == "RegistrySetString")
     42  { this->destroyItem(HKEY_LOCAL_MACHINE, params[0], params[1]);
     43  }
     44  else
     45  { return false;
    3546  }
    3647  return true;
    3748}
    3849
    39 bool gsRegistry::ensureKeyExists(HKEY base, const char *key)
    40 {   return(registry_ensureKeyExists(base, key));
     50bool gsRegistry::ensureKeysExist()
     51{ if (!this->ensureKeyExists(HKEY_LOCAL_MACHINE, this->collectKey))
     52    {   return false;
     53  }
     54  return this->ensureKeyExists(HKEY_LOCAL_MACHINE, this->volumeKey);
    4155}
    4256
    43 bool gsRegistry::storeKeyString(HKEY base, const char *path, const char *item, const char *string)
     57bool gsRegistry::ensureKeyExists(HKEY base, string key)
     58{ if (!registry_keyExists(base, key.c_str()))
     59    {   if (!registry_ensureKeyExists(base, key.c_str()))
     60    {   return false;
     61    }
     62    this->logAction("RegistryCreateKey", base, key, "", "");
     63  }
     64  return true;
     65}
     66
     67bool gsRegistry::destroyKey(HKEY base, string key)
     68{   registry_deletekey(base, key.c_str());
     69}
     70
     71bool gsRegistry::storeKeyString(HKEY base, string path, string item, string value)
    4472{   HKEY local;
    4573    bool    reply;
    4674
    47   if (!registry_openkey(base, (char *) path, &local))
     75  if (!registry_openkey(base, path.c_str(), &local))
    4876    {   return false;
    4977  }
    50   reply = registry_setstring(local, item, string);
     78  reply = registry_setstring(local, item.c_str(), value.c_str());
     79  if (reply)
     80  { this->logAction("RegistrySetString", base, path, item, value);
     81  }
    5182  registry_closekey(local);
    5283  return reply;
    5384}
    5485
     86bool gsRegistry::destroyItem(HKEY base, string path, string item)
     87{ HKEY local;
     88
     89    if (!registry_openkey(base, path.c_str(), &local))
     90  { return false;
     91  }
     92  registry_deleteitem(local, item.c_str());
     93  registry_closekey(local);
     94}
     95
    5596bool gsRegistry::collectionInstalled()
    56 {   return registry_keyExists(HKEY_LOCAL_MACHINE, this->collectKey);
     97{   return registry_keyExists(HKEY_LOCAL_MACHINE, this->collectKey.c_str());
    5798}
    5899
    59100bool gsRegistry::volumeInstalled()
    60 {   return registry_keyExists(HKEY_LOCAL_MACHINE, this->volumeKey);
     101{   return registry_keyExists(HKEY_LOCAL_MACHINE, this->volumeKey.c_str());
    61102}
    62103
    63 char *gsRegistry::collectKeyId()
     104string gsRegistry::collectKeyId()
    64105{   return this->collectKey;
    65106}
    66107
    67 char *gsRegistry::volumeKeyId()
     108string gsRegistry::volumeKeyId()
    68109{   return this->volumeKey;
    69110}
    70111
    71 char *gsRegistry::exeKeyId(char *exename)
    72 {   char *reply = new char[256];
     112string gsRegistry::exeKeyId(string exename)
     113{   string reply = "Software\\Microsoft\\Windows\\CurrentVersion\\App Paths\\";
     114    reply += exename;
     115  return reply;
     116}
    73117
    74     // Create string for exe path
    75     strcpy(reply, "Software\\Microsoft\\Windows\\CurrentVersion\\App Paths\\");
    76   strcat(reply, exename);
    77   return reply;
     118string gsRegistry::uninstallKeyId(string collectName)
     119{   return "Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\" + collectName;
    78120}
    79121
     
    83125    HKEY key;
    84126
    85   if (registry_openkey(HKEY_LOCAL_MACHINE, this->collectKey, &key))
     127  if (registry_openkey(HKEY_LOCAL_MACHINE, this->collectKey.c_str(), &key))
    86128  { if (registry_getstring(key, "library", &path))
    87129    { // get leaf (\library.exe) and remove it to give a path
  • trunk/gsinstaller/gsRegistry.h

    r1397 r1475  
    11#ifndef _GSREGISTRY_H_
    22#define _GSREGISTRY_H_
     3#include <string>
     4using namespace std;
     5
    36#include "registry.h"
    47#include "configFile.h"
    58#include "FilePath.h"
     9#include "uninstall.h"
     10#include "stringArray.h"
    611
    7 class gsRegistry
     12class gsRegistry : public installAgent
    813{   private:
    9         char volumeKey[256];
    10     char collectKey[256];
     14        string volumeKey;
     15    string collectKey;
     16
     17    bool logAction(string action, HKEY base, string path, string item, string value);
    1118    public:
    12     gsRegistry(configureFile &configFileb);
    13         bool            storeKeyString( HKEY base, const char *path,
    14                                                         const char *item, const char *string);
     19    gsRegistry(installManager &manager, configureFile &configFileb);
     20        bool            storeKeyString( HKEY base, string path, string item, string value);
    1521    bool            collectionInstalled();
    1622    bool            volumeInstalled();
    1723    bool            ensureKeysExist();
    18     bool            ensureKeyExists( HKEY base, const char *key);
    19     char *      collectKeyId();
    20     char *      volumeKeyId();
    21     char *      exeKeyId(char *exeName);
     24    bool            ensureKeyExists( HKEY base, string key);
     25    bool            destroyKey(HKEY base, string key);
     26    bool            destroyItem(HKEY base, string key, string name);
     27    string      collectKeyId();
     28    string      volumeKeyId();
     29    string      exeKeyId(string exeName);
     30    string    uninstallKeyId(string collectName);
    2231    FilePath *collectionPath();
    23     Path();
     32    bool undoAction(string ActionName, stringArray &params);
     33//    Path();
    2434};
    2535#endif
  • 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);
  • trunk/gsinstaller/install.cfg

    r1397 r1475  
    1 CompanyName:FAO
    2 CollectionName:Humanity Development Library
    3 CollectionDirName:HDL
     1CompanyName:Demo
     2CollectionName:Demo Collection
     3CollectionDirName:demo
    44CollectionVersion:1.0
    55CollectionVolume:1
    6 ProgramGroupName:FAO Library
     6ProgramGroupName:Demo Collection
  • trunk/gsinstaller/manifest.cfg

    r1397 r1475  
    33
    44library:
    5   gsdl.ini net32 net16 readme.html
     5  gsdl.ini library.exe Net32 Net16 readme.txt
    66
    77database:
  • trunk/gsinstaller/registry.cpp

    r1397 r1475  
    2121    reply = RegOpenKeyEx(key, name, NULL, KEY_QUERY_VALUE, keyout);
    2222  if (reply != ERROR_SUCCESS)
    23   { return FALSE;
    24   }
    25   return TRUE;
     23  { return false;
     24  }
     25  return true;
     26}
     27
     28bool registry_deletekey(HKEY key, const char *name)
     29{   if (RegDeleteKey(key, name) != ERROR_SUCCESS)
     30    {   return false;
     31  }
     32  return true;
    2633}
    2734
     
    5764}
    5865
     66bool registry_deleteitem(HKEY key, const char *name)
     67{   if (RegDeleteValue(key, name) != ERROR_SUCCESS)
     68    {   return false;
     69  }
     70  return true;
     71}
     72
    5973bool registry_setstring(HKEY key, const char *name, const char *value)
    6074{ LONG reply;
     
    6276    reply = RegSetValueEx(key, (LPCTSTR) name, NULL, REG_SZ, (CONST BYTE *) value, strlen(value) + 1);
    6377  if (reply != ERROR_SUCCESS)
    64   { return FALSE;
    65   }
    66   return TRUE;
     78  { return false;
     79  }
     80  return true;
    6781}
    6882
  • trunk/gsinstaller/registry.h

    r1397 r1475  
    88bool registry_getstring(HKEY key, char *name, char **string);
    99bool registry_setstring(HKEY key, const char *name, const char *string);
     10bool registry_deleteitem(HKEY key, const char *name);
    1011bool registry_createkey(HKEY key, const char *name, PHKEY keyout);
     12bool registry_deletekey(HKEY key, const char *name);
    1113bool registry_closekey(HKEY key);
    1214bool registry_keyExists(HKEY key, const char *name);
  • trunk/gsinstaller/stringArray.cpp

    r1397 r1475  
    5050  for (int i = 0; i < other.size(); i ++)
    5151  { this->add(other[i]);
     52  }
     53}
     54
     55/**
     56 * Insert a string at a given location
     57 */
     58void stringArray::insertAt(string s, unsigned int at)
     59{ if (at >= this->size())
     60    { this->add(s);
     61  }
     62  else
     63  { this->array.insert(this->array.begin() + at, s);
    5264  }
    5365}
  • trunk/gsinstaller/stringArray.h

    r1397 r1475  
    1717    void add(string member);
    1818    void add(stringArray &array);
     19    void insertAt(string member, unsigned int at);
    1920    void remove(char *member);
    2021    void remove(string member);
  • trunk/gsinstaller/unInstall.cpp

    r1397 r1475  
    44#include <stdarg.h>
    55#include "File.h"
     6
     7bool installManager::openLog(string filename, bool write)
     8{   if (this->logfile.rdbuf()->is_open())
     9    {   this->logfile.close();
     10  }
     11  this->logfile.open(filename.c_str(), (write ? ios::out : ios::in) | ios::app);
     12}
     13
     14void installManager::setModule(string moduleName)
     15{   this->currentModule = moduleName;
     16}
     17
     18bool installManager::writeString(char *buffer)
     19{ string s(buffer);
     20    this->writeString(s);
     21}
     22
     23bool installManager::writeString(string str)
     24{ bool quote;
     25
     26    // TODO: check for space characters in str and quote if necessary
     27  quote = str.find_first_of(' ') < str.length();
     28
     29    if (quote)
     30  { this->logfile << "\"";
     31  }
     32    this->logfile << str;
     33  if (quote)
     34  { this->logfile << "\"";
     35  }
     36  return true;
     37}
     38
     39bool installManager::writeSeparator()
     40{   this->logfile << " ";
     41    return true;
     42}
     43
     44string installManager::readString()
     45{   string reply;
     46    char c;
     47
     48  this->logfile >> c;
     49  while (c <= ' ')
     50  { this->logfile.get();
     51  }
     52  if (c == '\"')
     53  { do
     54    {   c = this->logfile.get();
     55        if (c != '\"')
     56      { reply += c;
     57      }
     58    }
     59    while (c != '\"');
     60  }
     61  else
     62  { /*while (c > ' ')
     63    { reply += c;
     64        c = this->logfile.get();
     65    }*/
     66    this->logfile.putback(c);
     67    this->logfile >> reply;
     68  }
     69  return reply;
     70}
     71
     72string installManager::readCommand(stringArray &array)
     73{   string reply;
     74  char c;
     75
     76  array.clear();
     77
     78    reply = this->readString();
     79  while((c = this->logfile.get()) != '\n')
     80  { this->logfile.putback(c);
     81    array.add(this->readString());
     82  }
     83  this->logfile.putback(c);
     84
     85  return reply;
     86}
     87
     88installManager::~installManager()
     89{   if (this->logfile.rdbuf()->is_open())
     90    {   this->logfile.close();
     91  }
     92}
    693
    794unInstaller::unInstaller(string &fileName)
  • trunk/gsinstaller/unInstall.h

    r1397 r1475  
    55#include <map>
    66using namespace std;
     7
     8#include <stdio.h>
     9#include <fstream.h>
    710
    811#include "stringArray.h"
     
    1821
    1922typedef map<string, unInstallCommandList, less<string> > unInstallCommandMap;
     23
     24class installManager
     25{   private:
     26        fstream logfile;
     27    string  currentModule;
     28    public:
     29    installManager() { };
     30    bool openLog(string filename, bool write);
     31    void setModule(string moduleName);
     32    bool writeString(string str);
     33    bool writeString(char *string);
     34    bool writeSeparator();
     35    string readString();
     36    string readCommand(stringArray &params);
     37    ~installManager();
     38};
     39
     40class installAgent
     41{   protected:
     42    installManager *manager;
     43    public:
     44    installAgent(installManager &useManager) { this->manager = &useManager; };
     45    virtual bool undoAction(string actionName, stringArray &params) { return false; };
     46//    bool undo(string actionName);
     47};
    2048
    2149class unInstaller
Note: See TracChangeset for help on using the changeset viewer.