From f78ed3f8f8a3b43231ae7fc57ca122bf5248da10 Mon Sep 17 00:00:00 2001 From: ericmenezesn@gmail.com Date: Mon, 25 Aug 2014 17:53:18 -0300 Subject: [PATCH] Coleta de software no windows (inclusive 64x) --- cacicD/cacicD.pro | 8 -------- gercols/gercols.pro | 4 ++++ src/cacic_hardware.h | 1 - src/cacic_software.cpp | 55 ++++++++++++++++++++++++++++++------------------------- src/cacic_software.h | 3 +++ src/vqtconvert.cpp | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/vqtconvert.h | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ src/vregistry.cpp | 477 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/vregistry.h | 127 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 9 files changed, 752 insertions(+), 34 deletions(-) create mode 100644 src/vqtconvert.cpp create mode 100644 src/vqtconvert.h create mode 100644 src/vregistry.cpp create mode 100644 src/vregistry.h diff --git a/cacicD/cacicD.pro b/cacicD/cacicD.pro index 98d500d..5fdd892 100644 --- a/cacicD/cacicD.pro +++ b/cacicD/cacicD.pro @@ -20,19 +20,11 @@ TEMPLATE = app SOURCES += main.cpp \ - ../src/cacic_computer.cpp \ ../src/ccacic.cpp \ - ../src/ccoleta.cpp \ - ../src/operatingsystem.cpp \ cacicd.cpp HEADERS += \ - ../src/cacic_comm.h \ - ../src/cacic_computer.h \ ../src/ccacic.h \ - ../src/ccoleta.h \ - ../src/console.h \ - ../src/operatingsystem.h \ cacicd.h include(../src/qtservice/src/qtservice.pri) diff --git a/gercols/gercols.pro b/gercols/gercols.pro index a28e681..4b624c2 100644 --- a/gercols/gercols.pro +++ b/gercols/gercols.pro @@ -29,6 +29,8 @@ SOURCES += \ ../src/cacic_hardware.cpp \ ../src/operatingsystem.cpp \ ../src/ccoleta.cpp \ + ../src/vregistry.cpp \ + ../src/vqtconvert.cpp \ ./gercols.cpp @@ -40,6 +42,8 @@ HEADERS += \ ../src/operatingsystem.h \ ../src/console.h \ ../src/ccoleta.h \ + ../src/vregistry.h \ + ../src/vqtconvert.h \ ./gercols.h \ ../src/cacic_hardware.h diff --git a/src/cacic_hardware.h b/src/cacic_hardware.h index 07603c3..a7dc663 100644 --- a/src/cacic_hardware.h +++ b/src/cacic_hardware.h @@ -10,7 +10,6 @@ #include #if defined(Q_OS_WIN) - #include #define _WIN32_DCOM #include //using namespace std; diff --git a/src/cacic_software.cpp b/src/cacic_software.cpp index 5208590..8048606 100644 --- a/src/cacic_software.cpp +++ b/src/cacic_software.cpp @@ -1,5 +1,7 @@ #include "cacic_software.h" - +#ifdef Q_OS_WIN + using namespace voidrealms::win32; +#endif cacic_software::cacic_software() { } @@ -18,33 +20,36 @@ QJsonObject cacic_software::coletaWin() { QJsonObject softwaresJson; QStringList regedit; - regedit.append("HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall"); - regedit.append("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall"); + regedit.append("SOFTWARE\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\"); + regedit.append("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\"); foreach(QString registry, regedit){ - QSettings softwares(registry, QSettings::NativeFormat); - // qDebug() << softwares.childGroups(); - foreach (QString group, softwares.childGroups()){ + VRegistry reg; + reg.OpenKey(HKEY_LOCAL_MACHINE, registry); + QStringList keys = reg.enum_Keys(); + foreach(QString key, keys){ QVariantMap software; - softwares.beginGroup(group); - qDebug() << softwares.fileName() << softwares.value("DisplayName"); - if (!softwares.value("DisplayName").isNull()) - software["DisplayName"] = softwares.value("DisplayName"); - if (!softwares.value("Publisher").isNull()) - software["Publisher"] = softwares.value("Publisher"); - if (!softwares.value("InstallLocation").isNull()) - software["InstallLocation"] = softwares.value("InstallLocation"); - if (!softwares.value("InstallDate").isNull()) - software["InstallDate"] = softwares.value("InstallDate"); - if (!softwares.value("URLInfoAbout").isNull()) - software["URLInfoAbout"] = softwares.value("URLInfoAbout"); - if (!softwares.value("UninstallString").isNull()) - software["UninstallString"] = software.value("UninstallString"); - if (!softwares.value("QuietUninstallString").isNull()) - software["QuietUninstallString"] = software.value("QuietUninstallString"); - softwares.endGroup(); - softwaresJson[group] = QJsonObject::fromVariantMap(software); + VRegistry subReg; + subReg.OpenKey(HKEY_LOCAL_MACHINE, registry + key); + if (!subReg.get_REG_SZ("DisplayName").isEmpty()) + software["DisplayName"] = subReg.get_REG_SZ("DisplayName"); + if (!subReg.get_REG_SZ("Publisher").isEmpty()) + software["Publisher"] = subReg.get_REG_SZ("Publisher"); + if (!subReg.get_REG_SZ("InstallLocation").isEmpty()) + software["InstallLocation"] = subReg.get_REG_SZ("InstallLocation"); + if (!subReg.get_REG_SZ("InstallDate").isEmpty()) + software["InstallDate"] = subReg.get_REG_SZ("InstallDate"); + if (!subReg.get_REG_SZ("URLInfoAbout").isEmpty()) + software["URLInfoAbout"] = subReg.get_REG_SZ("URLInfoAbout"); + if (!subReg.get_REG_EXPAND_SZ("UninstallString").isEmpty()) + software["UninstallString"] = subReg.get_REG_EXPAND_SZ("UninstallString"); + if (!subReg.get_REG_EXPAND_SZ("QuietUninstallString").isEmpty()) + software["QuietUninstallString"] = subReg.get_REG_EXPAND_SZ("QuietUninstallString"); + if (!subReg.get_REG_SZ("DisplayVersion").isEmpty()) + software["DisplayVersion"] = subReg.get_REG_SZ("DisplayVersion"); + + softwaresJson[key] = QJsonObject::fromVariantMap(software); } -// qDebug() << softwaresJson; + qDebug() << softwaresJson; } return softwaresJson; } diff --git a/src/cacic_software.h b/src/cacic_software.h index 5c41686..9518b8c 100644 --- a/src/cacic_software.h +++ b/src/cacic_software.h @@ -4,6 +4,9 @@ #include #include #include +#include +#include + class cacic_software { public: diff --git a/src/vqtconvert.cpp b/src/vqtconvert.cpp new file mode 100644 index 0000000..cbd6cda --- /dev/null +++ b/src/vqtconvert.cpp @@ -0,0 +1,60 @@ +#include "vqtconvert.h" + +#include +#include "windows.h" + +namespace voidrealms +{ + namespace win32 + { + + //Convert a QString To LPCTSTR + LPCTSTR VQTConvert::QString_To_LPCTSTR(QString mQTData) + { + return (LPCTSTR)mQTData.utf16(); + } + + //Convert a QString To LPCSTR + LPCSTR VQTConvert::QString_To_LPCSTR(QString mQTData) + { + return (LPCSTR)mQTData.utf16(); + } + + //Convert a QString To LPTSTR + LPTSTR VQTConvert::QString_To_LPTSTR(QString mQTData) + { + return (LPTSTR)mQTData.utf16(); + } + + //Convert a LPCTSTR To QString + QString VQTConvert::LPCTSTR_To_QString(LPCTSTR mWinData) + { + return QString::fromUtf16((ushort*)mWinData); + } + + //Convert a LPBYTE To QString + QString VQTConvert::LPBYTE_To_QString(LPBYTE mWinData) + { + return QString::fromUtf16((ushort*)mWinData); + } + + //Convert a Char[] To QString + QString VQTConvert::Char_To_QString(char mWinData[]) + { + return QString::fromUtf16((ushort*)mWinData); + } + + //Convert a WCHAR* to a QString + QString VQTConvert::WCHAR_to_QString(WCHAR* mBuffer) + { + return QString::fromWCharArray(mBuffer); + } + + //Convert a TCHAR To QString + QString VQTConvert::TChar_To_QString(TCHAR mWinData[]) + { + return QString::fromUtf16((ushort*)mWinData); + } + + } //end voidrealms::win32 namespace +} //end voidrealms namespace diff --git a/src/vqtconvert.h b/src/vqtconvert.h new file mode 100644 index 0000000..d24e24f --- /dev/null +++ b/src/vqtconvert.h @@ -0,0 +1,51 @@ +#ifndef VQTCONVERT_H +#define VQTCONVERT_H + +/* +Converts between QT types and Windows Types +Version: 1.0 +Modified on: 8-20-2009 +Created with: QT 4.5 and QT Creator 1.2 +Tested on: Windows XP SP3 +Bryan Cairns - August 2009 +*/ + +#include +#include "windows.h" + +namespace voidrealms +{ + namespace win32 + { + + class VQTConvert + { + public: + //Convert a QString To LPCTSTR + LPCTSTR static QString_To_LPCTSTR(QString mQTData); + + //Convert a QString To LPCSTR + LPCSTR static QString_To_LPCSTR(QString mQTData); + + //Convert a QString To LPTSTR + LPTSTR static QString_To_LPTSTR(QString mQTData); + + //Convert a LPCTSTR To QString + QString static LPCTSTR_To_QString(LPCTSTR mWinData); + + //Convert a LPBYTE To QString + QString static LPBYTE_To_QString(LPBYTE mWinData); + + //Convert a Char[] To QString + QString static Char_To_QString(char mWinData[]); + + //Convert a WCHAR* to a QString + QString static WCHAR_to_QString(WCHAR* mBuffer); + + //Convert a TCHAR To QString + QString static TChar_To_QString(TCHAR mWinData[]); + }; + + } //end voidrealms::win32 namespace +} //end voidrealms namespace +#endif // VQTCONVERT_H diff --git a/src/vregistry.cpp b/src/vregistry.cpp new file mode 100644 index 0000000..c6f7c3d --- /dev/null +++ b/src/vregistry.cpp @@ -0,0 +1,477 @@ +/* +Wrapper for the Windows Registry +Version: 1.0 +Modified on: 8-20-2009 +Created with: QT 4.5 and QT Creator 1.2 +Tested on: Windows XP SP3 +Bryan Cairns +*/ + +#include "vregistry.h" +#include "windows.h" +#include "VQTConvert.h" +#include +#include +#include +#include + +namespace voidrealms +{ + namespace win32 + { + + ////////////////////////////////////////////////////////////////////////////////////// + // Windows API Methods + ////////////////////////////////////////////////////////////////////////////////////// + + //Returns a boolean indicating if the Registry is open + bool VRegistry::isOpen() + { + return this->mOpen; + } + + //Opens a Registry Key + bool VRegistry::OpenKey(HKEY RootKey,LPCTSTR SubKey) + { + LONG lResult; + + lResult = RegOpenKeyEx(RootKey,SubKey,0,KEY_ALL_ACCESS | KEY_WOW64_64KEY,&mKey); + + switch(lResult) + { + case ERROR_SUCCESS: //ok + this->mOpen = true; + break; + default: //an error code from windows + this->mOpen = false; + break; + } + + return this->mOpen; + } + + //Creates a registry key and opens it + bool VRegistry::CreateKey(HKEY RootKey,LPCTSTR SubKey) + { + LONG lResult; + DWORD dwDisposition; + + //Create and open the key + lResult = RegCreateKeyEx(RootKey,SubKey,0,NULL,0,0,NULL,&mKey,&dwDisposition); + + switch(lResult) + { + case ERROR_SUCCESS: //ok + this->mOpen = true; + break; + default: //an error code from windows + this->mOpen = false; + break; + } + + return this->mOpen; + } + + //Closes the Registry Key + bool VRegistry::CloseKey() + { + //If it is not open just return + if(this->mOpen != true) return true; + + LONG lResult; + lResult = RegCloseKey(this->mKey); + + switch(lResult) + { + case ERROR_SUCCESS: //ok + this->mOpen = false; + break; + default: //an error code from windows + this->mOpen = true; + break; + } + + return this->mOpen; + } + + //Deletes a registry key and all values + bool VRegistry::DeleteKey(HKEY RootKey,LPCTSTR SubKey) + { + LONG lResult; + bool mReturn; + //Delete a key an all the values + lResult = RegDeleteKey(RootKey,SubKey); + + switch(lResult) + { + case ERROR_SUCCESS: //ok + mReturn = true; + break; + default: //an error code from windows + mReturn = false; + break; + } + + return mReturn; + } + + //Determines if the key exists + bool VRegistry::KeyExists(HKEY RootKey,LPCTSTR SubKey) + { + LONG lResult; + HKEY mTempKey; + lResult = RegOpenKeyEx(RootKey,SubKey,0,KEY_ALL_ACCESS,&mTempKey); + + switch(lResult) + { + case ERROR_SUCCESS: //ok + RegCloseKey(mTempKey); + return true; + break; + default: //an error code from windows + return false; + break; + } + } + + //Deletes a registry value and all values + bool VRegistry::DeleteValue(LPCTSTR ValueName) + { + LONG lResult; + bool mReturn; + //Delete a key an all the values + lResult = RegDeleteValue(this->mKey,ValueName); + + switch(lResult) + { + case ERROR_SUCCESS: //ok + mReturn = true; + break; + default: //an error code from windows + mReturn = false; + break; + } + + return mReturn; + } + + //Determines if a value exists + bool VRegistry::ValueExists(LPCTSTR ValueName) + { + LONG lResult; + DWORD dwSize = 0; + DWORD ValueType = REG_BINARY; + BYTE* pBuffer = new BYTE[dwSize]; + + //get the needed buffer size, recreate the buffer to match the size + lResult = RegQueryValueEx(this->mKey,ValueName,0,&ValueType,pBuffer, &dwSize); + delete[] pBuffer; + + switch(lResult) + { + case ERROR_SUCCESS: //ok + return true; + break; + case ERROR_MORE_DATA: //buffer was too small + return true; + break; + case ERROR_FILE_NOT_FOUND: //value was not found + return false; + break; + default: //an error code from windows + return false; + break; + } + } + + //Gets a Pointer to a Byte array filled with a REG_BINARY value from an open key (be sure to delete[] mVar) + BYTE* VRegistry::QueryValue(LPCTSTR ValueName, DWORD ValueType) + { + LONG lResult; + DWORD dwSize = 0; + BYTE* pBuffer = new BYTE[dwSize]; + + //get the needed buffer size, recreate the buffer to match the size + lResult = RegQueryValueEx(this->mKey,ValueName,0,&ValueType,pBuffer, &dwSize); + delete[] pBuffer; + pBuffer = new BYTE[dwSize]; + + //fill the buffer + lResult = RegQueryValueEx(this->mKey,ValueName,0,&ValueType,pBuffer, &dwSize); + + switch(lResult) + { + case ERROR_SUCCESS: //ok + return pBuffer; + break; + case ERROR_MORE_DATA: //buffer was too small + throw "ERROR_MORE_DATA = Buffer is too small to read the value"; + break; + case ERROR_FILE_NOT_FOUND: //value was not found + throw "ERROR_FILE_NOT_FOUND = The value was not found"; + break; + default: //an error code from windows + throw "ERROR = " + lResult; + break; + } + } + + //Sets a value in the regsitry + bool VRegistry::SetValue(LPCTSTR ValueName, DWORD ValueType, LPBYTE Value,DWORD dwSize) + { + + LONG lResult; + + //Attempt to save the value + lResult = RegSetValueEx(this->mKey,ValueName,0,ValueType,Value,dwSize); + + switch(lResult) + { + case ERROR_SUCCESS: //ok + return true; + break; + default: //an error code from windows + return false; + break; + } + } + + ////////////////////////////////////////////////////////////////////////////////////// + // QT Friendly Methods + ////////////////////////////////////////////////////////////////////////////////////// + + //Opens a Registry Key + bool VRegistry::OpenKey(HKEY RootKey,QString SubKey) + { + LPCTSTR mSubKey = VQTConvert::QString_To_LPCTSTR(SubKey); + return OpenKey(RootKey,mSubKey); + } + + //Creates a registry key and opens it + bool VRegistry::CreateKey(HKEY RootKey,QString SubKey) + { + LPCTSTR mSubKey = VQTConvert::QString_To_LPCTSTR(SubKey); + return CreateKey(RootKey,mSubKey); + } + + //Deletes a registry key and all values + bool VRegistry::DeleteKey(HKEY RootKey,QString SubKey) + { + LPCTSTR mSubKey = VQTConvert::QString_To_LPCTSTR(SubKey); + return DeleteKey(RootKey,mSubKey); + } + + //Determines if the key exists + bool VRegistry::KeyExists(HKEY RootKey,QString SubKey) + { + LPCTSTR mSubKey = VQTConvert::QString_To_LPCTSTR(SubKey); + return KeyExists(RootKey,mSubKey); + } + + //Deletes a registry value and all values + bool VRegistry::DeleteValue(QString ValueName) + { + LPCTSTR mValueName = VQTConvert::QString_To_LPCTSTR(ValueName); + return DeleteValue(mValueName); + } + + //Determines if a value exists + bool VRegistry::ValueExists(QString ValueName) + { + LPCTSTR mValueName = VQTConvert::QString_To_LPCTSTR(ValueName); + return ValueExists(mValueName); + } + + //Gets REG_SZ value as a QString + QString VRegistry::get_REG_SZ(QString ValueName) + { + if (ValueExists(ValueName)) { + LPCTSTR mValueName = VQTConvert::QString_To_LPCTSTR(ValueName); + DWORD mType = REG_SZ; + BYTE* mBuffer = QueryValue(mValueName, mType); + QString mRet = VQTConvert::WCHAR_to_QString((wchar_t*)mBuffer); + delete[] mBuffer; + return mRet; + } else { + return ""; + } + } + + //Gets REG_EXPAND_SZ value as a QString + QString VRegistry::get_REG_EXPAND_SZ(QString ValueName) + { + if (ValueExists(ValueName)){ + LPCTSTR mValueName = VQTConvert::QString_To_LPCTSTR(ValueName); + DWORD mType = REG_EXPAND_SZ; + BYTE* mBuffer = QueryValue(mValueName, mType); + QString mRet = VQTConvert::WCHAR_to_QString((wchar_t*)mBuffer); + delete[] mBuffer; + return mRet; + } else + return ""; + } + + //Gets REG_DWORD value as a UINT + uint VRegistry::get_REG_DWORD(QString ValueName) + { + LPCTSTR mValueName = VQTConvert::QString_To_LPCTSTR(ValueName); + DWORD mType = REG_DWORD; + BYTE* mBuffer = QueryValue(mValueName, mType); + DWORD mVal = *(DWORD*)&mBuffer[0]; + delete[] mBuffer; + return (uint)mVal; + } + + //Gets a REG_BINARY value as a QByteArray + QByteArray VRegistry::get_REG_BINARY(QString ValueName) + { + LPCTSTR mValueName = VQTConvert::QString_To_LPCTSTR(ValueName); + DWORD mType = REG_BINARY; + BYTE* mBuffer = QueryValue(mValueName, mType); + QByteArray mArray((const char*)mBuffer); + delete[] mBuffer; + return mArray; + } + + //Gets a REG_MUTLI_SZ value as a QStringList + QStringList VRegistry::get_MULTI_SZ(QString ValueName) + { + QStringList mList; + LPCTSTR mValueName = VQTConvert::QString_To_LPCTSTR(ValueName); + DWORD mType = REG_MULTI_SZ; + BYTE* mBuffer = QueryValue(mValueName, mType); + WCHAR* mItems =(WCHAR*)mBuffer; + while(*mItems != '\0') + { + //mItems is the current string + QString mRet = VQTConvert::WCHAR_to_QString(mItems); + mList.append(mRet); + mItems = mItems + lstrlen(mItems); // pStr now points to null at end of string + mItems++; // pStr now points to the next string, or the second null to terminate + } + + delete[] mBuffer; + return mList; + } + + //Sets a REG_SZ value with a QString + bool VRegistry::set_REG_SZ(QString ValueName, QString Value) + { + LPCTSTR mValueName = VQTConvert::QString_To_LPCTSTR(ValueName); + DWORD mType = REG_SZ; + DWORD mSize = sizeof(Value.utf16()) * Value.length(); + return SetValue(mValueName,mType,(LPBYTE)Value.utf16(),mSize); + } + + //Sets a REG_EXPAND_SZ value with a QString + bool VRegistry::set_REG_EXPAND_SZ(QString ValueName, QString Value) + { + LPCTSTR mValueName = VQTConvert::QString_To_LPCTSTR(ValueName); + DWORD mType = REG_EXPAND_SZ; + DWORD mSize = sizeof(Value.utf16()) * Value.length(); + return SetValue(mValueName,mType,(LPBYTE)Value.utf16(),mSize); + } + + //Sets a REG_DWORD value with a UINT + bool VRegistry::set_REG_DWORD(QString ValueName, UINT Value) + { + LPCTSTR mValueName = VQTConvert::QString_To_LPCTSTR(ValueName); + DWORD mType = REG_DWORD; + DWORD mSize = 4; + return SetValue(mValueName,mType,(LPBYTE)&Value,mSize); + } + + //Sets a REG_BINARY value with a QByteArray + bool VRegistry::set_REG_BINARY(QString ValueName, QByteArray Value) + { + LPCTSTR mValueName = VQTConvert::QString_To_LPCTSTR(ValueName); + DWORD mType = REG_BINARY; + BYTE* mData = (BYTE*)Value.data(); + DWORD mSize = Value.length(); + return SetValue(mValueName,mType,mData,mSize); + } + + //Sets a REG_MULTI_SZ value with a QStringList + bool VRegistry::set_REG_MULTI_SZ(QString ValueName, QStringList Value) + { + LPCTSTR mValueName = VQTConvert::QString_To_LPCTSTR(ValueName); + DWORD mType = REG_MULTI_SZ; + QString mValue; + //DWORD mSize = 0; + for (int i = 0; i < Value.size(); ++i) + { + mValue += Value.at(i); + mValue += '\0'; + } + mValue += '\0'; + + DWORD mSize = (sizeof(mValue.utf16()) * mValue.length()) / 2; + + return SetValue(mValueName,mType,(LPBYTE)mValue.utf16(),mSize); + } + + //Gets a string list filled with names of the sub keys from the current open key + QStringList VRegistry::enum_Keys() + { + LONG lResult; + LONG lNumber = 0; + QStringList mList; + bool mProcess = true; + + //Enum through the items + do + { + DWORD dwSize = 255; + WCHAR* pBuffer = new WCHAR[dwSize]; + + lResult = RegEnumKeyEx(this->mKey,lNumber, pBuffer, &dwSize,NULL,NULL,NULL,NULL); + if(lResult == ERROR_SUCCESS) + { + QString mRet = VQTConvert::WCHAR_to_QString(pBuffer); + mList.append(mRet); + } + else + { + mProcess = false; + } + delete[] pBuffer; + + lNumber++; + }while(mProcess); + + return mList; + } + + //Gets a string list filled with names of the values from the current open key + QStringList VRegistry::enum_Values() + { + LONG lResult; + LONG lNumber = 0; + QStringList mList; + bool mProcess = true; + + //Enum through the items + do + { + DWORD dwSize = 16383; + WCHAR* pBuffer = new WCHAR[dwSize]; + lResult = RegEnumValue(this->mKey,lNumber, pBuffer, &dwSize,NULL,NULL,NULL,NULL); + if(lResult == ERROR_SUCCESS) + { + QString mRet = VQTConvert::WCHAR_to_QString(pBuffer); + mList.append(mRet); + } + else + { + mProcess = false; + } + delete[] pBuffer; + + lNumber++; + }while(mProcess); + + return mList; + } + + } //end voidrealms::win32 namespace +} //end voidrealms namespace diff --git a/src/vregistry.h b/src/vregistry.h new file mode 100644 index 0000000..8609aee --- /dev/null +++ b/src/vregistry.h @@ -0,0 +1,127 @@ +/* +Wrapper for the Windows Registry +Version: 1.0 +Modified on: 8-20-2009 +Created with: QT 4.5 and QT Creator 1.2 +Tested on: Windows XP SP3 +Bryan Cairns +*/ + +#ifndef VREGISTRY_H +#define VREGISTRY_H + +#include "windows.h" +#include +#include +#include + +namespace voidrealms +{ + namespace win32 + { + + class VRegistry + { + private: + HKEY mKey; //The current opened key + bool mOpen; //Boolean indicates if the registry is open + + ////////////////////////////////////////////////////////////////////////////////////// + // Windows API Methods + ////////////////////////////////////////////////////////////////////////////////////// + + //Opens a Registry Key + bool OpenKey(HKEY RootKey,LPCTSTR SubKey); + + //Creates a registry key and opens it + bool CreateKey(HKEY RootKey,LPCTSTR SubKey); + + //Deletes a registry key and all values + bool DeleteKey(HKEY RootKey,LPCTSTR SubKey); + + //Determines if the key exists + bool KeyExists(HKEY RootKey,LPCTSTR SubKey); + + //Deletes a registry value and all values + bool DeleteValue(LPCTSTR ValueName); + + //Determines if a value exists + bool ValueExists(LPCTSTR ValueName); + + //Gets a Pointer to a Byte array filled with a reg type value from an open key (be sure to delete[] mVar) + BYTE* QueryValue(LPCTSTR ValueName, DWORD ValueType); + + //Sets a value in the regsitry + bool SetValue(LPCTSTR ValueName, DWORD ValueType, BYTE* Value, DWORD dwSize); + + public: + + ////////////////////////////////////////////////////////////////////////////////////// + // QT friendly Methods + ////////////////////////////////////////////////////////////////////////////////////// + + //Returns a boolean indicating if the Registry is open + bool isOpen(); + + //Closes the Registry Key + bool CloseKey(); + + //Opens a Registry Key + bool OpenKey(HKEY RootKey,QString SubKey); + + //Creates a registry key and opens it + bool CreateKey(HKEY RootKey,QString SubKey); + + //Deletes a registry key and all values + bool DeleteKey(HKEY RootKey,QString SubKey); + + //Determines if the key exists + bool KeyExists(HKEY RootKey,QString SubKey); + + //Deletes a registry value and all values + bool DeleteValue(QString ValueName); + + //Determines if a value exists + bool ValueExists(QString ValueName); + + //Gets a REG_SZ value as a QString + QString get_REG_SZ(QString ValueName); + + //Gets a REG_EXPAND_SZ value as a QString + QString get_REG_EXPAND_SZ(QString ValueName); + + //Gets a REG_DWORD value as a UINT + uint get_REG_DWORD(QString ValueName); + + //Gets a REG_BINARY value as a QByteArray + QByteArray get_REG_BINARY(QString ValueName); + + //Gets a REG_MUTLI_SZ value as a QStringList + QStringList get_MULTI_SZ(QString ValueName); + + //Sets a REG_SZ value with a QString + bool set_REG_SZ(QString ValueName, QString Value); + + //Sets a REG_EXPAND_SZ value with a QString + bool set_REG_EXPAND_SZ(QString ValueName, QString Value); + + //Sets a REG_DWORD value with a UINT + bool set_REG_DWORD(QString ValueName, UINT Value); + + //Sets a REG_BINARY value with a QByteArray + bool set_REG_BINARY(QString ValueName, QByteArray Value); + + //Sets a REG_MULTI_SZ value with a QStringList + bool set_REG_MULTI_SZ(QString ValueName, QStringList Value); + + //Gets a string list filled with names of the sub keys from the current open key + QStringList enum_Keys(); + + //Gets a string list filled with names of the values from the current open key + QStringList enum_Values(); + + }; + + } //end voidrealms::win32 namespace +} //end voidrealms namespace +#endif // VREGISTRY_H -- libgit2 0.21.2