MCPcopy Create free account
hub / github.com/PrismLauncher/PrismLauncher / FindJavaFromRegistryKey

Method FindJavaFromRegistryKey

launcher/java/JavaUtils.cpp:178–243  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

176
177#if defined(Q_OS_WIN32)
178QList<JavaInstallPtr> JavaUtils::FindJavaFromRegistryKey(DWORD keyType, QString keyName, QString keyJavaDir, QString subkeySuffix)
179{
180 QList<JavaInstallPtr> javas;
181
182 QString archType = "unknown";
183 if (keyType == KEY_WOW64_64KEY)
184 archType = "64";
185 else if (keyType == KEY_WOW64_32KEY)
186 archType = "32";
187
188 for (HKEY baseRegistry : { HKEY_CURRENT_USER, HKEY_LOCAL_MACHINE }) {
189 HKEY jreKey;
190 if (RegOpenKeyExW(baseRegistry, keyName.toStdWString().c_str(), 0, KEY_READ | keyType | KEY_ENUMERATE_SUB_KEYS, &jreKey) ==
191 ERROR_SUCCESS) {
192 // Read the current type version from the registry.
193 // This will be used to find any key that contains the JavaHome value.
194
195 WCHAR subKeyName[255];
196 DWORD subKeyNameSize, numSubKeys, retCode;
197
198 // Get the number of subkeys
199 RegQueryInfoKeyW(jreKey, NULL, NULL, NULL, &numSubKeys, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
200
201 // Iterate until RegEnumKeyEx fails
202 if (numSubKeys > 0) {
203 for (DWORD i = 0; i < numSubKeys; i++) {
204 subKeyNameSize = 255;
205 retCode = RegEnumKeyExW(jreKey, i, subKeyName, &subKeyNameSize, NULL, NULL, NULL, NULL);
206 QString newSubkeyName = QString::fromWCharArray(subKeyName);
207 if (retCode == ERROR_SUCCESS) {
208 // Now open the registry key for the version that we just got.
209 QString newKeyName = keyName + "\\" + newSubkeyName + subkeySuffix;
210
211 HKEY newKey;
212 if (RegOpenKeyExW(baseRegistry, newKeyName.toStdWString().c_str(), 0, KEY_READ | keyType, &newKey) ==
213 ERROR_SUCCESS) {
214 // Read the JavaHome value to find where Java is installed.
215 DWORD valueSz = 0;
216 if (RegQueryValueExW(newKey, keyJavaDir.toStdWString().c_str(), NULL, NULL, NULL, &valueSz) == ERROR_SUCCESS) {
217 WCHAR* value = new WCHAR[valueSz];
218 RegQueryValueExW(newKey, keyJavaDir.toStdWString().c_str(), NULL, NULL, (BYTE*)value, &valueSz);
219
220 QString newValue = QString::fromWCharArray(value);
221 delete[] value;
222
223 // Now, we construct the version object and add it to the list.
224 JavaInstallPtr javaVersion(new JavaInstall());
225
226 javaVersion->id = newSubkeyName;
227 javaVersion->arch = archType;
228 javaVersion->path = QDir(FS::PathCombine(newValue, "bin")).absoluteFilePath("javaw.exe");
229 javas.append(javaVersion);
230 }
231
232 RegCloseKey(newKey);
233 }
234 }
235 }

Callers 1

FindJavaPathsMethod · 0.95

Calls 3

PathCombineFunction · 0.85
appendMethod · 0.80
QDirClass · 0.50

Tested by

no test coverage detected