1 /**************************************************************************** |
1 /**************************************************************************** |
2 ** |
2 ** |
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
4 ** All rights reserved. |
4 ** All rights reserved. |
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
6 ** |
6 ** |
7 ** This file is part of the qmake application of the Qt Toolkit. |
7 ** This file is part of the qmake application of the Qt Toolkit. |
8 ** |
8 ** |
91 {NET2002, "MSVC.NET 2002 (7.0)", "Software\\Microsoft\\VisualStudio\\7.0\\Setup\\VC\\ProductDir"}, |
92 {NET2002, "MSVC.NET 2002 (7.0)", "Software\\Microsoft\\VisualStudio\\7.0\\Setup\\VC\\ProductDir"}, |
92 #endif |
93 #endif |
93 {NETUnknown, "", ""}, |
94 {NETUnknown, "", ""}, |
94 }; |
95 }; |
95 |
96 |
96 static QString keyPath(const QString &rKey) |
|
97 { |
|
98 int idx = rKey.lastIndexOf(QLatin1Char('\\')); |
|
99 if (idx == -1) |
|
100 return QString(); |
|
101 return rKey.left(idx + 1); |
|
102 } |
|
103 |
|
104 static QString keyName(const QString &rKey) |
|
105 { |
|
106 int idx = rKey.lastIndexOf(QLatin1Char('\\')); |
|
107 if (idx == -1) |
|
108 return rKey; |
|
109 |
|
110 QString res(rKey.mid(idx + 1)); |
|
111 if (res == "Default" || res == ".") |
|
112 res = ""; |
|
113 return res; |
|
114 } |
|
115 |
|
116 static QString readRegistryKey(HKEY parentHandle, const QString &rSubkey) |
|
117 { |
|
118 |
|
119 QString rSubkeyName = keyName(rSubkey); |
|
120 QString rSubkeyPath = keyPath(rSubkey); |
|
121 |
|
122 HKEY handle = 0; |
|
123 LONG res = RegOpenKeyEx(parentHandle, (wchar_t*)rSubkeyPath.utf16(), 0, KEY_READ, &handle); |
|
124 |
|
125 if (res != ERROR_SUCCESS) |
|
126 return QString(); |
|
127 |
|
128 // get the size and type of the value |
|
129 DWORD dataType; |
|
130 DWORD dataSize; |
|
131 res = RegQueryValueEx(handle, (wchar_t*)rSubkeyName.utf16(), 0, &dataType, 0, &dataSize); |
|
132 if (res != ERROR_SUCCESS) { |
|
133 RegCloseKey(handle); |
|
134 return QString(); |
|
135 } |
|
136 |
|
137 // get the value |
|
138 QByteArray data(dataSize, 0); |
|
139 res = RegQueryValueEx(handle, (wchar_t*)rSubkeyName.utf16(), 0, 0, |
|
140 reinterpret_cast<unsigned char*>(data.data()), &dataSize); |
|
141 if (res != ERROR_SUCCESS) { |
|
142 RegCloseKey(handle); |
|
143 return QString(); |
|
144 } |
|
145 |
|
146 QString result; |
|
147 switch (dataType) { |
|
148 case REG_EXPAND_SZ: |
|
149 case REG_SZ: { |
|
150 result = QString::fromWCharArray(((const wchar_t *)data.constData())); |
|
151 break; |
|
152 } |
|
153 |
|
154 case REG_MULTI_SZ: { |
|
155 QStringList l; |
|
156 int i = 0; |
|
157 for (;;) { |
|
158 QString s = QString::fromWCharArray((const wchar_t *)data.constData() + i); |
|
159 i += s.length() + 1; |
|
160 |
|
161 if (s.isEmpty()) |
|
162 break; |
|
163 l.append(s); |
|
164 } |
|
165 result = l.join(", "); |
|
166 break; |
|
167 } |
|
168 |
|
169 case REG_NONE: |
|
170 case REG_BINARY: { |
|
171 result = QString::fromWCharArray((const wchar_t *)data.constData(), data.size() / 2); |
|
172 break; |
|
173 } |
|
174 |
|
175 case REG_DWORD_BIG_ENDIAN: |
|
176 case REG_DWORD: { |
|
177 Q_ASSERT(data.size() == sizeof(int)); |
|
178 int i; |
|
179 memcpy((char*)&i, data.constData(), sizeof(int)); |
|
180 result = QString::number(i); |
|
181 break; |
|
182 } |
|
183 |
|
184 default: |
|
185 qWarning("QSettings: unknown data %d type in windows registry", dataType); |
|
186 break; |
|
187 } |
|
188 |
|
189 RegCloseKey(handle); |
|
190 return result; |
|
191 } |
|
192 QT_END_NAMESPACE |
97 QT_END_NAMESPACE |
193 #endif |
98 #endif |
194 |
99 |
195 QT_BEGIN_NAMESPACE |
100 QT_BEGIN_NAMESPACE |
196 DotNET which_dotnet_version() |
101 DotNET which_dotnet_version() |