mirror of
https://github.com/artegoser/pimi-launcher-core.git
synced 2024-11-22 20:26:22 +03:00
Fix EPERM error, debug event
This commit is contained in:
parent
8fb1b44f35
commit
25f889f091
4 changed files with 44 additions and 6 deletions
|
@ -96,6 +96,7 @@ If you are loading up a client outside of vanilla Minecraft and Forge (Optifine
|
||||||
| `package-extract` | null | Emitted when `clientPackage` finishes being extracted |
|
| `package-extract` | null | Emitted when `clientPackage` finishes being extracted |
|
||||||
| `download` | String | Emitted when a file successfully downloads |
|
| `download` | String | Emitted when a file successfully downloads |
|
||||||
| `download-status` | Object | Emitted when data is received while downloading |
|
| `download-status` | Object | Emitted when data is received while downloading |
|
||||||
|
| `debug` | String | Emitted when functions occur, made to help debug if errors occur |
|
||||||
#### 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.
|
||||||
|
|
|
@ -13,7 +13,6 @@ function downloadAsync (url, directory, name) {
|
||||||
const _request = request(url, {timeout: 10000});
|
const _request = request(url, {timeout: 10000});
|
||||||
|
|
||||||
_request.on('error', function(error) {
|
_request.on('error', function(error) {
|
||||||
shelljs.rm(path.join(directory, name)); // Prevents duplicates.
|
|
||||||
resolve({
|
resolve({
|
||||||
failed: true,
|
failed: true,
|
||||||
asset: {
|
asset: {
|
||||||
|
@ -41,6 +40,19 @@ function downloadAsync (url, directory, name) {
|
||||||
event.emit('download', name);
|
event.emit('download', name);
|
||||||
resolve({failed: false, asset: null});
|
resolve({failed: false, asset: null});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
file.on('error', (e) => {
|
||||||
|
event.emit('debug', `[MCLC]: Failed to download asset to ${path.join(directory, name)} due to\n${e}`);
|
||||||
|
if(fs.existsSync(path.join(directory, name))) shelljs.rm(path.join(directory, name));
|
||||||
|
resolve({
|
||||||
|
failed: true,
|
||||||
|
asset: {
|
||||||
|
url: url,
|
||||||
|
directory: directory,
|
||||||
|
name: name
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,6 +71,7 @@ module.exports.getVersion = function (version, directory) {
|
||||||
request.get(parsed.versions[desiredVersion].url, function(error, response, body) {
|
request.get(parsed.versions[desiredVersion].url, function(error, response, body) {
|
||||||
if (error) resolve(error);
|
if (error) resolve(error);
|
||||||
|
|
||||||
|
event.emit('debug', `[MCLC Debug]: Parsed version from version manifest`);
|
||||||
resolve(JSON.parse(body));
|
resolve(JSON.parse(body));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -73,6 +86,8 @@ module.exports.getJar = function (version, number, directory) {
|
||||||
|
|
||||||
fs.writeFileSync(path.join(directory, `${number}.json`), JSON.stringify(version, null, 4));
|
fs.writeFileSync(path.join(directory, `${number}.json`), JSON.stringify(version, null, 4));
|
||||||
|
|
||||||
|
event.emit('debug', '[MCLC]: Downloaded version jar and wrote version json');
|
||||||
|
|
||||||
resolve();
|
resolve();
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
@ -102,7 +117,7 @@ module.exports.getAssets = function (directory, version) {
|
||||||
|
|
||||||
// why do we have this? B/c sometimes Minecraft's resource site times out!
|
// why do we have this? B/c sometimes Minecraft's resource site times out!
|
||||||
if(failed) {
|
if(failed) {
|
||||||
for (const fail of failed) await downloadAsync(fail.url, fail.directory, fail.name);
|
await Promise.all(failed.map(async asset => await downloadAsync(asset.url, asset.directory, asset.name)))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Copy assets to legacy if it's an older Minecarft version.
|
// Copy assets to legacy if it's an older Minecarft version.
|
||||||
|
@ -125,6 +140,7 @@ module.exports.getAssets = function (directory, version) {
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
event.emit('debug', '[MCLC]: Downloaded assets');
|
||||||
resolve();
|
resolve();
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
@ -157,8 +173,10 @@ module.exports.getNatives = function (root, version, os) {
|
||||||
shelljs.rm(path.join(nativeDirectory, name));
|
shelljs.rm(path.join(nativeDirectory, name));
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
event.emit('debug', '[MCLC]: Downloaded and extracted natives');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
event.emit('debug', `[MCLC]: Set native path to ${nativeDirectory}`);
|
||||||
resolve(nativeDirectory);
|
resolve(nativeDirectory);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
@ -204,6 +222,8 @@ module.exports.getForgeDependencies = async function(root, version, forgeJarPath
|
||||||
paths.push(`${jarPath}${path.sep}${name}`);
|
paths.push(`${jarPath}${path.sep}${name}`);
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
event.emit('debug', '[MCLC]: Downloaded Forge dependencies');
|
||||||
|
|
||||||
return {paths, forge};
|
return {paths, forge};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -241,6 +261,7 @@ module.exports.getClasses = function (options, version) {
|
||||||
libs.push(libraryDirectory);
|
libs.push(libraryDirectory);
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
event.emit('debug', '[MCLC]: Collected class paths');
|
||||||
resolve(libs)
|
resolve(libs)
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
@ -287,6 +308,7 @@ module.exports.getLaunchOptions = function (version, modification, options) {
|
||||||
options.proxy.password
|
options.proxy.password
|
||||||
);
|
);
|
||||||
|
|
||||||
|
event.emit('debug', '[MCLC]: Set launch options');
|
||||||
resolve(arguments);
|
resolve(arguments);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
|
@ -7,9 +7,13 @@ const fs = require('fs');
|
||||||
|
|
||||||
module.exports = async function (options) {
|
module.exports = async function (options) {
|
||||||
options.root = path.resolve(options.root);
|
options.root = path.resolve(options.root);
|
||||||
if(!fs.existsSync(options.root)) fs.mkdirSync(options.root);
|
if(!fs.existsSync(options.root)) {
|
||||||
|
event.emit('debug', '[MCLC]: Attempting to create root folder');
|
||||||
|
fs.mkdirSync(options.root);
|
||||||
|
}
|
||||||
|
|
||||||
if(options.clientPackage) {
|
if(options.clientPackage) {
|
||||||
|
event.emit('debug', `[MCLC]: Extracting client package to ${options.root}`);
|
||||||
await handler.extractPackage(options.root, options.clientPackage);
|
await handler.extractPackage(options.root, options.clientPackage);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,13 +25,20 @@ module.exports = async function (options) {
|
||||||
const nativePath = await handler.getNatives(options.root, versionFile, options.os);
|
const nativePath = await handler.getNatives(options.root, versionFile, options.os);
|
||||||
|
|
||||||
if (!fs.existsSync(mcPath)) {
|
if (!fs.existsSync(mcPath)) {
|
||||||
|
event.emit('debug', '[MCLC]: Attempting to download Minecraft version jar');
|
||||||
await handler.getJar(versionFile, options.version.number, directory);
|
await handler.getJar(versionFile, options.version.number, directory);
|
||||||
}
|
}
|
||||||
|
|
||||||
let forge = null;
|
let forge = null;
|
||||||
let custom = null;
|
let custom = null;
|
||||||
if(options.forge) forge = await handler.getForgeDependencies(options.root, versionFile, options.forge.path);
|
if(options.forge) {
|
||||||
if(options.version.custom) custom = require(path.join(options.root, 'versions', options.version.custom, `${options.version.custom}.json`));
|
event.emit('debug', '[MCLC]: Detected Forge in options, getting dependencies');
|
||||||
|
forge = await handler.getForgeDependencies(options.root, versionFile, options.forge.path);
|
||||||
|
}
|
||||||
|
if(options.version.custom) {
|
||||||
|
event.emit('debug', '[MCLC]: Detected custom in options, setting custom version file');
|
||||||
|
custom = require(path.join(options.root, 'versions', options.version.custom, `${options.version.custom}.json`));
|
||||||
|
}
|
||||||
|
|
||||||
const args = [];
|
const args = [];
|
||||||
|
|
||||||
|
@ -47,7 +58,9 @@ module.exports = async function (options) {
|
||||||
const classes = await handler.getClasses(options, versionFile);
|
const classes = await handler.getClasses(options, versionFile);
|
||||||
const classPaths = ['-cp'];
|
const classPaths = ['-cp'];
|
||||||
const separator = options.os === "windows" ? ";" : ":";
|
const separator = options.os === "windows" ? ";" : ":";
|
||||||
|
event.emit('debug', `[MCLC]: Using ${separator} to separate class paths`);
|
||||||
if(forge) {
|
if(forge) {
|
||||||
|
event.emit('debug', '[MCLC]: Setting Forge class paths');
|
||||||
classPaths.push(`${options.forge.path}${separator}${forge.paths.join(separator)}${separator}${classes.join(separator)};${mcPath}`);
|
classPaths.push(`${options.forge.path}${separator}${forge.paths.join(separator)}${separator}${classes.join(separator)};${mcPath}`);
|
||||||
classPaths.push(forge.forge.mainClass)
|
classPaths.push(forge.forge.mainClass)
|
||||||
} else {
|
} else {
|
||||||
|
@ -56,6 +69,7 @@ module.exports = async function (options) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Download version's assets
|
// Download version's assets
|
||||||
|
event.emit('debug', '[MCLC]: Attempting to download assets');
|
||||||
await handler.getAssets(options.root, versionFile);
|
await handler.getAssets(options.root, versionFile);
|
||||||
|
|
||||||
// Launch options. Thank you Lyrus for the reformat <3
|
// Launch options. Thank you Lyrus for the reformat <3
|
||||||
|
@ -64,6 +78,7 @@ module.exports = async function (options) {
|
||||||
|
|
||||||
const launchArguments = args.concat(jvm, classPaths, launchOptions);
|
const launchArguments = args.concat(jvm, classPaths, launchOptions);
|
||||||
event.emit('arguments', launchArguments);
|
event.emit('arguments', launchArguments);
|
||||||
|
event.emit('debug', launchArguments.join(' '));
|
||||||
|
|
||||||
const minecraft = child.spawn(options.javaPath ? options.javaPath : 'java', launchArguments);
|
const minecraft = child.spawn(options.javaPath ? options.javaPath : 'java', launchArguments);
|
||||||
minecraft.stdout.on('data', (data) => event.emit('data', data));
|
minecraft.stdout.on('data', (data) => event.emit('data', data));
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "minecraft-launcher-core",
|
"name": "minecraft-launcher-core",
|
||||||
"version": "2.5.7",
|
"version": "2.6.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": {
|
||||||
|
|
Loading…
Add table
Reference in a new issue