Distribution data is now pulled from our servers.
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
const {AssetGuard} = require('./assetguard.js')
|
||||
|
||||
const tracker = new AssetGuard(process.argv[2], process.argv[3])
|
||||
const tracker = new AssetGuard(process.argv[2], process.argv[3], process.argv[4])
|
||||
console.log('AssetExec Started')
|
||||
|
||||
// Temporary for debug purposes.
|
||||
|
||||
@@ -179,10 +179,11 @@ class AssetGuard extends EventEmitter {
|
||||
* values. Each identifier is resolved to an empty DLTracker.
|
||||
*
|
||||
* @param {string} basePath The base path for asset validation (game root).
|
||||
* @param {string} launcherPath The root launcher directory.
|
||||
* @param {string} javaexec The path to a java executable which will be used
|
||||
* to finalize installation.
|
||||
*/
|
||||
constructor(basePath, javaexec){
|
||||
constructor(basePath, launcherPath, javaexec){
|
||||
super()
|
||||
this.totaldlsize = 0
|
||||
this.progress = 0
|
||||
@@ -193,6 +194,7 @@ class AssetGuard extends EventEmitter {
|
||||
this.java = new DLTracker([], 0)
|
||||
this.extractQueue = []
|
||||
this.basePath = basePath
|
||||
this.launcherPath = launcherPath
|
||||
this.javaexec = javaexec
|
||||
}
|
||||
|
||||
@@ -373,41 +375,51 @@ class AssetGuard extends EventEmitter {
|
||||
/**
|
||||
* Statically retrieve the distribution data.
|
||||
*
|
||||
* @param {string} basePath The base path for asset validation (game root).
|
||||
* @param {string} launcherPath The root launcher directory.
|
||||
* @param {boolean} cached Optional. False if the distro should be freshly downloaded, else
|
||||
* a cached copy will be returned.
|
||||
* @returns {Promise.<Object>} A promise which resolves to the distribution data object.
|
||||
*/
|
||||
static retrieveDistributionData(basePath, cached = true){
|
||||
return new Promise(function(fulfill, reject){
|
||||
static retrieveDistributionData(launcherPath, cached = true){
|
||||
return new Promise(function(resolve, reject){
|
||||
if(!cached || distributionData == null){
|
||||
// TODO Download file from upstream.
|
||||
//const distroURL = 'http://mc.westeroscraft.com/WesterosCraftLauncher/westeroscraft.json'
|
||||
// TODO Save file to path.join(basePath, 'westeroscraft.json')
|
||||
const distroURL = 'http://mc.westeroscraft.com/WesterosCraftLauncher/westeroscraft.json'
|
||||
const distroDest = path.join(launcherPath, 'westeroscraft.json')
|
||||
// TODO Fulfill with JSON.parse()
|
||||
request(distroURL, (error, resp, body) => {
|
||||
distributionData = JSON.parse(body)
|
||||
|
||||
fs.writeFile(distroDest, body, 'utf-8', (err) => {
|
||||
if(!err){
|
||||
resolve(distributionData)
|
||||
} else {
|
||||
reject(err)
|
||||
}
|
||||
})
|
||||
})
|
||||
// Workaround while file is not hosted.
|
||||
fs.readFile(path.join(__dirname, '..', 'westeroscraft.json'), 'utf-8', (err, data) => {
|
||||
/*fs.readFile(path.join(__dirname, '..', 'westeroscraft.json'), 'utf-8', (err, data) => {
|
||||
distributionData = JSON.parse(data)
|
||||
fulfill(distributionData)
|
||||
})
|
||||
})*/
|
||||
} else {
|
||||
fulfill(distributionData)
|
||||
resolve(distributionData)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Statically retrieve the distribution data.
|
||||
* Recieved a cached version of the distribution index.
|
||||
*
|
||||
* @param {string} basePath The base path for asset validation (game root).
|
||||
* @param {string} launcherPath The root launcher directory.
|
||||
* @param {boolean} cached Optional. False if the distro should be freshly downloaded, else
|
||||
* a cached copy will be returned.
|
||||
* @returns {Object} The distribution data object.
|
||||
*/
|
||||
static retrieveDistributionDataSync(basePath, cached = true){
|
||||
static retrieveDistributionDataSync(launcherPath, cached = true){
|
||||
if(!cached || distributionData == null){
|
||||
distributionData = JSON.parse(fs.readFileSync(path.join(__dirname, '..', 'westeroscraft.json'), 'utf-8'))
|
||||
distributionData = JSON.parse(fs.readFileSync(path.join(launcherPath, 'westeroscraft.json'), 'utf-8'))
|
||||
}
|
||||
return distributionData
|
||||
}
|
||||
@@ -415,11 +427,11 @@ class AssetGuard extends EventEmitter {
|
||||
/**
|
||||
* Resolve the default selected server from the distribution index.
|
||||
*
|
||||
* @param {string} basePath The base path for asset validation (game root).
|
||||
* @param {string} launcherPath The root launcher directory.
|
||||
* @returns {Object} An object resolving to the default selected server.
|
||||
*/
|
||||
static resolveSelectedServer(basePath){
|
||||
const distro = AssetGuard.retrieveDistributionDataSync(basePath)
|
||||
static resolveSelectedServer(launcherPath){
|
||||
const distro = AssetGuard.retrieveDistributionDataSync(launcherPath)
|
||||
const servers = distro.servers
|
||||
for(let i=0; i<servers.length; i++){
|
||||
if(servers[i].default_selected){
|
||||
@@ -435,13 +447,13 @@ class AssetGuard extends EventEmitter {
|
||||
* Returns null if the ID could not be found or the distro index has
|
||||
* not yet been loaded.
|
||||
*
|
||||
* @param {string} basePath The base path for asset validation (game root).
|
||||
* @param {string} launcherPath The root launcher directory.
|
||||
* @param {string} serverID The id of the server to retrieve.
|
||||
* @returns {Object} The server object whose id matches the parameter.
|
||||
*/
|
||||
static getServerById(basePath, serverID){
|
||||
static getServerById(launcherPath, serverID){
|
||||
if(distributionData == null){
|
||||
AssetGuard.retrieveDistributionDataSync(basePath, false)
|
||||
AssetGuard.retrieveDistributionDataSync(launcherPath, false)
|
||||
}
|
||||
const servers = distributionData.servers
|
||||
let serv = null
|
||||
@@ -465,7 +477,7 @@ class AssetGuard extends EventEmitter {
|
||||
* @returns {Promise.<void>} An empty promise to indicate the extraction has completed.
|
||||
*/
|
||||
static _extractPackXZ(filePaths, javaExecutable){
|
||||
return new Promise(function(fulfill, reject){
|
||||
return new Promise(function(resolve, reject){
|
||||
let libPath
|
||||
if(isDev){
|
||||
libPath = path.join(process.cwd(), 'libraries', 'java', 'PackXZExtract.jar')
|
||||
@@ -480,14 +492,14 @@ class AssetGuard extends EventEmitter {
|
||||
const filePath = filePaths.join(',')
|
||||
const child = child_process.spawn(javaExecutable, ['-jar', libPath, '-packxz', filePath])
|
||||
child.stdout.on('data', (data) => {
|
||||
//console.log('PackXZExtract:', data.toString('utf8'))
|
||||
console.log('PackXZExtract:', data.toString('utf8'))
|
||||
})
|
||||
child.stderr.on('data', (data) => {
|
||||
//console.log('PackXZExtract:', data.toString('utf8'))
|
||||
console.log('PackXZExtract:', data.toString('utf8'))
|
||||
})
|
||||
child.on('close', (code, signal) => {
|
||||
//console.log('PackXZExtract: Exited with code', code)
|
||||
fulfill()
|
||||
console.log('PackXZExtract: Exited with code', code)
|
||||
resolve()
|
||||
})
|
||||
})
|
||||
}
|
||||
@@ -503,7 +515,7 @@ class AssetGuard extends EventEmitter {
|
||||
* @returns {Promise.<Object>} A promise which resolves to the contents of forge's version.json.
|
||||
*/
|
||||
static _finalizeForgeAsset(asset, basePath){
|
||||
return new Promise(function(fulfill, reject){
|
||||
return new Promise(function(resolve, reject){
|
||||
fs.readFile(asset.to, (err, data) => {
|
||||
const zip = new AdmZip(data)
|
||||
const zipEntries = zip.getEntries()
|
||||
@@ -516,10 +528,10 @@ class AssetGuard extends EventEmitter {
|
||||
if(!fs.existsSync(versionFile)){
|
||||
mkpath.sync(versionPath)
|
||||
fs.writeFileSync(path.join(versionPath, forgeVersion.id + '.json'), zipEntries[i].getData())
|
||||
fulfill(forgeVersion)
|
||||
resolve(forgeVersion)
|
||||
} else {
|
||||
//Read the saved file to allow for user modifications.
|
||||
fulfill(JSON.parse(fs.readFileSync(versionFile, 'utf-8')))
|
||||
resolve(JSON.parse(fs.readFileSync(versionFile, 'utf-8')))
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -1269,7 +1281,7 @@ class AssetGuard extends EventEmitter {
|
||||
validateDistribution(serverpackid){
|
||||
const self = this
|
||||
return new Promise(function(fulfill, reject){
|
||||
AssetGuard.retrieveDistributionData(self.basePath, false).then((value) => {
|
||||
AssetGuard.retrieveDistributionData(self.launcherPath, false).then((value) => {
|
||||
/*const servers = value.servers
|
||||
let serv = null
|
||||
for(let i=0; i<servers.length; i++){
|
||||
@@ -1278,7 +1290,7 @@ class AssetGuard extends EventEmitter {
|
||||
break
|
||||
}
|
||||
}*/
|
||||
const serv = AssetGuard.getServerById(self.basePath, serverpackid)
|
||||
const serv = AssetGuard.getServerById(self.launcherPath, serverpackid)
|
||||
|
||||
if(serv == null) {
|
||||
console.error('Invalid server pack id:', serverpackid)
|
||||
@@ -1367,7 +1379,7 @@ class AssetGuard extends EventEmitter {
|
||||
loadForgeData(serverpack){
|
||||
const self = this
|
||||
return new Promise(async function(fulfill, reject){
|
||||
let distro = AssetGuard.retrieveDistributionDataSync(self.basePath)
|
||||
let distro = AssetGuard.retrieveDistributionDataSync(self.launcherPath)
|
||||
|
||||
const servers = distro.servers
|
||||
let serv = null
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
const {AssetGuard} = require('./assetguard.js')
|
||||
const ConfigManager = require('./configmanager.js')
|
||||
const {ipcRenderer} = require('electron')
|
||||
const os = require('os')
|
||||
const path = require('path')
|
||||
const rimraf = require('rimraf')
|
||||
@@ -10,14 +11,22 @@ console.log('%c[Preloader]', 'color: #a02d2a; font-weight: bold', 'Loading..')
|
||||
ConfigManager.load()
|
||||
|
||||
// Ensure Distribution is downloaded and cached.
|
||||
AssetGuard.retrieveDistributionDataSync(ConfigManager.getGameDirectory(), false)
|
||||
AssetGuard.retrieveDistributionData(ConfigManager.getLauncherDirectory(), false).then((data) => {
|
||||
console.log('%c[Preloader]', 'color: #a02d2a; font-weight: bold', 'Loaded distribution index.')
|
||||
|
||||
// Resolve the selected server if its value has yet to be set.
|
||||
if(ConfigManager.getSelectedServer() == null){
|
||||
console.log('Determining default selected server..')
|
||||
ConfigManager.setSelectedServer(AssetGuard.resolveSelectedServer(ConfigManager.getGameDirectory()).id)
|
||||
ConfigManager.save()
|
||||
}
|
||||
// Resolve the selected server if its value has yet to be set.
|
||||
if(ConfigManager.getSelectedServer() == null){
|
||||
console.log('Determining default selected server..')
|
||||
ConfigManager.setSelectedServer(AssetGuard.resolveSelectedServer(ConfigManager.getLauncherDirectory()).id)
|
||||
ConfigManager.save()
|
||||
}
|
||||
|
||||
ipcRenderer.send('distributionIndexDone', data)
|
||||
|
||||
}).catch(err => {
|
||||
console.log('%c[Preloader]', 'color: #a02d2a; font-weight: bold', 'Failed to load distribution index.')
|
||||
console.err(err)
|
||||
})
|
||||
|
||||
// Clean up temp dir incase previous launches ended unexpectedly.
|
||||
rimraf(path.join(os.tmpdir(), ConfigManager.getTempNativeFolder()), (err) => {
|
||||
|
||||
@@ -132,7 +132,8 @@ function updateSelectedServer(serverName){
|
||||
}
|
||||
server_selection_button.innerHTML = '\u2022 ' + serverName
|
||||
}
|
||||
updateSelectedServer(AssetGuard.getServerById(ConfigManager.getGameDirectory(), ConfigManager.getSelectedServer()).name)
|
||||
// Real text is set in uibinder.js on distributionIndexDone.
|
||||
updateSelectedServer('Loading..')
|
||||
server_selection_button.addEventListener('click', (e) => {
|
||||
e.target.blur()
|
||||
toggleServerSelection(true)
|
||||
@@ -198,7 +199,7 @@ const refreshServerStatus = async function(fade = false){
|
||||
}
|
||||
|
||||
refreshMojangStatuses()
|
||||
refreshServerStatus()
|
||||
// Server Status is refreshed in uibinder.js on distributionIndexDone.
|
||||
|
||||
// Set refresh rate to once every 5 minutes.
|
||||
let mojangStatusListener = setInterval(() => refreshMojangStatuses(true), 300000)
|
||||
@@ -220,6 +221,7 @@ function asyncSystemScan(launchAfter = true){
|
||||
// Fork a process to run validations.
|
||||
sysAEx = cp.fork(path.join(__dirname, 'assets', 'js', 'assetexec.js'), [
|
||||
ConfigManager.getGameDirectory(),
|
||||
ConfigManager.getLauncherDirectory(),
|
||||
ConfigManager.getJavaExecutable()
|
||||
])
|
||||
|
||||
@@ -388,6 +390,7 @@ function dlAsync(login = true){
|
||||
// Start AssetExec to run validations and downloads in a forked process.
|
||||
aEx = cp.fork(path.join(__dirname, 'assets', 'js', 'assetexec.js'), [
|
||||
ConfigManager.getGameDirectory(),
|
||||
ConfigManager.getLauncherDirectory(),
|
||||
ConfigManager.getJavaExecutable()
|
||||
])
|
||||
|
||||
@@ -542,7 +545,7 @@ function dlAsync(login = true){
|
||||
proc.stdout.on('data', gameStateChange)
|
||||
|
||||
// Init Discord Hook
|
||||
const distro = AssetGuard.retrieveDistributionDataSync(ConfigManager.getGameDirectory)
|
||||
const distro = AssetGuard.retrieveDistributionDataSync(ConfigManager.getLauncherDirectory())
|
||||
if(distro.discord != null && serv.discord != null){
|
||||
DiscordWrapper.initRPC(distro.discord, serv.discord)
|
||||
hasRPC = true
|
||||
|
||||
@@ -160,7 +160,7 @@ function setServerListingHandlers(){
|
||||
}
|
||||
|
||||
function populateServerListings(){
|
||||
const distro = AssetGuard.retrieveDistributionDataSync(ConfigManager.getGameDirectory())
|
||||
const distro = AssetGuard.retrieveDistributionDataSync(ConfigManager.getLauncherDirectory())
|
||||
const giaSel = ConfigManager.getSelectedServer()
|
||||
const servers = distro.servers
|
||||
let htmlString = ``
|
||||
|
||||
@@ -6,14 +6,18 @@
|
||||
const path = require('path')
|
||||
const ConfigManager = require(path.join(__dirname, 'assets', 'js', 'configmanager.js'))
|
||||
|
||||
let rscShouldLoad = false
|
||||
|
||||
// Synchronous Listener
|
||||
document.addEventListener('readystatechange', function(){
|
||||
|
||||
if (document.readyState === 'complete'){
|
||||
if(ConfigManager.isFirstLaunch()){
|
||||
$('#welcomeContainer').fadeIn(500)
|
||||
} else {
|
||||
$('#landingContainer').fadeIn(500)
|
||||
if(rscShouldLoad){
|
||||
if(ConfigManager.isFirstLaunch()){
|
||||
$('#welcomeContainer').fadeIn(500)
|
||||
} else {
|
||||
$('#landingContainer').fadeIn(500)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,3 +25,18 @@ document.addEventListener('readystatechange', function(){
|
||||
|
||||
}*/
|
||||
}, false)
|
||||
|
||||
// Actions that must be performed after the distribution index is downloaded.
|
||||
ipcRenderer.on('distributionIndexDone', (data) => {
|
||||
updateSelectedServer(AssetGuard.getServerById(ConfigManager.getLauncherDirectory(), ConfigManager.getSelectedServer()).name)
|
||||
refreshServerStatus()
|
||||
if(document.readyState === 'complete'){
|
||||
if(ConfigManager.isFirstLaunch()){
|
||||
$('#welcomeContainer').fadeIn(500)
|
||||
} else {
|
||||
$('#landingContainer').fadeIn(500)
|
||||
}
|
||||
} else {
|
||||
rscShouldLoad = true
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user