From dd9e1418c89e2c1fdf2d87ddf893ef0860769b12 Mon Sep 17 00:00:00 2001 From: Daniel Scalzi Date: Mon, 27 Nov 2017 04:31:54 -0500 Subject: [PATCH] Added progress tracking to landing page. Fixed exclusions when extracting native files, fixed minor issue with config manager, optimizations and improvements to assetguard. --- .gitignore | 3 +- app/assets/css/launcher.css | 149 ++++++++++++++++++++++++++++++++ app/assets/js/assetguard.js | 17 ++-- app/assets/js/configmanager.js | 2 + app/assets/js/processbuilder.js | 2 +- app/assets/js/script.js | 54 ++++++++++-- app/index.ejs | 12 +++ 7 files changed, 223 insertions(+), 16 deletions(-) diff --git a/.gitignore b/.gitignore index 08377b7..534c984 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ /node_modules/ /.vs/ /.vscode/ -/target/ \ No newline at end of file +/target/ +/logs/ \ No newline at end of file diff --git a/app/assets/css/launcher.css b/app/assets/css/launcher.css index 0fed7b3..c0273a5 100644 --- a/app/assets/css/launcher.css +++ b/app/assets/css/launcher.css @@ -9,11 +9,24 @@ body, html, div { padding: 0px; } +/* Reset p presets. */ +p { + -webkit-margin-before: 0em; + -webkit-margin-after: 0em; +} + + /*body { background: url('./../images/backgrounds/0.jpg') no-repeat center center fixed; background-size: cover; }*/ +/******************************************************************************* + * * + * frame.ejs * + * * + ******************************************************************************/ + #frame_bar { -webkit-app-region: drag; -webkit-user-select: none; @@ -21,6 +34,8 @@ body, html, div { min-height: 22px; display: flex; align-items: center; + position: relative; + z-index: 10000; } #frame_btn_dock { @@ -65,6 +80,93 @@ body, html, div { background-color: #D6FFA6; } +/******************************************************************************* + * * + * login.ejs * + * * + ******************************************************************************/ + +#login_main { + position: relative; + height: calc(100% - 22px); + width: 100%; + overflow: hidden; +} + +#login_filter { + height: calc(100% - 22px); + width: 100%; + z-index: 9000; + position: absolute; + filter: blur(8px) contrast(0.9) brightness(1.0); + background: url('./../images/backgrounds/0.jpg') no-repeat center center fixed; + transform: scale(1.2); + background-size: cover; +} + +#login_container { + height: 100%; + position: relative; + display: flex; + justify-content: center; + z-index: 9001; +} + +#login_content { + width: 400px; + display: flex; + flex-direction: column; + align-items: center; +} + +#login_image_seal { + height: 150px; + width: auto; +} + +.login_section { + display: flex; + flex-direction: column; + align-items: center; + padding: 5px; +} + +/* Adds padding between flex children */ +.login_section > * { + margin-bottom: 10px; +} +.login_section > *:last-child { + margin-bottom: 0px !important; +} + +#login_header_text { + font-family: 'Avenir Book'; + color: #ded8cb; +} + +#login_links a { + color: #5a534b; + font-family: 'Avenir Book'; + font-size: 10px; + text-decoration: none; +} + +#login_information input { + background: none; + border: none; + border-top: 2px solid #fff; +} + +/*#login_information input[type='password'] { + letter-spacing: 0.3em; +}*/ + +/******************************************************************************* + * * + * index.ejs * + * * + ******************************************************************************/ + #main { height: calc(100% - 22px); } @@ -132,6 +234,13 @@ body, html, div { display: inline-flex; } +#main > #lower > #right #launch_content { + position: relative; + top: 25px; + display: inline-flex; + line-height: 24px; +} + #image_seal { height: 70px; width: auto; @@ -242,6 +351,7 @@ body, html, div { color: white; font-family: 'Avenir Book'; font-size: 9px; + letter-spacing: 1px; font-weight: bold; text-shadow: 0px 0px 0px #bebcbb; } @@ -289,4 +399,43 @@ body, html, div { font-size: 11px; line-height: 30px; display: flex; +} + +#launch_button { + font-family: 'Avenir Book'; + background: none; + border: none; + cursor: pointer; + color: #fff; + font-weight: 900; + letter-spacing: 2px; + text-shadow: 0px 0px 0px #bebcbb; + font-size: 20px; + padding: 0px; +} + +#launch_details { + position: relative; + top: 25px; + /*display: flex;*/ + display: none; + flex-direction: column; +} + +#launch_progress[value] { + height: 2px; + width: 265px; + -webkit-appearance: none; +} + +#launch_progress[value]::-webkit-progress-bar { + background-color: transparent; +} + +#launch_progress[value]::-webkit-progress-value { + background-color: #fff; +} + +#launch_details_text { + font-size: 5px; } \ No newline at end of file diff --git a/app/assets/js/assetguard.js b/app/assets/js/assetguard.js index 1d9e88b..f4631d8 100644 --- a/app/assets/js/assetguard.js +++ b/app/assets/js/assetguard.js @@ -410,15 +410,12 @@ function _finalizeForgeAsset(asset, basePath){ */ function startAsyncProcess(identifier, limit = 5){ let win = remote.getCurrentWindow() - let acc = 0 const concurrentDlTracker = instance[identifier] const concurrentDlQueue = concurrentDlTracker.dlqueue.slice(0) - console.log(concurrentDlQueue); if(concurrentDlQueue.length === 0){ return false } else { - console.log(concurrentDlQueue) async.eachLimit(concurrentDlQueue, limit, function(asset, cb){ let count = 0; mkpath.sync(path.join(asset.to, "..")) @@ -441,6 +438,7 @@ function startAsyncProcess(identifier, limit = 5){ console.log('Failed to download ' + asset.from + '. Response code', resp.statusCode) instance.progress += asset.size*1 win.setProgressBar(instance.progress/instance.totaldlsize) + instance.emit('totaldlprogress', {acc: instance.progress, total: instance.totaldlsize}) cb() } }) @@ -451,6 +449,7 @@ function startAsyncProcess(identifier, limit = 5){ instance.emit(identifier + 'dlprogress', acc) //console.log(identifier + ' Progress', acc/instance[identifier].dlsize) win.setProgressBar(instance.progress/instance.totaldlsize) + instance.emit('totaldlprogress', {acc: instance.progress, total: instance.totaldlsize}) }) }, function(err){ if(err){ @@ -592,7 +591,6 @@ function _assetChainValidateAssets(versionData, basePath, indexData){ cb() }, function(err){ instance.assets = new DLTracker(assetDlQueue, dlSize) - instance.totaldlsize += dlSize*1 fulfill() }) }) @@ -630,7 +628,6 @@ function validateLibraries(versionData, basePath){ cb() }, function(err){ instance.libraries = new DLTracker(libDlQueue, dlSize) - instance.totaldlsize += dlSize*1 fulfill() }) }) @@ -697,7 +694,7 @@ function validateLogConfig(versionData, basePath){ if(!_validateLocal(logConfig.to, 'sha1', logConfig.hash)){ instance.files.dlqueue.push(logConfig) - instance.files.dlsize += client.size*1 + instance.files.dlsize += logConfig.size*1 fulfill() } else { fulfill() @@ -735,7 +732,6 @@ function validateDistribution(serverpackid, basePath){ _finalizeForgeAsset(asset, basePath) } } - instance.totaldlsize += instance.forge.dlsize*1 fulfill(serv) }) }) @@ -863,6 +859,13 @@ function processDlQueues(identifiers = [{id:'assets', limit:20}, {id:'libraries' let shouldFire = true + // Assign global dltracking variables. + instance.totaldlsize = 0 + instance.progress = 0 + for(let i=0; i -1){ + if(fileName.indexOf(exclusion) > -1){ shouldExclude = true } }) diff --git a/app/assets/js/script.js b/app/assets/js/script.js index b76b218..376adbf 100644 --- a/app/assets/js/script.js +++ b/app/assets/js/script.js @@ -37,11 +37,14 @@ document.onreadystatechange = function () { window.minimize() }) - document.getElementById("menu_button").addEventListener('click', function(e){ - console.log('testing') + // Bind launch button + document.getElementById("launch_button").addEventListener('click', function(e){ + console.log('Launching game..') testdownloads() }) + // Bind progress bar length to length of bot wrapper + document.getElementById("launch_progress").style.width = document.getElementById("launch_content").getBoundingClientRect().width } } @@ -53,26 +56,63 @@ $(document).on('click', 'a[href^="http"]', function(event) { }) testdownloads = async function(){ - //const lp = require(path.join(__dirname, 'assets', 'js', 'launchprocess.js')) - let versionData = await ag.loadVersionData('1.11.2', GAME_DIRECTORY) + const details = document.getElementById("launch_details") + const progress = document.getElementById("launch_progress") + const det_text = document.getElementById("launch_details_text") + + det_text.innerHTML = 'Please wait..' + progress.setAttribute('max', '100') + details.style.display = 'flex' + + det_text.innerHTML = 'Loading version information..' + const versionData = await ag.loadVersionData('1.11.2', GAME_DIRECTORY) + progress.setAttribute('value', 20) + + det_text.innerHTML = 'Validating asset integrity..' await ag.validateAssets(versionData, GAME_DIRECTORY) + progress.setAttribute('value', 40) console.log('assets done') + + det_text.innerHTML = 'Validating library integrity..' await ag.validateLibraries(versionData, GAME_DIRECTORY) + progress.setAttribute('value', 60) console.log('libs done') + + det_text.innerHTML = 'Validating miscellaneous file integrity..' await ag.validateMiscellaneous(versionData, GAME_DIRECTORY) + progress.setAttribute('value', 80) console.log('files done') + + det_text.innerHTML = 'Validating server distribution files..' const serv = await ag.validateDistribution('WesterosCraft-1.11.2', GAME_DIRECTORY) + progress.setAttribute('value', 100) console.log('forge stuff done') + + det_text.innerHTML = 'Downloading files..' + ag.instance.on('totaldlprogress', function(data){ + progress.setAttribute('max', data.total) + progress.setAttribute('value', data.acc) + }) + ag.instance.on('dlcomplete', async function(){ + det_text.innerHTML = 'Preparing to launch..' const forgeData = await ag.loadForgeData('WesterosCraft-1.11.2', GAME_DIRECTORY) const authUser = await mojang.auth('EMAIL', 'PASS', DEFAULT_CONFIG.getClientToken(), { name: 'Minecraft', version: 1 }) - //lp.launchMinecraft(versionData, forgeData, GAME_DIRECTORY) - //lp.launchMinecraft(versionData, GAME_DIRECTORY) let pb = new ProcessBuilder(GAME_DIRECTORY, serv, versionData, forgeData, authUser) - const proc = pb.build() + det_text.innerHTML = 'Launching game..' + let proc; + try{ + proc = pb.build() + det_text.innerHTML = 'Done. Enjoy the server!' + } catch(err) { + det_text.innerHTML = 'Error while launching: ' + err.message; + } + setTimeout(function(){ + details.style.display = 'none' + }, 5000) }) ag.processDlQueues() } diff --git a/app/index.ejs b/app/index.ejs index 38f0769..e02b2e0 100644 --- a/app/index.ejs +++ b/app/index.ejs @@ -54,6 +54,18 @@