Starting work on forge downloads

legacy
Daniel Scalzi 2017-05-21 01:06:01 -04:00
parent bd503f71c8
commit 247f63d64d
3 changed files with 84 additions and 20 deletions

View File

@ -160,16 +160,15 @@ const instance = new AssetGuard()
/**
* Resolve an artifact id into a path. For example, on windows
* net.minecraftforge:forge:1.11.2-13.20.0.2282
* becomes
* 'net.minecraftforge:forge:1.11.2-13.20.0.2282', '.jar' becomes
* net\minecraftforge\forge\1.11.2-13.20.0.2282\forge-1.11.2-13.20.0.2282.jar
*
* @param {String} artifact - the artifact id string.
* @param {String} extension - the extension of the file at the resolved path.
* @returns {String} - the resolved relative path from the artifact id.
*/
function _resolvePath(artifact, extension){
let ps = artifact.split(':')
function _resolvePath(artifactid, extension){
let ps = artifactid.split(':')
let cs = ps[0].split('.')
cs.push(ps[1])
@ -294,7 +293,6 @@ function _validateForgeJar(buf, checksums){
function _extractPackXZ(filePath){
return new Promise(function(fulfill, reject){
const libPath = path.join(__dirname, '..', 'libraries', 'java', 'PackXZExtract.jar')
console.log(libPath)
const child = child_process.spawn('C:\\Program Files\\Java\\jre1.8.0_131\\bin\\javaw.exe', ['-jar', libPath, '-packxz', filePath])
child.stdout.on('data', (data) => {
console.log('minecraft:', data.toString('utf8'))
@ -589,15 +587,74 @@ function validateLogConfig(versionData, basePath){
})
}
function validateForge(){
function validateDistribution(serverpackid, basePath){
return new Promise(function(fulfill, reject){
let distroindex = _chainValidateDistributionIndex(basePath).then((value) => {
let servers = value.servers
let serv = null
for(let i=0; i<servers.length; i++){
if(servers[i].id === serverpackid){
serv = servers[i]
break
}
}
instance.forge = _parseDistroModules(serv.modules, basePath, serv.mc_version)
instance.totaldlsize += instance.forge.dlsize*1
fulfill()
})
})
}
function _validateForgeAssets(forgePath){
//TODO The distro index should be downloaded in the 'pre-loader'. This is because
//we will eventually NEED the index to generate the server list on the ui.
function _chainValidateDistributionIndex(basePath){
return new Promise(function(fulfill, reject){
//const distroURL = 'http://mc.westeroscraft.com/WesterosCraftLauncher/westeroscraft.json'
const targetFile = path.join(basePath, 'westeroscraft.json')
//TEMP WORKAROUND TO TEST WHILE THIS IS NOT HOSTED
fs.readFile(path.join(basePath, '..', 'app', 'assets', 'westeroscraft.json'), 'utf-8', (err, data) => {
fulfill(JSON.parse(data))
})
})
}
function _parseDistroModules(modules, basePath, version){
let alist = []
let asize = 0;
for(let i=0; i<modules.length; i++){
let ob = modules[i]
let obType = ob.type
let obArtifact = ob.artifact
let obPath = obArtifact.path == null ? _resolvePath(ob.id, obArtifact.extension) : obArtifact.path
switch(obType){
case 'forge-hosted':
obPath = path.join(basePath, 'libraries', obPath)
break;
case 'library':
obPath = path.join(basePath, 'libraries', obPath)
break;
case 'forgemod':
obPath = path.join(basePath, 'mods', obPath)
break;
case 'litemod':
obPath = path.join(basePath, 'mods', version, obPath)
break;
default:
obPath = path.join(basePath, obPath)
}
let artifact = new Asset(ob.id, obArtifact.MD5, obArtifact.size, obArtifact.url, obPath)
asize += artifact.size*1
alist.push(artifact)
if(ob.sub_modules != null){
let dltrack = _parseDistroModules(ob.sub_modules, basePath, version)
asize += dltrack.dlsize
alist = alist.concat(dltrack.dlqueue)
}
}
return new DLTracker(alist, asize)
}
/**
* This function will initiate the download processed for the specified identifiers. If no argument is
@ -609,7 +666,7 @@ function _validateForgeAssets(forgePath){
*
* @param {Array.<{id: string, limit: number}>} identifiers - optional. The identifiers to process and corresponding parallel async task limit.
*/
function processDlQueues(identifiers = [{id:'assets', limit:20}, {id:'libraries', limit:5}, {id:'files', limit:5}]){
function processDlQueues(identifiers = [{id:'assets', limit:20}, {id:'libraries', limit:5}, {id:'files', limit:5}, {id:'forge', limit:5}]){
this.progress = 0;
let win = remote.getCurrentWindow()
@ -634,5 +691,6 @@ module.exports = {
processDlQueues,
instance,
Asset,
Library
Library,
validateDistribution
}

View File

@ -39,10 +39,13 @@ $(document).on('ready', function(){
/* Open web links in the user's default browser. */
$(document).on('click', 'a[href^="http"]', function(event) {
event.preventDefault();
//testdownloads()
shell.openExternal(this.href)
testdownloads()
//console.log(os.homedir())
//shell.openExternal(this.href)
});
testdownloads = async function(){
const lp = require(path.join(__dirname, 'assets', 'js', 'launchprocess.js'))
const basePath = path.join(__dirname, '..', 'mcfiles')
@ -53,8 +56,10 @@ testdownloads = async function(){
console.log('libs done')
await ag.validateMiscellaneous(versionData, basePath)
console.log('files done')
await ag.validateDistribution('WesterosCraft-1.11.2', basePath)
console.log('forge stuff done')
ag.instance.on('dlcomplete', function(){
lp.launchMinecraft(versionData, basePath)
//lp.launchMinecraft(versionData, basePath)
})
ag.processDlQueues()
}
@ -78,6 +83,7 @@ document.addEventListener('keydown', function (e) {
break
case match[3]:
if(at === 3) ++at
break
case match[4]:
if(at === 4) ++at
break

View File

@ -4,11 +4,11 @@
{
"id": "WesterosCraft-1.11.2",
"name": "WesterosCraft Production Client",
"news-feed": "http://www.westeroscraft.com/api/rss.php?preset_id=12700544",
"icon-url": "http://mc.westeroscraft.com/WesterosCraftLauncher/files/server-prod.png",
"news_feed": "http://www.westeroscraft.com/api/rss.php?preset_id=12700544",
"icon_url": "http://mc.westeroscraft.com/WesterosCraftLauncher/files/server-prod.png",
"revision": "0.0.1",
"server-ip": "mc.westeroscraft.com:4444",
"mc-version": "1.11.2",
"server_ip": "mc.westeroscraft.com:4444",
"mc_version": "1.11.2",
"autoconnect": true,
"modules": [
{
@ -21,7 +21,7 @@
"extension": ".jar",
"url": "http://files.minecraftforge.net/maven/net/minecraftforge/forge/1.11.2-13.20.0.2282/forge-1.11.2-13.20.0.2282-universal.jar"
},
"sub-modules": [
"sub_modules": [
{
"id": "net.minecraft:launchwrapper:1.12",
"name": "Mojang (LaunchWrapper)",
@ -210,7 +210,7 @@
}
},
{
"id": "net.minecraftforge.MercuriusUpdater:1.11.2",
"id": "net.minecraftforge:MercuriusUpdater:1.11.2",
"name": "MercuriusUpdater 1.11.2",
"type": "library",
"artifact": {
@ -289,7 +289,7 @@
"path": "mod_chatBubbles-1.0.1_for_1.11.2.litemod",
"url": "http://mc.westeroscraft.com/WesterosCraftLauncher/files/1.11.2/mod_chatBubbles-1.0.1_for_1.11.2.litemod"
},
"sub-modules": [
"sub_modules": [
{
"id": "customRegexes",
"name": "Custom Regexes for Chat Bubbles",