Changeset 769 for trunk/tools/configure/environment.cpp
- Timestamp:
- Aug 2, 2010, 9:27:30 PM (15 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
- Property svn:mergeinfo changed
/branches/vendor/nokia/qt/4.6.3 (added) merged: 768 /branches/vendor/nokia/qt/current merged: 767 /branches/vendor/nokia/qt/4.6.2 removed
- Property svn:mergeinfo changed
-
trunk/tools/configure/environment.cpp
r651 r769 61 61 #endif 62 62 63 #include <symbian/epocroot.h> // from tools/shared 64 #include <windows/registry.h> // from tools/shared 63 65 64 66 QT_BEGIN_NAMESPACE … … 95 97 ++i; 96 98 return &(compiler_info[i]); 97 }98 99 /*!100 Returns the path part of a registry key.101 Ei.102 For a key103 "Software\\Microsoft\\VisualStudio\\8.0\\Setup\\VC\\ProductDir"104 it returns105 "Software\\Microsoft\\VisualStudio\\8.0\\Setup\\VC\\"106 */107 QString Environment::keyPath(const QString &rKey)108 {109 int idx = rKey.lastIndexOf(QLatin1Char('\\'));110 if (idx == -1)111 return QString();112 return rKey.left(idx + 1);113 }114 115 /*!116 Returns the name part of a registry key.117 Ei.118 For a key119 "Software\\Microsoft\\VisualStudio\\8.0\\Setup\\VC\\ProductDir"120 it returns121 "ProductDir"122 */123 QString Environment::keyName(const QString &rKey)124 {125 int idx = rKey.lastIndexOf(QLatin1Char('\\'));126 if (idx == -1)127 return rKey;128 129 QString res(rKey.mid(idx + 1));130 if (res == "Default" || res == ".")131 res = "";132 return res;133 }134 135 /*!136 Returns a registry keys value in string form.137 If the registry key does not exist, or cannot be accessed, a138 QString() is returned.139 */140 QString Environment::readRegistryKey(HKEY parentHandle, const QString &rSubkey)141 {142 #ifndef Q_OS_WIN32143 return QString();144 #else145 QString rSubkeyName = keyName(rSubkey);146 QString rSubkeyPath = keyPath(rSubkey);147 148 HKEY handle = 0;149 LONG res = RegOpenKeyEx(parentHandle, (wchar_t*)rSubkeyPath.utf16(), 0, KEY_READ, &handle);150 if (res != ERROR_SUCCESS)151 return QString();152 153 // get the size and type of the value154 DWORD dataType;155 DWORD dataSize;156 res = RegQueryValueEx(handle, (wchar_t*)rSubkeyName.utf16(), 0, &dataType, 0, &dataSize);157 if (res != ERROR_SUCCESS) {158 RegCloseKey(handle);159 return QString();160 }161 162 // get the value163 QByteArray data(dataSize, 0);164 res = RegQueryValueEx(handle, (wchar_t*)rSubkeyName.utf16(), 0, 0,165 reinterpret_cast<unsigned char*>(data.data()), &dataSize);166 if (res != ERROR_SUCCESS) {167 RegCloseKey(handle);168 return QString();169 }170 171 QString result;172 switch (dataType) {173 case REG_EXPAND_SZ:174 case REG_SZ: {175 result = QString::fromWCharArray(((const wchar_t *)data.constData()));176 break;177 }178 179 case REG_MULTI_SZ: {180 QStringList l;181 int i = 0;182 for (;;) {183 QString s = QString::fromWCharArray((const wchar_t *)data.constData() + i);184 i += s.length() + 1;185 186 if (s.isEmpty())187 break;188 l.append(s);189 }190 result = l.join(", ");191 break;192 }193 194 case REG_NONE:195 case REG_BINARY: {196 result = QString::fromWCharArray((const wchar_t *)data.constData(), data.size() / 2);197 break;198 }199 200 case REG_DWORD_BIG_ENDIAN:201 case REG_DWORD: {202 Q_ASSERT(data.size() == sizeof(int));203 int i;204 memcpy((char*)&i, data.constData(), sizeof(int));205 result = QString::number(i);206 break;207 }208 209 default:210 qWarning("QSettings: unknown data %d type in windows registry", dataType);211 break;212 }213 214 RegCloseKey(handle);215 return result;216 #endif217 99 } 218 100 … … 580 462 } 581 463 464 QString Environment::symbianEpocRoot() 465 { 466 // Call function defined in tools/shared/symbian/epocroot.h 467 return ::epocRoot(); 468 } 469 582 470 QT_END_NAMESPACE
Note:
See TracChangeset
for help on using the changeset viewer.