Skip to content

Commit

Permalink
V2.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
XXdaugonXX committed Jan 4, 2022
1 parent f5648c6 commit a5fe7f3
Show file tree
Hide file tree
Showing 31 changed files with 3,248 additions and 3,649 deletions.
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
14
16
21 changes: 21 additions & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2017-2021 Daniel D. Scalzi

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -209,4 +209,4 @@ The best way to contact the developers is on Discord.
[discord]: https://discord.gg/zNWUXdt 'Discord'
[wiki]: https://github.com/XXdaugonXX/ZayvielLauncher/wiki 'wiki'
[nebula]: https://github.com/dscalzi/Nebula 'dscalzi/Nebula'
[v2branch]: https://github.com/dscalzi/HeliosLauncher/tree/ts-refactor 'v2 branch'
[v2branch]: https://github.com/dscalzi/HeliosLauncher/tree/ts-refactor 'v2 branch'
13 changes: 13 additions & 0 deletions app/assets/css/launcher.css
Original file line number Diff line number Diff line change
Expand Up @@ -859,6 +859,19 @@ body, button {
transform: rotate(45deg);
}

#loginMSButton {
border-color: transparent;
background-color: transparent;
cursor: pointer;
font-family: 'Avenir Medium';
font-size: 12px;
font-weight: bold;
margin-bottom: 253px;
margin-top: -250px;
color: rgba(255, 255, 255, 0.75);
}


/*
#login_filter {
height: calc(100% - 22px);
Expand Down
167 changes: 47 additions & 120 deletions app/assets/js/assetguard.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const child_process = require('child_process')
const crypto = require('crypto')
const EventEmitter = require('events')
const fs = require('fs-extra')
const StreamZip = require('node-stream-zip')
const path = require('path')
const Registry = require('winreg')
const request = require('request')
Expand Down Expand Up @@ -222,42 +223,6 @@ 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 OpenJDKData
* @property {string} uri The base uri of the JRE.
Expand All @@ -269,7 +234,7 @@ class JavaGuard extends EventEmitter {
* Fetch the last open JDK binary.
*
* HOTFIX: Uses Corretto 8 for macOS.
* See: https://github.com/dscalzi/HeliosLauncher/issues/70
* See: https://github.com/XXdaugonXX/ZayivelLauncher/issues/70
* See: https://github.com/AdoptOpenJDK/openjdk-support/issues/101
*
* @param {string} major The major version of Java to fetch.
Expand All @@ -281,30 +246,41 @@ class JavaGuard extends EventEmitter {
if(process.platform === 'darwin') {
return this._latestCorretto(major)
} else {
return this._latestAdoptOpenJDK(major)
return this._latestAdoptium(major)
}
}

static _latestAdoptOpenJDK(major) {
static _latestAdoptium(major) {

const majorNum = Number(major)
const sanitizedOS = process.platform === 'win32' ? 'windows' : (process.platform === 'darwin' ? 'mac' : process.platform)
const url = `https://api.adoptium.net/v3/assets/latest/${major}/hotspot?vendor=eclipse`

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, json: true}, (err, resp, body) => {
if(!err && body.length > 0){
resolve({
uri: body[0].binary_link,
size: body[0].binary_size,
name: body[0].binary_name

const targetBinary = body.find(entry => {
return entry.version.major === majorNum
&& entry.binary.os === sanitizedOS
&& entry.binary.image_type === 'jdk'
&& entry.binary.architecture === 'x64'
})

if(targetBinary != null) {
resolve({
uri: targetBinary.binary.package.link,
size: targetBinary.binary.package.size,
name: targetBinary.binary.package.name
})
} else {
resolve(null)
}
} else {
resolve(null)
}
})
})

}

static _latestCorretto(major) {
Expand Down Expand Up @@ -839,6 +815,7 @@ class JavaGuard extends EventEmitter {
pathSet1 = new Set([
...pathSet1,
...(await JavaGuard._scanFileSystem('C:\\Program Files\\Java')),
...(await JavaGuard._scanFileSystem('C:\\Program Files\\Eclipse Foundation')),
...(await JavaGuard._scanFileSystem('C:\\Program Files\\AdoptOpenJDK'))
])
}
Expand Down Expand Up @@ -1583,21 +1560,7 @@ class AssetGuard extends EventEmitter {
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)
}
self.emit('complete', 'java', JavaGuard.javaExecFromRoot(pos))
})
}
})
this._extractJdkZip(a.to, dataDir, self)

} else {
// Tar.gz
Expand Down Expand Up @@ -1638,67 +1601,31 @@ class AssetGuard extends EventEmitter {

}

// _enqueueOracleJRE(dataDir){
// return new Promise((resolve, reject) => {
// JavaGuard._latestJREOracle().then(verData => {
// if(verData != null){
async _extractJdkZip(zipPath, runtimeDir, self) {

const zip = new StreamZip.async({
file: zipPath,
storeEntries: true
})

// 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)
// }
// })
// })
let pos = ''
try {
const entries = await zip.entries()
pos = path.join(runtimeDir, Object.keys(entries)[0])

// }
console.log('Extracting jdk..')
await zip.extract(null, runtimeDir)
console.log('Cleaning up..')
await fs.remove(zipPath)
console.log('Jdk extraction complete.')

} catch(err) {
console.log(err)
} finally {
zip.close()
self.emit('complete', 'java', JavaGuard.javaExecFromRoot(pos))
}
}

// _enqueueMojangJRE(dir){
// return new Promise((resolve, reject) => {
Expand Down
Loading

0 comments on commit a5fe7f3

Please sign in to comment.