From 3fbea961c8318b51974f959fb9e6b4033193588e Mon Sep 17 00:00:00 2001 From: Pierce Date: Thu, 10 Oct 2019 13:21:23 -0400 Subject: [PATCH] v3.11 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. --- README.md | 3 ++- components/handler.js | 41 ++++++++++++++++++++++++++++------------- components/launcher.js | 3 +-- components/package.js | 16 ---------------- package.json | 2 +- 5 files changed, 32 insertions(+), 33 deletions(-) delete mode 100644 components/package.js diff --git a/README.md b/README.md index 1b806ee..4f4b2d8 100644 --- a/README.md +++ b/README.md @@ -60,9 +60,10 @@ launcher.on('data', (e) => console.log(e)); | Parameter | Type | Description | Required | |--------------------------|----------|-------------------------------------------------------------------------------------------|----------| | `options.clientPackage` | String | Path or URL to the client package zip file. | False | +| `options.removePackage` | Boolean | Option to remove the client package zip file after its finished extracting. | False | | `options.installer` | String | Path to installer being executed. | False | | `options.root` | String | Path where you want the launcher to work in. like `C:/Users/user/AppData/Roaming/.mc`, | True | -| `options.os` | String | windows, osx or linux. MCLC with auto determine the OS if this field isn't provided. | False | +| `options.os` | String | windows, osx or linux. MCLC will auto determine the OS if this field isn't provided. | False | | `options.customArgs` | Array | Array of custom java arguments you want to add. | False | | `options.version.number` | String | Minecraft version that is going to be launched. | True | | `options.version.type` | String | Any string. The actual Minecraft launcher uses `release` and `snapshot`. | True | diff --git a/components/handler.js b/components/handler.js index 5821e13..e8874a1 100644 --- a/components/handler.js +++ b/components/handler.js @@ -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; diff --git a/components/launcher.js b/components/launcher.js index 21c3d0e..e1bf9c6 100644 --- a/components/launcher.js +++ b/components/launcher.js @@ -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) { diff --git a/components/package.js b/components/package.js deleted file mode 100644 index 6a26f8d..0000000 --- a/components/package.js +++ /dev/null @@ -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(); - }); -}; diff --git a/package.json b/package.json index d101ac4..1094697 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "minecraft-launcher-core", - "version": "3.10.4", + "version": "3.11.0", "description": "Lightweight module that downloads and runs Minecraft using javascript / NodeJS", "main": "index.js", "dependencies": {