[1397] | 1 | #include "gsRegistry.h"
|
---|
| 2 |
|
---|
[1475] | 3 | gsRegistry::gsRegistry(installManager &manager, configureFile &configFile)
|
---|
| 4 | : installAgent(manager)
|
---|
[1498] | 5 | { // Create string for volume key
|
---|
[1475] | 6 | volumeKey = "Software\\" + configFile.getString("CompanyName") + "\\" +
|
---|
| 7 | configFile.getString("CollectionName") + "\\" +
|
---|
| 8 | configFile.getString("CollectionVolume") + "\\" +
|
---|
| 9 | configFile.getString("CollectionVersion");
|
---|
[1397] | 10 |
|
---|
| 11 | // Create string for collection key
|
---|
[1475] | 12 | collectKey = "Software\\" + configFile.getString("CompanyName") + "\\" +
|
---|
| 13 | configFile.getString("CollectionName") + "\\" +
|
---|
| 14 | configFile.getString("CollectionVersion");
|
---|
| 15 | }
|
---|
[1397] | 16 |
|
---|
[1475] | 17 | bool gsRegistry::logAction(string action, HKEY base, string path, string item, string value)
|
---|
[1498] | 18 | { unInstallCommand command(action);
|
---|
| 19 | command.addParameter(path);
|
---|
[1475] | 20 | if (item != "" || value != "")
|
---|
[1498] | 21 | { if (item == "")
|
---|
| 22 | { command.addParameter("{Default}");
|
---|
[1475] | 23 | }
|
---|
| 24 | else
|
---|
[1498] | 25 | { command.addParameter(item);
|
---|
[1475] | 26 | }
|
---|
[1498] | 27 | command.addParameter(value);
|
---|
[1475] | 28 | }
|
---|
[1498] | 29 | return manager->storeCommand(command);
|
---|
[1397] | 30 | }
|
---|
| 31 |
|
---|
[1475] | 32 | bool gsRegistry::undoAction(string actionName, stringArray ¶ms)
|
---|
| 33 | { if (actionName == "RegistryCreateKey")
|
---|
| 34 | { this->destroyKey(HKEY_LOCAL_MACHINE, params[0]);
|
---|
| 35 | }
|
---|
| 36 | else if (actionName == "RegistrySetString")
|
---|
| 37 | { this->destroyItem(HKEY_LOCAL_MACHINE, params[0], params[1]);
|
---|
| 38 | }
|
---|
| 39 | else
|
---|
| 40 | { return false;
|
---|
| 41 | }
|
---|
| 42 | return true;
|
---|
| 43 | }
|
---|
| 44 |
|
---|
[1397] | 45 | bool gsRegistry::ensureKeysExist()
|
---|
[1475] | 46 | { if (!this->ensureKeyExists(HKEY_LOCAL_MACHINE, this->collectKey))
|
---|
[1397] | 47 | { return false;
|
---|
| 48 | }
|
---|
[1475] | 49 | return this->ensureKeyExists(HKEY_LOCAL_MACHINE, this->volumeKey);
|
---|
| 50 | }
|
---|
| 51 |
|
---|
| 52 | 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;
|
---|
| 56 | }
|
---|
| 57 | this->logAction("RegistryCreateKey", base, key, "", "");
|
---|
[1397] | 58 | }
|
---|
| 59 | return true;
|
---|
| 60 | }
|
---|
| 61 |
|
---|
[1475] | 62 | bool gsRegistry::destroyKey(HKEY base, string key)
|
---|
[1498] | 63 | { return registry_deletekey(base, key.c_str());
|
---|
[1397] | 64 | }
|
---|
| 65 |
|
---|
[1475] | 66 | bool gsRegistry::storeKeyString(HKEY base, string path, string item, string value)
|
---|
[1397] | 67 | { HKEY local;
|
---|
| 68 | bool reply;
|
---|
| 69 |
|
---|
[1475] | 70 | if (!registry_openkey(base, path.c_str(), &local))
|
---|
[1397] | 71 | { return false;
|
---|
| 72 | }
|
---|
[1475] | 73 | reply = registry_setstring(local, item.c_str(), value.c_str());
|
---|
| 74 | if (reply)
|
---|
| 75 | { this->logAction("RegistrySetString", base, path, item, value);
|
---|
| 76 | }
|
---|
[1397] | 77 | registry_closekey(local);
|
---|
| 78 | return reply;
|
---|
| 79 | }
|
---|
| 80 |
|
---|
[1475] | 81 | 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 | }
|
---|
| 87 | registry_deleteitem(local, item.c_str());
|
---|
| 88 | registry_closekey(local);
|
---|
[1498] | 89 | return true;
|
---|
[1475] | 90 | }
|
---|
| 91 |
|
---|
[1397] | 92 | bool gsRegistry::collectionInstalled()
|
---|
[1475] | 93 | { return registry_keyExists(HKEY_LOCAL_MACHINE, this->collectKey.c_str());
|
---|
[1397] | 94 | }
|
---|
| 95 |
|
---|
| 96 | bool gsRegistry::volumeInstalled()
|
---|
[1475] | 97 | { return registry_keyExists(HKEY_LOCAL_MACHINE, this->volumeKey.c_str());
|
---|
[1397] | 98 | }
|
---|
| 99 |
|
---|
[1475] | 100 | string gsRegistry::collectKeyId()
|
---|
[1397] | 101 | { return this->collectKey;
|
---|
| 102 | }
|
---|
| 103 |
|
---|
[1475] | 104 | string gsRegistry::volumeKeyId()
|
---|
[1397] | 105 | { return this->volumeKey;
|
---|
| 106 | }
|
---|
| 107 |
|
---|
[1475] | 108 | string gsRegistry::exeKeyId(string exename)
|
---|
| 109 | { string reply = "Software\\Microsoft\\Windows\\CurrentVersion\\App Paths\\";
|
---|
| 110 | reply += exename;
|
---|
[1397] | 111 | return reply;
|
---|
| 112 | }
|
---|
| 113 |
|
---|
[1475] | 114 | string gsRegistry::uninstallKeyId(string collectName)
|
---|
| 115 | { return "Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\" + collectName;
|
---|
| 116 | }
|
---|
| 117 |
|
---|
[1397] | 118 | FilePath *gsRegistry::collectionPath()
|
---|
| 119 | { char *path = NULL;
|
---|
| 120 | FilePath *reply = NULL;
|
---|
| 121 | HKEY key;
|
---|
| 122 |
|
---|
[1475] | 123 | if (registry_openkey(HKEY_LOCAL_MACHINE, this->collectKey.c_str(), &key))
|
---|
[1397] | 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);
|
---|
| 134 | }
|
---|
| 135 | registry_closekey(key);
|
---|
| 136 | }
|
---|
| 137 | return reply;
|
---|
| 138 | }
|
---|
| 139 |
|
---|