Got Java download working, just need to integrate it into the program and add some safeguards to the code.
This commit is contained in:
parent
4b2cac1eff
commit
2062865e7f
@ -2,6 +2,7 @@ const cp = require('child_process')
|
|||||||
const fs = require('fs')
|
const fs = require('fs')
|
||||||
const path = require('path')
|
const path = require('path')
|
||||||
const Registry = require('winreg')
|
const Registry = require('winreg')
|
||||||
|
const request = require('request')
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Attempts to find a valid x64 installation of Java on Windows machines.
|
* Attempts to find a valid x64 installation of Java on Windows machines.
|
||||||
@ -79,6 +80,7 @@ function _validateBinary(binaryPath){
|
|||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
const fBp = path.join(binaryPath, 'bin', 'java.exe')
|
const fBp = path.join(binaryPath, 'bin', 'java.exe')
|
||||||
|
if(fs.existsSync(fBp)){
|
||||||
cp.exec('"' + fBp + '" -XshowSettings:properties', (err, stdout, stderr) => {
|
cp.exec('"' + fBp + '" -XshowSettings:properties', (err, stdout, stderr) => {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -104,6 +106,9 @@ function _validateBinary(binaryPath){
|
|||||||
resolve(true)
|
resolve(true)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
} else {
|
||||||
|
resolve(false)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -225,11 +230,44 @@ async function validate(){
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const PLATFORM_MAP = {
|
||||||
|
win32: '-windows-x64.tar.gz',
|
||||||
|
darwin: '-macosx-x64.tar.gz',
|
||||||
|
linux: '-linux-x64.tar.gz'
|
||||||
|
}
|
||||||
|
|
||||||
|
const BASE_URL = 'http://download.oracle.com/otn-pub/java/jdk/8u161-b12/2f38c3b165be4555a1fa6e98c45e0808/jre-8u161'
|
||||||
|
|
||||||
|
function _downloadJava(acceptLicense, dir){
|
||||||
|
if(!acceptLicense){
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO -> Complete this code. See format used in assetguard.js#510
|
||||||
|
|
||||||
|
const combined = BASE_URL + PLATFORM_MAP[process.platform]
|
||||||
|
const name = combined.substring(combined.lastIndexOf('/')+1)
|
||||||
|
const fDir = path.join(dir, name)
|
||||||
|
|
||||||
|
const opts = {
|
||||||
|
url: combined,
|
||||||
|
headers: {
|
||||||
|
'Cookie': 'oraclelicense=accept-securebackup-cookie'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const req = request(opts)
|
||||||
|
let writeStream = fs.createWriteStream(fDir)
|
||||||
|
req.pipe(writeStream)
|
||||||
|
req.resume()
|
||||||
|
}
|
||||||
|
|
||||||
async function test(){
|
async function test(){
|
||||||
console.log(await validate())
|
console.log(await validate())
|
||||||
}
|
}
|
||||||
|
|
||||||
test()
|
//test()
|
||||||
|
_downloadJava(true, 'C:\\Users\\Asus\\Desktop\\LauncherElectron\\target\\')
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
validate
|
validate
|
||||||
|
Loading…
Reference in New Issue
Block a user