Changeset 1498 for trunk/gsinstaller


Ignore:
Timestamp:
2000-09-05T03:30:48+12:00 (24 years ago)
Author:
cs025
Message:

Further changes for uninstaller

Location:
trunk/gsinstaller
Files:
14 edited

Legend:

Unmodified
Added
Removed
  • trunk/gsinstaller/FilePath.cpp

    r1475 r1498  
    9696}
    9797
    98 /**
    99  * Construct a Filepath from a directory and a sub-directory path
    100  */
    101 FilePath::FilePath(string filePath, string subPath)
     98void FilePath::_init(string filePath, string subPath)
    10299{ // copy the directory path
    103100  this->path = filePath;
     
    123120}
    124121
     122/**
     123 * Construct a Filepath from a directory and a sub-directory path
     124 */
     125FilePath::FilePath(string filePath, string subPath)
     126{ this->_init(filePath, subPath);
     127}
     128
     129FilePath::FilePath(FilePath &path, string subPath)
     130{ this->_init(path.pathString(), subPath);
     131}
     132
    125133FilePath::FilePath(string filePath)
    126134{ if (filePath.length() < 3)
     
    130138  else
    131139  { this->path  = filePath;
     140
     141    // trim trailing directory separators
     142    if (this->path[this->path.length() - 1] == '\\')
     143    {   this->path = this->path.substr(0, this->path.length() - 1);
     144    }
    132145  }
    133146
  • trunk/gsinstaller/FilePath.h

    r1397 r1498  
    88        string path;            // full path of this item
    99    bool     is_aRoot;  // indicates whether this directory/file is a file root
     10    void   _init(string path, string subPath);
    1011    public:
    1112    FilePath();
     
    1314    FilePath(string filePath, string filePath2);
    1415    FilePath(int nPaths, ...);
     16    FilePath(FilePath &path, string subPath);
    1517    bool      equals(FilePath &path);
    1618    bool      equals(const char *path);
     
    2729    string      pathString();
    2830    bool operator==(const FilePath &b) { return this->path == b.path; }
     31    bool operator!=(const FilePath &b) { return this->path != b.path; }
    2932    bool operator<(const FilePath &b) { return this->path < b.path; }
    3033};
  • trunk/gsinstaller/fileCopier.cpp

    r1475 r1498  
    116116    // this->copied += file->getRawFileSize();
    117117
     118    // note for uninstall the action done
     119      if (monitor != NULL)
     120    {   monitor->copied(file->getFileName(), thisDestDir, true);
     121    }
     122
    118123    // copy children
    119124    vector<File>::iterator here = file->childBegin();
     
    123128        here ++;
    124129    }
    125 
    126       if (monitor != NULL)
    127     {   monitor->copied(file->getFileName(), thisDestDir, true);
    128     }
    129130
    130131    // delete constructed destination name
  • trunk/gsinstaller/gsManifest.cpp

    r1475 r1498  
    248248
    249249void gsManifest::logAction(string actionName, string file)
    250 {   manager->writeString(actionName);
    251     manager->writeSeparator();
    252   manager->writeString(file);
    253   manager->writeString("\n");
     250{ unInstallCommand command(actionName);
     251    command.addParameter(file);
     252  manager->storeCommand(command);
    254253}
    255254
    256255void 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");
     256{   unInstallCommand command(actionName);
     257    command.addParameter(source);
     258  command.addParameter(dest);
     259  manager->storeCommand(command);
    263260}
    264261
  • trunk/gsinstaller/gsProfile.cpp

    r1475 r1498  
    1010void gsProfile::logAction(string action, string sectionName, string item,
    1111                                                    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");
     12{ unInstallCommand command(action);
     13    command.addParameter(this->fileName);
     14  command.addParameter(sectionName);
     15  command.addParameter(item);
     16  command.addParameter(value);
     17  manager->storeCommand(command);
    2218}
    2319
  • trunk/gsinstaller/gsProgman.cpp

    r1475 r1498  
    8787
    8888void gsProgramManager::logAction(string actionName, string group)
    89 {   manager->writeString(actionName);
    90     manager->writeSeparator();
    91   manager->writeString(group);
    92     manager->writeString("\n");
     89{ unInstallCommand command(actionName);
     90    command.addParameter(group);
     91    manager->storeCommand(command);
    9392}
    9493
    9594void 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");
     95{ unInstallCommand command(actionName);
     96  command.addParameter(group);
     97    command.addParameter(item);
     98  command.addParameter(parameter);
     99  manager->storeCommand(command);
    104100}
    105101
     
    109105    return true;
    110106  }
    111   else if (actionName == "ProgManAddIcon")
     107  else if (actionName == "ProgManAddItem")
    112108  { this->removeIcon(params[0], params[1]);
    113109    return true;
     
    211207        fullPath    = new FilePath(4, buffer, groupName.c_str(), iconName.c_str(), ".lnk");
    212208
     209    // check if the shortcut already exists then don't create this again
     210    if (fullPath->exists())
     211    { delete fullPath;
     212        return true;
     213    }
     214
    213215        // Get a pointer to the IShellLink interface.
    214216    hres = CoCreateInstance(CLSID_ShellLink, NULL,
     
    241243      psl->Release();
    242244      }
     245    delete fullPath;
    243246  }
    244247  else
     
    317320      }
    318321
     322    // get path of folder from shell
    319323        SHGetPathFromIDList(pidl, buffer);
    320         fullPath    = new FilePath(4, buffer, groupName.c_str(), iconName.c_str(), "!.lnk");
    321 
    322     // TODO: delete file
     324
     325    // delete file
     326    fullPath    = new FilePath(4, buffer, groupName.c_str(), iconName.c_str(), "!.lnk");
     327        if (!DeleteFile(fullPath->cString()))
     328    { reply = false;
     329    }
     330    delete fullPath;
    323331  }
    324332  else
  • trunk/gsinstaller/gsRegistry.cpp

    r1475 r1498  
    33gsRegistry::gsRegistry(installManager &manager, configureFile &configFile)
    44  : installAgent(manager)
    5 { unsigned int space;
    6 
    7     // Create string for volume key
     5{ // Create string for volume key
    86    volumeKey = "Software\\" + configFile.getString("CompanyName") + "\\" +
    97                            configFile.getString("CollectionName") + "\\" +
     
    1816
    1917bool gsRegistry::logAction(string action, HKEY base, string path, string item, string value)
    20 {   manager->writeString(action);
    21     manager->writeSeparator();
    22   manager->writeString(path);
     18{ unInstallCommand command(action);
     19    command.addParameter(path);
    2320    if (item != "" || value != "")
    24   { manager->writeSeparator();
    25     if (item == "")
    26     {   manager->writeString("{Default}");
     21  { if (item == "")
     22    {   command.addParameter("{Default}");
    2723    }
    2824    else
    29     {   manager->writeString(item);
     25    {   command.addParameter(item);
    3026    }
    31         manager->writeSeparator();
    32     manager->writeString(value);
     27    command.addParameter(value);
    3328  }
    34   manager->writeString("\n");
     29  return manager->storeCommand(command);
    3530}
    3631
     
    6661
    6762bool gsRegistry::destroyKey(HKEY base, string key)
    68 {   registry_deletekey(base, key.c_str());
     63{   return registry_deletekey(base, key.c_str());
    6964}
    7065
     
    9287  registry_deleteitem(local, item.c_str());
    9388  registry_closekey(local);
     89  return true;
    9490}
    9591
  • trunk/gsinstaller/gsinstall.cpp

    r1475 r1498  
    6767    bool                installNetscape();
    6868    void                setDestination();
    69     void                setUninstall();
     69    bool                setUninstall();
    7070    void                uninstall();
    7171    void                setManifest();
     
    320320}
    321321
    322 void GSInstall::setUninstall()
    323 {
    324   // open the log for reading
    325   FilePath *logPath = new FilePath(this->collectPath->pathString(), "install.log");
     322bool GSInstall::setUninstall()
     323{ char tempPathStr[MAX_PATH];
     324
     325  // if we failed to get the Windows temporary directory, abort
     326  if (GetTempPath(MAX_PATH, tempPathStr) == 0)
     327  { // TODO: abort!
     328    return false;
     329  }
     330
     331  FilePath tempPath(tempPathStr);
     332
     333  // if we are not running in the Windows temporary directory, copy this exe
     334  // and the installation log to the temporary directory and run them there
     335  if (*this->sourcePath != tempPath)
     336  { // copy this and install.log to temporary directory and restart
     337    FilePath exePath(*this->sourcePath, "gssetup.exe");
     338    FilePath logPath(*this->sourcePath, "install.log");
     339
     340    FilePath exeDest(tempPath, "gssetup.exe");
     341    FilePath logDest(tempPath, "install.log");
     342
     343    CopyFile(exePath.cString(), exeDest.cString(), false);
     344    CopyFile(logPath.cString(), logDest.cString(), false);
     345
     346    // now run the gssetup in the temporary directory
     347    launchApp launchUninstall(exeDest);
     348    launchUninstall.setCommandLine(" -u " + logPath.pathString());
     349    launchUninstall.run(false, 0, "", "", false);
     350
     351    return false;
     352  }
     353
     354  // open the log for reading from the directory this exe is now in (which
     355  // will in fact be the temporary directory as outlined above)
     356  FilePath *logPath = new FilePath(this->sourcePath->pathString(), "install.log");
    326357  this->openLog(logPath->pathString(), false);
    327358  delete logPath;
     359
     360  return true;
    328361}
    329362
     
    338371    gsProfile gsdlProfile(*this, iniPath->pathString());
    339372
    340     while ((command = this->readCommand(params)) != "")
     373    while ((command = this->popCommand(params)) != "")
    341374  { if (!this->manifest->undoAction(command, params))
    342375    { if (!gsdlProfile.undoAction(command, params))
     
    752785    case WM_USER:
    753786    { // uninstall action
    754         if (strstr(app_cmdLine, "-u") != NULL || true)
    755         { char *at = strstr(app_cmdLine, "-u");
    756         at += strlen("-u") + 1;
     787        if (strstr(app_cmdLine, "-u") != NULL)
     788        { // skip past the -u option itself
     789        char *at = strstr(app_cmdLine, "-u");
     790        at += strlen("-u");
     791
     792        // extract the log file path from the command line
     793        while (*at == ' ')
     794        { at ++;
     795        }
     796        string logPathString(at);
     797        FilePath logPath(logPathString);
    757798
    758799                GSInstall install(true);
    759         install.setUninstall();
    760         install.uninstall();
     800        // if we're running in the temporary directory, do the uninstall
     801        if (install.setUninstall())
     802        {   install.uninstall();
     803
     804            // close the log to write back all changes to the log; if the file
     805          // will be deleted, it must be closed; copying may also fail, so it's
     806          // safer to close it before doing either.
     807            install.closeLog();
     808
     809          // if the install is empty, terminate all final items (currently the
     810          // log and setup executables,
     811          if (install.isEmpty())
     812          { // delete the log file
     813            DeleteFile(logPath.cString());
     814
     815            // get it's parent to find where the gssetup executable will be
     816            FilePath *logParent = logPath.parent();
     817                        FilePath uninstallPath(*logParent, "gssetup.exe");
     818
     819            // delete the gssetup executable
     820            DeleteFile(uninstallPath.cString());
     821
     822            // dispose of the parent directory information
     823            delete logParent;
     824          }
     825          // if not, then overwrite the original log with the modified one
     826          else
     827          { // do nothing - should be changed already!
     828          }
     829        }
    761830      }
    762831      // install wizard
     
    777846              install.updateRegistry();
    778847            install.updateProfiles();
     848
     849          // the log will need reopening (probably failed initially)
     850                  install.reopenLog();
     851
     852          // close log
     853          install.closeLog();
    779854
    780855            // do further actions
  • trunk/gsinstaller/launchApp.cpp

    r1397 r1498  
    1111}
    1212
     13void launchApp::setCommandLine(string commandLine)
     14{   this->commandline = commandLine;
     15}
     16
    1317int launchApp::run(bool test, int deftest, string prompt, string header, bool wait)
    1418{ gsPlatform    platform;
    1519    FilePath        exePath;
     20  string            runLine;
    1621
    1722    if (test)
     
    4348  process.hProcess  =   0;
    4449
     50  // build command line if required
     51  if (this->commandline != "")
     52  { runLine = exePath.pathString() + " " + this->commandline;
     53  }
     54
    4555    // execute the process
    46   if (CreateProcess(exePath.cString(), NULL, NULL, NULL, FALSE, 0, NULL, NULL, &startup, &process) == 0)
     56  if (CreateProcess((LPSTR) exePath.cString(),
     57                                    runLine != "" ? (LPSTR) runLine.c_str() : NULL,
     58                    NULL, NULL, FALSE, 0, NULL, NULL,
     59                    &startup, &process) == 0)
    4760  { DWORD   error   = GetLastError();
    4861    return -2;
  • trunk/gsinstaller/launchApp.h

    r1397 r1498  
    1212{   private:
    1313        _exeMap exeMap;
     14    string  commandline;
    1415    public:
    1516    launchApp(FilePath &appsrc);
    1617    void platformApp(string platform, FilePath &appsrc);
     18    void setCommandLine(string commands);
    1719    int run(bool test, int deftest, string prompt, string title, bool wait);
    1820};
  • trunk/gsinstaller/stringArray.cpp

    r1475 r1498  
    146146}
    147147
     148string stringArray::toString(string separator)
     149{ string reply;
     150
     151    vector<string>::iterator here = this->array.begin();
     152    vector<string>::iterator end  = this->array.end();
     153  while (here != end)
     154  { if (here != this->array.begin())
     155    { reply += separator;
     156    }
     157    reply += *here;
     158  }
     159  return reply;
     160}
     161
    148162stringArray stringArray::words(char *buffer)
    149163{   stringArray reply;
     
    176190void stringArray::clear()
    177191{   this->array.empty();
     192    this->array.erase(this->array.begin(), this->array.end());
    178193}
    179194
  • trunk/gsinstaller/stringArray.h

    r1475 r1498  
    2828    int  indexOf(string member);
    2929    int  writeToCString(char *buffer, char *divider, int bufflen);
     30    string toString(string separator);
    3031    string &operator[](const unsigned int);
    3132};
  • trunk/gsinstaller/unInstall.cpp

    r1475 r1498  
    66
    77bool 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);
     8{ string command;
     9    stringArray params;
     10
     11    if (this->logfile.rdbuf()->is_open())
     12    {   this->closeLog();
     13  }
     14  this->logfileName = filename;
     15  this->logfile.open(filename.c_str(), ios::out | ios::in);
     16  if (write == false)
     17  { while ((command = this->readCommand(params)) != "")
     18    { if (command[0] == '[' && command[command.length()-1] == ']')
     19        { this->setModule(command.substr(1, command.length() - 2));
     20        }
     21        else
     22        { unInstallCommand action(command, params);
     23            this->storeCommand(action);
     24        }
     25    }
     26  }
     27  this->setModule("default");
     28  return true;
     29}
     30
     31bool installManager::reopenLog()
     32{ if (this->logfile.rdbuf()->is_open())
     33  { this->logfile.close();
     34  }
     35  else
     36  { this->logfile.close();
     37    }
     38 
     39  this->logfile.open(this->logfileName.c_str(), ios::out | ios::in);
     40  return true;
    1241}
    1342
     
    1645}
    1746
     47bool installManager::storeCommand(unInstallCommand &command)
     48{ this->modules[this->currentModule].push_back(command);
     49    return true;
     50}
     51
     52bool installManager::writeCommand(unInstallCommand &command)
     53{ if (!this->writeString(command.command))
     54    { return false;
     55  }
     56    for (unsigned int p = 0; p < command.parameters.size(); p ++)
     57  { if (!this->writeSeparator())
     58    { return false;
     59    }
     60    if (!this->writeString(command.parameters[p]))
     61    { return false;
     62    }
     63  }
     64  if (!this->writeString("\n"))
     65  { return false;
     66  }
     67  return true;
     68}
     69
    1870bool installManager::writeString(char *buffer)
    1971{ string s(buffer);
    20     this->writeString(s);
     72    return this->writeString(s);
    2173}
    2274
     
    4395
    4496string installManager::readString()
    45 {   string reply;
     97{   string reply = "";
    4698    char c;
    4799
     100  if (this->logfile.eof())
     101    {   return reply;
     102  }
     103
    48104  this->logfile >> c;
    49   while (c <= ' ')
     105  while (c <= ' ' && !this->logfile.eof())
    50106  { this->logfile.get();
    51107  }
     108
     109  if (this->logfile.eof())
     110  { return reply;
     111  }
     112
    52113  if (c == '\"')
    53114  { do
     
    57118      }
    58119    }
    59     while (c != '\"');
     120    while (c != '\"' && !this->logfile.eof());
    60121  }
    61122  else
    62   { /*while (c > ' ')
     123  { while (c > ' ')
    63124    { reply += c;
     125        if (this->logfile.eof())
     126      { break;
     127      }
    64128        c = this->logfile.get();
    65     }*/
    66     this->logfile.putback(c);
    67     this->logfile >> reply;
     129    }
     130    if (!this->logfile.eof())
     131    {   this->logfile.putback(c);
     132    }
     133    //this->logfile >> reply;
    68134  }
    69135  return reply;
     
    71137
    72138string installManager::readCommand(stringArray &array)
    73 {   string reply;
     139{   string reply = "";
    74140  char c;
    75141
    76142  array.clear();
    77143
     144  if (this->logfile.eof())
     145  { return reply;
     146  }
     147
    78148    reply = this->readString();
    79   while((c = this->logfile.get()) != '\n')
     149  if (reply == "")
     150  { return reply;
     151  }
     152
     153  while(!this->logfile.eof() &&
     154            (c = this->logfile.get()) != '\n')
    80155  { this->logfile.putback(c);
    81     array.add(this->readString());
    82   }
    83   this->logfile.putback(c);
     156    array.add(this->readString());
     157  }
     158  if (!this->logfile.eof())
     159  { this->logfile.putback(c);
     160  }
    84161
    85162  return reply;
     163}
     164
     165string installManager::popCommand(stringArray &array)
     166{ string command;
     167
     168  if (this->modules[this->currentModule].size() == 0)
     169  { command = "";
     170  }
     171  else
     172  { unsigned int last;
     173
     174      last = this->modules[this->currentModule].size() - 1;
     175    command = this->modules[this->currentModule][last].commandName();
     176    array       = this->modules[this->currentModule][last].parameterList();
     177    this->modules[this->currentModule].erase(this->modules[this->currentModule].begin() + last);
     178  }
     179  return command;
     180}
     181
     182bool installManager::closeLog()
     183{ if (this->logfile.rdbuf()->is_open() == false)
     184  { return false;
     185  }
     186
     187    unInstallCommandMap::iterator here = this->modules.begin();
     188    unInstallCommandMap::iterator end  = this->modules.end();
     189
     190  while (here != end)
     191  { this->writeString("[" + (*here).first + "]\n");
     192
     193    unInstallCommandList::iterator  ahere = (*here).second.begin();
     194    unInstallCommandList::iterator  aend  = (*here).second.end();
     195    while (ahere != aend)
     196        { this->writeCommand(*ahere);
     197        ahere ++;
     198    }
     199    here ++;
     200  }
     201    this->logfile.close();
     202  return true;
     203}
     204
     205bool installManager::isEmpty()
     206{ unInstallCommandMap::iterator here = this->modules.begin();
     207    unInstallCommandMap::iterator end  = this->modules.end();
     208
     209  while (here != end)
     210  { this->writeString("[" + (*here).first + "]\n");
     211
     212    unInstallCommandList::iterator  ahere = (*here).second.begin();
     213    unInstallCommandList::iterator  aend  = (*here).second.end();
     214    if (ahere != aend)
     215    {   return false;
     216    }
     217    here ++;
     218  }
     219  return true;
    86220}
    87221
    88222installManager::~installManager()
    89223{   if (this->logfile.rdbuf()->is_open())
    90     {   this->logfile.close();
     224    {   this->closeLog();
    91225  }
    92226}
  • trunk/gsinstaller/unInstall.h

    r1475 r1498  
    1313static string uninstall_ALL = "all";
    1414
    15 typedef struct unInstallCommand
    16 {   string          command;
    17     stringArray parameters;
     15typedef class unInstallCommand
     16{ public:
     17        string          command;
     18        stringArray parameters;
     19
     20    unInstallCommand() { };
     21    unInstallCommand(string commandname) { this->command = commandname; };
     22    unInstallCommand(string commandname, stringArray params)
     23    { this->command = commandname;
     24        this->parameters = params;
     25    };
     26    void addParameter(string parameter) { this->parameters.add(parameter); };
     27    string commandName() { return this->command; };
     28    stringArray &parameterList() { return this->parameters; };
    1829} unInstallCommand;
    1930
     
    2435class installManager
    2536{   private:
    26         fstream logfile;
    27     string  currentModule;
    28     public:
    29     installManager() { };
    30     bool openLog(string filename, bool write);
    31     void setModule(string moduleName);
     37        fstream                             logfile;
     38    string                              logfileName;
     39    string                              currentModule;
     40    unInstallCommandMap     modules;
     41
    3242    bool writeString(string str);
    3343    bool writeString(char *string);
    3444    bool writeSeparator();
    3545    string readString();
     46    bool writeCommand(unInstallCommand &command);
    3647    string readCommand(stringArray &params);
     48    public:
     49    installManager() { };
     50    bool openLog(string filename, bool write);
     51    bool closeLog();
     52    bool reopenLog();
     53    void setModule(string moduleName);
     54    bool storeCommand(unInstallCommand &command);
     55    string popCommand(stringArray &params);
     56    bool isEmpty();
    3757    ~installManager();
    3858};
Note: See TracChangeset for help on using the changeset viewer.