From 001f52e150d5c94057d363c32693fa8bb08837e3 Mon Sep 17 00:00:00 2001 From: Pierce Date: Sun, 28 Jul 2019 12:52:53 -0400 Subject: [PATCH] fix the download of client packages --- README.md | 2 +- components/launcher.js | 6 ++++-- components/package.js | 16 +++++++++------- package.json | 2 +- 4 files changed, 15 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 3d23439..d408f6d 100644 --- a/README.md +++ b/README.md @@ -51,7 +51,7 @@ launcher.on('error', (e) => console.log(e.toString('utf-8'))); | Parameter | Type | Description | Required | |--------------------------|----------|-------------------------------------------------------------------------------------------|----------| -| `options.clientPackage` | String | Path to the client package zip file. | False | +| `options.clientPackage` | String | Path or URL to the client package zip file. | 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 | diff --git a/components/launcher.js b/components/launcher.js index 473547f..e08a3a0 100644 --- a/components/launcher.js +++ b/components/launcher.js @@ -32,12 +32,14 @@ class MCLCore extends EventEmitter { if(this.options.clientPackage) { this.emit('debug', `[MCLC]: Extracting client package to ${this.options.root}`); - await packager.extractPackage(this.options.root, this.options.clientPackage); + await packager.extractPackage(this); } if(this.options.installer) { // So the forge installer can run without breaking :) - fs.writeFileSync(path.join(this.options.root, 'launcher_profiles.json'), JSON.stringify({}, null, 4)); + const profilePath = path.join(this.options.root, 'launcher_profiles.json'); + if(!fs.existsSync(profilePath)) + fs.writeFileSync(profilePath, JSON.stringify({}, null, 4)); await this.handler.runInstaller(this.options.installer) } diff --git a/components/package.js b/components/package.js index a76d6a8..2cd9414 100644 --- a/components/package.js +++ b/components/package.js @@ -1,14 +1,16 @@ const path = require('path'); const zip = require('adm-zip'); +const shelljs = require('shelljs'); -module.exports.extractPackage = function(root, clientPackage) { +module.exports.extractPackage = function(e) { return new Promise(async resolve => { - if(clientPackage.startsWith('http')) { - await downloadAsync(clientPackage, root, "clientPackage.zip"); - clientPackage = path.join(root, "clientPackage.zip") + if(e.options.clientPackage.startsWith('http')) { + await e.handler.downloadAsync(e.options.clientPackage, e.options.root, "clientPackage.zip"); + e.options.clientPackage = path.join(e.options.root, "clientPackage.zip") } - new zip(clientPackage).extractAllTo(root, true); - this.client.emit('package-extract', true); + new zip(e.options.clientPackage).extractAllTo(e.options.root, true); + e.emit('package-extract', true); + shelljs.rm(e.options.clientPackage); resolve(); }); -}; \ No newline at end of file +}; diff --git a/package.json b/package.json index 0fece52..04abfaa 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "minecraft-launcher-core", - "version": "3.7.1", + "version": "3.7.2", "description": "Lightweight module that downloads and runs Minecraft using javascript / NodeJS", "main": "index.js", "dependencies": {