mirror of
https://github.com/dscalzi/HeliosLauncher.git
synced 2024-12-22 11:42:14 -08:00
Completed Java validation for windows.
Possible paths are pulled from the registry and JAVA_HOME. These are sorted by version and whether they point to a JRE or JDK. Each path will be validated using an experimental option which yields the arch of the binary. The first one to be validated will be selected and returned.
This commit is contained in:
parent
4fd202d180
commit
4b2cac1eff
@ -4,7 +4,17 @@ const path = require('path')
|
|||||||
const Registry = require('winreg')
|
const Registry = require('winreg')
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* WIP -> get a valid x64 Java path on windows.
|
* Attempts to find a valid x64 installation of Java on Windows machines.
|
||||||
|
* Possible paths will be pulled from the registry and the JAVA_HOME environment
|
||||||
|
* variable. The paths will be sorted with higher versions preceeding lower, and
|
||||||
|
* JREs preceeding JDKs. The binaries at the sorted paths will then be validated.
|
||||||
|
* The first validated is returned.
|
||||||
|
*
|
||||||
|
* Higher versions > Lower versions
|
||||||
|
* If versions are equal, JRE > JDK.
|
||||||
|
*
|
||||||
|
* @returns {string} The root path of a valid x64 Java installation. If none are
|
||||||
|
* found, null is returned.
|
||||||
*/
|
*/
|
||||||
async function _win32Validate(){
|
async function _win32Validate(){
|
||||||
|
|
||||||
@ -20,16 +30,35 @@ async function _win32Validate(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Convert path set to an array for processing.
|
// Convert path set to an array for processing.
|
||||||
const pathArr = Array.from(pathSet)
|
let pathArr = Array.from(pathSet)
|
||||||
|
|
||||||
console.log(pathArr) // DEBUGGING
|
console.log(pathArr) // DEBUGGING
|
||||||
|
|
||||||
// TODO - Determine best candidate (based on version, etc).
|
// Sorts array. Higher version numbers preceed lower. JRE preceeds JDK.
|
||||||
|
pathArr = pathArr.sort((a, b) => {
|
||||||
|
// Note that Java 9+ uses semver and that will need to be accounted for in
|
||||||
|
// the future.
|
||||||
|
const aVer = parseInt(a.split('_')[1])
|
||||||
|
const bVer = parseInt(b.split('_')[1])
|
||||||
|
if(bVer === aVer){
|
||||||
|
return a.indexOf('jdk') > -1 ? 1 : 0
|
||||||
|
} else {
|
||||||
|
return bVer - aVer
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
console.log(pathArr) // DEBUGGING
|
||||||
|
|
||||||
|
// Validate that the binary is actually x64.
|
||||||
|
for(let i=0; i<pathArr.length; i++) {
|
||||||
|
let res = await _validateBinary(pathArr[i])
|
||||||
|
if(res){
|
||||||
|
return pathArr[i]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let res = await _validateBinary(pathArr[0]) // DEBUGGING
|
// No suitable candidates found.
|
||||||
console.log(res) // DEBUGGING
|
return null;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -168,29 +197,39 @@ function _scanRegistry(){
|
|||||||
* WIP -> get a valid x64 Java path on macOS.
|
* WIP -> get a valid x64 Java path on macOS.
|
||||||
*/
|
*/
|
||||||
function _darwinValidate(){
|
function _darwinValidate(){
|
||||||
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* WIP -> get a valid x64 Java path on linux.
|
* WIP -> get a valid x64 Java path on linux.
|
||||||
*/
|
*/
|
||||||
function _linuxValidate(){
|
function _linuxValidate(){
|
||||||
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
// This will eventually return something.
|
// This will eventually return something.
|
||||||
async function validate(){
|
async function validate(){
|
||||||
|
|
||||||
|
let res = null
|
||||||
|
|
||||||
const opSys = process.platform
|
const opSys = process.platform
|
||||||
if(opSys === 'win32'){
|
if(opSys === 'win32'){
|
||||||
await _win32Validate()
|
res = await _win32Validate()
|
||||||
} else if(opSys === 'darwin'){
|
} else if(opSys === 'darwin'){
|
||||||
_darwinValidate()
|
res = _darwinValidate()
|
||||||
} else if(opSys === 'linux'){
|
} else if(opSys === 'linux'){
|
||||||
_linuxValidate()
|
res = _linuxValidate()
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
validate()
|
return res;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
async function test(){
|
||||||
|
console.log(await validate())
|
||||||
|
}
|
||||||
|
|
||||||
|
test()
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
validate
|
validate
|
||||||
|
Loading…
Reference in New Issue
Block a user