mirror of
https://github.com/artegoser/pimi-launcher-core.git
synced 2024-11-22 12:16:21 +03:00
This commit is contained in:
parent
fafd82856f
commit
a21fe5036b
3 changed files with 23 additions and 7 deletions
|
@ -4,6 +4,7 @@ const path = require('path');
|
|||
const request = require('request');
|
||||
const checksum = require('checksum');
|
||||
const zip = require('adm-zip');
|
||||
const child = require('child_process');
|
||||
|
||||
class Handler {
|
||||
constructor(client) {
|
||||
|
@ -19,6 +20,7 @@ class Handler {
|
|||
const _request = request(url, {timeout: this.options.timeout || 10000});
|
||||
|
||||
_request.on('error', function(error) {
|
||||
this.client.emit('debug', `[MCLC]: Failed to download asset to ${path.join(directory, name)} due to\n${e}`);
|
||||
resolve({
|
||||
failed: true,
|
||||
asset: {
|
||||
|
@ -70,8 +72,8 @@ class Handler {
|
|||
|
||||
getVersion() {
|
||||
return new Promise(resolve => {
|
||||
if(fs.existsSync(path.join(this.options.directory, 'versions', this.options.version.number, `${this.options.version.number}.json`))) {
|
||||
this.version = require(path.join(this.options.directory, 'versions', this.options.version.number, `${this.options.version.number}.json`));
|
||||
if(fs.existsSync(path.join(this.options.directory, `${this.options.version.number}.json`))) {
|
||||
this.version = require(path.join(this.options.directory, `${this.options.version.number}.json`));
|
||||
resolve(this.version);
|
||||
return;
|
||||
}
|
||||
|
@ -197,7 +199,7 @@ class Handler {
|
|||
});
|
||||
}
|
||||
|
||||
async getForgeDependencies() {
|
||||
async getForgeDependenciesLegacy() {
|
||||
if(!fs.existsSync(path.join(this.options.root, 'forge'))) {
|
||||
shelljs.mkdir('-p', path.join(this.options.root, 'forge'));
|
||||
}
|
||||
|
@ -243,6 +245,13 @@ class Handler {
|
|||
return {paths, forge};
|
||||
}
|
||||
|
||||
runInstaller(path) {
|
||||
return new Promise(resolve => {
|
||||
const installer = child.exec(path);
|
||||
installer.on('close', (code) => resolve());
|
||||
})
|
||||
}
|
||||
|
||||
getClasses() {
|
||||
return new Promise(async (resolve) => {
|
||||
const libs = [];
|
||||
|
@ -308,7 +317,7 @@ class Handler {
|
|||
let args = type.minecraftArguments ? type.minecraftArguments.split(' ') : type.arguments.game;
|
||||
const assetPath = this.version.assets === "legacy" || this.version.assets === "pre-1.6" ? path.join(this.options.root, 'assets', 'legacy') : path.join(this.options.root, 'assets');
|
||||
|
||||
if(args.length < 5) args = args.concat(this.version.minecraftArguments ? this.version.minecraftArguments.split(' ') : this.version.arguments.game);
|
||||
if(args.length < 11) args = args.concat(this.version.minecraftArguments ? this.version.minecraftArguments.split(' ') : this.version.arguments.game);
|
||||
|
||||
if({}.toString.call(this.options.authorization) === "[object Promise]") {
|
||||
this.options.authorization = await this.options.authorization;
|
||||
|
|
|
@ -25,6 +25,12 @@ class MCLCore extends EventEmitter {
|
|||
await packager.extractPackage(this.options.root, this.options.clientPackage);
|
||||
}
|
||||
|
||||
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));
|
||||
await this.handler.runInstaller(this.options.installer)
|
||||
}
|
||||
|
||||
const directory = path.join(this.options.root, 'versions', this.options.version.number);
|
||||
this.options.directory = directory;
|
||||
|
||||
|
@ -43,7 +49,7 @@ class MCLCore extends EventEmitter {
|
|||
let custom = null;
|
||||
if(this.options.forge) {
|
||||
this.emit('debug', '[MCLC]: Detected Forge in options, getting dependencies');
|
||||
forge = await this.handler.getForgeDependencies();
|
||||
forge = await this.handler.getForgeDependenciesLegacy();
|
||||
}
|
||||
if(this.options.version.custom) {
|
||||
this.emit('debug', '[MCLC]: Detected custom in options, setting custom version file');
|
||||
|
@ -75,7 +81,8 @@ class MCLCore extends EventEmitter {
|
|||
classPaths.push(forge.forge.mainClass)
|
||||
} else {
|
||||
const file = custom || versionFile;
|
||||
classPaths.push(`${mcPath}${separator}${classes.join(separator)}`);
|
||||
const jar = fs.existsSync(mcPath) ? `${mcPath}${separator}` : '';
|
||||
classPaths.push(`${jar}${classes.join(separator)}`);
|
||||
classPaths.push(file.mainClass);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "minecraft-launcher-core",
|
||||
"version": "3.5.3",
|
||||
"version": "3.6.0",
|
||||
"description": "Lightweight module that downloads and runs Minecraft using javascript / NodeJS",
|
||||
"main": "index.js",
|
||||
"dependencies": {
|
||||
|
|
Loading…
Add table
Reference in a new issue