Beginning work on asset downloads

This commit is contained in:
Daniel Scalzi 2017-04-23 15:24:07 -04:00
parent b30707e535
commit d37857a979
4 changed files with 51 additions and 4 deletions

1
.gitignore vendored
View File

@ -1,3 +1,4 @@
/node_modules/ /node_modules/
/.vs/ /.vs/
/.vscode/ /.vscode/
/mcfiles/

View File

@ -0,0 +1,43 @@
const fs = require('fs')
const request = require('request')
const path = require('path')
var mkpath = require('mkdirp');
function Asset(from, to, size){
this.from = from
this.to = to
this.size = size
}
exports.getMojangAssets = function(version, basePath){
const name = version + '.json'
const indexURL = 'https://s3.amazonaws.com/Minecraft.Download/indexes/' + name
const resourceURL = 'http://resources.download.minecraft.net/'
const localPath = path.join(basePath, 'assets')
const indexPath = path.join(localPath, 'indexes')
const objectPath = path.join(localPath, 'objects')
request.head(indexURL, function (err, res, body) {
console.log('Downloading ' + version + ' asset index.')
mkpath.sync(indexPath)
let stream = request(indexURL).pipe(fs.createWriteStream(path.join(indexPath, name)))
stream.on('finish', function() {
let data = JSON.parse(fs.readFileSync(path.join(indexPath, name), 'utf-8'))
let assetArr = []
Object.keys(data['objects']).forEach(function(key, index){
let ob = data['objects'][key]
let hash = String(ob['hash'])
let assetName = path.join(hash.substring(0, 2), hash)
let urlName = hash.substring(0, 2) + "/" + hash
let ast = new Asset(resourceURL + urlName, path.join(objectPath, assetName), ob['size'])
assetArr.push(ast)
})
assetArr.forEach(function(item, index){
mkpath.sync(path.join(item.to, ".."))
console.log("downloading asset from " + item.from + " to " + item.to)
request(item.from).pipe(fs.createWriteStream(item.to))
})
})
})
}

View File

@ -17,6 +17,9 @@ function createWindow() {
win.setMenu(null) win.setMenu(null)
//Code for testing, marked for removal one it's properly implemented.
//require('./app/assets/js/assetdownload.js').getMojangAssets('1.11', path.join(__dirname, 'mcfiles'))
win.on('closed', () => { win.on('closed', () => {
win = null win = null
}) })

View File

@ -8,14 +8,14 @@
}, },
"repository": { "repository": {
"type": "git", "type": "git",
"url": "git+https://gitlab.com/westeroscraft/Active-Electron-Launcher.git" "url": "git+https://gitlab.com/westeroscraft/electronlauncher.git"
}, },
"author": "TheKraken7, Matan, Nightmare", "author": "TheKraken7, Matan, Nightmare",
"license": "AGPL-3.0", "license": "AGPL-3.0",
"bugs": { "bugs": {
"url": "https://gitlab.com/westeroscraft/Active-Electron-Launcher/issues" "url": "https://gitlab.com/westeroscraft/electronlauncher/issues"
}, },
"homepage": "https://gitlab.com/westeroscraft/Active-Electron-Launcher#README", "homepage": "http://www.westeroscraft.com/",
"devDependencies": { "devDependencies": {
"electron": "^1.6.5", "electron": "^1.6.5",
"mojang": "^0.4.0" "mojang": "^0.4.0"