diff --git a/README.md b/README.md index 46b77c1..f2680b1 100644 --- a/README.md +++ b/README.md @@ -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 | | `download` | String | Emitted when a file successfully downloads | | `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 Packages allow the client to run offline on setup. This function should be used outside the actual launcher. diff --git a/components/handler.js b/components/handler.js index f4c57eb..e8e83db 100644 --- a/components/handler.js +++ b/components/handler.js @@ -13,7 +13,6 @@ function downloadAsync (url, directory, name) { const _request = request(url, {timeout: 10000}); _request.on('error', function(error) { - shelljs.rm(path.join(directory, name)); // Prevents duplicates. resolve({ failed: true, asset: { @@ -41,6 +40,19 @@ function downloadAsync (url, directory, name) { event.emit('download', name); 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) { if (error) resolve(error); + event.emit('debug', `[MCLC Debug]: Parsed version from version manifest`); 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)); + event.emit('debug', '[MCLC]: Downloaded version jar and wrote version json'); + 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! 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. @@ -125,6 +140,7 @@ module.exports.getAssets = function (directory, version) { })); } + event.emit('debug', '[MCLC]: Downloaded assets'); resolve(); }); }; @@ -157,8 +173,10 @@ module.exports.getNatives = function (root, version, os) { 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); }); }; @@ -204,6 +222,8 @@ module.exports.getForgeDependencies = async function(root, version, forgeJarPath paths.push(`${jarPath}${path.sep}${name}`); })); + event.emit('debug', '[MCLC]: Downloaded Forge dependencies'); + return {paths, forge}; }; @@ -241,6 +261,7 @@ module.exports.getClasses = function (options, version) { libs.push(libraryDirectory); })); + event.emit('debug', '[MCLC]: Collected class paths'); resolve(libs) }); }; @@ -287,6 +308,7 @@ module.exports.getLaunchOptions = function (version, modification, options) { options.proxy.password ); + event.emit('debug', '[MCLC]: Set launch options'); resolve(arguments); }); }; diff --git a/components/launcher.js b/components/launcher.js index 4709611..f1a90e5 100644 --- a/components/launcher.js +++ b/components/launcher.js @@ -7,9 +7,13 @@ const fs = require('fs'); module.exports = async function (options) { 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) { + event.emit('debug', `[MCLC]: Extracting client package to ${options.root}`); 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); if (!fs.existsSync(mcPath)) { + event.emit('debug', '[MCLC]: Attempting to download Minecraft version jar'); await handler.getJar(versionFile, options.version.number, directory); } let forge = null; let custom = null; - if(options.forge) forge = await handler.getForgeDependencies(options.root, versionFile, options.forge.path); - if(options.version.custom) custom = require(path.join(options.root, 'versions', options.version.custom, `${options.version.custom}.json`)); + if(options.forge) { + 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 = []; @@ -47,7 +58,9 @@ module.exports = async function (options) { const classes = await handler.getClasses(options, versionFile); const classPaths = ['-cp']; const separator = options.os === "windows" ? ";" : ":"; + event.emit('debug', `[MCLC]: Using ${separator} to separate class paths`); 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(forge.forge.mainClass) } else { @@ -56,6 +69,7 @@ module.exports = async function (options) { } // Download version's assets + event.emit('debug', '[MCLC]: Attempting to download assets'); await handler.getAssets(options.root, versionFile); // 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); event.emit('arguments', launchArguments); + event.emit('debug', launchArguments.join(' ')); const minecraft = child.spawn(options.javaPath ? options.javaPath : 'java', launchArguments); minecraft.stdout.on('data', (data) => event.emit('data', data)); diff --git a/package.json b/package.json index 7ad60d9..56e0f8a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "minecraft-launcher-core", - "version": "2.5.7", + "version": "2.6.0", "description": "Module that downloads Minecraft assets and runs Minecraft. Also Supports Forge", "main": "index.js", "dependencies": {