mirror of
https://github.com/dscalzi/HeliosLauncher.git
synced 2024-12-22 11:42:14 -08:00
Compare commits
3 Commits
b9b67b7824
...
8d26db70dc
Author | SHA1 | Date | |
---|---|---|---|
|
8d26db70dc | ||
|
13f86339bb | ||
|
d9291d82e5 |
@ -6,8 +6,6 @@ const crypto = require('crypto')
|
||||
const EventEmitter = require('events')
|
||||
const fs = require('fs-extra')
|
||||
const { LoggerUtil } = require('helios-core')
|
||||
const { DistributionAPI } = require('helios-core/common')
|
||||
const { Type } = require('helios-distribution-types')
|
||||
const nodeDiskInfo = require('node-disk-info')
|
||||
const StreamZip = require('node-stream-zip')
|
||||
const path = require('path')
|
||||
@ -16,8 +14,6 @@ const request = require('request')
|
||||
const tar = require('tar-fs')
|
||||
const zlib = require('zlib')
|
||||
|
||||
const ConfigManager = require('./configmanager')
|
||||
const { REMOTE_DISTRO_URL } = require('./distromanager')
|
||||
const isDev = require('./isdev')
|
||||
|
||||
// Classes
|
||||
@ -42,86 +38,6 @@ class Asset {
|
||||
}
|
||||
}
|
||||
|
||||
/** Class representing a mojang library. */
|
||||
class Library extends Asset {
|
||||
|
||||
/**
|
||||
* Converts the process.platform OS names to match mojang's OS names.
|
||||
*/
|
||||
static mojangFriendlyOS(){
|
||||
const opSys = process.platform
|
||||
if (opSys === 'darwin') {
|
||||
return 'osx'
|
||||
} else if (opSys === 'win32'){
|
||||
return 'windows'
|
||||
} else if (opSys === 'linux'){
|
||||
return 'linux'
|
||||
} else {
|
||||
return 'unknown_os'
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether or not a library is valid for download on a particular OS, following
|
||||
* the rule format specified in the mojang version data index. If the allow property has
|
||||
* an OS specified, then the library can ONLY be downloaded on that OS. If the disallow
|
||||
* property has instead specified an OS, the library can be downloaded on any OS EXCLUDING
|
||||
* the one specified.
|
||||
*
|
||||
* If the rules are undefined, the natives property will be checked for a matching entry
|
||||
* for the current OS.
|
||||
*
|
||||
* @param {Array.<Object>} rules The Library's download rules.
|
||||
* @param {Object} natives The Library's natives object.
|
||||
* @returns {boolean} True if the Library follows the specified rules, otherwise false.
|
||||
*/
|
||||
static validateRules(rules, natives){
|
||||
if(rules == null) {
|
||||
if(natives == null) {
|
||||
return true
|
||||
} else {
|
||||
return natives[Library.mojangFriendlyOS()] != null
|
||||
}
|
||||
}
|
||||
|
||||
for(let rule of rules){
|
||||
const action = rule.action
|
||||
const osProp = rule.os
|
||||
if(action != null && osProp != null){
|
||||
const osName = osProp.name
|
||||
const osMoj = Library.mojangFriendlyOS()
|
||||
if(action === 'allow'){
|
||||
return osName === osMoj
|
||||
} else if(action === 'disallow'){
|
||||
return osName !== osMoj
|
||||
}
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
class DistroModule extends Asset {
|
||||
|
||||
/**
|
||||
* Create a DistroModule. This is for processing,
|
||||
* not equivalent to the module objects in the
|
||||
* distro index.
|
||||
*
|
||||
* @param {any} id The id of the asset.
|
||||
* @param {string} hash The hash value of the asset.
|
||||
* @param {number} size The size in bytes of the asset.
|
||||
* @param {string} from The url where the asset can be found.
|
||||
* @param {string} to The absolute local file path of the asset.
|
||||
* @param {string} type The the module type.
|
||||
*/
|
||||
constructor(id, hash, size, from, to, type){
|
||||
super(id, hash, size, from, to)
|
||||
this.type = type
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Class representing a download tracker. This is used to store meta data
|
||||
* about a download queue, including the queue itself.
|
||||
@ -1152,416 +1068,10 @@ class AssetGuard extends EventEmitter {
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Function which finalizes the forge installation process. This creates a 'version'
|
||||
* instance for forge and saves its version.json file into that instance. If that
|
||||
* instance already exists, the contents of the version.json file are read and returned
|
||||
* in a promise.
|
||||
*
|
||||
* @param {Asset} asset The Asset object representing Forge.
|
||||
* @param {string} commonPath The common path for shared game files.
|
||||
* @returns {Promise.<Object>} A promise which resolves to the contents of forge's version.json.
|
||||
*/
|
||||
static _finalizeForgeAsset(asset, commonPath){
|
||||
return new Promise((resolve, reject) => {
|
||||
fs.readFile(asset.to, (err, data) => {
|
||||
const zip = new AdmZip(data)
|
||||
const zipEntries = zip.getEntries()
|
||||
|
||||
for(let i=0; i<zipEntries.length; i++){
|
||||
if(zipEntries[i].entryName === 'version.json'){
|
||||
const forgeVersion = JSON.parse(zip.readAsText(zipEntries[i]))
|
||||
const versionPath = path.join(commonPath, 'versions', forgeVersion.id)
|
||||
const versionFile = path.join(versionPath, forgeVersion.id + '.json')
|
||||
if(!fs.existsSync(versionFile)){
|
||||
fs.ensureDirSync(versionPath)
|
||||
fs.writeFileSync(path.join(versionPath, forgeVersion.id + '.json'), zipEntries[i].getData())
|
||||
resolve(forgeVersion)
|
||||
} else {
|
||||
//Read the saved file to allow for user modifications.
|
||||
resolve(JSON.parse(fs.readFileSync(versionFile, 'utf-8')))
|
||||
}
|
||||
return
|
||||
}
|
||||
}
|
||||
//We didn't find forge's version.json.
|
||||
reject('Unable to finalize Forge processing, version.json not found! Has forge changed their format?')
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
// #endregion
|
||||
|
||||
// #endregion
|
||||
|
||||
// Validation Functions
|
||||
// #region
|
||||
|
||||
/**
|
||||
* Loads the version data for a given minecraft version.
|
||||
*
|
||||
* @param {string} version The game version for which to load the index data.
|
||||
* @param {boolean} force Optional. If true, the version index will be downloaded even if it exists locally. Defaults to false.
|
||||
* @returns {Promise.<Object>} Promise which resolves to the version data object.
|
||||
*/
|
||||
loadVersionData(version, force = false){
|
||||
const self = this
|
||||
return new Promise(async (resolve, reject) => {
|
||||
const versionPath = path.join(self.commonPath, 'versions', version)
|
||||
const versionFile = path.join(versionPath, version + '.json')
|
||||
if(!fs.existsSync(versionFile) || force){
|
||||
const url = await self._getVersionDataUrl(version)
|
||||
//This download will never be tracked as it's essential and trivial.
|
||||
AssetGuard.logger.info('Preparing download of ' + version + ' assets.')
|
||||
fs.ensureDirSync(versionPath)
|
||||
const stream = request(url).pipe(fs.createWriteStream(versionFile))
|
||||
stream.on('finish', () => {
|
||||
resolve(JSON.parse(fs.readFileSync(versionFile)))
|
||||
})
|
||||
} else {
|
||||
resolve(JSON.parse(fs.readFileSync(versionFile)))
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses Mojang's version manifest and retrieves the url of the version
|
||||
* data index.
|
||||
*
|
||||
* @param {string} version The version to lookup.
|
||||
* @returns {Promise.<string>} Promise which resolves to the url of the version data index.
|
||||
* If the version could not be found, resolves to null.
|
||||
*/
|
||||
_getVersionDataUrl(version){
|
||||
return new Promise((resolve, reject) => {
|
||||
request('https://launchermeta.mojang.com/mc/game/version_manifest.json', (error, resp, body) => {
|
||||
if(error){
|
||||
reject(error)
|
||||
} else {
|
||||
const manifest = JSON.parse(body)
|
||||
|
||||
for(let v of manifest.versions){
|
||||
if(v.id === version){
|
||||
resolve(v.url)
|
||||
}
|
||||
}
|
||||
|
||||
resolve(null)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
// Asset (Category=''') Validation Functions
|
||||
// #region
|
||||
|
||||
/**
|
||||
* Public asset validation function. This function will handle the validation of assets.
|
||||
* It will parse the asset index specified in the version data, analyzing each
|
||||
* asset entry. In this analysis it will check to see if the local file exists and is valid.
|
||||
* If not, it will be added to the download queue for the 'assets' identifier.
|
||||
*
|
||||
* @param {Object} versionData The version data for the assets.
|
||||
* @param {boolean} force Optional. If true, the asset index will be downloaded even if it exists locally. Defaults to false.
|
||||
* @returns {Promise.<void>} An empty promise to indicate the async processing has completed.
|
||||
*/
|
||||
validateAssets(versionData, force = false){
|
||||
const self = this
|
||||
return new Promise((resolve, reject) => {
|
||||
self._assetChainIndexData(versionData, force).then(() => {
|
||||
resolve()
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
//Chain the asset tasks to provide full async. The below functions are private.
|
||||
/**
|
||||
* Private function used to chain the asset validation process. This function retrieves
|
||||
* the index data.
|
||||
* @param {Object} versionData
|
||||
* @param {boolean} force
|
||||
* @returns {Promise.<void>} An empty promise to indicate the async processing has completed.
|
||||
*/
|
||||
_assetChainIndexData(versionData, force = false){
|
||||
const self = this
|
||||
return new Promise((resolve, reject) => {
|
||||
//Asset index constants.
|
||||
const assetIndex = versionData.assetIndex
|
||||
const name = assetIndex.id + '.json'
|
||||
const indexPath = path.join(self.commonPath, 'assets', 'indexes')
|
||||
const assetIndexLoc = path.join(indexPath, name)
|
||||
|
||||
let data = null
|
||||
if(!fs.existsSync(assetIndexLoc) || force){
|
||||
AssetGuard.logger.info('Downloading ' + versionData.id + ' asset index.')
|
||||
fs.ensureDirSync(indexPath)
|
||||
const stream = request(assetIndex.url).pipe(fs.createWriteStream(assetIndexLoc))
|
||||
stream.on('finish', () => {
|
||||
data = JSON.parse(fs.readFileSync(assetIndexLoc, 'utf-8'))
|
||||
self._assetChainValidateAssets(versionData, data).then(() => {
|
||||
resolve()
|
||||
})
|
||||
})
|
||||
} else {
|
||||
data = JSON.parse(fs.readFileSync(assetIndexLoc, 'utf-8'))
|
||||
self._assetChainValidateAssets(versionData, data).then(() => {
|
||||
resolve()
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Private function used to chain the asset validation process. This function processes
|
||||
* the assets and enqueues missing or invalid files.
|
||||
* @param {Object} versionData
|
||||
* @param {boolean} force
|
||||
* @returns {Promise.<void>} An empty promise to indicate the async processing has completed.
|
||||
*/
|
||||
_assetChainValidateAssets(versionData, indexData){
|
||||
const self = this
|
||||
return new Promise((resolve, reject) => {
|
||||
|
||||
//Asset constants
|
||||
const resourceURL = 'https://resources.download.minecraft.net/'
|
||||
const localPath = path.join(self.commonPath, 'assets')
|
||||
const objectPath = path.join(localPath, 'objects')
|
||||
|
||||
const assetDlQueue = []
|
||||
let dlSize = 0
|
||||
let acc = 0
|
||||
const total = Object.keys(indexData.objects).length
|
||||
//const objKeys = Object.keys(data.objects)
|
||||
async.forEachOfLimit(indexData.objects, 10, (value, key, cb) => {
|
||||
acc++
|
||||
self.emit('progress', 'assets', acc, total)
|
||||
const hash = value.hash
|
||||
const assetName = path.join(hash.substring(0, 2), hash)
|
||||
const urlName = hash.substring(0, 2) + '/' + hash
|
||||
const ast = new Asset(key, hash, value.size, resourceURL + urlName, path.join(objectPath, assetName))
|
||||
if(!AssetGuard._validateLocal(ast.to, 'sha1', ast.hash)){
|
||||
dlSize += (ast.size*1)
|
||||
assetDlQueue.push(ast)
|
||||
}
|
||||
cb()
|
||||
}, (err) => {
|
||||
self.assets = new DLTracker(assetDlQueue, dlSize)
|
||||
resolve()
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
// #endregion
|
||||
|
||||
// Library (Category=''') Validation Functions
|
||||
// #region
|
||||
|
||||
/**
|
||||
* Public library validation function. This function will handle the validation of libraries.
|
||||
* It will parse the version data, analyzing each library entry. In this analysis, it will
|
||||
* check to see if the local file exists and is valid. If not, it will be added to the download
|
||||
* queue for the 'libraries' identifier.
|
||||
*
|
||||
* @param {Object} versionData The version data for the assets.
|
||||
* @returns {Promise.<void>} An empty promise to indicate the async processing has completed.
|
||||
*/
|
||||
validateLibraries(versionData){
|
||||
const self = this
|
||||
return new Promise((resolve, reject) => {
|
||||
|
||||
const libArr = versionData.libraries
|
||||
const libPath = path.join(self.commonPath, 'libraries')
|
||||
|
||||
const libDlQueue = []
|
||||
let dlSize = 0
|
||||
|
||||
//Check validity of each library. If the hashs don't match, download the library.
|
||||
async.eachLimit(libArr, 5, (lib, cb) => {
|
||||
if(Library.validateRules(lib.rules, lib.natives)){
|
||||
let artifact = (lib.natives == null) ? lib.downloads.artifact : lib.downloads.classifiers[lib.natives[Library.mojangFriendlyOS()].replace('${arch}', process.arch.replace('x', ''))]
|
||||
const libItm = new Library(lib.name, artifact.sha1, artifact.size, artifact.url, path.join(libPath, artifact.path))
|
||||
if(!AssetGuard._validateLocal(libItm.to, 'sha1', libItm.hash)){
|
||||
dlSize += (libItm.size*1)
|
||||
libDlQueue.push(libItm)
|
||||
}
|
||||
}
|
||||
cb()
|
||||
}, (err) => {
|
||||
self.libraries = new DLTracker(libDlQueue, dlSize)
|
||||
resolve()
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
// #endregion
|
||||
|
||||
// Miscellaneous (Category=files) Validation Functions
|
||||
// #region
|
||||
|
||||
/**
|
||||
* Public miscellaneous mojang file validation function. These files will be enqueued under
|
||||
* the 'files' identifier.
|
||||
*
|
||||
* @param {Object} versionData The version data for the assets.
|
||||
* @returns {Promise.<void>} An empty promise to indicate the async processing has completed.
|
||||
*/
|
||||
validateMiscellaneous(versionData){
|
||||
const self = this
|
||||
return new Promise(async (resolve, reject) => {
|
||||
await self.validateClient(versionData)
|
||||
await self.validateLogConfig(versionData)
|
||||
resolve()
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate client file - artifact renamed from client.jar to '{version}'.jar.
|
||||
*
|
||||
* @param {Object} versionData The version data for the assets.
|
||||
* @param {boolean} force Optional. If true, the asset index will be downloaded even if it exists locally. Defaults to false.
|
||||
* @returns {Promise.<void>} An empty promise to indicate the async processing has completed.
|
||||
*/
|
||||
validateClient(versionData, force = false){
|
||||
const self = this
|
||||
return new Promise((resolve, reject) => {
|
||||
const clientData = versionData.downloads.client
|
||||
const version = versionData.id
|
||||
const targetPath = path.join(self.commonPath, 'versions', version)
|
||||
const targetFile = version + '.jar'
|
||||
|
||||
let client = new Asset(version + ' client', clientData.sha1, clientData.size, clientData.url, path.join(targetPath, targetFile))
|
||||
|
||||
if(!AssetGuard._validateLocal(client.to, 'sha1', client.hash) || force){
|
||||
self.files.dlqueue.push(client)
|
||||
self.files.dlsize += client.size*1
|
||||
resolve()
|
||||
} else {
|
||||
resolve()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate log config.
|
||||
*
|
||||
* @param {Object} versionData The version data for the assets.
|
||||
* @param {boolean} force Optional. If true, the asset index will be downloaded even if it exists locally. Defaults to false.
|
||||
* @returns {Promise.<void>} An empty promise to indicate the async processing has completed.
|
||||
*/
|
||||
validateLogConfig(versionData){
|
||||
const self = this
|
||||
return new Promise((resolve, reject) => {
|
||||
const client = versionData.logging.client
|
||||
const file = client.file
|
||||
const targetPath = path.join(self.commonPath, 'assets', 'log_configs')
|
||||
|
||||
let logConfig = new Asset(file.id, file.sha1, file.size, file.url, path.join(targetPath, file.id))
|
||||
|
||||
if(!AssetGuard._validateLocal(logConfig.to, 'sha1', logConfig.hash)){
|
||||
self.files.dlqueue.push(logConfig)
|
||||
self.files.dlsize += logConfig.size*1
|
||||
resolve()
|
||||
} else {
|
||||
resolve()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// #endregion
|
||||
|
||||
// Distribution (Category=forge) Validation Functions
|
||||
// #region
|
||||
|
||||
/**
|
||||
* Validate the distribution.
|
||||
*
|
||||
* @param {Server} server The Server to validate.
|
||||
* @returns {Promise.<Object>} A promise which resolves to the server distribution object.
|
||||
*/
|
||||
validateDistribution(server){
|
||||
const self = this
|
||||
return new Promise((resolve, reject) => {
|
||||
self.forge = self._parseDistroModules(server.getModules(), server.getMinecraftVersion(), server.getID())
|
||||
resolve(server)
|
||||
})
|
||||
}
|
||||
|
||||
_parseDistroModules(modules, version, servid){
|
||||
let alist = []
|
||||
let asize = 0
|
||||
for(let ob of modules){
|
||||
let obArtifact = ob.getArtifact()
|
||||
let obPath = obArtifact.getPath()
|
||||
let artifact = new DistroModule(ob.getIdentifier(), obArtifact.getHash(), obArtifact.getSize(), obArtifact.getURL(), obPath, ob.getType())
|
||||
const validationPath = obPath.toLowerCase().endsWith('.pack.xz') ? obPath.substring(0, obPath.toLowerCase().lastIndexOf('.pack.xz')) : obPath
|
||||
if(!AssetGuard._validateLocal(validationPath, 'MD5', artifact.hash)){
|
||||
asize += artifact.size*1
|
||||
alist.push(artifact)
|
||||
if(validationPath !== obPath) this.extractQueue.push(obPath)
|
||||
}
|
||||
//Recursively process the submodules then combine the results.
|
||||
if(ob.getSubModules() != null){
|
||||
let dltrack = this._parseDistroModules(ob.getSubModules(), version, servid)
|
||||
asize += dltrack.dlsize*1
|
||||
alist = alist.concat(dltrack.dlqueue)
|
||||
}
|
||||
}
|
||||
|
||||
return new DLTracker(alist, asize)
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads Forge's version.json data into memory for the specified server id.
|
||||
*
|
||||
* @param {string} server The Server to load Forge data for.
|
||||
* @returns {Promise.<Object>} A promise which resolves to Forge's version.json data.
|
||||
*/
|
||||
loadForgeData(server){
|
||||
const self = this
|
||||
return new Promise(async (resolve, reject) => {
|
||||
const modules = server.getModules()
|
||||
for(let ob of modules){
|
||||
const type = ob.getType()
|
||||
if(type === Type.ForgeHosted || type === Type.Forge){
|
||||
if(Util.isForgeGradle3(server.getMinecraftVersion(), ob.getVersion())){
|
||||
// Read Manifest
|
||||
for(let sub of ob.getSubModules()){
|
||||
if(sub.getType() === Type.VersionManifest){
|
||||
resolve(JSON.parse(fs.readFileSync(sub.getArtifact().getPath(), 'utf-8')))
|
||||
return
|
||||
}
|
||||
}
|
||||
reject('No forge version manifest found!')
|
||||
return
|
||||
} else {
|
||||
let obArtifact = ob.getArtifact()
|
||||
let obPath = obArtifact.getPath()
|
||||
let asset = new DistroModule(ob.getIdentifier(), obArtifact.getHash(), obArtifact.getSize(), obArtifact.getURL(), obPath, type)
|
||||
try {
|
||||
let forgeData = await AssetGuard._finalizeForgeAsset(asset, self.commonPath)
|
||||
resolve(forgeData)
|
||||
} catch (err){
|
||||
reject(err)
|
||||
}
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
reject('No forge module found!')
|
||||
})
|
||||
}
|
||||
|
||||
_parseForgeLibraries(){
|
||||
/* TODO
|
||||
* Forge asset validations are already implemented. When there's nothing much
|
||||
* to work on, implement forge downloads using forge's version.json. This is to
|
||||
* have the code on standby if we ever need it (since it's half implemented already).
|
||||
*/
|
||||
}
|
||||
|
||||
// #endregion
|
||||
|
||||
// Java (Category=''') Validation (download) Functions
|
||||
// #region
|
||||
|
||||
@ -1644,43 +1154,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
|
||||
|
||||
@ -1840,63 +1313,11 @@ class AssetGuard extends EventEmitter {
|
||||
})
|
||||
}
|
||||
|
||||
async validateEverything(serverid, dev = false){
|
||||
|
||||
try {
|
||||
if(!ConfigManager.isLoaded()){
|
||||
ConfigManager.load()
|
||||
}
|
||||
const api = new DistributionAPI(
|
||||
ConfigManager.getLauncherDirectory(),
|
||||
REMOTE_DISTRO_URL,
|
||||
dev
|
||||
)
|
||||
|
||||
const dI = await api.getDistributionLocalLoadOnly()
|
||||
|
||||
// TODO replace all
|
||||
const server = dI.getServer(serverid)
|
||||
|
||||
// Validate Everything
|
||||
|
||||
await this.validateDistribution(server)
|
||||
this.emit('validate', 'distribution')
|
||||
const versionData = await this.loadVersionData(server.getMinecraftVersion())
|
||||
this.emit('validate', 'version')
|
||||
await this.validateAssets(versionData)
|
||||
this.emit('validate', 'assets')
|
||||
await this.validateLibraries(versionData)
|
||||
this.emit('validate', 'libraries')
|
||||
await this.validateMiscellaneous(versionData)
|
||||
this.emit('validate', 'files')
|
||||
await this.processDlQueues()
|
||||
//this.emit('complete', 'download')
|
||||
const forgeData = await this.loadForgeData(server)
|
||||
|
||||
return {
|
||||
versionData,
|
||||
forgeData
|
||||
}
|
||||
|
||||
} catch (err){
|
||||
return {
|
||||
versionData: null,
|
||||
forgeData: null,
|
||||
error: err
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
// #endregion
|
||||
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
Util,
|
||||
AssetGuard,
|
||||
JavaGuard,
|
||||
Asset,
|
||||
Library
|
||||
JavaGuard
|
||||
}
|
@ -6,6 +6,8 @@ exports.REMOTE_DISTRO_URL = 'http://mc.westeroscraft.com/WesterosCraftLauncher/d
|
||||
|
||||
const api = new DistributionAPI(
|
||||
ConfigManager.getLauncherDirectory(),
|
||||
null, // Injected forcefully by the preloader.
|
||||
null, // Injected forcefully by the preloader.
|
||||
exports.REMOTE_DISTRO_URL,
|
||||
false
|
||||
)
|
||||
|
@ -17,6 +17,11 @@ logger.info('Loading..')
|
||||
// Load ConfigManager
|
||||
ConfigManager.load()
|
||||
|
||||
// Yuck!
|
||||
// TODO Fix this
|
||||
DistroAPI['commonDir'] = ConfigManager.getCommonDirectory()
|
||||
DistroAPI['instanceDir'] = ConfigManager.getInstanceDirectory()
|
||||
|
||||
// Load Strings
|
||||
LangLoader.loadLanguage('en_US')
|
||||
|
||||
|
@ -7,7 +7,6 @@ const { getMojangOS, isLibraryCompatible, mcVersionAtLeast } = require('helios-
|
||||
const { Type } = require('helios-distribution-types')
|
||||
const os = require('os')
|
||||
const path = require('path')
|
||||
const { URL } = require('url')
|
||||
|
||||
const ConfigManager = require('./configmanager')
|
||||
|
||||
@ -16,7 +15,7 @@ const logger = LoggerUtil.getLogger('ProcessBuilder')
|
||||
class ProcessBuilder {
|
||||
|
||||
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.server = distroServer
|
||||
this.versionData = versionData
|
||||
@ -41,10 +40,10 @@ class ProcessBuilder {
|
||||
process.throwDeprecation = true
|
||||
this.setupLiteLoader()
|
||||
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
|
||||
if(!mcVersionAtLeast('1.13', this.server.getMinecraftVersion())){
|
||||
if(!mcVersionAtLeast('1.13', this.server.rawServer.minecraftVersion)){
|
||||
this.constructJSONModList('forge', modObj.fMods, true)
|
||||
if(this.usingLiteLoader){
|
||||
this.constructJSONModList('liteloader', modObj.lMods, true)
|
||||
@ -54,14 +53,14 @@ class ProcessBuilder {
|
||||
const uberModArr = modObj.fMods.concat(modObj.lMods)
|
||||
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.constructModList(modObj.fMods))
|
||||
}
|
||||
|
||||
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,
|
||||
detached: ConfigManager.getLaunchDetached()
|
||||
})
|
||||
@ -137,15 +136,15 @@ class ProcessBuilder {
|
||||
if(!ll.getRequired().value){
|
||||
const modCfg = ConfigManager.getModConfiguration(this.server.rawServer.id).mods
|
||||
if(ProcessBuilder.isModEnabled(modCfg[ll.getVersionlessMavenIdentifier()], ll.getRequired())){
|
||||
if(fs.existsSync(ll.localPath)){
|
||||
if(fs.existsSync(ll.getPath())){
|
||||
this.usingLiteLoader = true
|
||||
this.llPath = ll.localPath
|
||||
this.llPath = ll.getPath()
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if(fs.existsSync(ll.localPath)){
|
||||
if(fs.existsSync(ll.getPath())){
|
||||
this.usingLiteLoader = true
|
||||
this.llPath = ll.localPath
|
||||
this.llPath = ll.getPath()
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -307,14 +306,11 @@ class ProcessBuilder {
|
||||
}
|
||||
|
||||
_processAutoConnectArg(args){
|
||||
if(ConfigManager.getAutoConnect() && this.server.isAutoConnect()){
|
||||
const serverURL = new URL('my://' + this.server.getAddress())
|
||||
if(ConfigManager.getAutoConnect() && this.server.rawServer.autoconnect){
|
||||
args.push('--server')
|
||||
args.push(serverURL.hostname)
|
||||
if(serverURL.port){
|
||||
args.push(this.server.hostname)
|
||||
args.push('--port')
|
||||
args.push(serverURL.port)
|
||||
}
|
||||
args.push(this.server.port)
|
||||
}
|
||||
}
|
||||
|
||||
@ -326,7 +322,7 @@ class ProcessBuilder {
|
||||
* @returns {Array.<string>} An array containing the full JVM arguments for this process.
|
||||
*/
|
||||
constructJVMArguments(mods, tempNativePath){
|
||||
if(mcVersionAtLeast('1.13', this.server.getMinecraftVersion())){
|
||||
if(mcVersionAtLeast('1.13', this.server.rawServer.minecraftVersion)){
|
||||
return this._constructJVMArguments113(mods, tempNativePath)
|
||||
} else {
|
||||
return this._constructJVMArguments112(mods, tempNativePath)
|
||||
@ -354,9 +350,9 @@ class ProcessBuilder {
|
||||
args.push('-Xdock:name=HeliosLauncher')
|
||||
args.push('-Xdock:icon=' + path.join(__dirname, '..', 'images', 'minecraft.icns'))
|
||||
}
|
||||
args.push('-Xmx' + ConfigManager.getMaxRAM(this.server.getID()))
|
||||
args.push('-Xms' + ConfigManager.getMinRAM(this.server.getID()))
|
||||
args = args.concat(ConfigManager.getJVMOptions(this.server.getID()))
|
||||
args.push('-Xmx' + ConfigManager.getMaxRAM(this.server.rawServer.id))
|
||||
args.push('-Xms' + ConfigManager.getMinRAM(this.server.rawServer.id))
|
||||
args = args.concat(ConfigManager.getJVMOptions(this.server.rawServer.id))
|
||||
args.push('-Djava.library.path=' + tempNativePath)
|
||||
|
||||
// Main Java Class
|
||||
@ -405,9 +401,9 @@ class ProcessBuilder {
|
||||
args.push('-Xdock:name=HeliosLauncher')
|
||||
args.push('-Xdock:icon=' + path.join(__dirname, '..', 'images', 'minecraft.icns'))
|
||||
}
|
||||
args.push('-Xmx' + ConfigManager.getMaxRAM(this.server.getID()))
|
||||
args.push('-Xms' + ConfigManager.getMinRAM(this.server.getID()))
|
||||
args = args.concat(ConfigManager.getJVMOptions(this.server.getID()))
|
||||
args.push('-Xmx' + ConfigManager.getMaxRAM(this.server.rawServer.id))
|
||||
args.push('-Xms' + ConfigManager.getMinRAM(this.server.rawServer.id))
|
||||
args = args.concat(ConfigManager.getJVMOptions(this.server.rawServer.id))
|
||||
|
||||
// Main Java Class
|
||||
args.push(this.forgeData.mainClass)
|
||||
@ -471,7 +467,7 @@ class ProcessBuilder {
|
||||
break
|
||||
case 'version_name':
|
||||
//val = versionData.id
|
||||
val = this.server.getID()
|
||||
val = this.server.rawServer.id
|
||||
break
|
||||
case 'game_directory':
|
||||
val = this.gameDir
|
||||
@ -569,7 +565,7 @@ class ProcessBuilder {
|
||||
break
|
||||
case 'version_name':
|
||||
//val = versionData.id
|
||||
val = this.server.getID()
|
||||
val = this.server.rawServer.id
|
||||
break
|
||||
case 'game_directory':
|
||||
val = this.gameDir
|
||||
@ -668,7 +664,7 @@ class ProcessBuilder {
|
||||
classpathArg(mods, tempNativePath){
|
||||
let cpArgs = []
|
||||
|
||||
if(!mcVersionAtLeast('1.17', this.server.getMinecraftVersion())) {
|
||||
if(!mcVersionAtLeast('1.17', this.server.rawServer.minecraftVersion)) {
|
||||
// Add the version.jar to the classpath.
|
||||
// Must not be added to the classpath for Forge 1.17+.
|
||||
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.
|
||||
*/
|
||||
_resolveServerLibraries(mods){
|
||||
const mdls = this.server.getModules()
|
||||
const mdls = this.server.modules
|
||||
let libs = {}
|
||||
|
||||
// Locate Forge/Libraries
|
||||
for(let mdl of mdls){
|
||||
const type = mdl.getType()
|
||||
const type = mdl.rawModule.type
|
||||
if(type === Type.ForgeHosted || type === Type.Library){
|
||||
libs[mdl.getVersionlessID()] = mdl.getArtifact().getPath()
|
||||
if(mdl.hasSubModules()){
|
||||
libs[mdl.getVersionlessMavenIdentifier()] = mdl.getPath()
|
||||
if(mdl.subModules.length > 0){
|
||||
const res = this._resolveModuleLibraries(mdl)
|
||||
if(res.length > 0){
|
||||
libs = {...libs, ...res}
|
||||
@ -863,20 +859,20 @@ class ProcessBuilder {
|
||||
* @returns {Array.<string>} An array containing the paths of each library this module requires.
|
||||
*/
|
||||
_resolveModuleLibraries(mdl){
|
||||
if(!mdl.hasSubModules()){
|
||||
if(!mdl.subModules.length > 0){
|
||||
return []
|
||||
}
|
||||
let libs = []
|
||||
for(let sm of mdl.getSubModules()){
|
||||
if(sm.getType() === Type.Library){
|
||||
for(let sm of mdl.subModules){
|
||||
if(sm.rawModule.type === Type.Library){
|
||||
|
||||
if(sm.getClasspath()) {
|
||||
libs.push(sm.getArtifact().getPath())
|
||||
if(sm.rawModule.classpath ?? true) {
|
||||
libs.push(sm.getPath())
|
||||
}
|
||||
}
|
||||
// If this module has submodules, we need to resolve the libraries for those.
|
||||
// To avoid unnecessary recursive calls, base case is checked here.
|
||||
if(mdl.hasSubModules()){
|
||||
if(mdl.subModules.length > 0){
|
||||
const res = this._resolveModuleLibraries(sm)
|
||||
if(res.length > 0){
|
||||
libs = libs.concat(res)
|
||||
|
@ -5,13 +5,24 @@
|
||||
const cp = require('child_process')
|
||||
const crypto = require('crypto')
|
||||
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
|
||||
const DiscordWrapper = require('./assets/js/discordwrapper')
|
||||
const ProcessBuilder = require('./assets/js/processbuilder')
|
||||
const { RestResponseStatus, isDisplayableError, mcVersionAtLeast } = require('helios-core/common')
|
||||
const { stdout } = require('process')
|
||||
|
||||
// Launch Elements
|
||||
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.
|
||||
*
|
||||
* @param {number} value The progress value.
|
||||
* @param {number} max The total size.
|
||||
* @param {number|string} percent Optional. The percentage to display on the progress label.
|
||||
* @param {number} percent Percentage (0-100)
|
||||
*/
|
||||
function setLaunchPercentage(value, max, percent = ((value/max)*100)){
|
||||
launch_progress.setAttribute('max', max)
|
||||
launch_progress.setAttribute('value', value)
|
||||
function setLaunchPercentage(percent){
|
||||
launch_progress.setAttribute('max', 100)
|
||||
launch_progress.setAttribute('value', percent)
|
||||
launch_progress_label.innerHTML = percent + '%'
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the value of the OS progress bar and display that on the UI.
|
||||
*
|
||||
* @param {number} value The progress value.
|
||||
* @param {number} max The total download size.
|
||||
* @param {number|string} percent Optional. The percentage to display on the progress label.
|
||||
* @param {number} percent Percentage (0-100)
|
||||
*/
|
||||
function setDownloadPercentage(value, max, percent = ((value/max)*100)){
|
||||
remote.getCurrentWindow().setProgressBar(value/max)
|
||||
setLaunchPercentage(value, max, percent)
|
||||
function setDownloadPercentage(percent){
|
||||
remote.getCurrentWindow().setProgressBar(percent/100)
|
||||
setLaunchPercentage(percent)
|
||||
}
|
||||
|
||||
/**
|
||||
@ -98,10 +105,10 @@ document.getElementById('launch_button').addEventListener('click', async (e) =>
|
||||
setLaunchPercentage(0, 100)
|
||||
|
||||
const jg = new JavaGuard(mcVersion)
|
||||
jg._validateJavaBinary(jExe).then((v) => {
|
||||
jg._validateJavaBinary(jExe).then(async v => {
|
||||
loggerLanding.info('Java version meta', v)
|
||||
if(v.valid){
|
||||
dlAsync()
|
||||
await dlAsync()
|
||||
} else {
|
||||
asyncSystemScan(mcVersion)
|
||||
}
|
||||
@ -369,7 +376,7 @@ function asyncSystemScan(mcVersion, launchAfter = true){
|
||||
await populateJavaExecDetails(settingsJavaExecVal.value)
|
||||
|
||||
if(launchAfter){
|
||||
dlAsync()
|
||||
await dlAsync()
|
||||
}
|
||||
sysAEx.disconnect()
|
||||
}
|
||||
@ -445,7 +452,7 @@ function asyncSystemScan(mcVersion, launchAfter = true){
|
||||
setLaunchDetails('Java Installed!')
|
||||
|
||||
if(launchAfter){
|
||||
dlAsync()
|
||||
await dlAsync()
|
||||
}
|
||||
|
||||
sysAEx.disconnect()
|
||||
@ -473,18 +480,28 @@ const GAME_JOINED_REGEX = /\[.+\]: Sound engine started/
|
||||
const GAME_LAUNCH_REGEX = /^\[.+\]: (?:MinecraftForge .+ Initialized|ModLauncher .+ starting: .+)$/
|
||||
const MIN_LINGER = 5000
|
||||
|
||||
let aEx
|
||||
let serv
|
||||
let versionData
|
||||
let forgeData
|
||||
|
||||
let progressListener
|
||||
|
||||
function dlAsync(login = true){
|
||||
async function dlAsync(login = true) {
|
||||
|
||||
// Login parameter is temporary for debug purposes. Allows testing the validation/downloads without
|
||||
// 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(ConfigManager.getSelectedAccount() == null){
|
||||
loggerLanding.error('You must be logged into an account.')
|
||||
@ -496,155 +513,66 @@ function dlAsync(login = true){
|
||||
toggleLaunchArea(true)
|
||||
setLaunchPercentage(0, 100)
|
||||
|
||||
const loggerLaunchSuite = LoggerUtil.getLogger('LaunchSuite')
|
||||
|
||||
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',
|
||||
const fullRepairModule = new FullRepair(
|
||||
ConfigManager.getCommonDirectory(),
|
||||
ConfigManager.getJavaExecutable(ConfigManager.getSelectedServer())
|
||||
], {
|
||||
env: forkEnv,
|
||||
stdio: 'pipe'
|
||||
})
|
||||
// Stdout
|
||||
aEx.stdio[1].setEncoding('utf8')
|
||||
aEx.stdio[1].on('data', (data) => {
|
||||
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) => {
|
||||
ConfigManager.getInstanceDirectory(),
|
||||
ConfigManager.getLauncherDirectory(),
|
||||
ConfigManager.getSelectedServer(),
|
||||
DistroAPI.isDevMode()
|
||||
)
|
||||
|
||||
fullRepairModule.spawnReceiver()
|
||||
|
||||
fullRepairModule.childProcess.on('error', (err) => {
|
||||
loggerLaunchSuite.error('Error during launch', err)
|
||||
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){
|
||||
loggerLaunchSuite.error(`AssetExec exited with code ${code}, assuming error.`)
|
||||
showLaunchFailure('Error During Launch', 'See console (CTRL + Shift + i) for more details.')
|
||||
}
|
||||
})
|
||||
|
||||
// Establish communications between the AssetExec and current process.
|
||||
aEx.on('message', async (m) => {
|
||||
loggerLaunchSuite.info('Validating files.')
|
||||
setLaunchDetails('Validating file integrity..')
|
||||
const invalidFileCount = await fullRepairModule.verifyFiles(percent => {
|
||||
setLaunchPercentage(percent)
|
||||
})
|
||||
setLaunchPercentage(100)
|
||||
|
||||
if(m.context === 'validate'){
|
||||
switch(m.data){
|
||||
case 'distribution':
|
||||
setLaunchPercentage(20, 100)
|
||||
loggerLaunchSuite.info('Validated distibution index.')
|
||||
setLaunchDetails('Loading version information..')
|
||||
break
|
||||
case 'version':
|
||||
setLaunchPercentage(40, 100)
|
||||
loggerLaunchSuite.info('Version data loaded.')
|
||||
setLaunchDetails('Validating asset integrity..')
|
||||
break
|
||||
case 'assets':
|
||||
setLaunchPercentage(60, 100)
|
||||
loggerLaunchSuite.info('Asset Validation Complete')
|
||||
setLaunchDetails('Validating library integrity..')
|
||||
break
|
||||
case 'libraries':
|
||||
setLaunchPercentage(80, 100)
|
||||
loggerLaunchSuite.info('Library validation complete.')
|
||||
setLaunchDetails('Validating miscellaneous file integrity..')
|
||||
break
|
||||
case 'files':
|
||||
setLaunchPercentage(100, 100)
|
||||
loggerLaunchSuite.info('File validation complete.')
|
||||
if(invalidFileCount > 0) {
|
||||
loggerLaunchSuite.info('Downloading files.')
|
||||
setLaunchDetails('Downloading files..')
|
||||
break
|
||||
}
|
||||
} else if(m.context === 'progress'){
|
||||
switch(m.data){
|
||||
case 'assets': {
|
||||
const perc = (m.value/m.total)*20
|
||||
setLaunchPercentage(40+perc, 100, parseInt(40+perc))
|
||||
break
|
||||
}
|
||||
case 'download':
|
||||
setDownloadPercentage(m.value, m.total, m.percent)
|
||||
break
|
||||
case 'extract': {
|
||||
// Show installing progress bar.
|
||||
remote.getCurrentWindow().setProgressBar(2)
|
||||
|
||||
// Download done, extracting.
|
||||
const eLStr = 'Extracting libraries'
|
||||
let dotStr = ''
|
||||
setLaunchDetails(eLStr)
|
||||
progressListener = setInterval(() => {
|
||||
if(dotStr.length >= 3){
|
||||
dotStr = ''
|
||||
await fullRepairModule.download(percent => {
|
||||
setDownloadPercentage(percent)
|
||||
})
|
||||
setDownloadPercentage(100)
|
||||
} else {
|
||||
dotStr += '.'
|
||||
loggerLaunchSuite.info('No invalid files, skipping download.')
|
||||
}
|
||||
setLaunchDetails(eLStr + dotStr)
|
||||
}, 750)
|
||||
break
|
||||
}
|
||||
}
|
||||
} else if(m.context === 'complete'){
|
||||
switch(m.data){
|
||||
case 'download':
|
||||
// Download and extraction complete, remove the loading from the OS progress bar.
|
||||
|
||||
// Remove download bar.
|
||||
remote.getCurrentWindow().setProgressBar(-1)
|
||||
if(progressListener != null){
|
||||
clearInterval(progressListener)
|
||||
progressListener = null
|
||||
}
|
||||
|
||||
fullRepairModule.destroyReceiver()
|
||||
|
||||
setLaunchDetails('Preparing to launch..')
|
||||
break
|
||||
}
|
||||
} else if(m.context === 'error'){
|
||||
switch(m.data){
|
||||
case 'download':
|
||||
loggerLaunchSuite.error('Error while downloading:', m.error)
|
||||
|
||||
if(m.error.code === 'ENOENT'){
|
||||
showLaunchFailure(
|
||||
'Download Error',
|
||||
'Could not connect to the file server. Ensure that you are connected to the internet and try again.'
|
||||
const mojangIndexProcessor = new MojangIndexProcessor(
|
||||
ConfigManager.getCommonDirectory(),
|
||||
serv.rawServer.minecraftVersion)
|
||||
const distributionIndexProcessor = new DistributionIndexProcessor(
|
||||
ConfigManager.getCommonDirectory(),
|
||||
distro,
|
||||
serv.rawServer.id
|
||||
)
|
||||
} else {
|
||||
showLaunchFailure(
|
||||
'Download Error',
|
||||
'Check the console (CTRL + Shift + i) for more details. Please try again.'
|
||||
)
|
||||
}
|
||||
|
||||
remote.getCurrentWindow().setProgressBar(-1)
|
||||
// TODO need to load these.
|
||||
const forgeData = await distributionIndexProcessor.loadForgeVersionJson(serv)
|
||||
const versionData = await mojangIndexProcessor.getVersionJson()
|
||||
|
||||
// Disconnect from AssetExec
|
||||
aEx.disconnect()
|
||||
break
|
||||
}
|
||||
} else if(m.context === 'validateEverything'){
|
||||
|
||||
let allGood = true
|
||||
|
||||
// If these properties are not defined it's likely an error.
|
||||
if(m.result.forgeData == null || m.result.versionData == null){
|
||||
loggerLaunchSuite.error('Error during validation:', m.result)
|
||||
|
||||
loggerLaunchSuite.error('Error during launch', m.result.error)
|
||||
showLaunchFailure('Error During Launch', 'Please check the console (CTRL + Shift + i) for more details.')
|
||||
|
||||
allGood = false
|
||||
}
|
||||
|
||||
forgeData = m.result.forgeData
|
||||
versionData = m.result.versionData
|
||||
|
||||
if(login && allGood) {
|
||||
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())
|
||||
@ -708,7 +636,6 @@ function dlAsync(login = true){
|
||||
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
|
||||
@ -728,30 +655,6 @@ function dlAsync(login = true){
|
||||
}
|
||||
}
|
||||
|
||||
// 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