diff --git a/.gitignore b/.gitignore index 4e3ba74..df516ba 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ /node_modules/ /.vs/ /.vscode/ -/mcfiles/ \ No newline at end of file +/mcfiles/ +/logs/ \ No newline at end of file diff --git a/app/assets/js/assetdownload.js b/app/assets/js/assetdownload.js index e1d0724..12c991f 100644 --- a/app/assets/js/assetdownload.js +++ b/app/assets/js/assetdownload.js @@ -4,6 +4,7 @@ const path = require('path') const mkpath = require('mkdirp'); const async = require('async') const crypto = require('crypto') +const libary = require('./library.js') function Asset(from, to, size, hash){ this.from = from @@ -93,7 +94,7 @@ exports.downloadLibraries = function(versionData, basePath){ const libArr = versionData['libraries'] const libPath = path.join(basePath, 'libraries') async.eachLimit(libArr, 1, function(lib, cb){ - if(validateRules(lib['rules'])){ + if(library.validateRules(lib['rules'])){ if(lib['natives'] == null){ const dlInfo = lib['downloads'] const artifact = dlInfo['artifact'] @@ -119,7 +120,7 @@ exports.downloadLibraries = function(versionData, basePath){ } } else { const natives = lib['natives'] - const opSys = mojangFriendlyOS() + const opSys = library.mojangFriendlyOS() const indexId = natives[opSys] const dlInfo = lib['downloads'] const classifiers = dlInfo['classifiers'] @@ -238,41 +239,4 @@ validateLocalIntegrity = function(filePath, algo, hash){ } } return false; -} - -validateRules = function(rules){ - if(rules == null) return true - - let result = true - rules.forEach(function(rule){ - const action = rule['action'] - const osProp = rule['os'] - if(action != null){ - if(osProp != null){ - const osName = osProp['name'] - const osMoj = mojangFriendlyOS() - if(action === 'allow'){ - result = osName === osMoj - return - } else if(action === 'disallow'){ - result = osName !== osMoj - return - } - } - } - }) - return result -} - -mojangFriendlyOS = function(){ - const opSys = process.platform - if (opSys === 'darwin') { - return 'osx'; - } else if (opSys === 'win32'){ - return 'windows'; - } else if (opSys === 'linux'){ - return 'linux'; - } else { - return 'unknown_os'; - } } \ No newline at end of file diff --git a/app/assets/js/launchprocess.js b/app/assets/js/launchprocess.js index 7ac9eb6..863d9a8 100644 --- a/app/assets/js/launchprocess.js +++ b/app/assets/js/launchprocess.js @@ -2,6 +2,10 @@ const mojang = require('mojang') const uuidV4 = require('uuid/v4') const path = require('path') const child_process = require('child_process') +const library = require('./library.js') +const fs = require('fs') +const unzip = require('unzip') +const mkpath = require('mkdirp'); exports.launchMinecraft = function(versionData, basePath){ const authPromise = mojang.auth('EMAIL', 'PASS', uuidV4(), { @@ -11,8 +15,9 @@ exports.launchMinecraft = function(versionData, basePath){ authPromise.then(function(data){ const hardcodedargs = '' const args = finalizeArguments(versionData, data, basePath) - console.log(args) - const child = child_process.execFile(basePath) + //console.log(args) + //TODO make this dynamic + const child = child_process.spawn('C:\\Program Files\\Java\\jre1.8.0_131\\bin\\javaw.exe', args) }) } @@ -20,6 +25,15 @@ finalizeArguments = function(versionData, authData, basePath){ const mcArgs = versionData['minecraftArguments'] const regex = new RegExp('\\${*(.*)}') const argArr = mcArgs.split(' ') + argArr.unshift('net.minecraft.client.main.Main') + argArr.unshift(classpathArg(versionData, basePath)) + argArr.unshift('-cp') + argArr.unshift('-Djava.library.path=' + path.join(basePath, 'natives')) + argArr.unshift('-Xmn128M') + argArr.unshift('-XX:-UseAdaptiveSizePolicy') + argArr.unshift('-XX:+CMSIncrementalMode') + argArr.unshift('-XX:+UseConcMarkSweepGC') + argArr.unshift('-Xmx1G') for(let i=0; i -1){ + shouldExclude = true + } + }) + + if(shouldExclude){ + entry.autodrain() + } + else { + mkpath.sync(path.join(nativePath, fileName, '..')) + entry.pipe(fs.createWriteStream(path.join(nativePath, fileName))) + } + }) + + cpArgs.push(to) + } + } + }) + + return cpArgs.join(';') } \ No newline at end of file diff --git a/app/assets/js/library.js b/app/assets/js/library.js new file mode 100644 index 0000000..f4a58f5 --- /dev/null +++ b/app/assets/js/library.js @@ -0,0 +1,37 @@ + +exports.mojangFriendlyOS = function(){ + const opSys = process.platform + if (opSys === 'darwin') { + return 'osx'; + } else if (opSys === 'win32'){ + return 'windows'; + } else if (opSys === 'linux'){ + return 'linux'; + } else { + return 'unknown_os'; + } +} + +exports.validateRules = function(rules){ + if(rules == null) return true + + let result = true + rules.forEach(function(rule){ + const action = rule['action'] + const osProp = rule['os'] + if(action != null){ + if(osProp != null){ + const osName = osProp['name'] + const osMoj = exports.mojangFriendlyOS() + if(action === 'allow'){ + result = osName === osMoj + return + } else if(action === 'disallow'){ + result = osName !== osMoj + return + } + } + } + }) + return result +} \ No newline at end of file diff --git a/index.js b/index.js index 08bf782..c545d32 100644 --- a/index.js +++ b/index.js @@ -18,16 +18,16 @@ function createWindow() { win.setMenu(null) //Code for testing, marked for removal one it's properly implemented. - /*const assetdl = require('./app/assets/js/assetdownload.js') + const assetdl = require('./app/assets/js/assetdownload.js') const basePath = path.join(__dirname, 'mcfiles') const dataPromise = assetdl.parseVersionData('1.11.2', basePath) dataPromise.then(function(data){ - assetdl.downloadAssets(data, basePath) - assetdl.downloadClient(data, basePath) - assetdl.downloadLogConfig(data, basePath) - assetdl.downloadLibraries(data, basePath) - //require('./app/assets/js/launchprocess.js').launchMinecraft(data, basePath) - })*/ + //assetdl.downloadAssets(data, basePath) + //assetdl.downloadClient(data, basePath) + //assetdl.downloadLogConfig(data, basePath) + //assetdl.downloadLibraries(data, basePath) + require('./app/assets/js/launchprocess.js').launchMinecraft(data, basePath) + }) win.on('closed', () => { win = null diff --git a/package.json b/package.json index a53333a..a05bc9a 100644 --- a/package.json +++ b/package.json @@ -21,6 +21,7 @@ "electron": "^1.6.5", "mojang": "^0.4.0", "promise": "^7.1.1", + "unzip": "^0.1.11", "uuid": "^3.0.1" } }