Changeset 1590 for trunk/gsinstaller


Ignore:
Timestamp:
2000-10-06T04:52:00+13:00 (24 years ago)
Author:
cs025
Message:

Added testing for the existence of parent keys when a key is created; this
fixed the omission of implicit parent creation when a key was created, and
the parent's creation was therefore not logged, resulting in a non-destruction
of the parent key when an uninstall was performed.

Location:
trunk/gsinstaller
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/gsinstaller/gsRegistry.cpp

    r1560 r1590  
    33gsRegistry::gsRegistry(installManager &manager, configureFile &configFile)
    44  : installAgent(manager)
    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");
     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");
    1616}
    1717
    1818bool gsRegistry::logAction(string action, HKEY base, string path, string item, string value)
    1919{
    20   unInstallCommand command(action);
    21   command.addParameter(path);
    22   if (item != "" || value != "")
     20    unInstallCommand command(action);
     21    command.addParameter(path);
     22    if (item != "" || value != "")
     23  {
     24    if (item == "")
    2325    {
    24       if (item == "")
    25     {
    26       command.addParameter("{Default}");
    27     }
    28       else
    29     {
    30       command.addParameter(item);
    31     }
    32       command.addParameter(value);
     26        command.addParameter("{Default}");
    3327    }
     28    else
     29    {
     30        command.addParameter(item);
     31    }
     32    command.addParameter(value);
     33  }
    3434  return manager->storeCommand(command);
    3535}
    3636
    3737bool gsRegistry::undoAction(string actionName, stringArray &params)
    38 {
    39   if (actionName == "RegistryCreateKey")
    40     {
    41       this->destroyKey(HKEY_LOCAL_MACHINE, params[0]);
    42     }
     38{ if (actionName == "RegistryCreateKey")
     39    {   this->destroyKey(HKEY_LOCAL_MACHINE, params[0]);
     40  }
    4341  else if (actionName == "RegistrySetString")
    44     {
    45       this->destroyItem(HKEY_LOCAL_MACHINE, params[0], params[1]);
    46     }
     42  { this->destroyItem(HKEY_LOCAL_MACHINE, params[0], params[1]);
     43  }
    4744  else
    48     {
    49       return false;
    50     }
     45  { return false;
     46  }
     47  return true;
     48}
     49
     50bool gsRegistry::ensureParentKeyExists(HKEY base, string key)
     51{   string parent;
     52    int foundat;
     53
     54    if ((foundat = key.rfind('\\', key.length())) < key.length())
     55  { parent = key.substr(0, foundat);
     56
     57    return this->ensureKeyExists(base, parent);
     58  }
    5159  return true;
    5260}
    5361
    5462bool gsRegistry::ensureKeysExist()
    55 {
    56   if (!this->ensureKeyExists(HKEY_LOCAL_MACHINE, this->collectKey))
    57     {
    58       return false;
    59     }
     63{ if (!this->ensureKeyExists(HKEY_LOCAL_MACHINE, this->collectKey))
     64    {   return false;
     65  }
    6066  return this->ensureKeyExists(HKEY_LOCAL_MACHINE, this->volumeKey);
    6167}
    6268
    6369bool gsRegistry::ensureKeyExists(HKEY base, string key)
    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, "", "");
     70{ if (!registry_keyExists(base, key.c_str()))
     71    { if (!this->ensureParentKeyExists(base, key))
     72    {   return false;
    7273    }
     74    if (!registry_ensureKeyExists(base, key.c_str()))
     75    {   return false;
     76    }
     77    this->logAction("RegistryCreateKey", base, key, "", "");
     78  }
    7379  return true;
    7480}
    7581
    7682bool gsRegistry::destroyKey(HKEY base, string key)
    77 {
    78   return registry_deletekey(base, key.c_str());
     83{   return registry_deletekey(base, key.c_str());
    7984}
    8085
    8186bool gsRegistry::storeKeyString(HKEY base, string path, string item, string value)
    82 {
    83   HKEY local;
    84   bool reply;
     87{   HKEY local;
     88    bool    reply;
    8589
    8690  if (!registry_openkey(base, path.c_str(), &local))
    87     {
    88       return false;
    89     }
     91    {   return false;
     92  }
    9093  reply = registry_setstring(local, item.c_str(), value.c_str());
    9194  if (reply)
    92     {
    93       this->logAction("RegistrySetString", base, path, item, value);
    94     }
     95  { this->logAction("RegistrySetString", base, path, item, value);
     96  }
    9597  registry_closekey(local);
    9698  return reply;
     
    98100
    99101bool gsRegistry::destroyItem(HKEY base, string path, string item)
    100 {
    101   HKEY local;
    102  
    103   if (!registry_openkey(base, path.c_str(), &local))
    104     {
    105       return false;
    106     }
     102{ HKEY local;
     103
     104    if (!registry_openkey(base, path.c_str(), &local))
     105  { return false;
     106  }
    107107  registry_deleteitem(local, item.c_str());
    108108  registry_closekey(local);
     
    111111
    112112bool gsRegistry::collectionInstalled()
    113 {
    114   return registry_keyExists(HKEY_LOCAL_MACHINE, this->collectKey.c_str());
     113{   return registry_keyExists(HKEY_LOCAL_MACHINE, this->collectKey.c_str());
    115114}
    116115
    117116bool gsRegistry::volumeInstalled()
    118 {
    119   return registry_keyExists(HKEY_LOCAL_MACHINE, this->volumeKey.c_str());
     117{   return registry_keyExists(HKEY_LOCAL_MACHINE, this->volumeKey.c_str());
    120118}
    121119
    122120string gsRegistry::collectKeyId()
    123 {
    124   return this->collectKey;
     121{   return this->collectKey;
    125122}
    126123
    127124string gsRegistry::volumeKeyId()
    128 {
    129   return this->volumeKey;
     125{   return this->volumeKey;
    130126}
    131127
    132128string gsRegistry::exeKeyId(string exename)
    133 {
    134   string reply = "Software\\Microsoft\\Windows\\CurrentVersion\\App Paths\\";
    135   reply += exename;
     129{   string reply = "Software\\Microsoft\\Windows\\CurrentVersion\\App Paths\\";
     130    reply += exename;
    136131  return reply;
    137132}
    138133
    139134string gsRegistry::uninstallKeyId(string collectName)
    140 {
    141   return "Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\" + collectName;
     135{   return "Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\" + collectName;
    142136}
    143137
    144138FilePath *gsRegistry::collectionPath()
    145 {
    146   char *path = NULL;
    147   FilePath *reply = NULL;
    148   HKEY key;
    149  
     139{ char *path = NULL;
     140    FilePath *reply = NULL;
     141    HKEY key;
     142
    150143  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;
     144  { if (registry_getstring(key, "library", &path))
     145    { // get leaf (\library.exe) and remove it to give a path
     146        char *leaf;
    156147
    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);
     148        leaf    = strrchr(path, '\\');
     149            if (leaf != NULL)
     150      { *leaf = '\0';
     151      }
     152      reply = new FilePath(path);
     153      free(path);
    166154    }
     155    registry_closekey(key);
     156  }
    167157  return reply;
    168158}
  • trunk/gsinstaller/gsRegistry.h

    r1543 r1590  
    1919
    2020class gsRegistry : public installAgent
    21 {
    22 private:
    23   string volumeKey;
    24   string collectKey;
     21{   private:
     22        string volumeKey;
     23    string collectKey;
    2524
    26   bool logAction(string action, HKEY base, string path, string item, string value);
    27 public:
    28   gsRegistry(installManager &manager, configureFile &configFileb);
    29   virtual ~gsRegistry () {}
    30   bool storeKeyString(HKEY base, string path, string item, string value);
    31   bool collectionInstalled();
    32   bool volumeInstalled();
    33   bool ensureKeysExist();
    34   bool ensureKeyExists( HKEY base, string key);
    35   bool destroyKey(HKEY base, string key);
    36   bool destroyItem(HKEY base, string key, string name);
    37   string collectKeyId();
    38   string volumeKeyId();
    39   string exeKeyId(string exeName);
    40   string uninstallKeyId(string collectName);
    41   FilePath *collectionPath();
    42   bool undoAction(string ActionName, stringArray &params);
    43   //    Path();
     25    bool logAction(string action, HKEY base, string path, string item, string value);
     26    bool ensureParentKeyExists( HKEY base, string key);
     27    public:
     28    gsRegistry(installManager &manager, configureFile &configFileb);
     29        bool            storeKeyString( HKEY base, string path, string item, string value);
     30    bool            collectionInstalled();
     31    bool            volumeInstalled();
     32    bool            ensureKeysExist();
     33    bool            ensureKeyExists( HKEY base, string key);
     34    bool            destroyKey(HKEY base, string key);
     35    bool            destroyItem(HKEY base, string key, string name);
     36    string      collectKeyId();
     37    string      volumeKeyId();
     38    string      exeKeyId(string exeName);
     39    string    uninstallKeyId(string collectName);
     40    FilePath *collectionPath();
     41    bool undoAction(string ActionName, stringArray &params);
     42//    Path();
    4443};
    4544#endif
     45
Note: See TracChangeset for help on using the changeset viewer.