diff options
author | axis <qt-info@nokia.com> | 2010-02-23 08:22:50 (GMT) |
---|---|---|
committer | axis <qt-info@nokia.com> | 2010-02-23 08:22:50 (GMT) |
commit | ba301c2e265f3132906254b145fad394eeb4091f (patch) | |
tree | b415d85f0d0224377ffd9bd46425acc380fcaccb /qmake/generators/win32 | |
parent | 127df63bbce367e7e2d77ae9f219feb5a4a2560e (diff) | |
download | Qt-ba301c2e265f3132906254b145fad394eeb4091f.zip Qt-ba301c2e265f3132906254b145fad394eeb4091f.tar.gz Qt-ba301c2e265f3132906254b145fad394eeb4091f.tar.bz2 |
Factored readRegistryKey implementation out of qmake
This function is now implemented with its own header and source
files, rather than being embedded within the MSVC qmake generator.
The motivation for this is to allow code to be shared between
qmake and configure, both of which query the registry when built for
Windows.
Reviewed-by: Miikka Heikkinen
(cherry picked from commit 5254184c07b4da800e29000a251ed2a026bd2be5)
Conflicts:
qmake/Makefile.unix
Diffstat (limited to 'qmake/generators/win32')
-rw-r--r-- | qmake/generators/win32/msvc_vcproj.cpp | 97 |
1 files changed, 1 insertions, 96 deletions
diff --git a/qmake/generators/win32/msvc_vcproj.cpp b/qmake/generators/win32/msvc_vcproj.cpp index 3536a02..f1777e1 100644 --- a/qmake/generators/win32/msvc_vcproj.cpp +++ b/qmake/generators/win32/msvc_vcproj.cpp @@ -67,6 +67,7 @@ QT_END_NAMESPACE #ifdef Q_OS_WIN32 #include <qt_windows.h> +#include <windows/registry.h> QT_BEGIN_NAMESPACE @@ -93,102 +94,6 @@ struct { {NETUnknown, "", ""}, }; -static QString keyPath(const QString &rKey) -{ - int idx = rKey.lastIndexOf(QLatin1Char('\\')); - if (idx == -1) - return QString(); - return rKey.left(idx + 1); -} - -static QString keyName(const QString &rKey) -{ - int idx = rKey.lastIndexOf(QLatin1Char('\\')); - if (idx == -1) - return rKey; - - QString res(rKey.mid(idx + 1)); - if (res == "Default" || res == ".") - res = ""; - return res; -} - -static QString readRegistryKey(HKEY parentHandle, const QString &rSubkey) -{ - - QString rSubkeyName = keyName(rSubkey); - QString rSubkeyPath = keyPath(rSubkey); - - HKEY handle = 0; - LONG res = RegOpenKeyEx(parentHandle, (wchar_t*)rSubkeyPath.utf16(), 0, KEY_READ, &handle); - - if (res != ERROR_SUCCESS) - return QString(); - - // get the size and type of the value - DWORD dataType; - DWORD dataSize; - res = RegQueryValueEx(handle, (wchar_t*)rSubkeyName.utf16(), 0, &dataType, 0, &dataSize); - if (res != ERROR_SUCCESS) { - RegCloseKey(handle); - return QString(); - } - - // get the value - QByteArray data(dataSize, 0); - res = RegQueryValueEx(handle, (wchar_t*)rSubkeyName.utf16(), 0, 0, - reinterpret_cast<unsigned char*>(data.data()), &dataSize); - if (res != ERROR_SUCCESS) { - RegCloseKey(handle); - return QString(); - } - - QString result; - switch (dataType) { - case REG_EXPAND_SZ: - case REG_SZ: { - result = QString::fromWCharArray(((const wchar_t *)data.constData())); - break; - } - - case REG_MULTI_SZ: { - QStringList l; - int i = 0; - for (;;) { - QString s = QString::fromWCharArray((const wchar_t *)data.constData() + i); - i += s.length() + 1; - - if (s.isEmpty()) - break; - l.append(s); - } - result = l.join(", "); - break; - } - - case REG_NONE: - case REG_BINARY: { - result = QString::fromWCharArray((const wchar_t *)data.constData(), data.size() / 2); - break; - } - - case REG_DWORD_BIG_ENDIAN: - case REG_DWORD: { - Q_ASSERT(data.size() == sizeof(int)); - int i; - memcpy((char*)&i, data.constData(), sizeof(int)); - result = QString::number(i); - break; - } - - default: - qWarning("QSettings: unknown data %d type in windows registry", dataType); - break; - } - - RegCloseKey(handle); - return result; -} QT_END_NAMESPACE #endif |