mirror of
https://github.com/dscalzi/HeliosLauncher.git
synced 2024-12-22 11:42:14 -08:00
Progress checkin, mostly works.
This commit is contained in:
parent
a22bd32cb1
commit
b32857e7de
@ -1661,43 +1661,6 @@ class AssetGuard extends EventEmitter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// _enqueueMojangJRE(dir){
|
|
||||||
// return new Promise((resolve, reject) => {
|
|
||||||
// // Mojang does not host the JRE for linux.
|
|
||||||
// if(process.platform === 'linux'){
|
|
||||||
// resolve(false)
|
|
||||||
// }
|
|
||||||
// AssetGuard.loadMojangLauncherData().then(data => {
|
|
||||||
// if(data != null) {
|
|
||||||
|
|
||||||
// try {
|
|
||||||
// const mJRE = data[Library.mojangFriendlyOS()]['64'].jre
|
|
||||||
// const url = mJRE.url
|
|
||||||
|
|
||||||
// request.head(url, (err, resp, body) => {
|
|
||||||
// if(err){
|
|
||||||
// resolve(false)
|
|
||||||
// } else {
|
|
||||||
// const name = url.substring(url.lastIndexOf('/')+1)
|
|
||||||
// const fDir = path.join(dir, name)
|
|
||||||
// const jre = new Asset('jre' + mJRE.version, mJRE.sha1, resp.headers['content-length'], url, fDir)
|
|
||||||
// this.java = new DLTracker([jre], jre.size, a => {
|
|
||||||
// fs.readFile(a.to, (err, data) => {
|
|
||||||
// // Data buffer needs to be decompressed from lzma,
|
|
||||||
// // not really possible using node.js
|
|
||||||
// })
|
|
||||||
// })
|
|
||||||
// }
|
|
||||||
// })
|
|
||||||
// } catch (err){
|
|
||||||
// resolve(false)
|
|
||||||
// }
|
|
||||||
|
|
||||||
// }
|
|
||||||
// })
|
|
||||||
// })
|
|
||||||
// }
|
|
||||||
|
|
||||||
|
|
||||||
// #endregion
|
// #endregion
|
||||||
|
|
||||||
@ -1911,7 +1874,6 @@ class AssetGuard extends EventEmitter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
Util,
|
|
||||||
AssetGuard,
|
AssetGuard,
|
||||||
JavaGuard,
|
JavaGuard,
|
||||||
Asset,
|
Asset,
|
||||||
|
@ -7,7 +7,6 @@ const { getMojangOS, isLibraryCompatible, mcVersionAtLeast } = require('helios-
|
|||||||
const { Type } = require('helios-distribution-types')
|
const { Type } = require('helios-distribution-types')
|
||||||
const os = require('os')
|
const os = require('os')
|
||||||
const path = require('path')
|
const path = require('path')
|
||||||
const { URL } = require('url')
|
|
||||||
|
|
||||||
const ConfigManager = require('./configmanager')
|
const ConfigManager = require('./configmanager')
|
||||||
|
|
||||||
@ -16,7 +15,7 @@ const logger = LoggerUtil.getLogger('ProcessBuilder')
|
|||||||
class ProcessBuilder {
|
class ProcessBuilder {
|
||||||
|
|
||||||
constructor(distroServer, versionData, forgeData, authUser, launcherVersion){
|
constructor(distroServer, versionData, forgeData, authUser, launcherVersion){
|
||||||
this.gameDir = path.join(ConfigManager.getInstanceDirectory(), distroServer.getID())
|
this.gameDir = path.join(ConfigManager.getInstanceDirectory(), distroServer.rawServer.id)
|
||||||
this.commonDir = ConfigManager.getCommonDirectory()
|
this.commonDir = ConfigManager.getCommonDirectory()
|
||||||
this.server = distroServer
|
this.server = distroServer
|
||||||
this.versionData = versionData
|
this.versionData = versionData
|
||||||
@ -41,10 +40,10 @@ class ProcessBuilder {
|
|||||||
process.throwDeprecation = true
|
process.throwDeprecation = true
|
||||||
this.setupLiteLoader()
|
this.setupLiteLoader()
|
||||||
logger.info('Using liteloader:', this.usingLiteLoader)
|
logger.info('Using liteloader:', this.usingLiteLoader)
|
||||||
const modObj = this.resolveModConfiguration(ConfigManager.getModConfiguration(this.server.getID()).mods, this.server.getModules())
|
const modObj = this.resolveModConfiguration(ConfigManager.getModConfiguration(this.server.rawServer.id).mods, this.server.modules)
|
||||||
|
|
||||||
// Mod list below 1.13
|
// Mod list below 1.13
|
||||||
if(!mcVersionAtLeast('1.13', this.server.getMinecraftVersion())){
|
if(!mcVersionAtLeast('1.13', this.server.rawServer.minecraftVersion)){
|
||||||
this.constructJSONModList('forge', modObj.fMods, true)
|
this.constructJSONModList('forge', modObj.fMods, true)
|
||||||
if(this.usingLiteLoader){
|
if(this.usingLiteLoader){
|
||||||
this.constructJSONModList('liteloader', modObj.lMods, true)
|
this.constructJSONModList('liteloader', modObj.lMods, true)
|
||||||
@ -54,14 +53,14 @@ class ProcessBuilder {
|
|||||||
const uberModArr = modObj.fMods.concat(modObj.lMods)
|
const uberModArr = modObj.fMods.concat(modObj.lMods)
|
||||||
let args = this.constructJVMArguments(uberModArr, tempNativePath)
|
let args = this.constructJVMArguments(uberModArr, tempNativePath)
|
||||||
|
|
||||||
if(mcVersionAtLeast('1.13', this.server.getMinecraftVersion())){
|
if(mcVersionAtLeast('1.13', this.server.rawServer.minecraftVersion)){
|
||||||
//args = args.concat(this.constructModArguments(modObj.fMods))
|
//args = args.concat(this.constructModArguments(modObj.fMods))
|
||||||
args = args.concat(this.constructModList(modObj.fMods))
|
args = args.concat(this.constructModList(modObj.fMods))
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.info('Launch Arguments:', args)
|
logger.info('Launch Arguments:', args)
|
||||||
|
|
||||||
const child = child_process.spawn(ConfigManager.getJavaExecutable(this.server.getID()), args, {
|
const child = child_process.spawn(ConfigManager.getJavaExecutable(this.server.rawServer.id), args, {
|
||||||
cwd: this.gameDir,
|
cwd: this.gameDir,
|
||||||
detached: ConfigManager.getLaunchDetached()
|
detached: ConfigManager.getLaunchDetached()
|
||||||
})
|
})
|
||||||
@ -137,15 +136,15 @@ class ProcessBuilder {
|
|||||||
if(!ll.getRequired().value){
|
if(!ll.getRequired().value){
|
||||||
const modCfg = ConfigManager.getModConfiguration(this.server.rawServer.id).mods
|
const modCfg = ConfigManager.getModConfiguration(this.server.rawServer.id).mods
|
||||||
if(ProcessBuilder.isModEnabled(modCfg[ll.getVersionlessMavenIdentifier()], ll.getRequired())){
|
if(ProcessBuilder.isModEnabled(modCfg[ll.getVersionlessMavenIdentifier()], ll.getRequired())){
|
||||||
if(fs.existsSync(ll.localPath)){
|
if(fs.existsSync(ll.getPath())){
|
||||||
this.usingLiteLoader = true
|
this.usingLiteLoader = true
|
||||||
this.llPath = ll.localPath
|
this.llPath = ll.getPath()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if(fs.existsSync(ll.localPath)){
|
if(fs.existsSync(ll.getPath())){
|
||||||
this.usingLiteLoader = true
|
this.usingLiteLoader = true
|
||||||
this.llPath = ll.localPath
|
this.llPath = ll.getPath()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -307,14 +306,11 @@ class ProcessBuilder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_processAutoConnectArg(args){
|
_processAutoConnectArg(args){
|
||||||
if(ConfigManager.getAutoConnect() && this.server.isAutoConnect()){
|
if(ConfigManager.getAutoConnect() && this.server.rawServer.autoconnect){
|
||||||
const serverURL = new URL('my://' + this.server.getAddress())
|
|
||||||
args.push('--server')
|
args.push('--server')
|
||||||
args.push(serverURL.hostname)
|
args.push(this.server.hostname)
|
||||||
if(serverURL.port){
|
args.push('--port')
|
||||||
args.push('--port')
|
args.push(this.server.port)
|
||||||
args.push(serverURL.port)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -326,7 +322,7 @@ class ProcessBuilder {
|
|||||||
* @returns {Array.<string>} An array containing the full JVM arguments for this process.
|
* @returns {Array.<string>} An array containing the full JVM arguments for this process.
|
||||||
*/
|
*/
|
||||||
constructJVMArguments(mods, tempNativePath){
|
constructJVMArguments(mods, tempNativePath){
|
||||||
if(mcVersionAtLeast('1.13', this.server.getMinecraftVersion())){
|
if(mcVersionAtLeast('1.13', this.server.rawServer.minecraftVersion)){
|
||||||
return this._constructJVMArguments113(mods, tempNativePath)
|
return this._constructJVMArguments113(mods, tempNativePath)
|
||||||
} else {
|
} else {
|
||||||
return this._constructJVMArguments112(mods, tempNativePath)
|
return this._constructJVMArguments112(mods, tempNativePath)
|
||||||
@ -354,9 +350,9 @@ class ProcessBuilder {
|
|||||||
args.push('-Xdock:name=HeliosLauncher')
|
args.push('-Xdock:name=HeliosLauncher')
|
||||||
args.push('-Xdock:icon=' + path.join(__dirname, '..', 'images', 'minecraft.icns'))
|
args.push('-Xdock:icon=' + path.join(__dirname, '..', 'images', 'minecraft.icns'))
|
||||||
}
|
}
|
||||||
args.push('-Xmx' + ConfigManager.getMaxRAM(this.server.getID()))
|
args.push('-Xmx' + ConfigManager.getMaxRAM(this.server.rawServer.id))
|
||||||
args.push('-Xms' + ConfigManager.getMinRAM(this.server.getID()))
|
args.push('-Xms' + ConfigManager.getMinRAM(this.server.rawServer.id))
|
||||||
args = args.concat(ConfigManager.getJVMOptions(this.server.getID()))
|
args = args.concat(ConfigManager.getJVMOptions(this.server.rawServer.id))
|
||||||
args.push('-Djava.library.path=' + tempNativePath)
|
args.push('-Djava.library.path=' + tempNativePath)
|
||||||
|
|
||||||
// Main Java Class
|
// Main Java Class
|
||||||
@ -405,9 +401,9 @@ class ProcessBuilder {
|
|||||||
args.push('-Xdock:name=HeliosLauncher')
|
args.push('-Xdock:name=HeliosLauncher')
|
||||||
args.push('-Xdock:icon=' + path.join(__dirname, '..', 'images', 'minecraft.icns'))
|
args.push('-Xdock:icon=' + path.join(__dirname, '..', 'images', 'minecraft.icns'))
|
||||||
}
|
}
|
||||||
args.push('-Xmx' + ConfigManager.getMaxRAM(this.server.getID()))
|
args.push('-Xmx' + ConfigManager.getMaxRAM(this.server.rawServer.id))
|
||||||
args.push('-Xms' + ConfigManager.getMinRAM(this.server.getID()))
|
args.push('-Xms' + ConfigManager.getMinRAM(this.server.rawServer.id))
|
||||||
args = args.concat(ConfigManager.getJVMOptions(this.server.getID()))
|
args = args.concat(ConfigManager.getJVMOptions(this.server.rawServer.id))
|
||||||
|
|
||||||
// Main Java Class
|
// Main Java Class
|
||||||
args.push(this.forgeData.mainClass)
|
args.push(this.forgeData.mainClass)
|
||||||
@ -471,7 +467,7 @@ class ProcessBuilder {
|
|||||||
break
|
break
|
||||||
case 'version_name':
|
case 'version_name':
|
||||||
//val = versionData.id
|
//val = versionData.id
|
||||||
val = this.server.getID()
|
val = this.server.rawServer.id
|
||||||
break
|
break
|
||||||
case 'game_directory':
|
case 'game_directory':
|
||||||
val = this.gameDir
|
val = this.gameDir
|
||||||
@ -569,7 +565,7 @@ class ProcessBuilder {
|
|||||||
break
|
break
|
||||||
case 'version_name':
|
case 'version_name':
|
||||||
//val = versionData.id
|
//val = versionData.id
|
||||||
val = this.server.getID()
|
val = this.server.rawServer.id
|
||||||
break
|
break
|
||||||
case 'game_directory':
|
case 'game_directory':
|
||||||
val = this.gameDir
|
val = this.gameDir
|
||||||
@ -668,7 +664,7 @@ class ProcessBuilder {
|
|||||||
classpathArg(mods, tempNativePath){
|
classpathArg(mods, tempNativePath){
|
||||||
let cpArgs = []
|
let cpArgs = []
|
||||||
|
|
||||||
if(!mcVersionAtLeast('1.17', this.server.getMinecraftVersion())) {
|
if(!mcVersionAtLeast('1.17', this.server.rawServer.minecraftVersion)) {
|
||||||
// Add the version.jar to the classpath.
|
// Add the version.jar to the classpath.
|
||||||
// Must not be added to the classpath for Forge 1.17+.
|
// Must not be added to the classpath for Forge 1.17+.
|
||||||
const version = this.versionData.id
|
const version = this.versionData.id
|
||||||
@ -826,15 +822,15 @@ class ProcessBuilder {
|
|||||||
* @returns {{[id: string]: string}} An object containing the paths of each library this server requires.
|
* @returns {{[id: string]: string}} An object containing the paths of each library this server requires.
|
||||||
*/
|
*/
|
||||||
_resolveServerLibraries(mods){
|
_resolveServerLibraries(mods){
|
||||||
const mdls = this.server.getModules()
|
const mdls = this.server.modules
|
||||||
let libs = {}
|
let libs = {}
|
||||||
|
|
||||||
// Locate Forge/Libraries
|
// Locate Forge/Libraries
|
||||||
for(let mdl of mdls){
|
for(let mdl of mdls){
|
||||||
const type = mdl.getType()
|
const type = mdl.rawModule.type
|
||||||
if(type === Type.ForgeHosted || type === Type.Library){
|
if(type === Type.ForgeHosted || type === Type.Library){
|
||||||
libs[mdl.getVersionlessID()] = mdl.getArtifact().getPath()
|
libs[mdl.getVersionlessMavenIdentifier()] = mdl.getPath()
|
||||||
if(mdl.hasSubModules()){
|
if(mdl.subModules.length > 0){
|
||||||
const res = this._resolveModuleLibraries(mdl)
|
const res = this._resolveModuleLibraries(mdl)
|
||||||
if(res.length > 0){
|
if(res.length > 0){
|
||||||
libs = {...libs, ...res}
|
libs = {...libs, ...res}
|
||||||
@ -863,20 +859,20 @@ class ProcessBuilder {
|
|||||||
* @returns {Array.<string>} An array containing the paths of each library this module requires.
|
* @returns {Array.<string>} An array containing the paths of each library this module requires.
|
||||||
*/
|
*/
|
||||||
_resolveModuleLibraries(mdl){
|
_resolveModuleLibraries(mdl){
|
||||||
if(!mdl.hasSubModules()){
|
if(!mdl.subModules.length > 0){
|
||||||
return []
|
return []
|
||||||
}
|
}
|
||||||
let libs = []
|
let libs = []
|
||||||
for(let sm of mdl.getSubModules()){
|
for(let sm of mdl.subModules){
|
||||||
if(sm.getType() === Type.Library){
|
if(sm.rawModule.type === Type.Library){
|
||||||
|
|
||||||
if(sm.getClasspath()) {
|
if(sm.rawModule.classpath ?? true) {
|
||||||
libs.push(sm.getArtifact().getPath())
|
libs.push(sm.getPath())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// If this module has submodules, we need to resolve the libraries for those.
|
// If this module has submodules, we need to resolve the libraries for those.
|
||||||
// To avoid unnecessary recursive calls, base case is checked here.
|
// To avoid unnecessary recursive calls, base case is checked here.
|
||||||
if(mdl.hasSubModules()){
|
if(mdl.subModules.length > 0){
|
||||||
const res = this._resolveModuleLibraries(sm)
|
const res = this._resolveModuleLibraries(sm)
|
||||||
if(res.length > 0){
|
if(res.length > 0){
|
||||||
libs = libs.concat(res)
|
libs = libs.concat(res)
|
||||||
|
@ -5,13 +5,24 @@
|
|||||||
const cp = require('child_process')
|
const cp = require('child_process')
|
||||||
const crypto = require('crypto')
|
const crypto = require('crypto')
|
||||||
const { URL } = require('url')
|
const { URL } = require('url')
|
||||||
const { MojangRestAPI, getServerStatus } = require('helios-core/mojang')
|
const {
|
||||||
|
MojangRestAPI,
|
||||||
|
getServerStatus
|
||||||
|
} = require('helios-core/mojang')
|
||||||
|
const {
|
||||||
|
RestResponseStatus,
|
||||||
|
isDisplayableError,
|
||||||
|
mcVersionAtLeast
|
||||||
|
} = require('helios-core/common')
|
||||||
|
const {
|
||||||
|
FullRepair,
|
||||||
|
DistributionIndexProcessor,
|
||||||
|
MojangIndexProcessor
|
||||||
|
} = require('helios-core/dl')
|
||||||
|
|
||||||
// Internal Requirements
|
// Internal Requirements
|
||||||
const DiscordWrapper = require('./assets/js/discordwrapper')
|
const DiscordWrapper = require('./assets/js/discordwrapper')
|
||||||
const ProcessBuilder = require('./assets/js/processbuilder')
|
const ProcessBuilder = require('./assets/js/processbuilder')
|
||||||
const { RestResponseStatus, isDisplayableError, mcVersionAtLeast } = require('helios-core/common')
|
|
||||||
const { stdout } = require('process')
|
|
||||||
|
|
||||||
// Launch Elements
|
// Launch Elements
|
||||||
const launch_content = document.getElementById('launch_content')
|
const launch_content = document.getElementById('launch_content')
|
||||||
@ -53,26 +64,22 @@ function setLaunchDetails(details){
|
|||||||
/**
|
/**
|
||||||
* Set the value of the loading progress bar and display that value.
|
* Set the value of the loading progress bar and display that value.
|
||||||
*
|
*
|
||||||
* @param {number} value The progress value.
|
* @param {number} percent Percentage (0-100)
|
||||||
* @param {number} max The total size.
|
|
||||||
* @param {number|string} percent Optional. The percentage to display on the progress label.
|
|
||||||
*/
|
*/
|
||||||
function setLaunchPercentage(value, max, percent = ((value/max)*100)){
|
function setLaunchPercentage(percent){
|
||||||
launch_progress.setAttribute('max', max)
|
launch_progress.setAttribute('max', 100)
|
||||||
launch_progress.setAttribute('value', value)
|
launch_progress.setAttribute('value', percent)
|
||||||
launch_progress_label.innerHTML = percent + '%'
|
launch_progress_label.innerHTML = percent + '%'
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the value of the OS progress bar and display that on the UI.
|
* Set the value of the OS progress bar and display that on the UI.
|
||||||
*
|
*
|
||||||
* @param {number} value The progress value.
|
* @param {number} percent Percentage (0-100)
|
||||||
* @param {number} max The total download size.
|
|
||||||
* @param {number|string} percent Optional. The percentage to display on the progress label.
|
|
||||||
*/
|
*/
|
||||||
function setDownloadPercentage(value, max, percent = ((value/max)*100)){
|
function setDownloadPercentage(percent){
|
||||||
remote.getCurrentWindow().setProgressBar(value/max)
|
remote.getCurrentWindow().setProgressBar(percent/100)
|
||||||
setLaunchPercentage(value, max, percent)
|
setLaunchPercentage(percent)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -98,10 +105,10 @@ document.getElementById('launch_button').addEventListener('click', async (e) =>
|
|||||||
setLaunchPercentage(0, 100)
|
setLaunchPercentage(0, 100)
|
||||||
|
|
||||||
const jg = new JavaGuard(mcVersion)
|
const jg = new JavaGuard(mcVersion)
|
||||||
jg._validateJavaBinary(jExe).then((v) => {
|
jg._validateJavaBinary(jExe).then(async v => {
|
||||||
loggerLanding.info('Java version meta', v)
|
loggerLanding.info('Java version meta', v)
|
||||||
if(v.valid){
|
if(v.valid){
|
||||||
dlAsync()
|
await dlAsync()
|
||||||
} else {
|
} else {
|
||||||
asyncSystemScan(mcVersion)
|
asyncSystemScan(mcVersion)
|
||||||
}
|
}
|
||||||
@ -369,7 +376,7 @@ function asyncSystemScan(mcVersion, launchAfter = true){
|
|||||||
await populateJavaExecDetails(settingsJavaExecVal.value)
|
await populateJavaExecDetails(settingsJavaExecVal.value)
|
||||||
|
|
||||||
if(launchAfter){
|
if(launchAfter){
|
||||||
dlAsync()
|
await dlAsync()
|
||||||
}
|
}
|
||||||
sysAEx.disconnect()
|
sysAEx.disconnect()
|
||||||
}
|
}
|
||||||
@ -445,7 +452,7 @@ function asyncSystemScan(mcVersion, launchAfter = true){
|
|||||||
setLaunchDetails('Java Installed!')
|
setLaunchDetails('Java Installed!')
|
||||||
|
|
||||||
if(launchAfter){
|
if(launchAfter){
|
||||||
dlAsync()
|
await dlAsync()
|
||||||
}
|
}
|
||||||
|
|
||||||
sysAEx.disconnect()
|
sysAEx.disconnect()
|
||||||
@ -473,18 +480,28 @@ const GAME_JOINED_REGEX = /\[.+\]: Sound engine started/
|
|||||||
const GAME_LAUNCH_REGEX = /^\[.+\]: (?:MinecraftForge .+ Initialized|ModLauncher .+ starting: .+)$/
|
const GAME_LAUNCH_REGEX = /^\[.+\]: (?:MinecraftForge .+ Initialized|ModLauncher .+ starting: .+)$/
|
||||||
const MIN_LINGER = 5000
|
const MIN_LINGER = 5000
|
||||||
|
|
||||||
let aEx
|
async function dlAsync(login = true) {
|
||||||
let serv
|
|
||||||
let versionData
|
|
||||||
let forgeData
|
|
||||||
|
|
||||||
let progressListener
|
|
||||||
|
|
||||||
function dlAsync(login = true){
|
|
||||||
|
|
||||||
// Login parameter is temporary for debug purposes. Allows testing the validation/downloads without
|
// Login parameter is temporary for debug purposes. Allows testing the validation/downloads without
|
||||||
// launching the game.
|
// launching the game.
|
||||||
|
|
||||||
|
const loggerLaunchSuite = LoggerUtil.getLogger('LaunchSuite')
|
||||||
|
|
||||||
|
setLaunchDetails('Loading server information..')
|
||||||
|
|
||||||
|
let distro
|
||||||
|
|
||||||
|
try {
|
||||||
|
distro = await DistroAPI.refreshDistributionOrFallback()
|
||||||
|
onDistroRefresh(distro)
|
||||||
|
} catch(err) {
|
||||||
|
loggerLaunchSuite.error('Unable to refresh distribution index.', err)
|
||||||
|
showLaunchFailure('Fatal Error', 'Could not load a copy of the distribution index. See the console (CTRL + Shift + i) for more details.')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const serv = distro.getServerById(ConfigManager.getSelectedServer())
|
||||||
|
|
||||||
if(login) {
|
if(login) {
|
||||||
if(ConfigManager.getSelectedAccount() == null){
|
if(ConfigManager.getSelectedAccount() == null){
|
||||||
loggerLanding.error('You must be logged into an account.')
|
loggerLanding.error('You must be logged into an account.')
|
||||||
@ -496,262 +513,147 @@ function dlAsync(login = true){
|
|||||||
toggleLaunchArea(true)
|
toggleLaunchArea(true)
|
||||||
setLaunchPercentage(0, 100)
|
setLaunchPercentage(0, 100)
|
||||||
|
|
||||||
const loggerLaunchSuite = LoggerUtil.getLogger('LaunchSuite')
|
const fullRepairModule = new FullRepair(
|
||||||
|
|
||||||
const forkEnv = JSON.parse(JSON.stringify(process.env))
|
|
||||||
forkEnv.CONFIG_DIRECT_PATH = ConfigManager.getLauncherDirectory()
|
|
||||||
|
|
||||||
// Start AssetExec to run validations and downloads in a forked process.
|
|
||||||
aEx = cp.fork(path.join(__dirname, 'assets', 'js', 'assetexec.js'), [
|
|
||||||
'AssetGuard',
|
|
||||||
ConfigManager.getCommonDirectory(),
|
ConfigManager.getCommonDirectory(),
|
||||||
ConfigManager.getJavaExecutable(ConfigManager.getSelectedServer())
|
ConfigManager.getLauncherDirectory(),
|
||||||
], {
|
ConfigManager.getSelectedServer(),
|
||||||
env: forkEnv,
|
DistroAPI.isDevMode()
|
||||||
stdio: 'pipe'
|
)
|
||||||
})
|
|
||||||
// Stdout
|
fullRepairModule.spawnReceiver()
|
||||||
aEx.stdio[1].setEncoding('utf8')
|
|
||||||
aEx.stdio[1].on('data', (data) => {
|
fullRepairModule.childProcess.on('error', (err) => {
|
||||||
console.log(`\x1b[32m[AEx]\x1b[0m ${data}`)
|
|
||||||
})
|
|
||||||
// Stderr
|
|
||||||
aEx.stdio[2].setEncoding('utf8')
|
|
||||||
aEx.stdio[2].on('data', (data) => {
|
|
||||||
console.log(`\x1b[31m[AEx]\x1b[0m ${data}`)
|
|
||||||
})
|
|
||||||
aEx.on('error', (err) => {
|
|
||||||
loggerLaunchSuite.error('Error during launch', err)
|
loggerLaunchSuite.error('Error during launch', err)
|
||||||
showLaunchFailure('Error During Launch', err.message || 'See console (CTRL + Shift + i) for more details.')
|
showLaunchFailure('Error During Launch', err.message || 'See console (CTRL + Shift + i) for more details.')
|
||||||
})
|
})
|
||||||
aEx.on('close', (code, signal) => {
|
fullRepairModule.childProcess.on('close', (code, _signal) => {
|
||||||
if(code !== 0){
|
if(code !== 0){
|
||||||
loggerLaunchSuite.error(`AssetExec exited with code ${code}, assuming error.`)
|
loggerLaunchSuite.error(`AssetExec exited with code ${code}, assuming error.`)
|
||||||
showLaunchFailure('Error During Launch', 'See console (CTRL + Shift + i) for more details.')
|
showLaunchFailure('Error During Launch', 'See console (CTRL + Shift + i) for more details.')
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
// Establish communications between the AssetExec and current process.
|
loggerLaunchSuite.info('Validating files.')
|
||||||
aEx.on('message', async (m) => {
|
setLaunchDetails('Validating file integrity..')
|
||||||
|
const invalidFileCount = await fullRepairModule.verifyFiles(percent => {
|
||||||
|
setLaunchPercentage(percent)
|
||||||
|
})
|
||||||
|
setLaunchPercentage(100)
|
||||||
|
|
||||||
if(m.context === 'validate'){
|
if(invalidFileCount > 0) {
|
||||||
switch(m.data){
|
loggerLaunchSuite.info('Downloading files.')
|
||||||
case 'distribution':
|
setLaunchDetails('Downloading files..')
|
||||||
setLaunchPercentage(20, 100)
|
await fullRepairModule.download(percent => {
|
||||||
loggerLaunchSuite.info('Validated distibution index.')
|
setDownloadPercentage(percent)
|
||||||
setLaunchDetails('Loading version information..')
|
})
|
||||||
break
|
setDownloadPercentage(100)
|
||||||
case 'version':
|
} else {
|
||||||
setLaunchPercentage(40, 100)
|
loggerLaunchSuite.info('No invalid files, skipping download.')
|
||||||
loggerLaunchSuite.info('Version data loaded.')
|
}
|
||||||
setLaunchDetails('Validating asset integrity..')
|
|
||||||
break
|
// Remove download bar.
|
||||||
case 'assets':
|
remote.getCurrentWindow().setProgressBar(-1)
|
||||||
setLaunchPercentage(60, 100)
|
|
||||||
loggerLaunchSuite.info('Asset Validation Complete')
|
fullRepairModule.destroyReceiver()
|
||||||
setLaunchDetails('Validating library integrity..')
|
|
||||||
break
|
setLaunchDetails('Preparing to launch..')
|
||||||
case 'libraries':
|
|
||||||
setLaunchPercentage(80, 100)
|
const mojangIndexProcessor = new MojangIndexProcessor(
|
||||||
loggerLaunchSuite.info('Library validation complete.')
|
ConfigManager.getCommonDirectory(),
|
||||||
setLaunchDetails('Validating miscellaneous file integrity..')
|
serv.rawServer.minecraftVersion)
|
||||||
break
|
const distributionIndexProcessor = new DistributionIndexProcessor(
|
||||||
case 'files':
|
ConfigManager.getCommonDirectory(),
|
||||||
setLaunchPercentage(100, 100)
|
distro,
|
||||||
loggerLaunchSuite.info('File validation complete.')
|
serv.rawServer.id
|
||||||
setLaunchDetails('Downloading files..')
|
)
|
||||||
break
|
|
||||||
|
// TODO need to load these.
|
||||||
|
const forgeData = await distributionIndexProcessor.loadForgeVersionJson(serv)
|
||||||
|
const versionData = await mojangIndexProcessor.getVersionJson()
|
||||||
|
|
||||||
|
if(login) {
|
||||||
|
const authUser = ConfigManager.getSelectedAccount()
|
||||||
|
loggerLaunchSuite.info(`Sending selected account (${authUser.displayName}) to ProcessBuilder.`)
|
||||||
|
let pb = new ProcessBuilder(serv, versionData, forgeData, authUser, remote.app.getVersion())
|
||||||
|
setLaunchDetails('Launching game..')
|
||||||
|
|
||||||
|
// const SERVER_JOINED_REGEX = /\[.+\]: \[CHAT\] [a-zA-Z0-9_]{1,16} joined the game/
|
||||||
|
const SERVER_JOINED_REGEX = new RegExp(`\\[.+\\]: \\[CHAT\\] ${authUser.displayName} joined the game`)
|
||||||
|
|
||||||
|
const onLoadComplete = () => {
|
||||||
|
toggleLaunchArea(false)
|
||||||
|
if(hasRPC){
|
||||||
|
DiscordWrapper.updateDetails('Loading game..')
|
||||||
}
|
}
|
||||||
} else if(m.context === 'progress'){
|
proc.stdout.on('data', gameStateChange)
|
||||||
switch(m.data){
|
proc.stdout.removeListener('data', tempListener)
|
||||||
case 'assets': {
|
proc.stderr.removeListener('data', gameErrorListener)
|
||||||
const perc = (m.value/m.total)*20
|
}
|
||||||
setLaunchPercentage(40+perc, 100, parseInt(40+perc))
|
const start = Date.now()
|
||||||
break
|
|
||||||
}
|
|
||||||
case 'download':
|
|
||||||
setDownloadPercentage(m.value, m.total, m.percent)
|
|
||||||
break
|
|
||||||
case 'extract': {
|
|
||||||
// Show installing progress bar.
|
|
||||||
remote.getCurrentWindow().setProgressBar(2)
|
|
||||||
|
|
||||||
// Download done, extracting.
|
// Attach a temporary listener to the client output.
|
||||||
const eLStr = 'Extracting libraries'
|
// Will wait for a certain bit of text meaning that
|
||||||
let dotStr = ''
|
// the client application has started, and we can hide
|
||||||
setLaunchDetails(eLStr)
|
// the progress bar stuff.
|
||||||
progressListener = setInterval(() => {
|
const tempListener = function(data){
|
||||||
if(dotStr.length >= 3){
|
if(GAME_LAUNCH_REGEX.test(data.trim())){
|
||||||
dotStr = ''
|
const diff = Date.now()-start
|
||||||
} else {
|
if(diff < MIN_LINGER) {
|
||||||
dotStr += '.'
|
setTimeout(onLoadComplete, MIN_LINGER-diff)
|
||||||
}
|
} else {
|
||||||
setLaunchDetails(eLStr + dotStr)
|
onLoadComplete()
|
||||||
}, 750)
|
|
||||||
break
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if(m.context === 'complete'){
|
}
|
||||||
switch(m.data){
|
|
||||||
case 'download':
|
|
||||||
// Download and extraction complete, remove the loading from the OS progress bar.
|
|
||||||
remote.getCurrentWindow().setProgressBar(-1)
|
|
||||||
if(progressListener != null){
|
|
||||||
clearInterval(progressListener)
|
|
||||||
progressListener = null
|
|
||||||
}
|
|
||||||
|
|
||||||
setLaunchDetails('Preparing to launch..')
|
// Listener for Discord RPC.
|
||||||
break
|
const gameStateChange = function(data){
|
||||||
|
data = data.trim()
|
||||||
|
if(SERVER_JOINED_REGEX.test(data)){
|
||||||
|
DiscordWrapper.updateDetails('Exploring the Realm!')
|
||||||
|
} else if(GAME_JOINED_REGEX.test(data)){
|
||||||
|
DiscordWrapper.updateDetails('Sailing to Westeros!')
|
||||||
}
|
}
|
||||||
} else if(m.context === 'error'){
|
}
|
||||||
switch(m.data){
|
|
||||||
case 'download':
|
|
||||||
loggerLaunchSuite.error('Error while downloading:', m.error)
|
|
||||||
|
|
||||||
if(m.error.code === 'ENOENT'){
|
const gameErrorListener = function(data){
|
||||||
showLaunchFailure(
|
data = data.trim()
|
||||||
'Download Error',
|
if(data.indexOf('Could not find or load main class net.minecraft.launchwrapper.Launch') > -1){
|
||||||
'Could not connect to the file server. Ensure that you are connected to the internet and try again.'
|
loggerLaunchSuite.error('Game launch failed, LaunchWrapper was not downloaded properly.')
|
||||||
)
|
showLaunchFailure('Error During Launch', 'The main file, LaunchWrapper, failed to download properly. As a result, the game cannot launch.<br><br>To fix this issue, temporarily turn off your antivirus software and launch the game again.<br><br>If you have time, please <a href="https://github.com/dscalzi/HeliosLauncher/issues">submit an issue</a> and let us know what antivirus software you use. We\'ll contact them and try to straighten things out.')
|
||||||
} else {
|
|
||||||
showLaunchFailure(
|
|
||||||
'Download Error',
|
|
||||||
'Check the console (CTRL + Shift + i) for more details. Please try again.'
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
remote.getCurrentWindow().setProgressBar(-1)
|
|
||||||
|
|
||||||
// Disconnect from AssetExec
|
|
||||||
aEx.disconnect()
|
|
||||||
break
|
|
||||||
}
|
}
|
||||||
} else if(m.context === 'validateEverything'){
|
}
|
||||||
|
|
||||||
let allGood = true
|
try {
|
||||||
|
// Build Minecraft process.
|
||||||
|
proc = pb.build()
|
||||||
|
|
||||||
// If these properties are not defined it's likely an error.
|
// Bind listeners to stdout.
|
||||||
if(m.result.forgeData == null || m.result.versionData == null){
|
proc.stdout.on('data', tempListener)
|
||||||
loggerLaunchSuite.error('Error during validation:', m.result)
|
proc.stderr.on('data', gameErrorListener)
|
||||||
|
|
||||||
loggerLaunchSuite.error('Error during launch', m.result.error)
|
setLaunchDetails('Done. Enjoy the server!')
|
||||||
showLaunchFailure('Error During Launch', 'Please check the console (CTRL + Shift + i) for more details.')
|
|
||||||
|
|
||||||
allGood = false
|
// Init Discord Hook
|
||||||
|
if(distro.rawDistribution.discord != null && serv.rawServerdiscord != null){
|
||||||
|
DiscordWrapper.initRPC(distro.rawDistribution.discord, serv.rawServer.discord)
|
||||||
|
hasRPC = true
|
||||||
|
proc.on('close', (code, signal) => {
|
||||||
|
loggerLaunchSuite.info('Shutting down Discord Rich Presence..')
|
||||||
|
DiscordWrapper.shutdownRPC()
|
||||||
|
hasRPC = false
|
||||||
|
proc = null
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
forgeData = m.result.forgeData
|
} catch(err) {
|
||||||
versionData = m.result.versionData
|
|
||||||
|
|
||||||
if(login && allGood) {
|
loggerLaunchSuite.error('Error during launch', err)
|
||||||
const authUser = ConfigManager.getSelectedAccount()
|
showLaunchFailure('Error During Launch', 'Please check the console (CTRL + Shift + i) for more details.')
|
||||||
loggerLaunchSuite.info(`Sending selected account (${authUser.displayName}) to ProcessBuilder.`)
|
|
||||||
let pb = new ProcessBuilder(serv, versionData, forgeData, authUser, remote.app.getVersion())
|
|
||||||
setLaunchDetails('Launching game..')
|
|
||||||
|
|
||||||
// const SERVER_JOINED_REGEX = /\[.+\]: \[CHAT\] [a-zA-Z0-9_]{1,16} joined the game/
|
|
||||||
const SERVER_JOINED_REGEX = new RegExp(`\\[.+\\]: \\[CHAT\\] ${authUser.displayName} joined the game`)
|
|
||||||
|
|
||||||
const onLoadComplete = () => {
|
|
||||||
toggleLaunchArea(false)
|
|
||||||
if(hasRPC){
|
|
||||||
DiscordWrapper.updateDetails('Loading game..')
|
|
||||||
}
|
|
||||||
proc.stdout.on('data', gameStateChange)
|
|
||||||
proc.stdout.removeListener('data', tempListener)
|
|
||||||
proc.stderr.removeListener('data', gameErrorListener)
|
|
||||||
}
|
|
||||||
const start = Date.now()
|
|
||||||
|
|
||||||
// Attach a temporary listener to the client output.
|
|
||||||
// Will wait for a certain bit of text meaning that
|
|
||||||
// the client application has started, and we can hide
|
|
||||||
// the progress bar stuff.
|
|
||||||
const tempListener = function(data){
|
|
||||||
if(GAME_LAUNCH_REGEX.test(data.trim())){
|
|
||||||
const diff = Date.now()-start
|
|
||||||
if(diff < MIN_LINGER) {
|
|
||||||
setTimeout(onLoadComplete, MIN_LINGER-diff)
|
|
||||||
} else {
|
|
||||||
onLoadComplete()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Listener for Discord RPC.
|
|
||||||
const gameStateChange = function(data){
|
|
||||||
data = data.trim()
|
|
||||||
if(SERVER_JOINED_REGEX.test(data)){
|
|
||||||
DiscordWrapper.updateDetails('Exploring the Realm!')
|
|
||||||
} else if(GAME_JOINED_REGEX.test(data)){
|
|
||||||
DiscordWrapper.updateDetails('Sailing to Westeros!')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const gameErrorListener = function(data){
|
|
||||||
data = data.trim()
|
|
||||||
if(data.indexOf('Could not find or load main class net.minecraft.launchwrapper.Launch') > -1){
|
|
||||||
loggerLaunchSuite.error('Game launch failed, LaunchWrapper was not downloaded properly.')
|
|
||||||
showLaunchFailure('Error During Launch', 'The main file, LaunchWrapper, failed to download properly. As a result, the game cannot launch.<br><br>To fix this issue, temporarily turn off your antivirus software and launch the game again.<br><br>If you have time, please <a href="https://github.com/dscalzi/HeliosLauncher/issues">submit an issue</a> and let us know what antivirus software you use. We\'ll contact them and try to straighten things out.')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
// Build Minecraft process.
|
|
||||||
proc = pb.build()
|
|
||||||
|
|
||||||
// Bind listeners to stdout.
|
|
||||||
proc.stdout.on('data', tempListener)
|
|
||||||
proc.stderr.on('data', gameErrorListener)
|
|
||||||
|
|
||||||
setLaunchDetails('Done. Enjoy the server!')
|
|
||||||
|
|
||||||
// Init Discord Hook
|
|
||||||
const distro = await DistroAPI.getDistribution()
|
|
||||||
if(distro.rawDistribution.discord != null && serv.rawServerdiscord != null){
|
|
||||||
DiscordWrapper.initRPC(distro.rawDistribution.discord, serv.rawServer.discord)
|
|
||||||
hasRPC = true
|
|
||||||
proc.on('close', (code, signal) => {
|
|
||||||
loggerLaunchSuite.info('Shutting down Discord Rich Presence..')
|
|
||||||
DiscordWrapper.shutdownRPC()
|
|
||||||
hasRPC = false
|
|
||||||
proc = null
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch(err) {
|
|
||||||
|
|
||||||
loggerLaunchSuite.error('Error during launch', err)
|
|
||||||
showLaunchFailure('Error During Launch', 'Please check the console (CTRL + Shift + i) for more details.')
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Disconnect from AssetExec
|
|
||||||
aEx.disconnect()
|
|
||||||
|
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
|
|
||||||
// Begin Validations
|
|
||||||
|
|
||||||
// Validate Forge files.
|
|
||||||
setLaunchDetails('Loading server information..')
|
|
||||||
|
|
||||||
DistroAPI.refreshDistributionOrFallback()
|
|
||||||
.then(data => {
|
|
||||||
onDistroRefresh(data)
|
|
||||||
serv = data.getServerById(ConfigManager.getSelectedServer())
|
|
||||||
aEx.send({task: 'execute', function: 'validateEverything', argsArr: [ConfigManager.getSelectedServer(), DistroAPI.isDevMode()]})
|
|
||||||
})
|
|
||||||
.catch(err => {
|
|
||||||
loggerLaunchSuite.error('Unable to refresh distribution index.', err)
|
|
||||||
showLaunchFailure('Fatal Error', 'Could not load a copy of the distribution index. See the console (CTRL + Shift + i) for more details.')
|
|
||||||
|
|
||||||
// Disconnect from AssetExec
|
|
||||||
aEx.disconnect()
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user