| 151 | |
| 152 | #if defined(Q_OS_WIN32) |
| 153 | QList<JavaInstallPtr> JavaUtils::FindJavaFromRegistryKey(DWORD keyType, QString keyName, QString keyJavaDir, QString subkeySuffix) |
| 154 | { |
| 155 | QList<JavaInstallPtr> javas; |
| 156 | |
| 157 | QString archType = "unknown"; |
| 158 | if (keyType == KEY_WOW64_64KEY) |
| 159 | archType = "64"; |
| 160 | else if (keyType == KEY_WOW64_32KEY) |
| 161 | archType = "32"; |
| 162 | |
| 163 | HKEY jreKey; |
| 164 | if (RegOpenKeyExA(HKEY_LOCAL_MACHINE, keyName.toStdString().c_str(), 0, |
| 165 | KEY_READ | keyType | KEY_ENUMERATE_SUB_KEYS, &jreKey) == ERROR_SUCCESS) |
| 166 | { |
| 167 | // Read the current type version from the registry. |
| 168 | // This will be used to find any key that contains the JavaHome value. |
| 169 | char *value = new char[0]; |
| 170 | DWORD valueSz = 0; |
| 171 | if (RegQueryValueExA(jreKey, "CurrentVersion", NULL, NULL, (BYTE *)value, &valueSz) == |
| 172 | ERROR_MORE_DATA) |
| 173 | { |
| 174 | value = new char[valueSz]; |
| 175 | RegQueryValueExA(jreKey, "CurrentVersion", NULL, NULL, (BYTE *)value, &valueSz); |
| 176 | } |
| 177 | |
| 178 | TCHAR subKeyName[255]; |
| 179 | DWORD subKeyNameSize, numSubKeys, retCode; |
| 180 | |
| 181 | // Get the number of subkeys |
| 182 | RegQueryInfoKey(jreKey, NULL, NULL, NULL, &numSubKeys, NULL, NULL, NULL, NULL, NULL, |
| 183 | NULL, NULL); |
| 184 | |
| 185 | // Iterate until RegEnumKeyEx fails |
| 186 | if (numSubKeys > 0) |
| 187 | { |
| 188 | for (DWORD i = 0; i < numSubKeys; i++) |
| 189 | { |
| 190 | subKeyNameSize = 255; |
| 191 | retCode = RegEnumKeyEx(jreKey, i, subKeyName, &subKeyNameSize, NULL, NULL, NULL, |
| 192 | NULL); |
| 193 | if (retCode == ERROR_SUCCESS) |
| 194 | { |
| 195 | // Now open the registry key for the version that we just got. |
| 196 | QString newKeyName = keyName + "\\" + subKeyName + subkeySuffix; |
| 197 | |
| 198 | HKEY newKey; |
| 199 | if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, newKeyName.toStdString().c_str(), 0, |
| 200 | KEY_READ | KEY_WOW64_64KEY, &newKey) == ERROR_SUCCESS) |
| 201 | { |
| 202 | // Read the JavaHome value to find where Java is installed. |
| 203 | value = new char[0]; |
| 204 | valueSz = 0; |
| 205 | if (RegQueryValueEx(newKey, keyJavaDir.toStdString().c_str(), NULL, NULL, (BYTE *)value, |
| 206 | &valueSz) == ERROR_MORE_DATA) |
| 207 | { |
| 208 | value = new char[valueSz]; |
| 209 | RegQueryValueEx(newKey, keyJavaDir.toStdString().c_str(), NULL, NULL, (BYTE *)value, |
| 210 | &valueSz); |
no test coverage detected