Changeset 1560
- Timestamp:
- 2000-09-22T16:49:54+12:00 (24 years ago)
- Location:
- trunk/gsinstaller
- Files:
-
- 1 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gsinstaller/gsRegistry.cpp
r1498 r1560 3 3 gsRegistry::gsRegistry(installManager &manager, configureFile &configFile) 4 4 : 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"); 15 16 } 16 17 17 18 bool 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); 23 33 } 24 else25 { command.addParameter(item);26 }27 command.addParameter(value);28 }29 34 return manager->storeCommand(command); 30 35 } 31 36 32 37 bool gsRegistry::undoAction(string actionName, stringArray ¶ms) 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 } 36 43 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 } 39 47 else 40 { return false; 41 } 48 { 49 return false; 50 } 42 51 return true; 43 52 } 44 53 45 54 bool 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 } 49 60 return this->ensureKeyExists(HKEY_LOCAL_MACHINE, this->volumeKey); 50 61 } 51 62 52 63 bool 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, "", ""); 56 72 } 57 this->logAction("RegistryCreateKey", base, key, "", "");58 }59 73 return true; 60 74 } 61 75 62 76 bool gsRegistry::destroyKey(HKEY base, string key) 63 { return registry_deletekey(base, key.c_str()); 77 { 78 return registry_deletekey(base, key.c_str()); 64 79 } 65 80 66 81 bool gsRegistry::storeKeyString(HKEY base, string path, string item, string value) 67 { HKEY local; 68 bool reply; 82 { 83 HKEY local; 84 bool reply; 69 85 70 86 if (!registry_openkey(base, path.c_str(), &local)) 71 { return false; 72 } 87 { 88 return false; 89 } 73 90 reply = registry_setstring(local, item.c_str(), value.c_str()); 74 91 if (reply) 75 { this->logAction("RegistrySetString", base, path, item, value); 76 } 92 { 93 this->logAction("RegistrySetString", base, path, item, value); 94 } 77 95 registry_closekey(local); 78 96 return reply; … … 80 98 81 99 bool 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 } 87 107 registry_deleteitem(local, item.c_str()); 88 108 registry_closekey(local); … … 91 111 92 112 bool 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()); 94 115 } 95 116 96 117 bool 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()); 98 120 } 99 121 100 122 string gsRegistry::collectKeyId() 101 { return this->collectKey; 123 { 124 return this->collectKey; 102 125 } 103 126 104 127 string gsRegistry::volumeKeyId() 105 { return this->volumeKey; 128 { 129 return this->volumeKey; 106 130 } 107 131 108 132 string 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; 111 136 return reply; 112 137 } 113 138 114 139 string gsRegistry::uninstallKeyId(string collectName) 115 { return "Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\" + collectName; 140 { 141 return "Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\" + collectName; 116 142 } 117 143 118 144 FilePath *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; 122 156 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); 134 166 } 135 registry_closekey(key);136 }137 167 return reply; 138 168 } 139 -
trunk/gsinstaller/unInstall.cpp
r1546 r1560 6 6 7 7 bool installManager::openLog(string filename, bool write) 8 { string command; 9 stringArray params; 8 { 9 string command; 10 stringArray params; 10 11 11 12 // 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 } 15 17 16 18 // note the new file details and do an open 17 18 19 19 this->logfileName = filename; 20 this->logfile.open(filename.c_str(), ios::out | ios::in); 21 20 22 // if the file didn't open, then this is almost certainly being compiled 21 23 // with Microsoft Visual C++ which has a library which fails to open the 22 24 // file if it doesn't already exist. Do a createfile and hope for success. 23 25 // 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 } 35 38 36 39 // if we aren't seeking write access, then get the commands into this 37 40 // 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 } 49 56 50 57 // set to the default module … … 54 61 55 62 bool 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 } 59 68 else 60 { this->logfile.close(); 61 } 69 { 70 this->logfile.close(); 71 } 62 72 63 73 this->logfile.open(this->logfileName.c_str(), ios::out | ios::in); … … 66 76 67 77 void installManager::setModule(string moduleName) 68 { this->currentModule = moduleName; 78 { 79 this->currentModule = moduleName; 69 80 } 70 81 71 82 bool 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; 74 86 } 75 87 76 88 bool 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 } 88 105 if (!this->writeString("\n")) 89 { return false; 90 } 106 { 107 return false; 108 } 91 109 return true; 92 110 } 93 111 94 112 bool installManager::writeString(char *buffer) 95 { string s(buffer); 96 return this->writeString(s); 113 { 114 string s(buffer); 115 return this->writeString(s); 97 116 } 98 117 99 118 bool 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 103 123 quote = str.find_first_of(' ') < str.length(); 104 124 105 if (quote)106 { this->logfile << "\"";107 }108 this->logfile << str;109 125 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 } 112 135 return true; 113 136 } 114 137 115 138 bool installManager::writeSeparator() 116 { this->logfile << " "; 117 return true; 139 { 140 this->logfile << string(" "); 141 return true; 118 142 } 119 143 120 144 string installManager::readString() 121 { string reply = ""; 122 char c; 145 { 146 string reply = ""; 147 char c; 123 148 124 149 if (this->logfile.eof()) 125 { return reply; 126 } 150 { 151 return reply; 152 } 127 153 128 154 this->logfile >> c; 129 155 while (c <= ' ' && !this->logfile.eof()) 130 { this->logfile.get(); 131 } 132 156 { 157 this->logfile.get(); 158 } 159 133 160 if (this->logfile.eof()) 134 { return reply; 135 } 136 161 { 162 return reply; 163 } 164 137 165 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 } 146 177 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 } 159 194 return reply; 160 195 } 161 196 162 197 string installManager::readCommand(stringArray &array) 163 { string reply = ""; 198 { 199 string reply = ""; 164 200 char c; 165 201 166 202 array.clear(); 167 203 168 204 if (this->logfile.eof()) 169 { return reply; 170 } 171 172 reply = this->readString(); 205 { 206 return reply; 207 } 208 209 reply = this->readString(); 173 210 if (reply == "") 174 { return reply; 175 } 176 211 { 212 return reply; 213 } 214 177 215 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 } 182 221 if (!this->logfile.eof()) 183 { this->logfile.putback(c); 184 } 185 222 { 223 this->logfile.putback(c); 224 } 225 186 226 return reply; 187 227 } 188 228 189 229 string installManager::popCommand(stringArray &array) 190 { string command; 191 230 { 231 string command; 232 192 233 if (this->modules[this->currentModule].size() == 0) 193 { command = ""; 194 } 234 { 235 command = ""; 236 } 195 237 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 } 203 246 return command; 204 247 } 205 248 206 249 bool 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 214 259 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(); 226 273 return true; 227 274 } 228 275 229 276 bool 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(); 232 280 233 281 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 } 243 293 return true; 244 294 } 245 295 246 296 installManager::~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.