|
|
@@ -16,11 +16,11 @@ const DistroManager = require('./distromanager')
|
|
|
const isDev = require('./isdev')
|
|
|
|
|
|
// Constants
|
|
|
-const PLATFORM_MAP = {
|
|
|
- win32: '-windows-x64.tar.gz',
|
|
|
- darwin: '-macosx-x64.tar.gz',
|
|
|
- linux: '-linux-x64.tar.gz'
|
|
|
-}
|
|
|
+// const PLATFORM_MAP = {
|
|
|
+// win32: '-windows-x64.tar.gz',
|
|
|
+// darwin: '-macosx-x64.tar.gz',
|
|
|
+// linux: '-linux-x64.tar.gz'
|
|
|
+// }
|
|
|
|
|
|
// Classes
|
|
|
|
|
|
@@ -176,34 +176,69 @@ class JavaGuard extends EventEmitter {
|
|
|
this.mcVersion = mcVersion
|
|
|
}
|
|
|
|
|
|
+ // /**
|
|
|
+ // * @typedef OracleJREData
|
|
|
+ // * @property {string} uri The base uri of the JRE.
|
|
|
+ // * @property {{major: string, update: string, build: string}} version Object containing version information.
|
|
|
+ // */
|
|
|
+
|
|
|
+ // /**
|
|
|
+ // * Resolves the latest version of Oracle's JRE and parses its download link.
|
|
|
+ // *
|
|
|
+ // * @returns {Promise.<OracleJREData>} Promise which resolved to an object containing the JRE download data.
|
|
|
+ // */
|
|
|
+ // static _latestJREOracle(){
|
|
|
+
|
|
|
+ // const url = 'https://www.oracle.com/technetwork/java/javase/downloads/jre8-downloads-2133155.html'
|
|
|
+ // const regex = /https:\/\/.+?(?=\/java)\/java\/jdk\/([0-9]+u[0-9]+)-(b[0-9]+)\/([a-f0-9]{32})?\/jre-\1/
|
|
|
+
|
|
|
+ // return new Promise((resolve, reject) => {
|
|
|
+ // request(url, (err, resp, body) => {
|
|
|
+ // if(!err){
|
|
|
+ // const arr = body.match(regex)
|
|
|
+ // const verSplit = arr[1].split('u')
|
|
|
+ // resolve({
|
|
|
+ // uri: arr[0],
|
|
|
+ // version: {
|
|
|
+ // major: verSplit[0],
|
|
|
+ // update: verSplit[1],
|
|
|
+ // build: arr[2]
|
|
|
+ // }
|
|
|
+ // })
|
|
|
+ // } else {
|
|
|
+ // resolve(null)
|
|
|
+ // }
|
|
|
+ // })
|
|
|
+ // })
|
|
|
+ // }
|
|
|
+
|
|
|
/**
|
|
|
- * @typedef OracleJREData
|
|
|
+ * @typedef OpenJDKData
|
|
|
* @property {string} uri The base uri of the JRE.
|
|
|
- * @property {{major: string, update: string, build: string}} version Object containing version information.
|
|
|
+ * @property {number} size The size of the download.
|
|
|
+ * @property {string} name The name of the artifact.
|
|
|
*/
|
|
|
|
|
|
/**
|
|
|
- * Resolves the latest version of Oracle's JRE and parses its download link.
|
|
|
+ * Fetch the last open JDK binary. Uses https://api.adoptopenjdk.net/
|
|
|
*
|
|
|
- * @returns {Promise.<OracleJREData>} Promise which resolved to an object containing the JRE download data.
|
|
|
+ * @param {string} major The major version of Java to fetch.
|
|
|
+ *
|
|
|
+ * @returns {Promise.<OpenJDKData>} Promise which resolved to an object containing the JRE download data.
|
|
|
*/
|
|
|
- static _latestJREOracle(){
|
|
|
+ static _latestOpenJDK(major = '8'){
|
|
|
|
|
|
- const url = 'https://www.oracle.com/technetwork/java/javase/downloads/jre8-downloads-2133155.html'
|
|
|
- const regex = /https:\/\/.+?(?=\/java)\/java\/jdk\/([0-9]+u[0-9]+)-(b[0-9]+)\/([a-f0-9]{32})?\/jre-\1/
|
|
|
-
|
|
|
+ const sanitizedOS = process.platform === 'win32' ? 'windows' : (process.platform === 'darwin' ? 'mac' : process.platform)
|
|
|
+
|
|
|
+ const url = `https://api.adoptopenjdk.net/v2/latestAssets/nightly/openjdk${major}?os=${sanitizedOS}&arch=x64&heap_size=normal&openjdk_impl=hotspot&type=jre`
|
|
|
+
|
|
|
return new Promise((resolve, reject) => {
|
|
|
- request(url, (err, resp, body) => {
|
|
|
- if(!err){
|
|
|
- const arr = body.match(regex)
|
|
|
- const verSplit = arr[1].split('u')
|
|
|
+ request({url, json: true}, (err, resp, body) => {
|
|
|
+ if(!err && body.length > 0){
|
|
|
resolve({
|
|
|
- uri: arr[0],
|
|
|
- version: {
|
|
|
- major: verSplit[0],
|
|
|
- update: verSplit[1],
|
|
|
- build: arr[2]
|
|
|
- }
|
|
|
+ uri: body[0].binary_link,
|
|
|
+ size: body[0].binary_size,
|
|
|
+ name: body[0].binary_name
|
|
|
})
|
|
|
} else {
|
|
|
resolve(null)
|
|
|
@@ -401,6 +436,11 @@ class JavaGuard extends EventEmitter {
|
|
|
if(!JavaGuard.isJavaExecPath(binaryExecPath)){
|
|
|
resolve({valid: false})
|
|
|
} else if(fs.existsSync(binaryExecPath)){
|
|
|
+ // Workaround (javaw.exe no longer outputs this information.)
|
|
|
+ console.log(typeof binaryExecPath)
|
|
|
+ if(binaryExecPath.indexOf('javaw.exe') > -1) {
|
|
|
+ binaryExecPath.replace('javaw.exe', 'java.exe')
|
|
|
+ }
|
|
|
child_process.exec('"' + binaryExecPath + '" -XshowSettings:properties', (err, stdout, stderr) => {
|
|
|
try {
|
|
|
// Output is stored in stderr?
|
|
|
@@ -1447,59 +1487,63 @@ class AssetGuard extends EventEmitter {
|
|
|
// Java (Category=''') Validation (download) Functions
|
|
|
// #region
|
|
|
|
|
|
- _enqueueOracleJRE(dataDir){
|
|
|
+ _enqueueOpenJDK(dataDir){
|
|
|
return new Promise((resolve, reject) => {
|
|
|
- AssetGuard._latestJREOracle().then(verData => {
|
|
|
+ JavaGuard._latestOpenJDK('8').then(verData => {
|
|
|
if(verData != null){
|
|
|
|
|
|
- const combined = verData.uri + PLATFORM_MAP[process.platform]
|
|
|
-
|
|
|
- const opts = {
|
|
|
- url: combined,
|
|
|
- headers: {
|
|
|
- 'Cookie': 'oraclelicense=accept-securebackup-cookie'
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- request.head(opts, (err, resp, body) => {
|
|
|
- if(err){
|
|
|
- resolve(false)
|
|
|
- } else {
|
|
|
- dataDir = path.join(dataDir, 'runtime', 'x64')
|
|
|
- const name = combined.substring(combined.lastIndexOf('/')+1)
|
|
|
- const fDir = path.join(dataDir, name)
|
|
|
- const jre = new Asset(name, null, parseInt(resp.headers['content-length']), opts, fDir)
|
|
|
- this.java = new DLTracker([jre], jre.size, (a, self) => {
|
|
|
- let h = null
|
|
|
- fs.createReadStream(a.to)
|
|
|
- .on('error', err => console.log(err))
|
|
|
- .pipe(zlib.createGunzip())
|
|
|
- .on('error', err => console.log(err))
|
|
|
- .pipe(tar.extract(dataDir, {
|
|
|
- map: (header) => {
|
|
|
- if(h == null){
|
|
|
- h = header.name
|
|
|
- }
|
|
|
+ dataDir = path.join(dataDir, 'runtime', 'x64')
|
|
|
+ const fDir = path.join(dataDir, verData.name)
|
|
|
+ const jre = new Asset(verData.name, null, verData.size, verData.uri, fDir)
|
|
|
+ this.java = new DLTracker([jre], jre.size, (a, self) => {
|
|
|
+ if(verData.name.endsWith('zip')){
|
|
|
+
|
|
|
+ const zip = new AdmZip(a.to)
|
|
|
+ const pos = path.join(dataDir, zip.getEntries()[0].entryName)
|
|
|
+ zip.extractAllToAsync(dataDir, true, (err) => {
|
|
|
+ if(err){
|
|
|
+ console.log(err)
|
|
|
+ self.emit('complete', 'java', JavaGuard.javaExecFromRoot(pos))
|
|
|
+ } else {
|
|
|
+ fs.unlink(a.to, err => {
|
|
|
+ if(err){
|
|
|
+ console.log(err)
|
|
|
}
|
|
|
- }))
|
|
|
- .on('error', err => console.log(err))
|
|
|
- .on('finish', () => {
|
|
|
- fs.unlink(a.to, err => {
|
|
|
- if(err){
|
|
|
- console.log(err)
|
|
|
- }
|
|
|
- if(h.indexOf('/') > -1){
|
|
|
- h = h.substring(0, h.indexOf('/'))
|
|
|
- }
|
|
|
- const pos = path.join(dataDir, h)
|
|
|
- self.emit('complete', 'java', AssetGuard.javaExecFromRoot(pos))
|
|
|
- })
|
|
|
+ self.emit('complete', 'java', JavaGuard.javaExecFromRoot(pos))
|
|
|
})
|
|
|
-
|
|
|
+ }
|
|
|
})
|
|
|
- resolve(true)
|
|
|
+
|
|
|
+ } else {
|
|
|
+ // Tar.gz
|
|
|
+ let h = null
|
|
|
+ fs.createReadStream(a.to)
|
|
|
+ .on('error', err => console.log(err))
|
|
|
+ .pipe(zlib.createGunzip())
|
|
|
+ .on('error', err => console.log(err))
|
|
|
+ .pipe(tar.extract(dataDir, {
|
|
|
+ map: (header) => {
|
|
|
+ if(h == null){
|
|
|
+ h = header.name
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }))
|
|
|
+ .on('error', err => console.log(err))
|
|
|
+ .on('finish', () => {
|
|
|
+ fs.unlink(a.to, err => {
|
|
|
+ if(err){
|
|
|
+ console.log(err)
|
|
|
+ }
|
|
|
+ if(h.indexOf('/') > -1){
|
|
|
+ h = h.substring(0, h.indexOf('/'))
|
|
|
+ }
|
|
|
+ const pos = path.join(dataDir, h)
|
|
|
+ self.emit('complete', 'java', JavaGuard.javaExecFromRoot(pos))
|
|
|
+ })
|
|
|
+ })
|
|
|
}
|
|
|
})
|
|
|
+ resolve(true)
|
|
|
|
|
|
} else {
|
|
|
resolve(false)
|
|
|
@@ -1509,42 +1553,104 @@ class AssetGuard extends EventEmitter {
|
|
|
|
|
|
}
|
|
|
|
|
|
- /*_enqueueMojangJRE(dir){
|
|
|
- return new Promise((resolve, reject) => {
|
|
|
- // Mojang does not host the JRE for linux.
|
|
|
- if(process.platform === 'linux'){
|
|
|
- resolve(false)
|
|
|
- }
|
|
|
- AssetGuard.loadMojangLauncherData().then(data => {
|
|
|
- if(data != null) {
|
|
|
-
|
|
|
- try {
|
|
|
- const mJRE = data[Library.mojangFriendlyOS()]['64'].jre
|
|
|
- const url = mJRE.url
|
|
|
-
|
|
|
- request.head(url, (err, resp, body) => {
|
|
|
- if(err){
|
|
|
- resolve(false)
|
|
|
- } else {
|
|
|
- const name = url.substring(url.lastIndexOf('/')+1)
|
|
|
- const fDir = path.join(dir, name)
|
|
|
- const jre = new Asset('jre' + mJRE.version, mJRE.sha1, resp.headers['content-length'], url, fDir)
|
|
|
- this.java = new DLTracker([jre], jre.size, a => {
|
|
|
- fs.readFile(a.to, (err, data) => {
|
|
|
- // Data buffer needs to be decompressed from lzma,
|
|
|
- // not really possible using node.js
|
|
|
- })
|
|
|
- })
|
|
|
- }
|
|
|
- })
|
|
|
- } catch (err){
|
|
|
- resolve(false)
|
|
|
- }
|
|
|
+ // _enqueueOracleJRE(dataDir){
|
|
|
+ // return new Promise((resolve, reject) => {
|
|
|
+ // JavaGuard._latestJREOracle().then(verData => {
|
|
|
+ // if(verData != null){
|
|
|
|
|
|
- }
|
|
|
- })
|
|
|
- })
|
|
|
- }*/
|
|
|
+ // const combined = verData.uri + PLATFORM_MAP[process.platform]
|
|
|
+
|
|
|
+ // const opts = {
|
|
|
+ // url: combined,
|
|
|
+ // headers: {
|
|
|
+ // 'Cookie': 'oraclelicense=accept-securebackup-cookie'
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+
|
|
|
+ // request.head(opts, (err, resp, body) => {
|
|
|
+ // if(err){
|
|
|
+ // resolve(false)
|
|
|
+ // } else {
|
|
|
+ // dataDir = path.join(dataDir, 'runtime', 'x64')
|
|
|
+ // const name = combined.substring(combined.lastIndexOf('/')+1)
|
|
|
+ // const fDir = path.join(dataDir, name)
|
|
|
+ // const jre = new Asset(name, null, parseInt(resp.headers['content-length']), opts, fDir)
|
|
|
+ // this.java = new DLTracker([jre], jre.size, (a, self) => {
|
|
|
+ // let h = null
|
|
|
+ // fs.createReadStream(a.to)
|
|
|
+ // .on('error', err => console.log(err))
|
|
|
+ // .pipe(zlib.createGunzip())
|
|
|
+ // .on('error', err => console.log(err))
|
|
|
+ // .pipe(tar.extract(dataDir, {
|
|
|
+ // map: (header) => {
|
|
|
+ // if(h == null){
|
|
|
+ // h = header.name
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // }))
|
|
|
+ // .on('error', err => console.log(err))
|
|
|
+ // .on('finish', () => {
|
|
|
+ // fs.unlink(a.to, err => {
|
|
|
+ // if(err){
|
|
|
+ // console.log(err)
|
|
|
+ // }
|
|
|
+ // if(h.indexOf('/') > -1){
|
|
|
+ // h = h.substring(0, h.indexOf('/'))
|
|
|
+ // }
|
|
|
+ // const pos = path.join(dataDir, h)
|
|
|
+ // self.emit('complete', 'java', JavaGuard.javaExecFromRoot(pos))
|
|
|
+ // })
|
|
|
+ // })
|
|
|
+
|
|
|
+ // })
|
|
|
+ // resolve(true)
|
|
|
+ // }
|
|
|
+ // })
|
|
|
+
|
|
|
+ // } else {
|
|
|
+ // resolve(false)
|
|
|
+ // }
|
|
|
+ // })
|
|
|
+ // })
|
|
|
+
|
|
|
+ // }
|
|
|
+
|
|
|
+ // _enqueueMojangJRE(dir){
|
|
|
+ // return new Promise((resolve, reject) => {
|
|
|
+ // // Mojang does not host the JRE for linux.
|
|
|
+ // if(process.platform === 'linux'){
|
|
|
+ // resolve(false)
|
|
|
+ // }
|
|
|
+ // AssetGuard.loadMojangLauncherData().then(data => {
|
|
|
+ // if(data != null) {
|
|
|
+
|
|
|
+ // try {
|
|
|
+ // const mJRE = data[Library.mojangFriendlyOS()]['64'].jre
|
|
|
+ // const url = mJRE.url
|
|
|
+
|
|
|
+ // request.head(url, (err, resp, body) => {
|
|
|
+ // if(err){
|
|
|
+ // resolve(false)
|
|
|
+ // } else {
|
|
|
+ // const name = url.substring(url.lastIndexOf('/')+1)
|
|
|
+ // const fDir = path.join(dir, name)
|
|
|
+ // const jre = new Asset('jre' + mJRE.version, mJRE.sha1, resp.headers['content-length'], url, fDir)
|
|
|
+ // this.java = new DLTracker([jre], jre.size, a => {
|
|
|
+ // fs.readFile(a.to, (err, data) => {
|
|
|
+ // // Data buffer needs to be decompressed from lzma,
|
|
|
+ // // not really possible using node.js
|
|
|
+ // })
|
|
|
+ // })
|
|
|
+ // }
|
|
|
+ // })
|
|
|
+ // } catch (err){
|
|
|
+ // resolve(false)
|
|
|
+ // }
|
|
|
+
|
|
|
+ // }
|
|
|
+ // })
|
|
|
+ // })
|
|
|
+ // }
|
|
|
|
|
|
|
|
|
// #endregion
|