Changeset 1590 for trunk/gsinstaller
- Timestamp:
- 2000-10-06T04:52:00+13:00 (24 years ago)
- Location:
- trunk/gsinstaller
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gsinstaller/gsRegistry.cpp
r1560 r1590 3 3 gsRegistry::gsRegistry(installManager &manager, configureFile &configFile) 4 4 : installAgent(manager) 5 { 6 7 8 9 10 11 12 13 14 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"); 16 16 } 17 17 18 18 bool gsRegistry::logAction(string action, HKEY base, string path, string item, string value) 19 19 { 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 == "") 23 25 { 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}"); 33 27 } 28 else 29 { 30 command.addParameter(item); 31 } 32 command.addParameter(value); 33 } 34 34 return manager->storeCommand(command); 35 35 } 36 36 37 37 bool gsRegistry::undoAction(string actionName, stringArray ¶ms) 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 } 43 41 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 } 47 44 else 48 { 49 return false; 50 } 45 { return false; 46 } 47 return true; 48 } 49 50 bool 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 } 51 59 return true; 52 60 } 53 61 54 62 bool 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 } 60 66 return this->ensureKeyExists(HKEY_LOCAL_MACHINE, this->volumeKey); 61 67 } 62 68 63 69 bool 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; 72 73 } 74 if (!registry_ensureKeyExists(base, key.c_str())) 75 { return false; 76 } 77 this->logAction("RegistryCreateKey", base, key, "", ""); 78 } 73 79 return true; 74 80 } 75 81 76 82 bool gsRegistry::destroyKey(HKEY base, string key) 77 { 78 return registry_deletekey(base, key.c_str()); 83 { return registry_deletekey(base, key.c_str()); 79 84 } 80 85 81 86 bool gsRegistry::storeKeyString(HKEY base, string path, string item, string value) 82 { 83 HKEY local; 84 bool reply; 87 { HKEY local; 88 bool reply; 85 89 86 90 if (!registry_openkey(base, path.c_str(), &local)) 87 { 88 return false; 89 } 91 { return false; 92 } 90 93 reply = registry_setstring(local, item.c_str(), value.c_str()); 91 94 if (reply) 92 { 93 this->logAction("RegistrySetString", base, path, item, value); 94 } 95 { this->logAction("RegistrySetString", base, path, item, value); 96 } 95 97 registry_closekey(local); 96 98 return reply; … … 98 100 99 101 bool 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 } 107 107 registry_deleteitem(local, item.c_str()); 108 108 registry_closekey(local); … … 111 111 112 112 bool 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()); 115 114 } 116 115 117 116 bool 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()); 120 118 } 121 119 122 120 string gsRegistry::collectKeyId() 123 { 124 return this->collectKey; 121 { return this->collectKey; 125 122 } 126 123 127 124 string gsRegistry::volumeKeyId() 128 { 129 return this->volumeKey; 125 { return this->volumeKey; 130 126 } 131 127 132 128 string 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; 136 131 return reply; 137 132 } 138 133 139 134 string gsRegistry::uninstallKeyId(string collectName) 140 { 141 return "Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\" + collectName; 135 { return "Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\" + collectName; 142 136 } 143 137 144 138 FilePath *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 150 143 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; 156 147 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); 166 154 } 155 registry_closekey(key); 156 } 167 157 return reply; 168 158 } -
trunk/gsinstaller/gsRegistry.h
r1543 r1590 19 19 20 20 class gsRegistry : public installAgent 21 { 22 private: 23 string volumeKey; 24 string collectKey; 21 { private: 22 string volumeKey; 23 string collectKey; 25 24 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 boolcollectionInstalled();32 boolvolumeInstalled();33 boolensureKeysExist();34 boolensureKeyExists( HKEY base, string key);35 booldestroyKey(HKEY base, string key);36 booldestroyItem(HKEY base, string key, string name);37 stringcollectKeyId();38 stringvolumeKeyId();39 stringexeKeyId(string exeName);40 stringuninstallKeyId(string collectName);41 FilePath *collectionPath();42 bool undoAction(string ActionName, stringArray ¶ms);43 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 ¶ms); 42 // Path(); 44 43 }; 45 44 #endif 45
Note:
See TracChangeset
for help on using the changeset viewer.