mirror of
https://github.com/dscalzi/HeliosLauncher.git
synced 2024-12-22 03:32:12 -08:00
Minor fixes, beginning work on configuration system.
This commit is contained in:
parent
2c7dc16247
commit
5352239f91
47
app/assets/js/configmanager.js
Normal file
47
app/assets/js/configmanager.js
Normal file
@ -0,0 +1,47 @@
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
const uuidV4 = require('uuid/v4')
|
||||
|
||||
class ConfigManager {
|
||||
|
||||
constructor(path){
|
||||
this.path = path
|
||||
this.config = null
|
||||
this.load()
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a default configuration object and saves it.
|
||||
*
|
||||
* @param {Boolean} save - optional. If true, the default config will be saved after being generated.
|
||||
*/
|
||||
_generateDefault(save = true){
|
||||
this.config = {
|
||||
settings: {},
|
||||
clientToken: uuidV4(),
|
||||
authenticationDatabase: []
|
||||
}
|
||||
if(save){
|
||||
this.save()
|
||||
}
|
||||
}
|
||||
|
||||
load(){
|
||||
if(!fs.existsSync(this.path)){
|
||||
this._generateDefault()
|
||||
} else {
|
||||
this.config = JSON.parse(fs.readFileSync(this.path, 'UTF-8'))
|
||||
}
|
||||
}
|
||||
|
||||
save(){
|
||||
fs.writeFileSync(this.path, JSON.stringify(this.config, null, 4), 'UTF-8')
|
||||
}
|
||||
|
||||
getClientToken(){
|
||||
return this.config.clientToken
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module.exports = ConfigManager
|
6
app/assets/js/constants.js
Normal file
6
app/assets/js/constants.js
Normal file
@ -0,0 +1,6 @@
|
||||
const path = require('path')
|
||||
const ConfigManager = require('./configmanager')
|
||||
|
||||
//TODO: Resolve game directory based on windows, linux, or mac..
|
||||
exports.GAME_DIRECTORY = path.join(__dirname, '..', '..', '..', 'target', 'test', 'mcfiles')
|
||||
exports.DEFAULT_CONFIG = new ConfigManager(path.join(exports.GAME_DIRECTORY, 'config.yml'))
|
@ -6,7 +6,7 @@ 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 uuidV4 = require('uuid/v4')
|
||||
const {GAME_DIRECTORY, DEFAULT_CONFIG} = require(path.join(__dirname, 'assets', 'js', 'constants.js'))
|
||||
|
||||
$(document).on('ready', function(){
|
||||
console.log('okay');
|
||||
@ -15,11 +15,13 @@ $(document).on('ready', function(){
|
||||
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()){
|
||||
@ -29,6 +31,7 @@ document.onreadystatechange = function () {
|
||||
}
|
||||
})
|
||||
|
||||
// Bind minimize button.
|
||||
document.getElementById("frame_btn_minimize").addEventListener("click", function (e) {
|
||||
const window = remote.getCurrentWindow()
|
||||
window.minimize()
|
||||
@ -42,43 +45,43 @@ document.onreadystatechange = function () {
|
||||
}
|
||||
}
|
||||
|
||||
/* Open web links in the user's default browser. */
|
||||
// Open web links in the user's default browser.
|
||||
$(document).on('click', 'a[href^="http"]', function(event) {
|
||||
event.preventDefault();
|
||||
testdownloads()
|
||||
//console.log(os.homedir())
|
||||
//shell.openExternal(this.href)
|
||||
shell.openExternal(this.href)
|
||||
})
|
||||
|
||||
testdownloads = async function(){
|
||||
//const lp = require(path.join(__dirname, 'assets', 'js', 'launchprocess.js'))
|
||||
const basePath = path.join(__dirname, '..', 'target', 'test', 'mcfiles')
|
||||
let versionData = await ag.loadVersionData('1.11.2', basePath)
|
||||
await ag.validateAssets(versionData, basePath)
|
||||
let versionData = await ag.loadVersionData('1.11.2', GAME_DIRECTORY)
|
||||
await ag.validateAssets(versionData, GAME_DIRECTORY)
|
||||
console.log('assets done')
|
||||
await ag.validateLibraries(versionData, basePath)
|
||||
await ag.validateLibraries(versionData, GAME_DIRECTORY)
|
||||
console.log('libs done')
|
||||
await ag.validateMiscellaneous(versionData, basePath)
|
||||
await ag.validateMiscellaneous(versionData, GAME_DIRECTORY)
|
||||
console.log('files done')
|
||||
const serv = await ag.validateDistribution('WesterosCraft-1.11.2', basePath)
|
||||
const serv = await ag.validateDistribution('WesterosCraft-1.11.2', GAME_DIRECTORY)
|
||||
console.log('forge stuff done')
|
||||
ag.instance.on('dlcomplete', async function(){
|
||||
const forgeData = await ag.loadForgeData('WesterosCraft-1.11.2', basePath)
|
||||
const authUser = await mojang.auth('EMAIL', 'PASS', uuidV4(), {
|
||||
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, basePath)
|
||||
//lp.launchMinecraft(versionData, basePath)
|
||||
let pb = new ProcessBuilder(basePath, serv, versionData, forgeData, authUser)
|
||||
//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()
|
||||
})
|
||||
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. */
|
||||
/**
|
||||
* 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;
|
||||
|
||||
|
2
index.js
2
index.js
@ -11,7 +11,7 @@ let win
|
||||
function createWindow() {
|
||||
win = new BrowserWindow({ width: 980, height: 552, icon: getPlatformIcon('WesterosSealSquare'), frame: false})
|
||||
|
||||
ejse.data('bkid', Math.floor((Math.random() * fs.readdirSync('app/assets/images/backgrounds').length)))
|
||||
ejse.data('bkid', Math.floor((Math.random() * fs.readdirSync(path.join(__dirname, 'app', 'assets', 'images', 'backgrounds')).length)))
|
||||
|
||||
win.loadURL(url.format({
|
||||
pathname: path.join(__dirname, 'app', 'index.ejs'),
|
||||
|
Loading…
Reference in New Issue
Block a user