LPWSTR apxGetJavaSoftHome()

in src/native/windows/src/registry.c [764:811]


LPWSTR apxGetJavaSoftHome(APXHANDLE hPool, BOOL bPreferJre)
{
    LPWSTR  wsJhome, off;
    DWORD   err, dwLen, dwRegKey = 0;
    HKEY    hKey;
    WCHAR   wsBuf[SIZ_BUFLEN];
    WCHAR   wsKey[SIZ_RESLEN];

#if 1 /* XXX: Add that customizable using function call arg */
    if (!bPreferJre && (wsJhome = __apxGetEnvironmentVariableW(hPool, JAVA_HOME)))
        return wsJhome;
#endif

    while (JRE_REGKEYS[dwRegKey]) {
        lstrcpyW(wsKey, JAVA_CURRENT);
        if (bPreferJre)
            lstrcpyW(wsBuf, JRE_REGKEYS[dwRegKey]);
        else
            lstrcpyW(wsBuf, JDK_REGKEYS[dwRegKey]);
        dwRegKey++;
        dwLen = lstrlenW(wsBuf);
        off = &wsBuf[dwLen];
        dwLen = SIZ_RESMAX;
        if ((err = RegOpenKeyExW(HKEY_LOCAL_MACHINE, wsBuf,
                                 0, KEY_READ, &hKey)) != ERROR_SUCCESS) {
            continue;
        }
        if ((err = RegQueryValueExW(hKey, JAVA_CURRENT, NULL, NULL,
                                    (LPBYTE)off,
                                    &dwLen)) != ERROR_SUCCESS) {
            RegCloseKey(hKey);
            continue;
        }
        RegCloseKey(hKey);
        if ((err = RegOpenKeyExW(HKEY_LOCAL_MACHINE, wsBuf,
                                 0, KEY_READ, &hKey)) != ERROR_SUCCESS) {
            continue;
        }
        wsJhome = __apxGetRegistrySzW(hPool, hKey, JAVAHOME);
        if (wsJhome)
            SetEnvironmentVariableW(JAVA_HOME, wsJhome);
        RegCloseKey(hKey);

        return wsJhome;
    }

    return NULL;
}