Fixed downloads causing crashes. Better Docs

This commit is contained in:
Pierce 2019-02-10 21:21:14 -05:00
parent 9574095696
commit 2652654c18
3 changed files with 17 additions and 15 deletions

View file

@ -1,8 +1,8 @@
# Minecraft Launcher Core # Minecraft Launcher Core
### Currently only supports MC 1.7.3 and up. ### Currently only supports MC 1.7.3 and up.
A script that launches Minecraft using NodeJS. MCLC is a NodeJS solution for launching modded and vanilla Minecraft without having to download and format everything yourself.
Supports Vanilla and Forge. Basically a core for your Electron or script based launchers.
### Installing ### Installing
@ -10,7 +10,6 @@ Supports Vanilla and Forge.
### Usage ### Usage
##### launcher.core Options ##### launcher.core Options
| Parameter | Type | Description | Required | | Parameter | Type | Description | Required |
@ -49,14 +48,15 @@ Supports Vanilla and Forge.
#### Events #### Events
| Event Name | Type | Description | | Event Name | Type | Description |
|-------------------|---------|-------------------------------------------------------------------------------------| |-------------------|---------|---------------------------------------------------------------------------------------|
| `data` | Buffer | Emitted when information is returned from the Minecraft Process | | `data` | Buffer | Emitted when information is returned from the Minecraft Process |
| `close` | Integer | Code number that is returned by the Minecraft Process | | `close` | Integer | Code number that is returned by the Minecraft Process |
| `error` | String | Emitted when the Minecraft Process errors | | `error` | String | Emitted when the Minecraft Process errors |
| `package-extract` | null | Emitted when `clientPackage` finishes being extracted | | `package-extract` | null | Emitted when `clientPackage` finishes being extracted |
| `start` | null | Emitted after `launchArguments` are set. THIS WILL BE DEPRECATED AS ITS NOT ACCURATE | | `start` | null | Emitted after `launchArguments` are set. THIS WILL BE DEPRECATED AS ITS NOT ACCURATE |
| `download` | String | Emitted when a file successfully downloads |
| `download-status` | Object | Emitted when data is received while downloading |
#### Client Package Function #### Client Package Function
Client Packages allow the client to run offline on setup. This function should be used outside the actual launcher. Client Packages allow the client to run offline on setup. This function should be used outside the actual launcher.
@ -69,7 +69,6 @@ this function is in the `handler` component.
| `versions` | Array | Array of the versions being downloaded and being made into a package. | True | | `versions` | Array | Array of the versions being downloaded and being made into a package. | True |
| `os` | String | OS that the package will be loaded on. OS specific natives need this. | True | | `os` | String | OS that the package will be loaded on. OS specific natives need this. | True |
### Examples ### Examples
```javascript ```javascript
const launcher = require('minecraft-launcher-core'); const launcher = require('minecraft-launcher-core');

View file

@ -25,8 +25,11 @@ function downloadAsync (url, directory, name) {
}); });
_request.on('data', (data) => { _request.on('data', (data) => {
let size = 0;
if(fs.existsSync(path.join(directory, name))) size = fs.statSync(path.join(directory, name))["size"];
event.emit('download-status', { event.emit('download-status', {
"current": Math.round(fs.statSync(path.join(directory, name))["size"] / 10000), "name": name,
"current": Math.round(size / 10000),
"total": data.length "total": data.length
}) })
}); });
@ -35,7 +38,7 @@ function downloadAsync (url, directory, name) {
_request.pipe(file); _request.pipe(file);
file.once('finish', function() { file.once('finish', function() {
console.log("Downloaded: " + name); event.emit('download', name);
resolve({failed: false, asset: null}); resolve({failed: false, asset: null});
}); });
}); });

View file

@ -1,6 +1,6 @@
{ {
"name": "minecraft-launcher-core", "name": "minecraft-launcher-core",
"version": "2.1.3", "version": "2.2.0",
"description": "Module that downloads Minecraft assets and runs Minecraft. Also Supports Forge", "description": "Module that downloads Minecraft assets and runs Minecraft. Also Supports Forge",
"main": "index.js", "main": "index.js",
"dependencies": { "dependencies": {