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