Added hash validation for distro index, updated hashes.

This commit is contained in:
Daniel Scalzi 2017-05-21 16:27:11 -04:00
parent daa5abd5bd
commit d00f09aaf0
3 changed files with 35 additions and 29 deletions

View File

@ -114,16 +114,12 @@ class Library extends Asset{
* about a download queue, including the queue itself. * about a download queue, including the queue itself.
*/ */
class DLTracker { class DLTracker {
/**
* @typedef {function(Asset)} assetComplete
*/
/** /**
* Create a DLTracker * Create a DLTracker
* *
* @param {Array.<Asset>} dlqueue - an array containing assets queued for download. * @param {Array.<Asset>} dlqueue - an array containing assets queued for download.
* @param {Number} dlsize - the combined size of each asset in the download queue array. * @param {Number} dlsize - the combined size of each asset in the download queue array.
* @param {assetComplete} callback - optional callback which is called when an asset finishes downloading. * @param {function(Asset)} callback - optional callback which is called when an asset finishes downloading.
*/ */
constructor(dlqueue, dlsize, callback = null){ constructor(dlqueue, dlsize, callback = null){
this.dlqueue = dlqueue this.dlqueue = dlqueue
@ -224,6 +220,10 @@ function _parseChecksumsFile(content){
* @returns {Boolean} - true if the file exists and calculated hash matches the given hash, otherwise false. * @returns {Boolean} - true if the file exists and calculated hash matches the given hash, otherwise false.
*/ */
function _validateLocal(filePath, algo, hash){ function _validateLocal(filePath, algo, hash){
//No hash provided, have to assume it's good.
if(hash == null){
return true
}
if(fs.existsSync(filePath)){ if(fs.existsSync(filePath)){
let fileName = path.basename(filePath) let fileName = path.basename(filePath)
let buf = fs.readFileSync(filePath) let buf = fs.readFileSync(filePath)
@ -356,7 +356,7 @@ function startAsyncProcess(identifier, limit = 5){
req.resume() req.resume()
} else { } else {
req.abort() req.abort()
console.log('Failed to download ' + asset.from + '. Response code ', resp.statusCode) console.log('Failed to download ' + asset.from + '. Response code', resp.statusCode)
instance.progress += asset.size*1 instance.progress += asset.size*1
win.setProgressBar(instance.progress/instance.totaldlsize) win.setProgressBar(instance.progress/instance.totaldlsize)
cb() cb()
@ -638,11 +638,12 @@ function validateDistribution(serverpackid, basePath){
instance.forge = _parseDistroModules(serv.modules, basePath, serv.mc_version) instance.forge = _parseDistroModules(serv.modules, basePath, serv.mc_version)
//Correct our workaround here. //Correct our workaround here.
let decompressqueue = instance.forge.callback let decompressqueue = instance.forge.callback
instance.forge.callback = async function(asset){ instance.forge.callback = function(asset){
if(asset.to.toLowerCase().endsWith('.pack.xz')){ if(asset.to.toLowerCase().endsWith('.pack.xz')){
_extractPackXZ([asset.to]) _extractPackXZ([asset.to])
} }
} }
console.log(instance.forge)
instance.totaldlsize += instance.forge.dlsize*1 instance.totaldlsize += instance.forge.dlsize*1
fulfill() fulfill()
}) })
@ -690,11 +691,16 @@ function _parseDistroModules(modules, basePath, version){
obPath = path.join(basePath, obPath) obPath = path.join(basePath, obPath)
} }
let artifact = new Asset(ob.id, obArtifact.MD5, obArtifact.size, obArtifact.url, obPath) let artifact = new Asset(ob.id, obArtifact.MD5, obArtifact.size, obArtifact.url, obPath)
if(obPath.toLowerCase().endsWith('.pack.xz')){
if(!_validateLocal(obPath.substring(0, obPath.toLowerCase().lastIndexOf('.pack.xz')), 'MD5', artifact.hash)){
asize += artifact.size*1 asize += artifact.size*1
alist.push(artifact) alist.push(artifact)
if(obPath.toLowerCase().endsWith('.pack.xz')){
decompressqueue.push(obPath) decompressqueue.push(obPath)
} }
} else if(!_validateLocal(obPath, 'MD5', artifact.hash)){
asize += artifact.size*1
alist.push(artifact)
}
if(ob.sub_modules != null){ if(ob.sub_modules != null){
let dltrack = _parseDistroModules(ob.sub_modules, basePath, version) let dltrack = _parseDistroModules(ob.sub_modules, basePath, version)
asize += dltrack.dlsize*1 asize += dltrack.dlsize*1

View File

@ -39,9 +39,9 @@ $(document).on('ready', function(){
/* Open web links in the user's default browser. */ /* Open web links in the user's default browser. */
$(document).on('click', 'a[href^="http"]', function(event) { $(document).on('click', 'a[href^="http"]', function(event) {
event.preventDefault(); event.preventDefault();
//testdownloads() testdownloads()
//console.log(os.homedir()) //console.log(os.homedir())
shell.openExternal(this.href) //shell.openExternal(this.href)
}); });
@ -59,7 +59,7 @@ testdownloads = async function(){
await ag.validateDistribution('WesterosCraft-1.11.2', basePath) await ag.validateDistribution('WesterosCraft-1.11.2', basePath)
console.log('forge stuff done') console.log('forge stuff done')
ag.instance.on('dlcomplete', function(){ ag.instance.on('dlcomplete', function(){
lp.launchMinecraft(versionData, basePath) //lp.launchMinecraft(versionData, basePath)
}) })
ag.processDlQueues() ag.processDlQueues()
} }

View File

@ -50,7 +50,7 @@
"type": "library", "type": "library",
"artifact": { "artifact": {
"size": 1474672, "size": 1474672,
"MD5": "f2d0c1ce6ab76531bbd48acbcd3d4ff1", "MD5": "379c15c4f724421c6d5d7aecedaf87a6",
"extension": ".jar.pack.xz", "extension": ".jar.pack.xz",
"url": "http://mc.westeroscraft.com/WesterosCraftLauncher/files/1.11.2/scala-library-2.11.1.jar.pack.xz" "url": "http://mc.westeroscraft.com/WesterosCraftLauncher/files/1.11.2/scala-library-2.11.1.jar.pack.xz"
} }
@ -61,7 +61,7 @@
"type": "library", "type": "library",
"artifact": { "artifact": {
"size": 3076920, "size": 3076920,
"MD5": "9c88616e35796955e0ff1235b11f1475", "MD5": "7d89e952f2d5c74577310cd2c28e3f20",
"extension": ".jar.pack.xz", "extension": ".jar.pack.xz",
"url": "http://mc.westeroscraft.com/WesterosCraftLauncher/files/1.11.2/scala-compiler-2.11.1.jar.pack.xz" "url": "http://mc.westeroscraft.com/WesterosCraftLauncher/files/1.11.2/scala-compiler-2.11.1.jar.pack.xz"
} }
@ -72,7 +72,7 @@
"type": "library", "type": "library",
"artifact": { "artifact": {
"size": 21324, "size": 21324,
"MD5": "55e0dc48a2a122353628a463b9499cf0", "MD5": "04e3428b2600ace33c7ae2bf1f6c0a4c",
"extension": ".jar.pack.xz", "extension": ".jar.pack.xz",
"url": "http://mc.westeroscraft.com/WesterosCraftLauncher/files/1.11.2/scala-actors-migration_2.11-1.1.0.jar.pack.xz" "url": "http://mc.westeroscraft.com/WesterosCraftLauncher/files/1.11.2/scala-actors-migration_2.11-1.1.0.jar.pack.xz"
} }
@ -83,7 +83,7 @@
"type": "library", "type": "library",
"artifact": { "artifact": {
"size": 7956, "size": 7956,
"MD5": "820008ee6df308dafa0a6c478270aa19", "MD5": "ed9b1d27aba8ac4090a3749c4dfc895a",
"extension": ".jar.pack.xz", "extension": ".jar.pack.xz",
"url": "http://mc.westeroscraft.com/WesterosCraftLauncher/files/1.11.2/scala-continuations-library_2.11-1.0.2.jar.pack.xz" "url": "http://mc.westeroscraft.com/WesterosCraftLauncher/files/1.11.2/scala-continuations-library_2.11-1.0.2.jar.pack.xz"
} }
@ -94,7 +94,7 @@
"type": "library", "type": "library",
"artifact": { "artifact": {
"size": 46140, "size": 46140,
"MD5": "657a7ad23928bf4bee68202c7d7e1d56", "MD5": "a8232db22a72a981de6b1399eb86dff7",
"extension": ".jar.pack.xz", "extension": ".jar.pack.xz",
"url": "http://mc.westeroscraft.com/WesterosCraftLauncher/files/1.11.2/scala-continuations-plugin_2.11.1-1.0.2.jar.pack.xz" "url": "http://mc.westeroscraft.com/WesterosCraftLauncher/files/1.11.2/scala-continuations-plugin_2.11.1-1.0.2.jar.pack.xz"
} }
@ -105,7 +105,7 @@
"type": "library", "type": "library",
"artifact": { "artifact": {
"size": 85568, "size": 85568,
"MD5": "de496467c91610e55e6e711b6bdbf10c", "MD5": "2e50a7df17680daadacca69f07f8a16d",
"extension": ".jar.pack.xz", "extension": ".jar.pack.xz",
"url": "http://mc.westeroscraft.com/WesterosCraftLauncher/files/1.11.2/scala-parser-combinators_2.11-1.0.1.jar.pack.xz" "url": "http://mc.westeroscraft.com/WesterosCraftLauncher/files/1.11.2/scala-parser-combinators_2.11-1.0.1.jar.pack.xz"
} }
@ -116,7 +116,7 @@
"type": "library", "type": "library",
"artifact": { "artifact": {
"size": 1070312, "size": 1070312,
"MD5": "abbdaf710e856f6e65376706c9505952", "MD5": "84e5dc81c10e2bd74c579c9d0332fdd9",
"extension": ".jar.pack.xz", "extension": ".jar.pack.xz",
"url": "http://mc.westeroscraft.com/WesterosCraftLauncher/files/1.11.2/scala-reflect-2.11.1.jar.pack.xz" "url": "http://mc.westeroscraft.com/WesterosCraftLauncher/files/1.11.2/scala-reflect-2.11.1.jar.pack.xz"
} }
@ -138,7 +138,7 @@
"type": "library", "type": "library",
"artifact": { "artifact": {
"size": 217812, "size": 217812,
"MD5": "1c5a20efca1474626e0e0123f9cdd8ce", "MD5": "cc891b094a4c32dedc56bfefe9b072ff",
"extension": ".jar.pack.xz", "extension": ".jar.pack.xz",
"url": "http://mc.westeroscraft.com/WesterosCraftLauncher/files/1.11.2/scala-xml_2.11-1.0.2.jar.pack.xz" "url": "http://mc.westeroscraft.com/WesterosCraftLauncher/files/1.11.2/scala-xml_2.11-1.0.2.jar.pack.xz"
} }
@ -149,7 +149,7 @@
"type": "library", "type": "library",
"artifact": { "artifact": {
"size": 746612, "size": 746612,
"MD5": "469367f3308e571b1bdf2192d7779807", "MD5": "25cb22c3078e9fb3f7a861c912924862",
"extension": ".jar.pack.xz", "extension": ".jar.pack.xz",
"url": "http://mc.westeroscraft.com/WesterosCraftLauncher/files/1.11.2/akka-actor_2.11-2.3.3.jar.pack.xz" "url": "http://mc.westeroscraft.com/WesterosCraftLauncher/files/1.11.2/akka-actor_2.11-2.3.3.jar.pack.xz"
} }
@ -160,7 +160,7 @@
"type": "library", "type": "library",
"artifact": { "artifact": {
"size": 56636, "size": 56636,
"MD5": "f24b281c40daef1280d5ef26b11caa63", "MD5": "10ec4ccabc4e68aac9cf87165ead5d7d",
"extension": ".jar.pack.xz", "extension": ".jar.pack.xz",
"url": "http://mc.westeroscraft.com/WesterosCraftLauncher/files/1.11.2/config-1.2.1.jar.pack.xz" "url": "http://mc.westeroscraft.com/WesterosCraftLauncher/files/1.11.2/config-1.2.1.jar.pack.xz"
} }
@ -215,7 +215,7 @@
"type": "library", "type": "library",
"artifact": { "artifact": {
"size": 15146, "size": 15146,
"MD5": "13560a58a79b46b82057686543e8d727", "MD5": "7556d06064ebbfa3b334a15092d725d0",
"extension": ".jar", "extension": ".jar",
"url": "http://mc.westeroscraft.com/WesterosCraftLauncher/files/1.11.2/MercuriusUpdater-1.11.2.jar" "url": "http://mc.westeroscraft.com/WesterosCraftLauncher/files/1.11.2/MercuriusUpdater-1.11.2.jar"
} }
@ -228,7 +228,7 @@
"type": "forgemod", "type": "forgemod",
"artifact": { "artifact": {
"size": 2050500, "size": 2050500,
"MD5": "c18c80f8bfa2a440cc5af4ab8816bc4b", "MD5": "cf4da33e1014b1b77fea17d64668aff6",
"path": "OptiFine-1.11.2_HD_U_B8.jar", "path": "OptiFine-1.11.2_HD_U_B8.jar",
"url": "http://optifine.net/download.php?f=OptiFine_1.11.2_HD_U_B8.jar" "url": "http://optifine.net/download.php?f=OptiFine_1.11.2_HD_U_B8.jar"
} }
@ -239,18 +239,18 @@
"type": "forgemod", "type": "forgemod",
"artifact": { "artifact": {
"size": 16230253, "size": 16230253,
"MD5": "2a71c13afd289d15c9f95a23712b095d", "MD5": "2e3ea10730720b8abbf408262d922249",
"path": "WesterosBlocks.jar", "path": "WesterosBlocks.jar",
"url": "http://mc.westeroscraft.com/WesterosCraftLauncher/test-1.11.2/mods/WesterosBlocks.jar" "url": "http://mc.westeroscraft.com/WesterosCraftLauncher/test-1.11.2/mods/WesterosBlocks.jar"
} }
}, },
{ {
"id": "com.westeroscraft:westeroscraftrp:2017-03-21", "id": "com.westeroscraft:westeroscraftrp:2017-05-20",
"name": "WesterosCraft Resource Pack (2017-03-21)", "name": "WesterosCraft Resource Pack (2017-05-20)",
"type": "file", "type": "file",
"artifact": { "artifact": {
"size": 44704858, "size": 44704858,
"MD5": "1b5dd219a21bda8cd0fb8f7ee986515a", "MD5": "a2e552df2d5f7f6d6d34f3afe5674670",
"path": "resourcepacks/WesterosCraft.zip", "path": "resourcepacks/WesterosCraft.zip",
"url": "http://mc.westeroscraft.com/WesterosCraftLauncher/test-1.11.2/resourcepacks/WesterosCraft.zip" "url": "http://mc.westeroscraft.com/WesterosCraftLauncher/test-1.11.2/resourcepacks/WesterosCraft.zip"
} }