Changeset 1560


Ignore:
Timestamp:
2000-09-22T16:49:54+12:00 (24 years ago)
Author:
sjboddie
Message:

fixed a few problems relating to compiling on VC++ 4.2

Location:
trunk/gsinstaller
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/gsinstaller/gsRegistry.cpp

    r1498 r1560  
    33gsRegistry::gsRegistry(installManager &manager, configureFile &configFile)
    44  : installAgent(manager)
    5 { // Create string for volume key
    6     volumeKey = "Software\\" + configFile.getString("CompanyName") + "\\" +
    7                             configFile.getString("CollectionName") + "\\" +
    8                             configFile.getString("CollectionVolume") + "\\" +
    9                             configFile.getString("CollectionVersion");
    10 
    11     // Create string for collection key
    12     collectKey = "Software\\" + configFile.getString("CompanyName") + "\\" +
    13                             configFile.getString("CollectionName") + "\\" +
    14                 configFile.getString("CollectionVersion");
     5{
     6  // Create string for volume key
     7  volumeKey = "Software\\" + configFile.getString("CompanyName") + "\\" +
     8    configFile.getString("CollectionName") + "\\" +
     9    configFile.getString("CollectionVolume") + "\\" +
     10    configFile.getString("CollectionVersion");
     11 
     12  // Create string for collection key
     13  collectKey = "Software\\" + configFile.getString("CompanyName") + "\\" +
     14    configFile.getString("CollectionName") + "\\" +
     15    configFile.getString("CollectionVersion");
    1516}
    1617
    1718bool gsRegistry::logAction(string action, HKEY base, string path, string item, string value)
    18 { unInstallCommand command(action);
    19     command.addParameter(path);
    20     if (item != "" || value != "")
    21   { if (item == "")
    22     {   command.addParameter("{Default}");
     19{
     20  unInstallCommand command(action);
     21  command.addParameter(path);
     22  if (item != "" || value != "")
     23    {
     24      if (item == "")
     25    {
     26      command.addParameter("{Default}");
     27    }
     28      else
     29    {
     30      command.addParameter(item);
     31    }
     32      command.addParameter(value);
    2333    }
    24     else
    25     {   command.addParameter(item);
    26     }
    27     command.addParameter(value);
    28   }
    2934  return manager->storeCommand(command);
    3035}
    3136
    3237bool gsRegistry::undoAction(string actionName, stringArray &params)
    33 { if (actionName == "RegistryCreateKey")
    34     {   this->destroyKey(HKEY_LOCAL_MACHINE, params[0]);
    35   }
     38{
     39  if (actionName == "RegistryCreateKey")
     40    {
     41      this->destroyKey(HKEY_LOCAL_MACHINE, params[0]);
     42    }
    3643  else if (actionName == "RegistrySetString")
    37   { this->destroyItem(HKEY_LOCAL_MACHINE, params[0], params[1]);
    38   }
     44    {
     45      this->destroyItem(HKEY_LOCAL_MACHINE, params[0], params[1]);
     46    }
    3947  else
    40   { return false;
    41   }
     48    {
     49      return false;
     50    }
    4251  return true;
    4352}
    4453
    4554bool gsRegistry::ensureKeysExist()
    46 { if (!this->ensureKeyExists(HKEY_LOCAL_MACHINE, this->collectKey))
    47     {   return false;
    48   }
     55{
     56  if (!this->ensureKeyExists(HKEY_LOCAL_MACHINE, this->collectKey))
     57    {
     58      return false;
     59    }
    4960  return this->ensureKeyExists(HKEY_LOCAL_MACHINE, this->volumeKey);
    5061}
    5162
    5263bool gsRegistry::ensureKeyExists(HKEY base, string key)
    53 { if (!registry_keyExists(base, key.c_str()))
    54     {   if (!registry_ensureKeyExists(base, key.c_str()))
    55     {   return false;
     64{
     65  if (!registry_keyExists(base, key.c_str()))
     66    {
     67      if (!registry_ensureKeyExists(base, key.c_str()))
     68    {
     69      return false;
     70    }
     71      this->logAction("RegistryCreateKey", base, key, "", "");
    5672    }
    57     this->logAction("RegistryCreateKey", base, key, "", "");
    58   }
    5973  return true;
    6074}
    6175
    6276bool gsRegistry::destroyKey(HKEY base, string key)
    63 {   return registry_deletekey(base, key.c_str());
     77{
     78  return registry_deletekey(base, key.c_str());
    6479}
    6580
    6681bool gsRegistry::storeKeyString(HKEY base, string path, string item, string value)
    67 {   HKEY local;
    68     bool    reply;
     82{
     83  HKEY local;
     84  bool reply;
    6985
    7086  if (!registry_openkey(base, path.c_str(), &local))
    71     {   return false;
    72   }
     87    {
     88      return false;
     89    }
    7390  reply = registry_setstring(local, item.c_str(), value.c_str());
    7491  if (reply)
    75   { this->logAction("RegistrySetString", base, path, item, value);
    76   }
     92    {
     93      this->logAction("RegistrySetString", base, path, item, value);
     94    }
    7795  registry_closekey(local);
    7896  return reply;
     
    8098
    8199bool gsRegistry::destroyItem(HKEY base, string path, string item)
    82 { HKEY local;
    83 
    84     if (!registry_openkey(base, path.c_str(), &local))
    85   { return false;
    86   }
     100{
     101  HKEY local;
     102 
     103  if (!registry_openkey(base, path.c_str(), &local))
     104    {
     105      return false;
     106    }
    87107  registry_deleteitem(local, item.c_str());
    88108  registry_closekey(local);
     
    91111
    92112bool gsRegistry::collectionInstalled()
    93 {   return registry_keyExists(HKEY_LOCAL_MACHINE, this->collectKey.c_str());
     113{
     114  return registry_keyExists(HKEY_LOCAL_MACHINE, this->collectKey.c_str());
    94115}
    95116
    96117bool gsRegistry::volumeInstalled()
    97 {   return registry_keyExists(HKEY_LOCAL_MACHINE, this->volumeKey.c_str());
     118{
     119  return registry_keyExists(HKEY_LOCAL_MACHINE, this->volumeKey.c_str());
    98120}
    99121
    100122string gsRegistry::collectKeyId()
    101 {   return this->collectKey;
     123{
     124  return this->collectKey;
    102125}
    103126
    104127string gsRegistry::volumeKeyId()
    105 {   return this->volumeKey;
     128{
     129  return this->volumeKey;
    106130}
    107131
    108132string gsRegistry::exeKeyId(string exename)
    109 {   string reply = "Software\\Microsoft\\Windows\\CurrentVersion\\App Paths\\";
    110     reply += exename;
     133{
     134  string reply = "Software\\Microsoft\\Windows\\CurrentVersion\\App Paths\\";
     135  reply += exename;
    111136  return reply;
    112137}
    113138
    114139string gsRegistry::uninstallKeyId(string collectName)
    115 {   return "Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\" + collectName;
     140{
     141  return "Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\" + collectName;
    116142}
    117143
    118144FilePath *gsRegistry::collectionPath()
    119 { char *path = NULL;
    120     FilePath *reply = NULL;
    121     HKEY key;
     145{
     146  char *path = NULL;
     147  FilePath *reply = NULL;
     148  HKEY key;
     149 
     150  if (registry_openkey(HKEY_LOCAL_MACHINE, this->collectKey.c_str(), &key))
     151    {
     152      if (registry_getstring(key, "library", &path))
     153    {
     154      // get leaf (\library.exe) and remove it to give a path
     155      char *leaf;
    122156
    123   if (registry_openkey(HKEY_LOCAL_MACHINE, this->collectKey.c_str(), &key))
    124   { if (registry_getstring(key, "library", &path))
    125     { // get leaf (\library.exe) and remove it to give a path
    126         char *leaf;
    127 
    128         leaf    = strrchr(path, '\\');
    129             if (leaf != NULL)
    130       { *leaf = '\0';
    131       }
    132       reply = new FilePath(path);
    133       free(path);
     157      leaf = strrchr(path, '\\');
     158      if (leaf != NULL)
     159        {
     160          *leaf = '\0';
     161        }
     162      reply = new FilePath(path);
     163      free(path);
     164    }
     165      registry_closekey(key);
    134166    }
    135     registry_closekey(key);
    136   }
    137167  return reply;
    138168}
    139 
  • trunk/gsinstaller/unInstall.cpp

    r1546 r1560  
    66
    77bool installManager::openLog(string filename, bool write)
    8 { string command;
    9     stringArray params;
     8{
     9  string command;
     10  stringArray params;
    1011
    1112  // close the log if already open
    12     if (this->logfile.rdbuf()->is_open())
    13     {   this->closeLog();
    14     }
     13  if (this->logfile.rdbuf()->is_open())
     14    {
     15      this->closeLog();
     16    }
    1517
    1618  // note the new file details and do an open
    17     this->logfileName = filename;
    18     this->logfile.open(filename.c_str(), ios::out | ios::in);
    19 
     19  this->logfileName = filename;
     20  this->logfile.open(filename.c_str(), ios::out | ios::in);
     21   
    2022  // if the file didn't open, then this is almost certainly being compiled
    2123  // with Microsoft Visual C++ which has a library which fails to open the
    2224  // file if it doesn't already exist.  Do a createfile and hope for success.
    2325  // TODO: add proper error handling here
    24     if (!this->logfile.rdbuf()->is_open() && write == true)
    25     { HANDLE fHandle;
    26 
    27     fHandle = CreateFile(filename.c_str(), GENERIC_READ | GENERIC_WRITE,
    28                          FILE_SHARE_WRITE, NULL, CREATE_NEW,
    29                              FILE_ATTRIBUTE_NORMAL, NULL);
    30     if (fHandle)
    31     { CloseHandle(fHandle);
    32     }
    33         this->logfile.open(filename.c_str(), ios::out | ios::in);
    34     }
     26  if (!this->logfile.rdbuf()->is_open() && write == true)
     27    {
     28      HANDLE fHandle;
     29      fHandle = CreateFile(filename.c_str(), GENERIC_READ | GENERIC_WRITE,
     30               FILE_SHARE_WRITE, NULL, CREATE_NEW,
     31               FILE_ATTRIBUTE_NORMAL, NULL);
     32      if (fHandle)
     33    {
     34      CloseHandle(fHandle);
     35    }
     36      this->logfile.open(filename.c_str(), ios::out | ios::in);
     37    }
    3538
    3639  // if we aren't seeking write access, then get the commands into this
    3740  // object
    38     if (write == false)
    39     {   while ((command = this->readCommand(params)) != "")
    40         {   if (command[0] == '[' && command[command.length()-1] == ']')
    41             { this->setModule(command.substr(1, command.length() - 2));
    42         }
    43         else
    44         {   unInstallCommand action(command, params);
    45             this->storeCommand(action);
    46         }
    47     }
    48   }
     41  if (write == false)
     42    {
     43      while ((command = this->readCommand(params)) != "")
     44    {
     45      if (command[0] == '[' && command[command.length()-1] == ']')
     46        {
     47          this->setModule(command.substr(1, command.length() - 2));
     48        }
     49      else
     50        {   
     51          unInstallCommand action(command, params);
     52          this->storeCommand(action);
     53        }
     54    }
     55    }
    4956
    5057  // set to the default module
     
    5461
    5562bool installManager::reopenLog()
    56 { if (this->logfile.rdbuf()->is_open())
    57   { this->logfile.close();
    58   }
     63{
     64  if (this->logfile.rdbuf()->is_open())
     65    {
     66      this->logfile.close();
     67    }
    5968  else
    60   { this->logfile.close();
    61     }
     69    {
     70      this->logfile.close();
     71    }
    6272 
    6373  this->logfile.open(this->logfileName.c_str(), ios::out | ios::in);
     
    6676
    6777void installManager::setModule(string moduleName)
    68 {   this->currentModule = moduleName;
     78{
     79  this->currentModule = moduleName;
    6980}
    7081
    7182bool installManager::storeCommand(unInstallCommand &command)
    72 { this->modules[this->currentModule].push_back(command);
    73     return true;
     83{
     84  this->modules[this->currentModule].push_back(command);
     85  return true;
    7486}
    7587
    7688bool installManager::writeCommand(unInstallCommand &command)
    77 { if (!this->writeString(command.command))
    78     { return false;
    79   }
    80     for (unsigned int p = 0; p < command.parameters.size(); p ++)
    81   { if (!this->writeSeparator())
    82     { return false;
    83     }
    84     if (!this->writeString(command.parameters[p]))
    85     { return false;
    86     }
    87   }
     89{
     90  if (!this->writeString(command.command))
     91    {
     92      return false;
     93    }
     94  for (unsigned int p = 0; p < command.parameters.size(); p ++)
     95    {
     96      if (!this->writeSeparator())
     97    {
     98      return false;
     99    }
     100      if (!this->writeString(command.parameters[p]))
     101    {
     102      return false;
     103    }
     104    }
    88105  if (!this->writeString("\n"))
    89   { return false;
    90   }
     106    {
     107      return false;
     108    }
    91109  return true;
    92110}
    93111
    94112bool installManager::writeString(char *buffer)
    95 { string s(buffer);
    96     return this->writeString(s);
     113{
     114  string s(buffer);
     115  return this->writeString(s);
    97116}
    98117
    99118bool installManager::writeString(string str)
    100 { bool quote;
    101 
    102     // TODO: check for space characters in str and quote if necessary
     119{
     120  bool quote;
     121
     122  // TODO: check for space characters in str and quote if necessary
    103123  quote = str.find_first_of(' ') < str.length();
    104124
    105     if (quote)
    106   { this->logfile << "\"";
    107   }
    108     this->logfile << str;
    109125  if (quote)
    110   { this->logfile << "\"";
    111   }
     126    {
     127      this->logfile << string("\"");
     128    }
     129  this->logfile << str;
     130
     131  if (quote)
     132    {
     133      this->logfile << string("\"");
     134    }
    112135  return true;
    113136}
    114137
    115138bool installManager::writeSeparator()
    116 {   this->logfile << " ";
    117     return true;
     139{
     140  this->logfile << string(" ");
     141  return true;
    118142}
    119143
    120144string installManager::readString()
    121 {   string reply = "";
    122     char c;
     145{
     146  string reply = "";
     147  char c;
    123148
    124149  if (this->logfile.eof())
    125     {   return reply;
    126   }
     150    {
     151      return reply;
     152    }
    127153
    128154  this->logfile >> c;
    129155  while (c <= ' ' && !this->logfile.eof())
    130   { this->logfile.get();
    131   }
    132 
     156    {
     157      this->logfile.get();
     158    }
     159 
    133160  if (this->logfile.eof())
    134   { return reply;
    135   }
    136 
     161    {
     162      return reply;
     163    }
     164 
    137165  if (c == '\"')
    138   { do
    139     {   c = this->logfile.get();
    140         if (c != '\"')
    141       { reply += c;
    142       }
    143     }
    144     while (c != '\"' && !this->logfile.eof());
    145   }
     166    {
     167      do
     168    {
     169      c = this->logfile.get();
     170      if (c != '\"')
     171        {
     172          reply += c;
     173        }
     174    }
     175      while (c != '\"' && !this->logfile.eof());
     176    }
    146177  else
    147   { while (c > ' ')
    148     { reply += c;
    149         if (this->logfile.eof())
    150       { break;
    151       }
    152         c = this->logfile.get();
    153     }
    154     if (!this->logfile.eof())
    155     {   this->logfile.putback(c);
    156     }
    157     //this->logfile >> reply;
    158   }
     178    {
     179      while (c > ' ')
     180    {
     181      reply += c;
     182      if (this->logfile.eof())
     183        {
     184          break;
     185        }
     186      c = this->logfile.get();
     187    }
     188      if (!this->logfile.eof())
     189    {
     190      this->logfile.putback(c);
     191    }
     192      //this->logfile >> reply;
     193    }
    159194  return reply;
    160195}
    161196
    162197string installManager::readCommand(stringArray &array)
    163 {   string reply = "";
     198{
     199  string reply = "";
    164200  char c;
    165 
     201 
    166202  array.clear();
    167 
     203 
    168204  if (this->logfile.eof())
    169   { return reply;
    170   }
    171 
    172     reply = this->readString();
     205    {
     206      return reply;
     207    }
     208 
     209  reply = this->readString();
    173210  if (reply == "")
    174   { return reply;
    175   }
    176 
     211    {
     212      return reply;
     213    }
     214 
    177215  while(!this->logfile.eof() &&
    178             (c = this->logfile.get()) != '\n')
    179   { this->logfile.putback(c);
    180     array.add(this->readString());
    181   }
     216    (c = this->logfile.get()) != '\n')
     217    {
     218      this->logfile.putback(c);
     219      array.add(this->readString());
     220    }
    182221  if (!this->logfile.eof())
    183   { this->logfile.putback(c);
    184   }
    185 
     222    {
     223      this->logfile.putback(c);
     224    }
     225 
    186226  return reply;
    187227}
    188228
    189229string installManager::popCommand(stringArray &array)
    190 { string command;
    191 
     230{
     231  string command;
     232 
    192233  if (this->modules[this->currentModule].size() == 0)
    193   { command = "";
    194   }
     234    {
     235      command = "";
     236    }
    195237  else
    196   { unsigned int last;
    197 
    198       last = this->modules[this->currentModule].size() - 1;
    199     command = this->modules[this->currentModule][last].commandName();
    200     array       = this->modules[this->currentModule][last].parameterList();
    201     this->modules[this->currentModule].erase(this->modules[this->currentModule].begin() + last);
    202   }
     238    {
     239      unsigned int last;
     240     
     241      last = this->modules[this->currentModule].size() - 1;
     242      command = this->modules[this->currentModule][last].commandName();
     243      array = this->modules[this->currentModule][last].parameterList();
     244      this->modules[this->currentModule].erase(this->modules[this->currentModule].begin() + last);
     245    }
    203246  return command;
    204247}
    205248
    206249bool installManager::closeLog()
    207 { if (this->logfile.rdbuf()->is_open() == false)
    208   { return false;
    209   }
    210 
    211     unInstallCommandMap::iterator here = this->modules.begin();
    212     unInstallCommandMap::iterator end  = this->modules.end();
    213 
     250{
     251  if (this->logfile.rdbuf()->is_open() == false)
     252    {
     253      return false;
     254    }
     255
     256  unInstallCommandMap::iterator here = this->modules.begin();
     257  unInstallCommandMap::iterator end = this->modules.end();
     258 
    214259  while (here != end)
    215   { this->writeString("[" + (*here).first + "]\n");
    216 
    217     unInstallCommandList::iterator  ahere = (*here).second.begin();
    218     unInstallCommandList::iterator  aend  = (*here).second.end();
    219     while (ahere != aend)
    220         { this->writeCommand(*ahere);
    221         ahere ++;
    222     }
    223     here ++;
    224   }
    225     this->logfile.close();
     260    {
     261      this->writeString("[" + (*here).first + "]\n");
     262     
     263      unInstallCommandList::iterator ahere = (*here).second.begin();
     264      unInstallCommandList::iterator aend  = (*here).second.end();
     265      while (ahere != aend)
     266    {
     267      this->writeCommand(*ahere);
     268      ahere ++;
     269    }
     270      here ++;
     271    }
     272  this->logfile.close();
    226273  return true;
    227274}
    228275
    229276bool installManager::isEmpty()
    230 { unInstallCommandMap::iterator here = this->modules.begin();
    231     unInstallCommandMap::iterator end  = this->modules.end();
     277{
     278  unInstallCommandMap::iterator here = this->modules.begin();
     279  unInstallCommandMap::iterator end = this->modules.end();
    232280
    233281  while (here != end)
    234   { this->writeString("[" + (*here).first + "]\n");
    235 
    236     unInstallCommandList::iterator  ahere = (*here).second.begin();
    237     unInstallCommandList::iterator  aend  = (*here).second.end();
    238     if (ahere != aend)
    239     {   return false;
    240     }
    241     here ++;
    242   }
     282    {
     283      this->writeString("[" + (*here).first + "]\n");
     284
     285      unInstallCommandList::iterator ahere = (*here).second.begin();
     286      unInstallCommandList::iterator aend = (*here).second.end();
     287      if (ahere != aend)
     288    {
     289      return false;
     290    }
     291      here ++;
     292    }
    243293  return true;
    244294}
    245295
    246296installManager::~installManager()
    247 {   if (this->logfile.rdbuf()->is_open())
    248     {   this->closeLog();
    249   }
    250 }
    251 
    252 
     297{
     298  if (this->logfile.rdbuf()->is_open())
     299    {
     300      this->closeLog();
     301    }
     302}
Note: See TracChangeset for help on using the changeset viewer.