Commit f78ed3f8f8a3b43231ae7fc57ca122bf5248da10
1 parent
d6cc22d1
Exists in
master
Coleta de software no windows (inclusive 64x)
Showing
9 changed files
with
752 additions
and
34 deletions
Show diff stats
cacicD/cacicD.pro
@@ -20,19 +20,11 @@ TEMPLATE = app | @@ -20,19 +20,11 @@ TEMPLATE = app | ||
20 | 20 | ||
21 | 21 | ||
22 | SOURCES += main.cpp \ | 22 | SOURCES += main.cpp \ |
23 | - ../src/cacic_computer.cpp \ | ||
24 | ../src/ccacic.cpp \ | 23 | ../src/ccacic.cpp \ |
25 | - ../src/ccoleta.cpp \ | ||
26 | - ../src/operatingsystem.cpp \ | ||
27 | cacicd.cpp | 24 | cacicd.cpp |
28 | 25 | ||
29 | HEADERS += \ | 26 | HEADERS += \ |
30 | - ../src/cacic_comm.h \ | ||
31 | - ../src/cacic_computer.h \ | ||
32 | ../src/ccacic.h \ | 27 | ../src/ccacic.h \ |
33 | - ../src/ccoleta.h \ | ||
34 | - ../src/console.h \ | ||
35 | - ../src/operatingsystem.h \ | ||
36 | cacicd.h | 28 | cacicd.h |
37 | 29 | ||
38 | include(../src/qtservice/src/qtservice.pri) | 30 | include(../src/qtservice/src/qtservice.pri) |
gercols/gercols.pro
@@ -29,6 +29,8 @@ SOURCES += \ | @@ -29,6 +29,8 @@ SOURCES += \ | ||
29 | ../src/cacic_hardware.cpp \ | 29 | ../src/cacic_hardware.cpp \ |
30 | ../src/operatingsystem.cpp \ | 30 | ../src/operatingsystem.cpp \ |
31 | ../src/ccoleta.cpp \ | 31 | ../src/ccoleta.cpp \ |
32 | + ../src/vregistry.cpp \ | ||
33 | + ../src/vqtconvert.cpp \ | ||
32 | ./gercols.cpp | 34 | ./gercols.cpp |
33 | 35 | ||
34 | 36 | ||
@@ -40,6 +42,8 @@ HEADERS += \ | @@ -40,6 +42,8 @@ HEADERS += \ | ||
40 | ../src/operatingsystem.h \ | 42 | ../src/operatingsystem.h \ |
41 | ../src/console.h \ | 43 | ../src/console.h \ |
42 | ../src/ccoleta.h \ | 44 | ../src/ccoleta.h \ |
45 | + ../src/vregistry.h \ | ||
46 | + ../src/vqtconvert.h \ | ||
43 | ./gercols.h \ | 47 | ./gercols.h \ |
44 | ../src/cacic_hardware.h | 48 | ../src/cacic_hardware.h |
45 | 49 |
src/cacic_hardware.h
@@ -10,7 +10,6 @@ | @@ -10,7 +10,6 @@ | ||
10 | #include <operatingsystem.h> | 10 | #include <operatingsystem.h> |
11 | 11 | ||
12 | #if defined(Q_OS_WIN) | 12 | #if defined(Q_OS_WIN) |
13 | - #include <querysink.h> | ||
14 | #define _WIN32_DCOM | 13 | #define _WIN32_DCOM |
15 | #include <iostream> | 14 | #include <iostream> |
16 | //using namespace std; | 15 | //using namespace std; |
src/cacic_software.cpp
1 | #include "cacic_software.h" | 1 | #include "cacic_software.h" |
2 | - | 2 | +#ifdef Q_OS_WIN |
3 | + using namespace voidrealms::win32; | ||
4 | +#endif | ||
3 | cacic_software::cacic_software() | 5 | cacic_software::cacic_software() |
4 | { | 6 | { |
5 | } | 7 | } |
@@ -18,33 +20,36 @@ QJsonObject cacic_software::coletaWin() | @@ -18,33 +20,36 @@ QJsonObject cacic_software::coletaWin() | ||
18 | { | 20 | { |
19 | QJsonObject softwaresJson; | 21 | QJsonObject softwaresJson; |
20 | QStringList regedit; | 22 | QStringList regedit; |
21 | - regedit.append("HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall"); | ||
22 | - regedit.append("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall"); | 23 | + regedit.append("SOFTWARE\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\"); |
24 | + regedit.append("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\"); | ||
23 | foreach(QString registry, regedit){ | 25 | foreach(QString registry, regedit){ |
24 | - QSettings softwares(registry, QSettings::NativeFormat); | ||
25 | - // qDebug() << softwares.childGroups(); | ||
26 | - foreach (QString group, softwares.childGroups()){ | 26 | + VRegistry reg; |
27 | + reg.OpenKey(HKEY_LOCAL_MACHINE, registry); | ||
28 | + QStringList keys = reg.enum_Keys(); | ||
29 | + foreach(QString key, keys){ | ||
27 | QVariantMap software; | 30 | QVariantMap software; |
28 | - softwares.beginGroup(group); | ||
29 | - qDebug() << softwares.fileName() << softwares.value("DisplayName"); | ||
30 | - if (!softwares.value("DisplayName").isNull()) | ||
31 | - software["DisplayName"] = softwares.value("DisplayName"); | ||
32 | - if (!softwares.value("Publisher").isNull()) | ||
33 | - software["Publisher"] = softwares.value("Publisher"); | ||
34 | - if (!softwares.value("InstallLocation").isNull()) | ||
35 | - software["InstallLocation"] = softwares.value("InstallLocation"); | ||
36 | - if (!softwares.value("InstallDate").isNull()) | ||
37 | - software["InstallDate"] = softwares.value("InstallDate"); | ||
38 | - if (!softwares.value("URLInfoAbout").isNull()) | ||
39 | - software["URLInfoAbout"] = softwares.value("URLInfoAbout"); | ||
40 | - if (!softwares.value("UninstallString").isNull()) | ||
41 | - software["UninstallString"] = software.value("UninstallString"); | ||
42 | - if (!softwares.value("QuietUninstallString").isNull()) | ||
43 | - software["QuietUninstallString"] = software.value("QuietUninstallString"); | ||
44 | - softwares.endGroup(); | ||
45 | - softwaresJson[group] = QJsonObject::fromVariantMap(software); | 31 | + VRegistry subReg; |
32 | + subReg.OpenKey(HKEY_LOCAL_MACHINE, registry + key); | ||
33 | + if (!subReg.get_REG_SZ("DisplayName").isEmpty()) | ||
34 | + software["DisplayName"] = subReg.get_REG_SZ("DisplayName"); | ||
35 | + if (!subReg.get_REG_SZ("Publisher").isEmpty()) | ||
36 | + software["Publisher"] = subReg.get_REG_SZ("Publisher"); | ||
37 | + if (!subReg.get_REG_SZ("InstallLocation").isEmpty()) | ||
38 | + software["InstallLocation"] = subReg.get_REG_SZ("InstallLocation"); | ||
39 | + if (!subReg.get_REG_SZ("InstallDate").isEmpty()) | ||
40 | + software["InstallDate"] = subReg.get_REG_SZ("InstallDate"); | ||
41 | + if (!subReg.get_REG_SZ("URLInfoAbout").isEmpty()) | ||
42 | + software["URLInfoAbout"] = subReg.get_REG_SZ("URLInfoAbout"); | ||
43 | + if (!subReg.get_REG_EXPAND_SZ("UninstallString").isEmpty()) | ||
44 | + software["UninstallString"] = subReg.get_REG_EXPAND_SZ("UninstallString"); | ||
45 | + if (!subReg.get_REG_EXPAND_SZ("QuietUninstallString").isEmpty()) | ||
46 | + software["QuietUninstallString"] = subReg.get_REG_EXPAND_SZ("QuietUninstallString"); | ||
47 | + if (!subReg.get_REG_SZ("DisplayVersion").isEmpty()) | ||
48 | + software["DisplayVersion"] = subReg.get_REG_SZ("DisplayVersion"); | ||
49 | + | ||
50 | + softwaresJson[key] = QJsonObject::fromVariantMap(software); | ||
46 | } | 51 | } |
47 | -// qDebug() << softwaresJson; | 52 | + qDebug() << softwaresJson; |
48 | } | 53 | } |
49 | return softwaresJson; | 54 | return softwaresJson; |
50 | } | 55 | } |
src/cacic_software.h
@@ -4,6 +4,9 @@ | @@ -4,6 +4,9 @@ | ||
4 | #include <ccacic.h> | 4 | #include <ccacic.h> |
5 | #include <console.h> | 5 | #include <console.h> |
6 | #include <operatingsystem.h> | 6 | #include <operatingsystem.h> |
7 | +#include <vqtconvert.h> | ||
8 | +#include <vregistry.h> | ||
9 | + | ||
7 | class cacic_software | 10 | class cacic_software |
8 | { | 11 | { |
9 | public: | 12 | public: |
@@ -0,0 +1,60 @@ | @@ -0,0 +1,60 @@ | ||
1 | +#include "vqtconvert.h" | ||
2 | + | ||
3 | +#include <QString> | ||
4 | +#include "windows.h" | ||
5 | + | ||
6 | +namespace voidrealms | ||
7 | +{ | ||
8 | + namespace win32 | ||
9 | + { | ||
10 | + | ||
11 | + //Convert a QString To LPCTSTR | ||
12 | + LPCTSTR VQTConvert::QString_To_LPCTSTR(QString mQTData) | ||
13 | + { | ||
14 | + return (LPCTSTR)mQTData.utf16(); | ||
15 | + } | ||
16 | + | ||
17 | + //Convert a QString To LPCSTR | ||
18 | + LPCSTR VQTConvert::QString_To_LPCSTR(QString mQTData) | ||
19 | + { | ||
20 | + return (LPCSTR)mQTData.utf16(); | ||
21 | + } | ||
22 | + | ||
23 | + //Convert a QString To LPTSTR | ||
24 | + LPTSTR VQTConvert::QString_To_LPTSTR(QString mQTData) | ||
25 | + { | ||
26 | + return (LPTSTR)mQTData.utf16(); | ||
27 | + } | ||
28 | + | ||
29 | + //Convert a LPCTSTR To QString | ||
30 | + QString VQTConvert::LPCTSTR_To_QString(LPCTSTR mWinData) | ||
31 | + { | ||
32 | + return QString::fromUtf16((ushort*)mWinData); | ||
33 | + } | ||
34 | + | ||
35 | + //Convert a LPBYTE To QString | ||
36 | + QString VQTConvert::LPBYTE_To_QString(LPBYTE mWinData) | ||
37 | + { | ||
38 | + return QString::fromUtf16((ushort*)mWinData); | ||
39 | + } | ||
40 | + | ||
41 | + //Convert a Char[] To QString | ||
42 | + QString VQTConvert::Char_To_QString(char mWinData[]) | ||
43 | + { | ||
44 | + return QString::fromUtf16((ushort*)mWinData); | ||
45 | + } | ||
46 | + | ||
47 | + //Convert a WCHAR* to a QString | ||
48 | + QString VQTConvert::WCHAR_to_QString(WCHAR* mBuffer) | ||
49 | + { | ||
50 | + return QString::fromWCharArray(mBuffer); | ||
51 | + } | ||
52 | + | ||
53 | + //Convert a TCHAR To QString | ||
54 | + QString VQTConvert::TChar_To_QString(TCHAR mWinData[]) | ||
55 | + { | ||
56 | + return QString::fromUtf16((ushort*)mWinData); | ||
57 | + } | ||
58 | + | ||
59 | + } //end voidrealms::win32 namespace | ||
60 | +} //end voidrealms namespace |
@@ -0,0 +1,51 @@ | @@ -0,0 +1,51 @@ | ||
1 | +#ifndef VQTCONVERT_H | ||
2 | +#define VQTCONVERT_H | ||
3 | + | ||
4 | +/* | ||
5 | +Converts between QT types and Windows Types | ||
6 | +Version: 1.0 | ||
7 | +Modified on: 8-20-2009 | ||
8 | +Created with: QT 4.5 and QT Creator 1.2 | ||
9 | +Tested on: Windows XP SP3 | ||
10 | +Bryan Cairns - August 2009 | ||
11 | +*/ | ||
12 | + | ||
13 | +#include <QString> | ||
14 | +#include "windows.h" | ||
15 | + | ||
16 | +namespace voidrealms | ||
17 | +{ | ||
18 | + namespace win32 | ||
19 | + { | ||
20 | + | ||
21 | + class VQTConvert | ||
22 | + { | ||
23 | + public: | ||
24 | + //Convert a QString To LPCTSTR | ||
25 | + LPCTSTR static QString_To_LPCTSTR(QString mQTData); | ||
26 | + | ||
27 | + //Convert a QString To LPCSTR | ||
28 | + LPCSTR static QString_To_LPCSTR(QString mQTData); | ||
29 | + | ||
30 | + //Convert a QString To LPTSTR | ||
31 | + LPTSTR static QString_To_LPTSTR(QString mQTData); | ||
32 | + | ||
33 | + //Convert a LPCTSTR To QString | ||
34 | + QString static LPCTSTR_To_QString(LPCTSTR mWinData); | ||
35 | + | ||
36 | + //Convert a LPBYTE To QString | ||
37 | + QString static LPBYTE_To_QString(LPBYTE mWinData); | ||
38 | + | ||
39 | + //Convert a Char[] To QString | ||
40 | + QString static Char_To_QString(char mWinData[]); | ||
41 | + | ||
42 | + //Convert a WCHAR* to a QString | ||
43 | + QString static WCHAR_to_QString(WCHAR* mBuffer); | ||
44 | + | ||
45 | + //Convert a TCHAR To QString | ||
46 | + QString static TChar_To_QString(TCHAR mWinData[]); | ||
47 | + }; | ||
48 | + | ||
49 | + } //end voidrealms::win32 namespace | ||
50 | +} //end voidrealms namespace | ||
51 | +#endif // VQTCONVERT_H |
@@ -0,0 +1,477 @@ | @@ -0,0 +1,477 @@ | ||
1 | +/* | ||
2 | +Wrapper for the Windows Registry | ||
3 | +Version: 1.0 | ||
4 | +Modified on: 8-20-2009 | ||
5 | +Created with: QT 4.5 and QT Creator 1.2 | ||
6 | +Tested on: Windows XP SP3 | ||
7 | +Bryan Cairns | ||
8 | +*/ | ||
9 | + | ||
10 | +#include "vregistry.h" | ||
11 | +#include "windows.h" | ||
12 | +#include "VQTConvert.h" | ||
13 | +#include <QString> | ||
14 | +#include <QByteArray> | ||
15 | +#include <QStringList> | ||
16 | +#include <qdebug.h> | ||
17 | + | ||
18 | +namespace voidrealms | ||
19 | +{ | ||
20 | + namespace win32 | ||
21 | + { | ||
22 | + | ||
23 | + ////////////////////////////////////////////////////////////////////////////////////// | ||
24 | + // Windows API Methods | ||
25 | + ////////////////////////////////////////////////////////////////////////////////////// | ||
26 | + | ||
27 | + //Returns a boolean indicating if the Registry is open | ||
28 | + bool VRegistry::isOpen() | ||
29 | + { | ||
30 | + return this->mOpen; | ||
31 | + } | ||
32 | + | ||
33 | + //Opens a Registry Key | ||
34 | + bool VRegistry::OpenKey(HKEY RootKey,LPCTSTR SubKey) | ||
35 | + { | ||
36 | + LONG lResult; | ||
37 | + | ||
38 | + lResult = RegOpenKeyEx(RootKey,SubKey,0,KEY_ALL_ACCESS | KEY_WOW64_64KEY,&mKey); | ||
39 | + | ||
40 | + switch(lResult) | ||
41 | + { | ||
42 | + case ERROR_SUCCESS: //ok | ||
43 | + this->mOpen = true; | ||
44 | + break; | ||
45 | + default: //an error code from windows | ||
46 | + this->mOpen = false; | ||
47 | + break; | ||
48 | + } | ||
49 | + | ||
50 | + return this->mOpen; | ||
51 | + } | ||
52 | + | ||
53 | + //Creates a registry key and opens it | ||
54 | + bool VRegistry::CreateKey(HKEY RootKey,LPCTSTR SubKey) | ||
55 | + { | ||
56 | + LONG lResult; | ||
57 | + DWORD dwDisposition; | ||
58 | + | ||
59 | + //Create and open the key | ||
60 | + lResult = RegCreateKeyEx(RootKey,SubKey,0,NULL,0,0,NULL,&mKey,&dwDisposition); | ||
61 | + | ||
62 | + switch(lResult) | ||
63 | + { | ||
64 | + case ERROR_SUCCESS: //ok | ||
65 | + this->mOpen = true; | ||
66 | + break; | ||
67 | + default: //an error code from windows | ||
68 | + this->mOpen = false; | ||
69 | + break; | ||
70 | + } | ||
71 | + | ||
72 | + return this->mOpen; | ||
73 | + } | ||
74 | + | ||
75 | + //Closes the Registry Key | ||
76 | + bool VRegistry::CloseKey() | ||
77 | + { | ||
78 | + //If it is not open just return | ||
79 | + if(this->mOpen != true) return true; | ||
80 | + | ||
81 | + LONG lResult; | ||
82 | + lResult = RegCloseKey(this->mKey); | ||
83 | + | ||
84 | + switch(lResult) | ||
85 | + { | ||
86 | + case ERROR_SUCCESS: //ok | ||
87 | + this->mOpen = false; | ||
88 | + break; | ||
89 | + default: //an error code from windows | ||
90 | + this->mOpen = true; | ||
91 | + break; | ||
92 | + } | ||
93 | + | ||
94 | + return this->mOpen; | ||
95 | + } | ||
96 | + | ||
97 | + //Deletes a registry key and all values | ||
98 | + bool VRegistry::DeleteKey(HKEY RootKey,LPCTSTR SubKey) | ||
99 | + { | ||
100 | + LONG lResult; | ||
101 | + bool mReturn; | ||
102 | + //Delete a key an all the values | ||
103 | + lResult = RegDeleteKey(RootKey,SubKey); | ||
104 | + | ||
105 | + switch(lResult) | ||
106 | + { | ||
107 | + case ERROR_SUCCESS: //ok | ||
108 | + mReturn = true; | ||
109 | + break; | ||
110 | + default: //an error code from windows | ||
111 | + mReturn = false; | ||
112 | + break; | ||
113 | + } | ||
114 | + | ||
115 | + return mReturn; | ||
116 | + } | ||
117 | + | ||
118 | + //Determines if the key exists | ||
119 | + bool VRegistry::KeyExists(HKEY RootKey,LPCTSTR SubKey) | ||
120 | + { | ||
121 | + LONG lResult; | ||
122 | + HKEY mTempKey; | ||
123 | + lResult = RegOpenKeyEx(RootKey,SubKey,0,KEY_ALL_ACCESS,&mTempKey); | ||
124 | + | ||
125 | + switch(lResult) | ||
126 | + { | ||
127 | + case ERROR_SUCCESS: //ok | ||
128 | + RegCloseKey(mTempKey); | ||
129 | + return true; | ||
130 | + break; | ||
131 | + default: //an error code from windows | ||
132 | + return false; | ||
133 | + break; | ||
134 | + } | ||
135 | + } | ||
136 | + | ||
137 | + //Deletes a registry value and all values | ||
138 | + bool VRegistry::DeleteValue(LPCTSTR ValueName) | ||
139 | + { | ||
140 | + LONG lResult; | ||
141 | + bool mReturn; | ||
142 | + //Delete a key an all the values | ||
143 | + lResult = RegDeleteValue(this->mKey,ValueName); | ||
144 | + | ||
145 | + switch(lResult) | ||
146 | + { | ||
147 | + case ERROR_SUCCESS: //ok | ||
148 | + mReturn = true; | ||
149 | + break; | ||
150 | + default: //an error code from windows | ||
151 | + mReturn = false; | ||
152 | + break; | ||
153 | + } | ||
154 | + | ||
155 | + return mReturn; | ||
156 | + } | ||
157 | + | ||
158 | + //Determines if a value exists | ||
159 | + bool VRegistry::ValueExists(LPCTSTR ValueName) | ||
160 | + { | ||
161 | + LONG lResult; | ||
162 | + DWORD dwSize = 0; | ||
163 | + DWORD ValueType = REG_BINARY; | ||
164 | + BYTE* pBuffer = new BYTE[dwSize]; | ||
165 | + | ||
166 | + //get the needed buffer size, recreate the buffer to match the size | ||
167 | + lResult = RegQueryValueEx(this->mKey,ValueName,0,&ValueType,pBuffer, &dwSize); | ||
168 | + delete[] pBuffer; | ||
169 | + | ||
170 | + switch(lResult) | ||
171 | + { | ||
172 | + case ERROR_SUCCESS: //ok | ||
173 | + return true; | ||
174 | + break; | ||
175 | + case ERROR_MORE_DATA: //buffer was too small | ||
176 | + return true; | ||
177 | + break; | ||
178 | + case ERROR_FILE_NOT_FOUND: //value was not found | ||
179 | + return false; | ||
180 | + break; | ||
181 | + default: //an error code from windows | ||
182 | + return false; | ||
183 | + break; | ||
184 | + } | ||
185 | + } | ||
186 | + | ||
187 | + //Gets a Pointer to a Byte array filled with a REG_BINARY value from an open key (be sure to delete[] mVar) | ||
188 | + BYTE* VRegistry::QueryValue(LPCTSTR ValueName, DWORD ValueType) | ||
189 | + { | ||
190 | + LONG lResult; | ||
191 | + DWORD dwSize = 0; | ||
192 | + BYTE* pBuffer = new BYTE[dwSize]; | ||
193 | + | ||
194 | + //get the needed buffer size, recreate the buffer to match the size | ||
195 | + lResult = RegQueryValueEx(this->mKey,ValueName,0,&ValueType,pBuffer, &dwSize); | ||
196 | + delete[] pBuffer; | ||
197 | + pBuffer = new BYTE[dwSize]; | ||
198 | + | ||
199 | + //fill the buffer | ||
200 | + lResult = RegQueryValueEx(this->mKey,ValueName,0,&ValueType,pBuffer, &dwSize); | ||
201 | + | ||
202 | + switch(lResult) | ||
203 | + { | ||
204 | + case ERROR_SUCCESS: //ok | ||
205 | + return pBuffer; | ||
206 | + break; | ||
207 | + case ERROR_MORE_DATA: //buffer was too small | ||
208 | + throw "ERROR_MORE_DATA = Buffer is too small to read the value"; | ||
209 | + break; | ||
210 | + case ERROR_FILE_NOT_FOUND: //value was not found | ||
211 | + throw "ERROR_FILE_NOT_FOUND = The value was not found"; | ||
212 | + break; | ||
213 | + default: //an error code from windows | ||
214 | + throw "ERROR = " + lResult; | ||
215 | + break; | ||
216 | + } | ||
217 | + } | ||
218 | + | ||
219 | + //Sets a value in the regsitry | ||
220 | + bool VRegistry::SetValue(LPCTSTR ValueName, DWORD ValueType, LPBYTE Value,DWORD dwSize) | ||
221 | + { | ||
222 | + | ||
223 | + LONG lResult; | ||
224 | + | ||
225 | + //Attempt to save the value | ||
226 | + lResult = RegSetValueEx(this->mKey,ValueName,0,ValueType,Value,dwSize); | ||
227 | + | ||
228 | + switch(lResult) | ||
229 | + { | ||
230 | + case ERROR_SUCCESS: //ok | ||
231 | + return true; | ||
232 | + break; | ||
233 | + default: //an error code from windows | ||
234 | + return false; | ||
235 | + break; | ||
236 | + } | ||
237 | + } | ||
238 | + | ||
239 | + ////////////////////////////////////////////////////////////////////////////////////// | ||
240 | + // QT Friendly Methods | ||
241 | + ////////////////////////////////////////////////////////////////////////////////////// | ||
242 | + | ||
243 | + //Opens a Registry Key | ||
244 | + bool VRegistry::OpenKey(HKEY RootKey,QString SubKey) | ||
245 | + { | ||
246 | + LPCTSTR mSubKey = VQTConvert::QString_To_LPCTSTR(SubKey); | ||
247 | + return OpenKey(RootKey,mSubKey); | ||
248 | + } | ||
249 | + | ||
250 | + //Creates a registry key and opens it | ||
251 | + bool VRegistry::CreateKey(HKEY RootKey,QString SubKey) | ||
252 | + { | ||
253 | + LPCTSTR mSubKey = VQTConvert::QString_To_LPCTSTR(SubKey); | ||
254 | + return CreateKey(RootKey,mSubKey); | ||
255 | + } | ||
256 | + | ||
257 | + //Deletes a registry key and all values | ||
258 | + bool VRegistry::DeleteKey(HKEY RootKey,QString SubKey) | ||
259 | + { | ||
260 | + LPCTSTR mSubKey = VQTConvert::QString_To_LPCTSTR(SubKey); | ||
261 | + return DeleteKey(RootKey,mSubKey); | ||
262 | + } | ||
263 | + | ||
264 | + //Determines if the key exists | ||
265 | + bool VRegistry::KeyExists(HKEY RootKey,QString SubKey) | ||
266 | + { | ||
267 | + LPCTSTR mSubKey = VQTConvert::QString_To_LPCTSTR(SubKey); | ||
268 | + return KeyExists(RootKey,mSubKey); | ||
269 | + } | ||
270 | + | ||
271 | + //Deletes a registry value and all values | ||
272 | + bool VRegistry::DeleteValue(QString ValueName) | ||
273 | + { | ||
274 | + LPCTSTR mValueName = VQTConvert::QString_To_LPCTSTR(ValueName); | ||
275 | + return DeleteValue(mValueName); | ||
276 | + } | ||
277 | + | ||
278 | + //Determines if a value exists | ||
279 | + bool VRegistry::ValueExists(QString ValueName) | ||
280 | + { | ||
281 | + LPCTSTR mValueName = VQTConvert::QString_To_LPCTSTR(ValueName); | ||
282 | + return ValueExists(mValueName); | ||
283 | + } | ||
284 | + | ||
285 | + //Gets REG_SZ value as a QString | ||
286 | + QString VRegistry::get_REG_SZ(QString ValueName) | ||
287 | + { | ||
288 | + if (ValueExists(ValueName)) { | ||
289 | + LPCTSTR mValueName = VQTConvert::QString_To_LPCTSTR(ValueName); | ||
290 | + DWORD mType = REG_SZ; | ||
291 | + BYTE* mBuffer = QueryValue(mValueName, mType); | ||
292 | + QString mRet = VQTConvert::WCHAR_to_QString((wchar_t*)mBuffer); | ||
293 | + delete[] mBuffer; | ||
294 | + return mRet; | ||
295 | + } else { | ||
296 | + return ""; | ||
297 | + } | ||
298 | + } | ||
299 | + | ||
300 | + //Gets REG_EXPAND_SZ value as a QString | ||
301 | + QString VRegistry::get_REG_EXPAND_SZ(QString ValueName) | ||
302 | + { | ||
303 | + if (ValueExists(ValueName)){ | ||
304 | + LPCTSTR mValueName = VQTConvert::QString_To_LPCTSTR(ValueName); | ||
305 | + DWORD mType = REG_EXPAND_SZ; | ||
306 | + BYTE* mBuffer = QueryValue(mValueName, mType); | ||
307 | + QString mRet = VQTConvert::WCHAR_to_QString((wchar_t*)mBuffer); | ||
308 | + delete[] mBuffer; | ||
309 | + return mRet; | ||
310 | + } else | ||
311 | + return ""; | ||
312 | + } | ||
313 | + | ||
314 | + //Gets REG_DWORD value as a UINT | ||
315 | + uint VRegistry::get_REG_DWORD(QString ValueName) | ||
316 | + { | ||
317 | + LPCTSTR mValueName = VQTConvert::QString_To_LPCTSTR(ValueName); | ||
318 | + DWORD mType = REG_DWORD; | ||
319 | + BYTE* mBuffer = QueryValue(mValueName, mType); | ||
320 | + DWORD mVal = *(DWORD*)&mBuffer[0]; | ||
321 | + delete[] mBuffer; | ||
322 | + return (uint)mVal; | ||
323 | + } | ||
324 | + | ||
325 | + //Gets a REG_BINARY value as a QByteArray | ||
326 | + QByteArray VRegistry::get_REG_BINARY(QString ValueName) | ||
327 | + { | ||
328 | + LPCTSTR mValueName = VQTConvert::QString_To_LPCTSTR(ValueName); | ||
329 | + DWORD mType = REG_BINARY; | ||
330 | + BYTE* mBuffer = QueryValue(mValueName, mType); | ||
331 | + QByteArray mArray((const char*)mBuffer); | ||
332 | + delete[] mBuffer; | ||
333 | + return mArray; | ||
334 | + } | ||
335 | + | ||
336 | + //Gets a REG_MUTLI_SZ value as a QStringList | ||
337 | + QStringList VRegistry::get_MULTI_SZ(QString ValueName) | ||
338 | + { | ||
339 | + QStringList mList; | ||
340 | + LPCTSTR mValueName = VQTConvert::QString_To_LPCTSTR(ValueName); | ||
341 | + DWORD mType = REG_MULTI_SZ; | ||
342 | + BYTE* mBuffer = QueryValue(mValueName, mType); | ||
343 | + WCHAR* mItems =(WCHAR*)mBuffer; | ||
344 | + while(*mItems != '\0') | ||
345 | + { | ||
346 | + //mItems is the current string | ||
347 | + QString mRet = VQTConvert::WCHAR_to_QString(mItems); | ||
348 | + mList.append(mRet); | ||
349 | + mItems = mItems + lstrlen(mItems); // pStr now points to null at end of string | ||
350 | + mItems++; // pStr now points to the next string, or the second null to terminate | ||
351 | + } | ||
352 | + | ||
353 | + delete[] mBuffer; | ||
354 | + return mList; | ||
355 | + } | ||
356 | + | ||
357 | + //Sets a REG_SZ value with a QString | ||
358 | + bool VRegistry::set_REG_SZ(QString ValueName, QString Value) | ||
359 | + { | ||
360 | + LPCTSTR mValueName = VQTConvert::QString_To_LPCTSTR(ValueName); | ||
361 | + DWORD mType = REG_SZ; | ||
362 | + DWORD mSize = sizeof(Value.utf16()) * Value.length(); | ||
363 | + return SetValue(mValueName,mType,(LPBYTE)Value.utf16(),mSize); | ||
364 | + } | ||
365 | + | ||
366 | + //Sets a REG_EXPAND_SZ value with a QString | ||
367 | + bool VRegistry::set_REG_EXPAND_SZ(QString ValueName, QString Value) | ||
368 | + { | ||
369 | + LPCTSTR mValueName = VQTConvert::QString_To_LPCTSTR(ValueName); | ||
370 | + DWORD mType = REG_EXPAND_SZ; | ||
371 | + DWORD mSize = sizeof(Value.utf16()) * Value.length(); | ||
372 | + return SetValue(mValueName,mType,(LPBYTE)Value.utf16(),mSize); | ||
373 | + } | ||
374 | + | ||
375 | + //Sets a REG_DWORD value with a UINT | ||
376 | + bool VRegistry::set_REG_DWORD(QString ValueName, UINT Value) | ||
377 | + { | ||
378 | + LPCTSTR mValueName = VQTConvert::QString_To_LPCTSTR(ValueName); | ||
379 | + DWORD mType = REG_DWORD; | ||
380 | + DWORD mSize = 4; | ||
381 | + return SetValue(mValueName,mType,(LPBYTE)&Value,mSize); | ||
382 | + } | ||
383 | + | ||
384 | + //Sets a REG_BINARY value with a QByteArray | ||
385 | + bool VRegistry::set_REG_BINARY(QString ValueName, QByteArray Value) | ||
386 | + { | ||
387 | + LPCTSTR mValueName = VQTConvert::QString_To_LPCTSTR(ValueName); | ||
388 | + DWORD mType = REG_BINARY; | ||
389 | + BYTE* mData = (BYTE*)Value.data(); | ||
390 | + DWORD mSize = Value.length(); | ||
391 | + return SetValue(mValueName,mType,mData,mSize); | ||
392 | + } | ||
393 | + | ||
394 | + //Sets a REG_MULTI_SZ value with a QStringList | ||
395 | + bool VRegistry::set_REG_MULTI_SZ(QString ValueName, QStringList Value) | ||
396 | + { | ||
397 | + LPCTSTR mValueName = VQTConvert::QString_To_LPCTSTR(ValueName); | ||
398 | + DWORD mType = REG_MULTI_SZ; | ||
399 | + QString mValue; | ||
400 | + //DWORD mSize = 0; | ||
401 | + for (int i = 0; i < Value.size(); ++i) | ||
402 | + { | ||
403 | + mValue += Value.at(i); | ||
404 | + mValue += '\0'; | ||
405 | + } | ||
406 | + mValue += '\0'; | ||
407 | + | ||
408 | + DWORD mSize = (sizeof(mValue.utf16()) * mValue.length()) / 2; | ||
409 | + | ||
410 | + return SetValue(mValueName,mType,(LPBYTE)mValue.utf16(),mSize); | ||
411 | + } | ||
412 | + | ||
413 | + //Gets a string list filled with names of the sub keys from the current open key | ||
414 | + QStringList VRegistry::enum_Keys() | ||
415 | + { | ||
416 | + LONG lResult; | ||
417 | + LONG lNumber = 0; | ||
418 | + QStringList mList; | ||
419 | + bool mProcess = true; | ||
420 | + | ||
421 | + //Enum through the items | ||
422 | + do | ||
423 | + { | ||
424 | + DWORD dwSize = 255; | ||
425 | + WCHAR* pBuffer = new WCHAR[dwSize]; | ||
426 | + | ||
427 | + lResult = RegEnumKeyEx(this->mKey,lNumber, pBuffer, &dwSize,NULL,NULL,NULL,NULL); | ||
428 | + if(lResult == ERROR_SUCCESS) | ||
429 | + { | ||
430 | + QString mRet = VQTConvert::WCHAR_to_QString(pBuffer); | ||
431 | + mList.append(mRet); | ||
432 | + } | ||
433 | + else | ||
434 | + { | ||
435 | + mProcess = false; | ||
436 | + } | ||
437 | + delete[] pBuffer; | ||
438 | + | ||
439 | + lNumber++; | ||
440 | + }while(mProcess); | ||
441 | + | ||
442 | + return mList; | ||
443 | + } | ||
444 | + | ||
445 | + //Gets a string list filled with names of the values from the current open key | ||
446 | + QStringList VRegistry::enum_Values() | ||
447 | + { | ||
448 | + LONG lResult; | ||
449 | + LONG lNumber = 0; | ||
450 | + QStringList mList; | ||
451 | + bool mProcess = true; | ||
452 | + | ||
453 | + //Enum through the items | ||
454 | + do | ||
455 | + { | ||
456 | + DWORD dwSize = 16383; | ||
457 | + WCHAR* pBuffer = new WCHAR[dwSize]; | ||
458 | + lResult = RegEnumValue(this->mKey,lNumber, pBuffer, &dwSize,NULL,NULL,NULL,NULL); | ||
459 | + if(lResult == ERROR_SUCCESS) | ||
460 | + { | ||
461 | + QString mRet = VQTConvert::WCHAR_to_QString(pBuffer); | ||
462 | + mList.append(mRet); | ||
463 | + } | ||
464 | + else | ||
465 | + { | ||
466 | + mProcess = false; | ||
467 | + } | ||
468 | + delete[] pBuffer; | ||
469 | + | ||
470 | + lNumber++; | ||
471 | + }while(mProcess); | ||
472 | + | ||
473 | + return mList; | ||
474 | + } | ||
475 | + | ||
476 | + } //end voidrealms::win32 namespace | ||
477 | +} //end voidrealms namespace |
@@ -0,0 +1,127 @@ | @@ -0,0 +1,127 @@ | ||
1 | +/* | ||
2 | +Wrapper for the Windows Registry | ||
3 | +Version: 1.0 | ||
4 | +Modified on: 8-20-2009 | ||
5 | +Created with: QT 4.5 and QT Creator 1.2 | ||
6 | +Tested on: Windows XP SP3 | ||
7 | +Bryan Cairns | ||
8 | +*/ | ||
9 | + | ||
10 | +#ifndef VREGISTRY_H | ||
11 | +#define VREGISTRY_H | ||
12 | + | ||
13 | +#include "windows.h" | ||
14 | +#include <QString> | ||
15 | +#include <QByteArray> | ||
16 | +#include <QStringList> | ||
17 | + | ||
18 | +namespace voidrealms | ||
19 | +{ | ||
20 | + namespace win32 | ||
21 | + { | ||
22 | + | ||
23 | + class VRegistry | ||
24 | + { | ||
25 | + private: | ||
26 | + HKEY mKey; //The current opened key | ||
27 | + bool mOpen; //Boolean indicates if the registry is open | ||
28 | + | ||
29 | + ////////////////////////////////////////////////////////////////////////////////////// | ||
30 | + // Windows API Methods | ||
31 | + ////////////////////////////////////////////////////////////////////////////////////// | ||
32 | + | ||
33 | + //Opens a Registry Key | ||
34 | + bool OpenKey(HKEY RootKey,LPCTSTR SubKey); | ||
35 | + | ||
36 | + //Creates a registry key and opens it | ||
37 | + bool CreateKey(HKEY RootKey,LPCTSTR SubKey); | ||
38 | + | ||
39 | + //Deletes a registry key and all values | ||
40 | + bool DeleteKey(HKEY RootKey,LPCTSTR SubKey); | ||
41 | + | ||
42 | + //Determines if the key exists | ||
43 | + bool KeyExists(HKEY RootKey,LPCTSTR SubKey); | ||
44 | + | ||
45 | + //Deletes a registry value and all values | ||
46 | + bool DeleteValue(LPCTSTR ValueName); | ||
47 | + | ||
48 | + //Determines if a value exists | ||
49 | + bool ValueExists(LPCTSTR ValueName); | ||
50 | + | ||
51 | + //Gets a Pointer to a Byte array filled with a reg type value from an open key (be sure to delete[] mVar) | ||
52 | + BYTE* QueryValue(LPCTSTR ValueName, DWORD ValueType); | ||
53 | + | ||
54 | + //Sets a value in the regsitry | ||
55 | + bool SetValue(LPCTSTR ValueName, DWORD ValueType, BYTE* Value, DWORD dwSize); | ||
56 | + | ||
57 | + public: | ||
58 | + | ||
59 | + ////////////////////////////////////////////////////////////////////////////////////// | ||
60 | + // QT friendly Methods | ||
61 | + ////////////////////////////////////////////////////////////////////////////////////// | ||
62 | + | ||
63 | + //Returns a boolean indicating if the Registry is open | ||
64 | + bool isOpen(); | ||
65 | + | ||
66 | + //Closes the Registry Key | ||
67 | + bool CloseKey(); | ||
68 | + | ||
69 | + //Opens a Registry Key | ||
70 | + bool OpenKey(HKEY RootKey,QString SubKey); | ||
71 | + | ||
72 | + //Creates a registry key and opens it | ||
73 | + bool CreateKey(HKEY RootKey,QString SubKey); | ||
74 | + | ||
75 | + //Deletes a registry key and all values | ||
76 | + bool DeleteKey(HKEY RootKey,QString SubKey); | ||
77 | + | ||
78 | + //Determines if the key exists | ||
79 | + bool KeyExists(HKEY RootKey,QString SubKey); | ||
80 | + | ||
81 | + //Deletes a registry value and all values | ||
82 | + bool DeleteValue(QString ValueName); | ||
83 | + | ||
84 | + //Determines if a value exists | ||
85 | + bool ValueExists(QString ValueName); | ||
86 | + | ||
87 | + //Gets a REG_SZ value as a QString | ||
88 | + QString get_REG_SZ(QString ValueName); | ||
89 | + | ||
90 | + //Gets a REG_EXPAND_SZ value as a QString | ||
91 | + QString get_REG_EXPAND_SZ(QString ValueName); | ||
92 | + | ||
93 | + //Gets a REG_DWORD value as a UINT | ||
94 | + uint get_REG_DWORD(QString ValueName); | ||
95 | + | ||
96 | + //Gets a REG_BINARY value as a QByteArray | ||
97 | + QByteArray get_REG_BINARY(QString ValueName); | ||
98 | + | ||
99 | + //Gets a REG_MUTLI_SZ value as a QStringList | ||
100 | + QStringList get_MULTI_SZ(QString ValueName); | ||
101 | + | ||
102 | + //Sets a REG_SZ value with a QString | ||
103 | + bool set_REG_SZ(QString ValueName, QString Value); | ||
104 | + | ||
105 | + //Sets a REG_EXPAND_SZ value with a QString | ||
106 | + bool set_REG_EXPAND_SZ(QString ValueName, QString Value); | ||
107 | + | ||
108 | + //Sets a REG_DWORD value with a UINT | ||
109 | + bool set_REG_DWORD(QString ValueName, UINT Value); | ||
110 | + | ||
111 | + //Sets a REG_BINARY value with a QByteArray | ||
112 | + bool set_REG_BINARY(QString ValueName, QByteArray Value); | ||
113 | + | ||
114 | + //Sets a REG_MULTI_SZ value with a QStringList | ||
115 | + bool set_REG_MULTI_SZ(QString ValueName, QStringList Value); | ||
116 | + | ||
117 | + //Gets a string list filled with names of the sub keys from the current open key | ||
118 | + QStringList enum_Keys(); | ||
119 | + | ||
120 | + //Gets a string list filled with names of the values from the current open key | ||
121 | + QStringList enum_Values(); | ||
122 | + | ||
123 | + }; | ||
124 | + | ||
125 | + } //end voidrealms::win32 namespace | ||
126 | +} //end voidrealms namespace | ||
127 | +#endif // VREGISTRY_H |