Large update to AssetGuard to make the module purely object based. This fixed several issues which were present with the static implementation and seems to have increased performance. Several other bugs related to the front-end scripts have been fixed.

This commit is contained in:
Daniel Scalzi 2017-11-30 03:00:06 -05:00
parent 4c2c46f535
commit 52ab270ce3
4 changed files with 703 additions and 691 deletions

View File

@ -1,10 +1,10 @@
const mojang = require('mojang') const mojang = require('mojang')
const path = require('path') const path = require('path')
const AssetGuard = require(path.join(__dirname, 'assets', 'js', 'assetguard.js')) const {AssetGuard} = require(path.join(__dirname, 'assets', 'js', 'assetguard.js'))
const ProcessBuilder = require(path.join(__dirname, 'assets', 'js', 'processbuilder.js')) const ProcessBuilder = require(path.join(__dirname, 'assets', 'js', 'processbuilder.js'))
const {GAME_DIRECTORY, DEFAULT_CONFIG} = require(path.join(__dirname, 'assets', 'js', 'constants.js')) const {GAME_DIRECTORY, DEFAULT_CONFIG} = require(path.join(__dirname, 'assets', 'js', 'constants.js'))
document.onreadystatechange = function(){ document.addEventListener('readystatechange', function(){
if (document.readyState === 'interactive'){ if (document.readyState === 'interactive'){
// Bind launch button // Bind launch button
@ -14,7 +14,10 @@ document.onreadystatechange = function(){
}) })
} }
} }, false)
// Keep reference to AssetGuard object temporarily
let tracker;
testdownloads = async function(){ testdownloads = async function(){
const content = document.getElementById("launch_content") const content = document.getElementById("launch_content")
@ -28,45 +31,48 @@ testdownloads = async function(){
details.style.display = 'flex' details.style.display = 'flex'
content.style.display = 'none' content.style.display = 'none'
tracker = new AssetGuard()
det_text.innerHTML = 'Loading version information..' det_text.innerHTML = 'Loading version information..'
const versionData = await AssetGuard.loadVersionData('1.11.2', GAME_DIRECTORY) const versionData = await tracker.loadVersionData('1.11.2', GAME_DIRECTORY)
progress.setAttribute('value', 20) progress.setAttribute('value', 20)
progress_text.innerHTML = '20%' progress_text.innerHTML = '20%'
det_text.innerHTML = 'Validating asset integrity..' det_text.innerHTML = 'Validating asset integrity..'
await AssetGuard.validateAssets(versionData, GAME_DIRECTORY) await tracker.validateAssets(versionData, GAME_DIRECTORY)
progress.setAttribute('value', 40) progress.setAttribute('value', 40)
progress_text.innerHTML = '40%' progress_text.innerHTML = '40%'
console.log('assets done') console.log('assets done')
det_text.innerHTML = 'Validating library integrity..' det_text.innerHTML = 'Validating library integrity..'
await AssetGuard.validateLibraries(versionData, GAME_DIRECTORY) await tracker.validateLibraries(versionData, GAME_DIRECTORY)
progress.setAttribute('value', 60) progress.setAttribute('value', 60)
progress_text.innerHTML = '60%' progress_text.innerHTML = '60%'
console.log('libs done') console.log('libs done')
det_text.innerHTML = 'Validating miscellaneous file integrity..' det_text.innerHTML = 'Validating miscellaneous file integrity..'
await AssetGuard.validateMiscellaneous(versionData, GAME_DIRECTORY) await tracker.validateMiscellaneous(versionData, GAME_DIRECTORY)
progress.setAttribute('value', 80) progress.setAttribute('value', 80)
progress_text.innerHTML = '80%' progress_text.innerHTML = '80%'
console.log('files done') console.log('files done')
det_text.innerHTML = 'Validating server distribution files..' det_text.innerHTML = 'Validating server distribution files..'
const serv = await AssetGuard.validateDistribution('WesterosCraft-1.11.2', GAME_DIRECTORY) const serv = await tracker.validateDistribution('WesterosCraft-1.11.2', GAME_DIRECTORY)
progress.setAttribute('value', 100) progress.setAttribute('value', 100)
progress_text.innerHTML = '100%' progress_text.innerHTML = '100%'
console.log('forge stuff done') console.log('forge stuff done')
det_text.innerHTML = 'Downloading files..' det_text.innerHTML = 'Downloading files..'
AssetGuard.instance.on('totaldlprogress', function(data){ tracker.on('totaldlprogress', function(data){
progress.setAttribute('max', data.total) progress.setAttribute('max', data.total)
progress.setAttribute('value', data.acc) progress.setAttribute('value', data.acc)
progress_text.innerHTML = parseInt((data.acc/data.total)*100) + '%' progress_text.innerHTML = parseInt((data.acc/data.total)*100) + '%'
}) })
AssetGuard.instance.on('dlcomplete', async function(){ tracker.on('dlcomplete', async function(){
det_text.innerHTML = 'Preparing to launch..' det_text.innerHTML = 'Preparing to launch..'
const forgeData = await AssetGuard.loadForgeData('WesterosCraft-1.11.2', GAME_DIRECTORY) const forgeData = await tracker.loadForgeData('WesterosCraft-1.11.2', GAME_DIRECTORY)
const authUser = await mojang.auth('EMAIL', 'PASS', DEFAULT_CONFIG.getClientToken(), { const authUser = await mojang.auth('EMAIL', 'PASS', DEFAULT_CONFIG.getClientToken(), {
name: 'Minecraft', name: 'Minecraft',
version: 1 version: 1
@ -94,6 +100,8 @@ testdownloads = async function(){
content.style.display = 'inline-flex' content.style.display = 'inline-flex'
}, 5000) }, 5000)
} }
// Remove reference to tracker.
tracker = null
}) })
AssetGuard.processDlQueues() tracker.processDlQueues()
} }

