1 | #include "gsRegistry.h"
|
---|
2 |
|
---|
3 | gsRegistry::gsRegistry(configureFile &configFile)
|
---|
4 | { unsigned int space;
|
---|
5 |
|
---|
6 | // Create string for volume key
|
---|
7 | strcpy(volumeKey, "Software\\");
|
---|
8 | space = 255 - strlen(volumeKey);
|
---|
9 |
|
---|
10 | configFile.concat("CompanyName", volumeKey, space);
|
---|
11 | strcat(volumeKey, "\\");
|
---|
12 | configFile.concat("CollectionName", volumeKey, space);
|
---|
13 | strcat(volumeKey, "\\");
|
---|
14 | configFile.concat("CollectionVolume", volumeKey, space);
|
---|
15 | strcat(volumeKey, "\\");
|
---|
16 | configFile.concat("CollectionVersion", volumeKey, space);
|
---|
17 |
|
---|
18 | // Create string for collection key
|
---|
19 | strcpy(collectKey, "Software\\");
|
---|
20 | space = 255 - strlen(collectKey);
|
---|
21 |
|
---|
22 | configFile.concat("CompanyName", collectKey, space);
|
---|
23 | strcat(collectKey, "\\");
|
---|
24 | configFile.concat("CollectionName", collectKey, space);
|
---|
25 | strcat(collectKey, "\\");
|
---|
26 | configFile.concat("CollectionVersion", collectKey, space);
|
---|
27 | }
|
---|
28 |
|
---|
29 | bool gsRegistry::ensureKeysExist()
|
---|
30 | { if (registry_ensureKeyExists(HKEY_LOCAL_MACHINE, this->collectKey) == false)
|
---|
31 | { return false;
|
---|
32 | }
|
---|
33 | if (registry_ensureKeyExists(HKEY_LOCAL_MACHINE, this->volumeKey) == false)
|
---|
34 | { return false;
|
---|
35 | }
|
---|
36 | return true;
|
---|
37 | }
|
---|
38 |
|
---|
39 | bool gsRegistry::ensureKeyExists(HKEY base, const char *key)
|
---|
40 | { return(registry_ensureKeyExists(base, key));
|
---|
41 | }
|
---|
42 |
|
---|
43 | bool gsRegistry::storeKeyString(HKEY base, const char *path, const char *item, const char *string)
|
---|
44 | { HKEY local;
|
---|
45 | bool reply;
|
---|
46 |
|
---|
47 | if (!registry_openkey(base, (char *) path, &local))
|
---|
48 | { return false;
|
---|
49 | }
|
---|
50 | reply = registry_setstring(local, item, string);
|
---|
51 | registry_closekey(local);
|
---|
52 | return reply;
|
---|
53 | }
|
---|
54 |
|
---|
55 | bool gsRegistry::collectionInstalled()
|
---|
56 | { return registry_keyExists(HKEY_LOCAL_MACHINE, this->collectKey);
|
---|
57 | }
|
---|
58 |
|
---|
59 | bool gsRegistry::volumeInstalled()
|
---|
60 | { return registry_keyExists(HKEY_LOCAL_MACHINE, this->volumeKey);
|
---|
61 | }
|
---|
62 |
|
---|
63 | char *gsRegistry::collectKeyId()
|
---|
64 | { return this->collectKey;
|
---|
65 | }
|
---|
66 |
|
---|
67 | char *gsRegistry::volumeKeyId()
|
---|
68 | { return this->volumeKey;
|
---|
69 | }
|
---|
70 |
|
---|
71 | char *gsRegistry::exeKeyId(char *exename)
|
---|
72 | { char *reply = new char[256];
|
---|
73 |
|
---|
74 | // Create string for exe path
|
---|
75 | strcpy(reply, "Software\\Microsoft\\Windows\\CurrentVersion\\App Paths\\");
|
---|
76 | strcat(reply, exename);
|
---|
77 | return reply;
|
---|
78 | }
|
---|
79 |
|
---|
80 | FilePath *gsRegistry::collectionPath()
|
---|
81 | { char *path = NULL;
|
---|
82 | FilePath *reply = NULL;
|
---|
83 | HKEY key;
|
---|
84 |
|
---|
85 | if (registry_openkey(HKEY_LOCAL_MACHINE, this->collectKey, &key))
|
---|
86 | { if (registry_getstring(key, "library", &path))
|
---|
87 | { // get leaf (\library.exe) and remove it to give a path
|
---|
88 | char *leaf;
|
---|
89 |
|
---|
90 | leaf = strrchr(path, '\\');
|
---|
91 | if (leaf != NULL)
|
---|
92 | { *leaf = '\0';
|
---|
93 | }
|
---|
94 | reply = new FilePath(path);
|
---|
95 | free(path);
|
---|
96 | }
|
---|
97 | registry_closekey(key);
|
---|
98 | }
|
---|
99 | return reply;
|
---|
100 | }
|
---|
101 |
|
---|