| 195 | |
| 196 | #if defined(Q_OS_WIN32) |
| 197 | QList<JavaInstallPtr> JavaUtils::FindJavaFromRegistryKey(DWORD keyType, QString keyName, QString keyJavaDir, QString subkeySuffix) |
| 198 | { |
| 199 | QList<JavaInstallPtr> javas; |
| 200 | |
| 201 | QString archType = "unknown"; |
| 202 | if (keyType == KEY_WOW64_64KEY) |
| 203 | archType = "64"; |
| 204 | else if (keyType == KEY_WOW64_32KEY) |
| 205 | archType = "32"; |
| 206 | |
| 207 | HKEY jreKey; |
| 208 | if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, keyName.toStdWString().c_str(), 0, |
| 209 | KEY_READ | keyType | KEY_ENUMERATE_SUB_KEYS, &jreKey) == ERROR_SUCCESS) |
| 210 | { |
| 211 | // Read the current type version from the registry. |
| 212 | // This will be used to find any key that contains the JavaHome value. |
| 213 | |
| 214 | WCHAR subKeyName[255]; |
| 215 | DWORD subKeyNameSize, numSubKeys, retCode; |
| 216 | |
| 217 | // Get the number of subkeys |
| 218 | RegQueryInfoKeyW(jreKey, NULL, NULL, NULL, &numSubKeys, NULL, NULL, NULL, NULL, NULL, |
| 219 | NULL, NULL); |
| 220 | |
| 221 | // Iterate until RegEnumKeyEx fails |
| 222 | if (numSubKeys > 0) |
| 223 | { |
| 224 | for (DWORD i = 0; i < numSubKeys; i++) |
| 225 | { |
| 226 | subKeyNameSize = 255; |
| 227 | retCode = RegEnumKeyExW(jreKey, i, subKeyName, &subKeyNameSize, NULL, NULL, NULL, |
| 228 | NULL); |
| 229 | QString newSubkeyName = QString::fromWCharArray(subKeyName); |
| 230 | if (retCode == ERROR_SUCCESS) |
| 231 | { |
| 232 | // Now open the registry key for the version that we just got. |
| 233 | QString newKeyName = keyName + "\\" + newSubkeyName + subkeySuffix; |
| 234 | |
| 235 | HKEY newKey; |
| 236 | if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, newKeyName.toStdWString().c_str(), 0, |
| 237 | KEY_READ | KEY_WOW64_64KEY, &newKey) == ERROR_SUCCESS) |
| 238 | { |
| 239 | // Read the JavaHome value to find where Java is installed. |
| 240 | DWORD valueSz = 0; |
| 241 | if (RegQueryValueExW(newKey, keyJavaDir.toStdWString().c_str(), NULL, NULL, NULL, |
| 242 | &valueSz) == ERROR_SUCCESS) |
| 243 | { |
| 244 | WCHAR *value = new WCHAR[valueSz]; |
| 245 | RegQueryValueExW(newKey, keyJavaDir.toStdWString().c_str(), NULL, NULL, (BYTE *)value, |
| 246 | &valueSz); |
| 247 | |
| 248 | QString newValue = QString::fromWCharArray(value); |
| 249 | delete [] value; |
| 250 | |
| 251 | // Now, we construct the version object and add it to the list. |
| 252 | JavaInstallPtr javaVersion(new JavaInstall()); |
| 253 | |
| 254 | javaVersion->id = newSubkeyName; |
no test coverage detected