File diff suppressed because it is too large Load Diff

View File

@ -6,7 +6,7 @@
* TODO why are logs not working?????? * TODO why are logs not working??????
*/ */
const AdmZip = require('adm-zip') const AdmZip = require('adm-zip')
const ag = require('./assetguard.js') const {AssetGuard, Library} = require('./assetguard.js')
const child_process = require('child_process') const child_process = require('child_process')
const {DEFAULT_CONFIG} = require('./constants') const {DEFAULT_CONFIG} = require('./constants')
const fs = require('fs') const fs = require('fs')
@ -232,7 +232,7 @@ class ProcessBuilder {
const nativePath = path.join(this.dir, 'natives') const nativePath = path.join(this.dir, 'natives')
for(let i=0; i<libArr.length; i++){ for(let i=0; i<libArr.length; i++){
const lib = libArr[i] const lib = libArr[i]
if(ag.Library.validateRules(lib.rules)){ if(Library.validateRules(lib.rules)){
if(lib.natives == null){ if(lib.natives == null){
const dlInfo = lib.downloads const dlInfo = lib.downloads
const artifact = dlInfo.artifact const artifact = dlInfo.artifact
@ -243,7 +243,7 @@ class ProcessBuilder {
const natives = lib.natives const natives = lib.natives
const extractInst = lib.extract const extractInst = lib.extract
const exclusionArr = extractInst.exclude const exclusionArr = extractInst.exclude
const opSys = ag.Library.mojangFriendlyOS() const opSys = Library.mojangFriendlyOS()
const indexId = natives[opSys] const indexId = natives[opSys]
const dlInfo = lib.downloads const dlInfo = lib.downloads
const classifiers = dlInfo.classifiers const classifiers = dlInfo.classifiers
@ -304,7 +304,7 @@ class ProcessBuilder {
for(let i=0; i<mdles.length; i++){ for(let i=0; i<mdles.length; i++){
if(mdles[i].type != null && (mdles[i].type === 'forge-hosted' || mdles[i].type === 'library')){ if(mdles[i].type != null && (mdles[i].type === 'forge-hosted' || mdles[i].type === 'library')){
let lib = mdles[i] let lib = mdles[i]
libs.push(path.join(this.libPath, lib.artifact.path == null ? ag._resolvePath(lib.id, lib.artifact.extension) : lib.artifact.path)) libs.push(path.join(this.libPath, lib.artifact.path == null ? AssetGuard._resolvePath(lib.id, lib.artifact.extension) : lib.artifact.path))
if(lib.sub_modules != null){ if(lib.sub_modules != null){
const res = this._resolveModuleLibraries(lib) const res = this._resolveModuleLibraries(lib)
if(res.length > 0){ if(res.length > 0){
@ -341,7 +341,7 @@ class ProcessBuilder {
for(let i=0; i<mdle.sub_modules.length; i++){ for(let i=0; i<mdle.sub_modules.length; i++){
const sm = mdle.sub_modules[i] const sm = mdle.sub_modules[i]
if(sm.type != null && sm.type == 'library'){ if(sm.type != null && sm.type == 'library'){
libs.push(path.join(this.libPath, sm.artifact.path == null ? ag._resolvePath(sm.id, sm.artifact.extension) : sm.artifact.path)) libs.push(path.join(this.libPath, sm.artifact.path == null ? AssetGuard._resolvePath(sm.id, sm.artifact.extension) : sm.artifact.path))
} }
// If this module has submodules, we need to resolve the libraries for those. // If this module has submodules, we need to resolve the libraries for those.
// To avoid unnecessary recursive calls, base case is checked here. // To avoid unnecessary recursive calls, base case is checked here.

View File

@ -10,9 +10,8 @@ $(function(){
console.log('UICore Initialized'); console.log('UICore Initialized');
})*/ })*/
document.onreadystatechange = function () { document.addEventListener('readystatechange', function () {
if (document.readyState === "interactive") { if (document.readyState === 'interactive'){
console.log('UICore Initializing..'); console.log('UICore Initializing..');
// Bind close button. // Bind close button.
@ -37,6 +36,8 @@ document.onreadystatechange = function () {
window.minimize() window.minimize()
}) })
} else if(document.readyState === 'complete'){
// Bind progress bar length to length of bot wrapper // Bind progress bar length to length of bot wrapper
const targetWidth = document.getElementById("launch_content").getBoundingClientRect().width const targetWidth = document.getElementById("launch_content").getBoundingClientRect().width
const targetWidth2 = document.getElementById("server_selection").getBoundingClientRect().width const targetWidth2 = document.getElementById("server_selection").getBoundingClientRect().width
@ -45,8 +46,10 @@ document.onreadystatechange = function () {
document.getElementById("launch_progress").style.width = targetWidth2 document.getElementById("launch_progress").style.width = targetWidth2
document.getElementById("launch_details_right").style.maxWidth = targetWidth2 document.getElementById("launch_details_right").style.maxWidth = targetWidth2
document.getElementById("launch_progress_label").style.width = targetWidth3 document.getElementById("launch_progress_label").style.width = targetWidth3
} }
}
}, false)
/** /**
* Open web links in the user's default browser. * Open web links in the user's default browser.