MCPcopy Create free account
hub / github.com/FreesmTeam/FreesmLauncher / FindJavaFromRegistryKey

Method FindJavaFromRegistryKey

launcher/java/JavaUtils.cpp:177–242  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers 1

FindJavaPathsMethod · 0.95

Calls 3

PathCombineFunction · 0.85
appendMethod · 0.80
QDirClass · 0.50

Tested by

no test coverage detected