Added initial support for optional mods.
Optional mods are stored by ID in the configuration. Their enabled state is stored here. The mod configurations are updated each time the distro index is refreshed. Configurations are stored by server id. If the id no longer exists (changed/removed), the mod configuration is removed. If new optional mods are added, they are added to the configuration. If they are removed, they are removed from the configuration. Currently only top level optional mods are supported.
This commit is contained in:
parent
4196856d31
commit
145a2fe77b
@ -247,6 +247,20 @@ class AssetGuard extends EventEmitter {
|
||||
return cs.join('/')
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolves an artiface id without the version. For example,
|
||||
* 'net.minecraftforge:forge:1.11.2-13.20.0.2282' becomes
|
||||
* 'net.minecraftforge:forge'.
|
||||
*
|
||||
* @param {string} artifactid The artifact id string.
|
||||
* @returns {string} The resolved identifier without the version.
|
||||
*/
|
||||
static _resolveWithoutVersion(artifactid){
|
||||
let ps = artifactid.split(':')
|
||||
|
||||
return ps[0] + ':' + ps[1]
|
||||
}
|
||||
|
||||
// #endregion
|
||||
|
||||
// Static Hash Validation Functions
|
||||
|
@ -69,7 +69,8 @@ const DEFAULT_CONFIG = {
|
||||
clientToken: uuidV4().replace(/-/g, ''),
|
||||
selectedServer: null, // Resolved
|
||||
selectedAccount: null,
|
||||
authenticationDatabase: {}
|
||||
authenticationDatabase: {},
|
||||
modConfigurations: []
|
||||
}
|
||||
|
||||
let config = null;
|
||||
@ -92,7 +93,6 @@ exports.save = function(){
|
||||
*/
|
||||
exports.load = function(){
|
||||
// Determine the effective configuration.
|
||||
//const EFFECTIVE_CONFIG = config == null ? DEFAULT_CONFIG : config
|
||||
const filePath = path.join(dataPath, 'config.json')
|
||||
|
||||
if(!fs.existsSync(filePath)){
|
||||
@ -353,6 +353,57 @@ exports.setSelectedAccount = function(uuid){
|
||||
return authAcc
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an array of each mod configuration currently stored.
|
||||
*
|
||||
* @returns {Array.<Object>} An array of each stored mod configuration.
|
||||
*/
|
||||
exports.getModConfigurations = function(){
|
||||
return config.modConfigurations
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the array of stored mod configurations.
|
||||
*
|
||||
* @param {Array.<Object>} configurations An array of mod configurations.
|
||||
*/
|
||||
exports.setModConfigurations = function(configurations){
|
||||
config.modConfigurations = configurations
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the mod configuration for a specific server.
|
||||
*
|
||||
* @param {string} serverid The id of the server.
|
||||
* @returns {Object} The mod configuration for the given server.
|
||||
*/
|
||||
exports.getModConfiguration = function(serverid){
|
||||
const cfgs = config.modConfigurations
|
||||
for(let i=0; i<cfgs.length; i++){
|
||||
if(cfgs[i].id === serverid){
|
||||
return cfgs[i]
|
||||
}
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the mod configuration for a specific server. This overrides any existing value.
|
||||
*
|
||||
* @param {string} serverid The id of the server for the given mod configuration.
|
||||
* @param {Object} configuration The mod configuration for the given server.
|
||||
*/
|
||||
exports.setModConfiguration = function(serverid, configuration){
|
||||
const cfgs = config.modConfigurations
|
||||
for(let i=0; i<cfgs.length; i++){
|
||||
if(cfgs[i].id === serverid){
|
||||
cfgs[i] = configuration
|
||||
return
|
||||
}
|
||||
}
|
||||
cfgs.push(configuration)
|
||||
}
|
||||
|
||||
// User Configurable Settings
|
||||
|
||||
// Java Settings
|
||||
|
@ -1,18 +1,14 @@
|
||||
/**
|
||||
* The initial iteration of this file will not support optional submodules.
|
||||
* Support will be added down the line, only top-level modules will recieve optional support.
|
||||
*/
|
||||
const AdmZip = require('adm-zip')
|
||||
const AdmZip = require('adm-zip')
|
||||
const {AssetGuard, Library} = require('./assetguard.js')
|
||||
const child_process = require('child_process')
|
||||
const ConfigManager = require('./configmanager.js')
|
||||
const crypto = require('crypto')
|
||||
const fs = require('fs')
|
||||
const mkpath = require('mkdirp')
|
||||
const os = require('os')
|
||||
const path = require('path')
|
||||
const rimraf = require('rimraf')
|
||||
const {URL} = require('url')
|
||||
const child_process = require('child_process')
|
||||
const ConfigManager = require('./configmanager.js')
|
||||
const crypto = require('crypto')
|
||||
const fs = require('fs')
|
||||
const mkpath = require('mkdirp')
|
||||
const os = require('os')
|
||||
const path = require('path')
|
||||
const rimraf = require('rimraf')
|
||||
const {URL} = require('url')
|
||||
|
||||
class ProcessBuilder {
|
||||
|
||||
@ -27,11 +23,6 @@ class ProcessBuilder {
|
||||
this.libPath = path.join(this.commonDir, 'libraries')
|
||||
}
|
||||
|
||||
static shouldInclude(mdle){
|
||||
//If the module should be included by default
|
||||
return mdle.required == null || mdle.required.value == null || mdle.required.value === true || (mdle.required.value === false && (mdle.required.def == null || mdle.required.def === true))
|
||||
}
|
||||
|
||||
/**
|
||||
* Convienence method to run the functions typically used to build a process.
|
||||
*/
|
||||
@ -77,12 +68,19 @@ class ProcessBuilder {
|
||||
resolveDefaultMods(options = {type: 'forgemod'}){
|
||||
//Returns array of default forge mods to load.
|
||||
const mods = []
|
||||
const mdles = this.server.modules
|
||||
const mdls = this.server.modules
|
||||
const modCfg = ConfigManager.getModConfiguration(this.server.id).mods
|
||||
|
||||
for(let i=0; i<mdles.length; ++i){
|
||||
if(mdles[i].type != null && mdles[i].type === options.type){
|
||||
if(ProcessBuilder.shouldInclude(mdles[i])){
|
||||
mods.push(mdles[i])
|
||||
for(let i=0; i<mdls.length; ++i){
|
||||
const mdl = mdls[i]
|
||||
if(mdl.type != null && mdl.type === options.type){
|
||||
if(mdl.required != null && mdl.required.value === false){
|
||||
const val = modCfg[AssetGuard._resolveWithoutVersion(mdl.id)]
|
||||
if(val === true){
|
||||
mods.push(mdl)
|
||||
}
|
||||
} else {
|
||||
mods.push(mdl)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -125,10 +125,86 @@ function showFatalStartupError(){
|
||||
}, 750)
|
||||
}
|
||||
|
||||
/**
|
||||
* Common functions to perform after refreshing the distro index.
|
||||
*
|
||||
* @param {Object} data The distro index object.
|
||||
*/
|
||||
function onDistroRefresh(data){
|
||||
updateSelectedServer(AssetGuard.getServerById(ConfigManager.getSelectedServer()).name)
|
||||
refreshServerStatus()
|
||||
initNews()
|
||||
syncModConfigurations(data)
|
||||
}
|
||||
|
||||
/**
|
||||
* Sync the mod configurations with the distro index.
|
||||
*
|
||||
* @param {Object} data The distro index object.
|
||||
*/
|
||||
function syncModConfigurations(data){
|
||||
|
||||
const syncedCfgs = []
|
||||
|
||||
const servers = data.servers
|
||||
|
||||
for(let i=0; i<servers.length; i++){
|
||||
|
||||
const id = servers[i].id
|
||||
const mdls = servers[i].modules
|
||||
const cfg = ConfigManager.getModConfiguration(servers[i].id)
|
||||
|
||||
if(cfg != null){
|
||||
|
||||
const modsOld = cfg.mods
|
||||
const mods = {}
|
||||
|
||||
for(let j=0; j<mdls.length; j++){
|
||||
const mdl = mdls[j]
|
||||
if(mdl.type === 'forgemod'){
|
||||
if(mdl.required != null){
|
||||
if(mdl.required.value === false){
|
||||
const mdlID = AssetGuard._resolveWithoutVersion(mdl.id)
|
||||
if(modsOld[mdlID] == null){
|
||||
mods[mdlID] = mdl.required.def != null ? mdl.required.def : true
|
||||
} else {
|
||||
mods[mdlID] = modsOld[mdlID]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
syncedCfgs.push({
|
||||
id,
|
||||
mods
|
||||
})
|
||||
|
||||
} else {
|
||||
|
||||
const mods = {}
|
||||
|
||||
for(let j=0; j<mdls.length; j++){
|
||||
const mdl = mdls[j]
|
||||
if(mdl.type === 'forgemod'){
|
||||
if(mdl.required != null){
|
||||
if(mdl.required.value === false){
|
||||
mods[AssetGuard._resolveWithoutVersion(mdl.id)] = mdl.required.def != null ? mdl.required.def : true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
syncedCfgs.push({
|
||||
id,
|
||||
mods
|
||||
})
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
ConfigManager.setModConfigurations(syncedCfgs)
|
||||
ConfigManager.save()
|
||||
}
|
||||
|
||||
function refreshDistributionIndex(remote, onSuccess, onError){
|
||||
@ -223,6 +299,7 @@ document.addEventListener('readystatechange', function(){
|
||||
// Actions that must be performed after the distribution index is downloaded.
|
||||
ipcRenderer.on('distributionIndexDone', (event, data) => {
|
||||
if(data != null) {
|
||||
syncModConfigurations(data)
|
||||
if(document.readyState === 'complete'){
|
||||
showMainUI()
|
||||
} else {
|
||||
|
Loading…
Reference in New Issue
Block a user