diff --git a/.gitignore b/.gitignore index c96f02a..4e3ba74 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ /node_modules/ /.vs/ -/.vscode/ \ No newline at end of file +/.vscode/ +/mcfiles/ \ No newline at end of file diff --git a/app/assets/js/assetdownload.js b/app/assets/js/assetdownload.js new file mode 100644 index 0000000..7f681cf --- /dev/null +++ b/app/assets/js/assetdownload.js @@ -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)) + + }) + }) + }) +} \ No newline at end of file diff --git a/index.js b/index.js index 498b177..47af155 100644 --- a/index.js +++ b/index.js @@ -17,6 +17,9 @@ function createWindow() { 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 = null }) diff --git a/package.json b/package.json index cad6236..746d40c 100644 --- a/package.json +++ b/package.json @@ -8,14 +8,14 @@ }, "repository": { "type": "git", - "url": "git+https://gitlab.com/westeroscraft/Active-Electron-Launcher.git" + "url": "git+https://gitlab.com/westeroscraft/electronlauncher.git" }, "author": "TheKraken7, Matan, Nightmare", "license": "AGPL-3.0", "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": { "electron": "^1.6.5", "mojang": "^0.4.0"