HeliosLauncher/app/assets/js/assetexec.js
Daniel Scalzi 0a79634b8a
Implemented Java validations within the UI.
When a user attemps to launch, the configured Java executable will be validated. If it is invalid, we will look for a valid installation. If no valid installation is found, the user will be prompted with an option to install Java. An option to decline needs to be added. If they choose to install, it will download, extract, and update the executable in the config. The game will then be launched.

Also added progress tracking for asset validations, as they can potentially take a bit longer. Showing progress assures the user that the program isn't stuck or broken.
2018-04-07 18:06:49 -04:00

47 lines
1.4 KiB
JavaScript

const {AssetGuard} = require('./assetguard.js')
const tracker = new AssetGuard(process.argv[2], process.argv[3])
console.log('AssetExec Started')
// Temporary for debug purposes.
process.on('unhandledRejection', r => console.log(r))
tracker.on('assetVal', (data) => {
process.send({task: 0, total: data.total, value: data.acc, content: 'validateAssets'})
})
tracker.on('totaldlprogress', (data) => {
process.send({task: 0, total: data.total, value: data.acc, percent: parseInt((data.acc/data.total)*100), content: 'dl'})
})
tracker.on('dlcomplete', () => {
process.send({task: 1, content: 'dl'})
})
tracker.on('jExtracted', (jPath) => {
process.send({task: 2, content: 'dl', jPath})
})
process.on('message', (msg) => {
if(msg.task === 0){
const func = msg.content
let nS = tracker[func]
let iS = AssetGuard[func]
if(typeof nS === 'function' || typeof iS === 'function'){
const f = typeof nS === 'function' ? nS : iS
const res = f.apply(f === nS ? tracker : null, msg.argsArr)
if(res instanceof Promise){
res.then((v) => {
process.send({result: v, content: msg.content})
})
} else {
process.send({result: res, content: msg.content})
}
}
}
})
process.on('disconnect', () => {
console.log('AssetExec Disconnected')
process.exit(0)
})