source: trunk/gsinstaller/gsRegistry.cpp@ 1498

Last change on this file since 1498 was 1498, checked in by cs025, 24 years ago

Further changes for uninstaller

  • 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{ // 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");
15}
16
17bool 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}");
23 }
24 else
25 { command.addParameter(item);
26 }
27 command.addParameter(value);
28 }
29 return manager->storeCommand(command);
30}
31
32bool gsRegistry::undoAction(string actionName, stringArray &params)
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
45bool gsRegistry::ensureKeysExist()
46{ if (!this->ensureKeyExists(HKEY_LOCAL_MACHINE, this->collectKey))
47 { return false;
48 }
49 return this->ensureKeyExists(HKEY_LOCAL_MACHINE, this->volumeKey);
50}
51
52bool 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, "", "");
58 }
59 return true;
60}
61
62bool gsRegistry::destroyKey(HKEY base, string key)
63{ return registry_deletekey(base, key.c_str());
64}
65
66bool gsRegistry::storeKeyString(HKEY base, string path, string item, string value)
67{ HKEY local;
68 bool reply;
69
70 if (!registry_openkey(base, path.c_str(), &local))
71 { return false;
72 }
73 reply = registry_setstring(local, item.c_str(), value.c_str());
74 if (reply)
75 { this->logAction("RegistrySetString", base, path, item, value);
76 }
77 registry_closekey(local);
78 return reply;
79}
80
81bool 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);
89 return true;
90}
91
92bool gsRegistry::collectionInstalled()
93{ return registry_keyExists(HKEY_LOCAL_MACHINE, this->collectKey.c_str());
94}
95
96bool gsRegistry::volumeInstalled()
97{ return registry_keyExists(HKEY_LOCAL_MACHINE, this->volumeKey.c_str());
98}
99
100string gsRegistry::collectKeyId()
101{ return this->collectKey;
102}
103
104string gsRegistry::volumeKeyId()
105{ return this->volumeKey;
106}
107
108string gsRegistry::exeKeyId(string exename)
109{ string reply = "Software\\Microsoft\\Windows\\CurrentVersion\\App Paths\\";
110 reply += exename;
111 return reply;
112}
113
114string gsRegistry::uninstallKeyId(string collectName)
115{ return "Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\" + collectName;
116}
117
118FilePath *gsRegistry::collectionPath()
119{ char *path = NULL;
120 FilePath *reply = NULL;
121 HKEY key;
122
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);
134 }
135 registry_closekey(key);
136 }
137 return reply;
138}
139
Note: See TracBrowser for help on using the repository browser.