153 lines
5.1 KiB
JavaScript
153 lines
5.1 KiB
JavaScript
const $ = require('jquery');
|
|
const remote = require('electron').remote
|
|
const shell = require('electron').shell
|
|
const path = require('path')
|
|
const os = require('os');
|
|
const ag = require(path.join(__dirname, 'assets', 'js', 'assetguard.js'))
|
|
const ProcessBuilder = require(path.join(__dirname, 'assets', 'js', 'processbuilder.js'))
|
|
const mojang = require('mojang')
|
|
const {GAME_DIRECTORY, DEFAULT_CONFIG} = require(path.join(__dirname, 'assets', 'js', 'constants.js'))
|
|
|
|
$(document).on('ready', function(){
|
|
console.log('okay');
|
|
})
|
|
|
|
document.onreadystatechange = function () {
|
|
if (document.readyState == "complete") {
|
|
|
|
// Bind close button.
|
|
document.getElementById("frame_btn_close").addEventListener("click", function (e) {
|
|
const window = remote.getCurrentWindow()
|
|
window.close()
|
|
})
|
|
|
|
// Bind restore down button.
|
|
document.getElementById("frame_btn_restoredown").addEventListener("click", function (e) {
|
|
const window = remote.getCurrentWindow()
|
|
if(window.isMaximized()){
|
|
window.unmaximize();
|
|
} else {
|
|
window.maximize()
|
|
}
|
|
})
|
|
|
|
// Bind minimize button.
|
|
document.getElementById("frame_btn_minimize").addEventListener("click", function (e) {
|
|
const window = remote.getCurrentWindow()
|
|
window.minimize()
|
|
})
|
|
|
|
// 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
|
|
}
|
|
}
|
|
|
|
// Open web links in the user's default browser.
|
|
$(document).on('click', 'a[href^="http"]', function(event) {
|
|
event.preventDefault();
|
|
//console.log(os.homedir())
|
|
shell.openExternal(this.href)
|
|
})
|
|
|
|
testdownloads = async function(){
|
|
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
|
|
})
|
|
let pb = new ProcessBuilder(GAME_DIRECTORY, serv, versionData, forgeData, authUser)
|
|
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()
|
|
}
|
|
|
|
/**
|
|
* Opens DevTools window if you type "wcdev" in sequence.
|
|
* This will crash the program if you are using multiple
|
|
* DevTools, for example the chrome debugger in VS Code.
|
|
*/
|
|
const match = [87, 67, 68, 69, 86]
|
|
let at = 0;
|
|
|
|
document.addEventListener('keydown', function (e) {
|
|
switch(e.keyCode){
|
|
case match[0]:
|
|
if(at === 0) ++at
|
|
break
|
|
case match[1]:
|
|
if(at === 1) ++at
|
|
break
|
|
case match[2]:
|
|
if(at === 2) ++at
|
|
break
|
|
case match[3]:
|
|
if(at === 3) ++at
|
|
break
|
|
case match[4]:
|
|
if(at === 4) ++at
|
|
break
|
|
default:
|
|
at = 0
|
|
}
|
|
if(at === 5) {
|
|
var window = remote.getCurrentWindow()
|
|
window.toggleDevTools()
|
|
at = 0
|
|
}
|
|
}) |