From ea34fbde76a0407dc4a9bb9f4a3140c4764ca6ba Mon Sep 17 00:00:00 2001 From: Gareth Stockwell Date: Wed, 10 Feb 2010 15:16:20 +0000 Subject: Removed duplicated implementation of readRegistryKeys from configure Configure now shares - at the source level - a single implementation of this function with qmake. Reviewed-by: Miikka Heikkinen --- tools/configure/configure.pro | 7 ++- tools/configure/environment.cpp | 121 +--------------------------------------- tools/configure/environment.h | 3 - 3 files changed, 6 insertions(+), 125 deletions(-) diff --git a/tools/configure/configure.pro b/tools/configure/configure.pro index 243183c..ca2ba84 100644 --- a/tools/configure/configure.pro +++ b/tools/configure/configure.pro @@ -27,6 +27,7 @@ INCPATH += $$QT_SOURCE_TREE/src/corelib/arch/generic \ $$QT_SOURCE_TREE/src/corelib/global \ $$QT_BUILD_TREE/include \ $$QT_BUILD_TREE/include/QtCore \ + $$QT_BUILD_TREE/tools/shared HEADERS = configureapp.h environment.h tools.h\ $$QT_SOURCE_TREE/src/corelib/tools/qbytearray.h \ @@ -58,7 +59,8 @@ HEADERS = configureapp.h environment.h tools.h\ $$QT_SOURCE_TREE/src/corelib/tools/qstring.h \ $$QT_SOURCE_TREE/src/corelib/tools/qstringlist.h \ $$QT_SOURCE_TREE/src/corelib/tools/qstringmatcher.h \ - $$QT_SOURCE_TREE/src/corelib/tools/qunicodetables_p.h + $$QT_SOURCE_TREE/src/corelib/tools/qunicodetables_p.h \ + $$QT_SOURCE_TREE/tools/shared/windows/registry.h SOURCES = main.cpp configureapp.cpp environment.cpp tools.cpp \ @@ -102,7 +104,8 @@ SOURCES = main.cpp configureapp.cpp environment.cpp tools.cpp \ $$QT_SOURCE_TREE/src/corelib/tools/qpoint.cpp \ $$QT_SOURCE_TREE/src/corelib/tools/qrect.cpp \ $$QT_SOURCE_TREE/src/corelib/kernel/qmetatype.cpp \ - $$QT_SOURCE_TREE/src/corelib/global/qmalloc.cpp + $$QT_SOURCE_TREE/src/corelib/global/qmalloc.cpp \ + $$QT_SOURCE_TREE/tools/shared/windows/registry.cpp win32:SOURCES += $$QT_SOURCE_TREE/src/corelib/io/qfsfileengine_win.cpp diff --git a/tools/configure/environment.cpp b/tools/configure/environment.cpp index af6f9e5..da86f5d 100644 --- a/tools/configure/environment.cpp +++ b/tools/configure/environment.cpp @@ -60,6 +60,7 @@ using namespace std; #include #endif +#include // from tools/shared QT_BEGIN_NAMESPACE @@ -97,126 +98,6 @@ CompilerInfo *Environment::compilerInfo(Compiler compiler) } /*! - Returns the path part of a registry key. - Ei. - For a key - "Software\\Microsoft\\VisualStudio\\8.0\\Setup\\VC\\ProductDir" - it returns - "Software\\Microsoft\\VisualStudio\\8.0\\Setup\\VC\\" -*/ -QString Environment::keyPath(const QString &rKey) -{ - int idx = rKey.lastIndexOf(QLatin1Char('\\')); - if (idx == -1) - return QString(); - return rKey.left(idx + 1); -} - -/*! - Returns the name part of a registry key. - Ei. - For a key - "Software\\Microsoft\\VisualStudio\\8.0\\Setup\\VC\\ProductDir" - it returns - "ProductDir" -*/ -QString Environment::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; -} - -/*! - Returns a registry keys value in string form. - If the registry key does not exist, or cannot be accessed, a - QString() is returned. -*/ -QString Environment::readRegistryKey(HKEY parentHandle, const QString &rSubkey) -{ -#ifndef Q_OS_WIN32 - return QString(); -#else - 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(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; -#endif -} - -/*! Returns the qmakespec for the compiler detected on the system. */ QString Environment::detectQMakeSpec() diff --git a/tools/configure/environment.h b/tools/configure/environment.h index 2d0eafd..549dcfa 100644 --- a/tools/configure/environment.h +++ b/tools/configure/environment.h @@ -75,9 +75,6 @@ private: static Compiler detectedCompiler; static CompilerInfo *compilerInfo(Compiler compiler); - static QString keyPath(const QString &rKey); - static QString keyName(const QString &rKey); - static QString readRegistryKey(HKEY parentHandle, const QString &rSubkey); }; -- cgit v0.12