Better handling of Forge when it doesnt have a version.json.

remove package.js and moved it to main handler file.

display whether or not java is 64 or 32 bit.
This commit is contained in:
Pierce 2019-10-10 13:21:23 -04:00
parent 8291f9a15d
commit 3fbea961c8
5 changed files with 32 additions and 33 deletions

View file

@ -20,22 +20,18 @@ class Handler {
checkJava(java) {
return new Promise(resolve => {
let spawned = false;
const javaVer = child.spawn(java, ["-version"]);
javaVer.stderr.on('data', (data) => {
if (spawned) return;
spawned = true;
this.client.emit('debug', `[MCLC]: Using Java version ${data.toString().match(/"(.*?)"/).pop()}`);
child.exec(`${java} -version`, (error, stdout, stderr) => {
if(error) {
resolve({
run: false,
message: e
})
}
this.client.emit('debug', `[MCLC]: Using Java version ${stderr.match(/"(.*?)"/).pop()} ${stderr.includes('64-Bit') ? '64-bit': '32-Bit'}`);
resolve({
run: true
});
});
javaVer.on('error', (e) => {
resolve({
run: false,
message: e
})
});
});
}
@ -297,7 +293,13 @@ class Handler {
if(!fs.existsSync(path.join(this.options.root, 'forge'))) {
shelljs.mkdir('-p', path.join(this.options.root, 'forge'));
}
await new zip(this.options.forge).extractEntryTo('version.json', path.join(this.options.root, 'forge', `${this.version.id}`), false, true);
try {
await new zip(this.options.forge).extractEntryTo('version.json', path.join(this.options.root, 'forge', `${this.version.id}`), false, true);
} catch(e) {
this.client.emit('debug', `[MCLC]: Unable to extract version.json from the forge jar due to ${e}`);
return null;
}
const forge = require(path.join(this.options.root, 'forge', `${this.version.id}`, 'version.json'));
const paths = [];
@ -528,6 +530,19 @@ class Handler {
}
}
}
extractPackage(options = this.options) {
return new Promise(async resolve => {
if(options.clientPackage.startsWith('http')) {
await this.downloadAsync(options.clientPackage, options.root, "clientPackage.zip", true, 'client-package');
options.clientPackage = path.join(options.root, "clientPackage.zip")
}
new zip(options.clientPackage).extractAllTo(options.root, true);
this.client.emit('package-extract', true);
if(options.removePackage) shelljs.rm(options.clientPackage);
resolve();
});
}
}
module.exports = Handler;

View file

@ -1,7 +1,6 @@
const child = require('child_process');
const path = require('path');
const handler = require('./handler');
const packager = require('./package');
const fs = require('fs');
const EventEmitter = require('events').EventEmitter;
@ -42,7 +41,7 @@ class MCLCore extends EventEmitter {
if(this.options.clientPackage) {
this.emit('debug', `[MCLC]: Extracting client package to ${this.options.root}`);
await packager.extractPackage(this);
await this.handler.extractPackage();
}
if(this.options.installer) {

View file

@ -1,16 +0,0 @@
const path = require('path');
const zip = require('adm-zip');
const shelljs = require('shelljs');
module.exports.extractPackage = function(e) {
return new Promise(async resolve => {
if(e.options.clientPackage.startsWith('http')) {
await e.handler.downloadAsync(e.options.clientPackage, e.options.root, "clientPackage.zip", true, 'client-package');
e.options.clientPackage = path.join(e.options.root, "clientPackage.zip")
}
new zip(e.options.clientPackage).extractAllTo(e.options.root, true);
e.emit('package-extract', true);
shelljs.rm(e.options.clientPackage);
resolve();
});
};