source: trunk/gsinstaller/gsRegistry.cpp@ 1560

Last change on this file since 1560 was 1560, checked in by sjboddie, 24 years ago

fixed a few problems relating to compiling on VC++ 4.2

  • Property svn:keywords set to Author Date Id Revision
File size: 3.7 KB
Line 
1#include "gsRegistry.h"
2
3gsRegistry::gsRegistry(installManager &manager, configureFile &configFile)
4 : 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");
16}
17
18bool gsRegistry::logAction(string action, HKEY base, string path, string item, string value)
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);
33 }
34 return manager->storeCommand(command);
35}
36
37bool gsRegistry::undoAction(string actionName, stringArray &params)
38{
39 if (actionName == "RegistryCreateKey")
40 {
41 this->destroyKey(HKEY_LOCAL_MACHINE, params[0]);
42 }
43 else if (actionName == "RegistrySetString")
44 {
45 this->destroyItem(HKEY_LOCAL_MACHINE, params[0], params[1]);
46 }
47 else
48 {
49 return false;
50 }
51 return true;
52}
53
54bool gsRegistry::ensureKeysExist()
55{
56 if (!this->ensureKeyExists(HKEY_LOCAL_MACHINE, this->collectKey))
57 {
58 return false;
59 }
60 return this->ensureKeyExists(HKEY_LOCAL_MACHINE, this->volumeKey);
61}
62
63bool 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, "", "");
72 }
73 return true;
74}
75
76bool gsRegistry::destroyKey(HKEY base, string key)
77{
78 return registry_deletekey(base, key.c_str());
79}
80
81bool gsRegistry::storeKeyString(HKEY base, string path, string item, string value)
82{
83 HKEY local;
84 bool reply;
85
86 if (!registry_openkey(base, path.c_str(), &local))
87 {
88 return false;
89 }
90 reply = registry_setstring(local, item.c_str(), value.c_str());
91 if (reply)
92 {
93 this->logAction("RegistrySetString", base, path, item, value);
94 }
95 registry_closekey(local);
96 return reply;
97}
98
99bool 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 }
107 registry_deleteitem(local, item.c_str());
108 registry_closekey(local);
109 return true;
110}
111
112bool gsRegistry::collectionInstalled()
113{
114 return registry_keyExists(HKEY_LOCAL_MACHINE, this->collectKey.c_str());
115}
116
117bool gsRegistry::volumeInstalled()
118{
119 return registry_keyExists(HKEY_LOCAL_MACHINE, this->volumeKey.c_str());
120}
121
122string gsRegistry::collectKeyId()
123{
124 return this->collectKey;
125}
126
127string gsRegistry::volumeKeyId()
128{
129 return this->volumeKey;
130}
131
132string gsRegistry::exeKeyId(string exename)
133{
134 string reply = "Software\\Microsoft\\Windows\\CurrentVersion\\App Paths\\";
135 reply += exename;
136 return reply;
137}
138
139string gsRegistry::uninstallKeyId(string collectName)
140{
141 return "Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\" + collectName;
142}
143
144FilePath *gsRegistry::collectionPath()
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;
156
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);
166 }
167 return reply;
168}
Note: See TracBrowser for help on using the repository browser.