void trySetCompatibleJava()

in src/main/cpp/launcher/windows/src/Launcher.c [213:284]


void trySetCompatibleJava(WCHAR * location, LauncherProperties * props) {
    if(isTerminated(props)) return;
    if(location!=NULL) {
        JavaProperties * javaProps = NULL;
        
        if(inList(props->alreadyCheckedJava, location)) {
            writeMessageA(props, OUTPUT_LEVEL_NORMAL, 0, "... already checked location ", 0);
            writeMessageW(props, OUTPUT_LEVEL_NORMAL, 0, location, 1);
            // return here and don`t proceed with private jre checking since it`s already checked as well
            return;
        } else {
            props->alreadyCheckedJava = addStringToList(props->alreadyCheckedJava, location);
        }
        
        getJavaProperties(location, props, &javaProps);
        
        if(isOK(props)) {
            writeMessageA(props, OUTPUT_LEVEL_NORMAL, 0, "... some java at ", 0);
            writeMessageW(props, OUTPUT_LEVEL_NORMAL, 0, location, 1);
            // some java there, check compatibility
            writeMessageA(props, OUTPUT_LEVEL_NORMAL, 0, "... checking compatibility of java : ", 0);
            writeMessageW(props, OUTPUT_LEVEL_NORMAL, 0, javaProps->javaHome, 1);
            if(isJavaCompatible(javaProps, props->compatibleJava, props->compatibleJavaNumber)) {
                writeMessageA(props, OUTPUT_LEVEL_NORMAL, 0, "... compatible", 1);
                props->java = javaProps;
            } else {
                props->status = ERROR_JVM_UNCOMPATIBLE;
                writeMessageA(props, OUTPUT_LEVEL_NORMAL, 0, "... uncompatible", 1);
                freeJavaProperties(&javaProps);
            }
        } else {
            writeMessageA(props, OUTPUT_LEVEL_NORMAL, 0, "... no java at ", 0);
            writeMessageW(props, OUTPUT_LEVEL_NORMAL, 0, location, 1);
            if (props->status==ERROR_INPUTOUPUT) {
                props->status = ERROR_JVM_NOT_FOUND;
            }
        }
        
        if(props->status == ERROR_JVM_NOT_FOUND) { // check private JRE
            //DWORD privateJreStatus = props->status;
            WCHAR * privateJre = appendStringW(NULL, location);
            privateJre = appendStringW(privateJre, L"\\jre");
            writeMessageA(props, OUTPUT_LEVEL_NORMAL, 0, "... check private jre at ", 0);
            writeMessageW(props, OUTPUT_LEVEL_NORMAL, 0, privateJre, 1);
            
            if(inList(props->alreadyCheckedJava, privateJre)) {
                writeMessageA(props, OUTPUT_LEVEL_NORMAL, 0, "... already checked location ", 0);
                writeMessageW(props, OUTPUT_LEVEL_NORMAL, 0, privateJre, 1);
            } else {
                props->alreadyCheckedJava = addStringToList(props->alreadyCheckedJava, privateJre);
                
                getJavaProperties(privateJre, props, &javaProps);
                if(isOK(props)) {
                    writeMessageA(props, OUTPUT_LEVEL_NORMAL, 0, "... checking compatibility of private jre : ", 0);
                    writeMessageW(props, OUTPUT_LEVEL_NORMAL, 0, javaProps->javaHome, 1);
                    if(isJavaCompatible(javaProps, props->compatibleJava, props->compatibleJavaNumber)) {
                        props->java = javaProps;
                        props->status = ERROR_OK;
                    } else {
                        freeJavaProperties(&javaProps);
                        props->status = ERROR_JVM_UNCOMPATIBLE;
                    }
                } else if (props->status==ERROR_INPUTOUPUT) {
                    props->status = ERROR_JVM_NOT_FOUND;
                }
            }
            FREE(privateJre);
        }
    } else {
        props->status = ERROR_JVM_NOT_FOUND;
    }
}