2017-11-22 02:48:40 -08:00
|
|
|
const fs = require('fs')
|
2017-11-27 01:31:54 -08:00
|
|
|
const mkpath = require('mkdirp')
|
2017-11-29 22:40:56 -08:00
|
|
|
const os = require('os')
|
2017-11-22 02:48:40 -08:00
|
|
|
const path = require('path')
|
|
|
|
const uuidV4 = require('uuid/v4')
|
|
|
|
|
2018-05-14 19:33:38 -07:00
|
|
|
const sysRoot = process.env.APPDATA || (process.platform == 'darwin' ? process.env.HOME + '/Library/Application Support' : process.env.HOME)
|
2018-03-31 10:05:05 -07:00
|
|
|
const dataPath = path.join(sysRoot, '.westeroscraft')
|
|
|
|
|
2018-04-02 13:05:48 -07:00
|
|
|
const firstLaunch = !fs.existsSync(dataPath)
|
|
|
|
|
2018-06-11 19:11:05 -07:00
|
|
|
exports.getAbsoluteMinRAM = function(){
|
|
|
|
const mem = os.totalmem()
|
|
|
|
return mem >= 6000000000 ? 3 : 2
|
|
|
|
}
|
|
|
|
|
|
|
|
exports.getAbsoluteMaxRAM = function(){
|
|
|
|
const mem = os.totalmem()
|
|
|
|
const gT16 = mem-16000000000
|
|
|
|
return Math.floor((mem-1000000000-(gT16 > 0 ? (Number.parseInt(gT16/8) + 16000000000/4) : mem/4))/1000000000)
|
|
|
|
}
|
|
|
|
|
2017-12-02 21:38:22 -08:00
|
|
|
function resolveMaxRAM(){
|
|
|
|
const mem = os.totalmem()
|
|
|
|
return mem >= 8000000000 ? '4G' : (mem >= 6000000000 ? '3G' : '2G')
|
|
|
|
}
|
|
|
|
|
2018-06-11 19:11:05 -07:00
|
|
|
function resolveMinRAM(){
|
|
|
|
return exports.getAbsoluteMinRAM() + 'G'
|
|
|
|
}
|
|
|
|
|
2017-12-02 21:38:22 -08:00
|
|
|
/**
|
|
|
|
* Three types of values:
|
|
|
|
* Static = Explicitly declared.
|
|
|
|
* Dynamic = Calculated by a private function.
|
|
|
|
* Resolved = Resolved externally, defaults to null.
|
|
|
|
*/
|
|
|
|
const DEFAULT_CONFIG = {
|
|
|
|
settings: {
|
|
|
|
java: {
|
2018-06-11 19:11:05 -07:00
|
|
|
minRAM: resolveMinRAM(),
|
2017-12-02 21:38:22 -08:00
|
|
|
maxRAM: resolveMaxRAM(), // Dynamic
|
2018-04-07 15:06:49 -07:00
|
|
|
executable: null,
|
2017-12-02 21:38:22 -08:00
|
|
|
jvmOptions: [
|
|
|
|
'-XX:+UseConcMarkSweepGC',
|
|
|
|
'-XX:+CMSIncrementalMode',
|
|
|
|
'-XX:-UseAdaptiveSizePolicy',
|
|
|
|
'-Xmn128M'
|
|
|
|
],
|
|
|
|
},
|
|
|
|
game: {
|
|
|
|
resWidth: 1280,
|
|
|
|
resHeight: 720,
|
|
|
|
fullscreen: false,
|
2018-05-09 21:01:38 -07:00
|
|
|
autoConnect: true,
|
|
|
|
launchDetached: true
|
2017-12-02 21:38:22 -08:00
|
|
|
},
|
2018-06-04 16:34:47 -07:00
|
|
|
launcher: {
|
|
|
|
allowPrerelease: false
|
|
|
|
}
|
2017-12-02 21:38:22 -08:00
|
|
|
},
|
2018-06-04 20:08:03 -07:00
|
|
|
newsCache: {
|
|
|
|
date: null,
|
|
|
|
content: null,
|
|
|
|
dismissed: false
|
|
|
|
},
|
2018-06-03 21:17:20 -07:00
|
|
|
commonDirectory: path.join(dataPath, 'common'),
|
|
|
|
instanceDirectory: path.join(dataPath, 'instances'),
|
2018-01-18 20:41:03 -08:00
|
|
|
clientToken: uuidV4().replace(/-/g, ''),
|
2017-12-02 21:38:22 -08:00
|
|
|
selectedServer: null, // Resolved
|
|
|
|
selectedAccount: null,
|
2018-06-23 12:17:26 -07:00
|
|
|
authenticationDatabase: {},
|
|
|
|
modConfigurations: []
|
2017-12-02 21:38:22 -08:00
|
|
|
}
|
2017-11-22 02:48:40 -08:00
|
|
|
|
2017-12-02 21:38:22 -08:00
|
|
|
let config = null;
|
2017-11-29 22:40:56 -08:00
|
|
|
|
2017-12-02 21:38:22 -08:00
|
|
|
// Persistance Utility Functions
|
2017-11-29 22:40:56 -08:00
|
|
|
|
2017-12-02 21:38:22 -08:00
|
|
|
/**
|
|
|
|
* Save the current configuration to a file.
|
|
|
|
*/
|
|
|
|
exports.save = function(){
|
2018-03-31 10:05:05 -07:00
|
|
|
const filePath = path.join(dataPath, 'config.json')
|
2017-12-02 21:38:22 -08:00
|
|
|
fs.writeFileSync(filePath, JSON.stringify(config, null, 4), 'UTF-8')
|
|
|
|
}
|
2017-11-22 02:48:40 -08:00
|
|
|
|
2017-12-02 21:38:22 -08:00
|
|
|
/**
|
|
|
|
* Load the configuration into memory. If a configuration file exists,
|
|
|
|
* that will be read and saved. Otherwise, a default configuration will
|
|
|
|
* be generated. Note that "resolved" values default to null and will
|
|
|
|
* need to be externally assigned.
|
|
|
|
*/
|
|
|
|
exports.load = function(){
|
|
|
|
// Determine the effective configuration.
|
2018-03-31 10:05:05 -07:00
|
|
|
const filePath = path.join(dataPath, 'config.json')
|
2017-11-22 02:48:40 -08:00
|
|
|
|
2017-12-02 21:38:22 -08:00
|
|
|
if(!fs.existsSync(filePath)){
|
|
|
|
// Create all parent directories.
|
|
|
|
mkpath.sync(path.join(filePath, '..'))
|
|
|
|
config = DEFAULT_CONFIG
|
|
|
|
exports.save()
|
|
|
|
} else {
|
|
|
|
config = JSON.parse(fs.readFileSync(filePath, 'UTF-8'))
|
2018-05-09 21:01:38 -07:00
|
|
|
config = validateKeySet(DEFAULT_CONFIG, config)
|
|
|
|
exports.save()
|
|
|
|
}
|
2018-06-04 17:06:34 -07:00
|
|
|
console.log('%c[ConfigManager]', 'color: #a02d2a; font-weight: bold', 'Successfully Loaded')
|
2018-05-09 21:01:38 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Validate that the destination object has at least every field
|
|
|
|
* present in the source object. Assign a default value otherwise.
|
|
|
|
*
|
|
|
|
* @param {Object} srcObj The source object to reference against.
|
|
|
|
* @param {Object} destObj The destination object.
|
|
|
|
* @returns {Object} A validated destination object.
|
|
|
|
*/
|
|
|
|
function validateKeySet(srcObj, destObj){
|
|
|
|
if(srcObj == null){
|
|
|
|
srcObj = {}
|
2017-11-22 02:48:40 -08:00
|
|
|
}
|
2018-05-09 21:01:38 -07:00
|
|
|
const validationBlacklist = ['authenticationDatabase']
|
|
|
|
const keys = Object.keys(srcObj)
|
|
|
|
for(let i=0; i<keys.length; i++){
|
|
|
|
if(typeof destObj[keys[i]] === 'undefined'){
|
|
|
|
destObj[keys[i]] = srcObj[keys[i]]
|
|
|
|
} else if(typeof srcObj[keys[i]] === 'object' && srcObj[keys[i]] != null && !(srcObj[keys[i]] instanceof Array) && validationBlacklist.indexOf(keys[i]) === -1){
|
|
|
|
destObj[keys[i]] = validateKeySet(srcObj[keys[i]], destObj[keys[i]])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return destObj
|
2017-12-02 21:38:22 -08:00
|
|
|
}
|
2017-11-22 02:48:40 -08:00
|
|
|
|
2018-03-31 10:05:05 -07:00
|
|
|
/**
|
|
|
|
* Retrieve the absolute path of the launcher directory.
|
|
|
|
*
|
|
|
|
* @returns {string} The absolute path of the launcher directory.
|
|
|
|
*/
|
|
|
|
exports.getLauncherDirectory = function(){
|
|
|
|
return dataPath
|
|
|
|
}
|
|
|
|
|
2018-04-02 13:05:48 -07:00
|
|
|
/**
|
|
|
|
* Check to see if this is the first time the user has launched the
|
|
|
|
* application. This is determined by the existance of the data path.
|
|
|
|
*
|
|
|
|
* @returns {boolean} True if this is the first launch, otherwise false.
|
|
|
|
*/
|
|
|
|
exports.isFirstLaunch = function(){
|
|
|
|
return firstLaunch
|
|
|
|
}
|
|
|
|
|
2018-04-14 21:00:08 -07:00
|
|
|
/**
|
|
|
|
* Returns the name of the folder in the OS temp directory which we
|
|
|
|
* will use to extract and store native dependencies for game launch.
|
|
|
|
*
|
|
|
|
* @returns {string} The name of the folder.
|
|
|
|
*/
|
|
|
|
exports.getTempNativeFolder = function(){
|
|
|
|
return 'WCNatives'
|
|
|
|
}
|
|
|
|
|
2017-12-02 21:38:22 -08:00
|
|
|
// System Settings (Unconfigurable on UI)
|
2017-11-22 02:48:40 -08:00
|
|
|
|
2018-06-04 20:08:03 -07:00
|
|
|
/**
|
|
|
|
* Retrieve the news cache to determine
|
|
|
|
* whether or not there is newer news.
|
|
|
|
*
|
|
|
|
* @returns {Object} The news cache object.
|
|
|
|
*/
|
|
|
|
exports.getNewsCache = function(){
|
|
|
|
return config.newsCache
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the new news cache object.
|
|
|
|
*
|
|
|
|
* @param {Object} newsCache The new news cache object.
|
|
|
|
*/
|
|
|
|
exports.setNewsCache = function(newsCache){
|
|
|
|
config.newsCache = newsCache
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set whether or not the news has been dismissed (checked)
|
|
|
|
*
|
|
|
|
* @param {boolean} dismissed Whether or not the news has been dismissed (checked).
|
|
|
|
*/
|
|
|
|
exports.setNewsCacheDismissed = function(dismissed){
|
|
|
|
config.newsCache.dismissed = dismissed
|
|
|
|
}
|
|
|
|
|
2018-06-03 21:17:20 -07:00
|
|
|
/**
|
|
|
|
* Retrieve the common directory for shared
|
|
|
|
* game files (assets, libraries, etc).
|
2018-06-04 20:08:03 -07:00
|
|
|
*
|
|
|
|
* @returns {string} The launcher's common directory.
|
2018-06-03 21:17:20 -07:00
|
|
|
*/
|
|
|
|
exports.getCommonDirectory = function(){
|
|
|
|
return config.commonDirectory
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieve the instance directory for the per
|
|
|
|
* server game directories.
|
2018-06-04 20:08:03 -07:00
|
|
|
*
|
|
|
|
* @returns {string} The launcher's instance directory.
|
2018-06-03 21:17:20 -07:00
|
|
|
*/
|
|
|
|
exports.getInstanceDirectory = function(){
|
|
|
|
return config.instanceDirectory
|
|
|
|
}
|
|
|
|
|
2017-12-02 21:38:22 -08:00
|
|
|
/**
|
|
|
|
* Retrieve the launcher's Client Token.
|
2018-01-18 20:41:03 -08:00
|
|
|
* There is no default client token.
|
2017-12-02 21:38:22 -08:00
|
|
|
*
|
2018-03-28 13:42:10 -07:00
|
|
|
* @returns {string} The launcher's Client Token.
|
2017-12-02 21:38:22 -08:00
|
|
|
*/
|
2018-01-18 20:41:03 -08:00
|
|
|
exports.getClientToken = function(){
|
|
|
|
return config.clientToken
|
2017-12-02 21:38:22 -08:00
|
|
|
}
|
2017-11-29 22:40:56 -08:00
|
|
|
|
2017-12-02 21:38:22 -08:00
|
|
|
/**
|
|
|
|
* Set the launcher's Client Token.
|
|
|
|
*
|
2018-03-28 13:42:10 -07:00
|
|
|
* @param {string} clientToken The launcher's new Client Token.
|
2017-12-02 21:38:22 -08:00
|
|
|
*/
|
|
|
|
exports.setClientToken = function(clientToken){
|
|
|
|
config.clientToken = clientToken
|
|
|
|
}
|
2017-11-29 22:40:56 -08:00
|
|
|
|
2017-12-02 21:38:22 -08:00
|
|
|
/**
|
|
|
|
* Retrieve the ID of the selected serverpack.
|
|
|
|
*
|
2018-03-28 13:42:10 -07:00
|
|
|
* @param {boolean} def Optional. If true, the default value will be returned.
|
|
|
|
* @returns {string} The ID of the selected serverpack.
|
2017-12-02 21:38:22 -08:00
|
|
|
*/
|
|
|
|
exports.getSelectedServer = function(def = false){
|
|
|
|
return !def ? config.selectedServer : DEFAULT_CONFIG.clientToken
|
|
|
|
}
|
2017-11-29 22:40:56 -08:00
|
|
|
|
2017-12-02 21:38:22 -08:00
|
|
|
/**
|
|
|
|
* Set the ID of the selected serverpack.
|
|
|
|
*
|
2018-03-28 13:42:10 -07:00
|
|
|
* @param {string} serverID The ID of the new selected serverpack.
|
2017-12-02 21:38:22 -08:00
|
|
|
*/
|
|
|
|
exports.setSelectedServer = function(serverID){
|
|
|
|
config.selectedServer = serverID
|
|
|
|
}
|
2017-11-29 22:40:56 -08:00
|
|
|
|
2017-12-03 05:12:55 -08:00
|
|
|
/**
|
|
|
|
* Get an array of each account currently authenticated by the launcher.
|
|
|
|
*
|
2018-03-28 13:42:10 -07:00
|
|
|
* @returns {Array.<Object>} An array of each stored authenticated account.
|
2017-12-03 05:12:55 -08:00
|
|
|
*/
|
|
|
|
exports.getAuthAccounts = function(){
|
|
|
|
return config.authenticationDatabase
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the authenticated account with the given uuid. Value may
|
|
|
|
* be null.
|
|
|
|
*
|
2018-03-28 13:42:10 -07:00
|
|
|
* @param {string} uuid The uuid of the authenticated account.
|
|
|
|
* @returns {Object} The authenticated account with the given uuid.
|
2017-12-03 05:12:55 -08:00
|
|
|
*/
|
|
|
|
exports.getAuthAccount = function(uuid){
|
|
|
|
return config.authenticationDatabase[uuid]
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update the access token of an authenticated account.
|
|
|
|
*
|
2018-03-28 13:42:10 -07:00
|
|
|
* @param {string} uuid The uuid of the authenticated account.
|
|
|
|
* @param {string} accessToken The new Access Token.
|
2017-12-03 05:12:55 -08:00
|
|
|
*
|
2018-03-28 13:42:10 -07:00
|
|
|
* @returns {Object} The authenticated account object created by this action.
|
2017-12-03 05:12:55 -08:00
|
|
|
*/
|
|
|
|
exports.updateAuthAccount = function(uuid, accessToken){
|
|
|
|
config.authenticationDatabase[uuid].accessToken = accessToken
|
|
|
|
return config.authenticationDatabase[uuid]
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds an authenticated account to the database to be stored.
|
|
|
|
*
|
2018-03-28 13:42:10 -07:00
|
|
|
* @param {string} uuid The uuid of the authenticated account.
|
|
|
|
* @param {string} accessToken The accessToken of the authenticated account.
|
|
|
|
* @param {string} username The username (usually email) of the authenticated account.
|
|
|
|
* @param {string} displayName The in game name of the authenticated account.
|
2017-12-03 05:12:55 -08:00
|
|
|
*
|
2018-03-28 13:42:10 -07:00
|
|
|
* @returns {Object} The authenticated account object created by this action.
|
2017-12-03 05:12:55 -08:00
|
|
|
*/
|
|
|
|
exports.addAuthAccount = function(uuid, accessToken, username, displayName){
|
|
|
|
config.selectedAccount = uuid
|
|
|
|
config.authenticationDatabase[uuid] = {
|
|
|
|
accessToken,
|
|
|
|
username,
|
|
|
|
uuid,
|
|
|
|
displayName
|
|
|
|
}
|
|
|
|
return config.authenticationDatabase[uuid]
|
|
|
|
}
|
|
|
|
|
2018-04-08 17:56:44 -07:00
|
|
|
/**
|
|
|
|
* Remove an authenticated account from the database. If the account
|
|
|
|
* was also the selected account, a new one will be selected. If there
|
|
|
|
* are no accounts, the selected account will be null.
|
|
|
|
*
|
|
|
|
* @param {string} uuid The uuid of the authenticated account.
|
|
|
|
*
|
|
|
|
* @returns {boolean} True if the account was removed, false if it never existed.
|
|
|
|
*/
|
|
|
|
exports.removeAuthAccount = function(uuid){
|
|
|
|
if(config.authenticationDatabase[uuid] != null){
|
|
|
|
delete config.authenticationDatabase[uuid]
|
|
|
|
if(config.selectedAccount === uuid){
|
|
|
|
const keys = Object.keys(config.authenticationDatabase)
|
|
|
|
if(keys.length > 0){
|
|
|
|
config.selectedAccount = keys[0]
|
|
|
|
} else {
|
|
|
|
config.selectedAccount = null
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2017-12-03 05:12:55 -08:00
|
|
|
/**
|
|
|
|
* Get the currently selected authenticated account.
|
|
|
|
*
|
2018-03-28 13:42:10 -07:00
|
|
|
* @returns {Object} The selected authenticated account.
|
2017-12-03 05:12:55 -08:00
|
|
|
*/
|
|
|
|
exports.getSelectedAccount = function(){
|
|
|
|
return config.authenticationDatabase[config.selectedAccount]
|
|
|
|
}
|
2017-11-29 22:40:56 -08:00
|
|
|
|
2018-05-09 19:23:37 -07:00
|
|
|
/**
|
|
|
|
* Set the selected authenticated account.
|
|
|
|
*
|
|
|
|
* @param {string} uuid The UUID of the account which is to be set
|
|
|
|
* as the selected account.
|
|
|
|
*
|
|
|
|
* @returns {Object} The selected authenticated account.
|
|
|
|
*/
|
|
|
|
exports.setSelectedAccount = function(uuid){
|
|
|
|
const authAcc = config.authenticationDatabase[uuid]
|
|
|
|
if(authAcc != null) {
|
|
|
|
config.selectedAccount = uuid
|
|
|
|
}
|
|
|
|
return authAcc
|
|
|
|
}
|
|
|
|
|
2018-06-23 12:17:26 -07:00
|
|
|
/**
|
|
|
|
* 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)
|
|
|
|
}
|
|
|
|
|
2017-12-02 21:38:22 -08:00
|
|
|
// User Configurable Settings
|
2017-11-29 22:40:56 -08:00
|
|
|
|
2017-12-02 21:38:22 -08:00
|
|
|
// Java Settings
|
2017-11-29 22:40:56 -08:00
|
|
|
|
2017-12-02 21:38:22 -08:00
|
|
|
/**
|
|
|
|
* Retrieve the minimum amount of memory for JVM initialization. This value
|
|
|
|
* contains the units of memory. For example, '5G' = 5 GigaBytes, '1024M' =
|
|
|
|
* 1024 MegaBytes, etc.
|
|
|
|
*
|
2018-03-28 13:42:10 -07:00
|
|
|
* @param {boolean} def Optional. If true, the default value will be returned.
|
|
|
|
* @returns {string} The minimum amount of memory for JVM initialization.
|
2017-12-02 21:38:22 -08:00
|
|
|
*/
|
|
|
|
exports.getMinRAM = function(def = false){
|
|
|
|
return !def ? config.settings.java.minRAM : DEFAULT_CONFIG.settings.java.minRAM
|
|
|
|
}
|
2017-11-29 22:40:56 -08:00
|
|
|
|
2017-12-02 21:38:22 -08:00
|
|
|
/**
|
|
|
|
* Set the minimum amount of memory for JVM initialization. This value should
|
|
|
|
* contain the units of memory. For example, '5G' = 5 GigaBytes, '1024M' =
|
|
|
|
* 1024 MegaBytes, etc.
|
|
|
|
*
|
2018-03-28 13:42:10 -07:00
|
|
|
* @param {string} minRAM The new minimum amount of memory for JVM initialization.
|
2017-12-02 21:38:22 -08:00
|
|
|
*/
|
|
|
|
exports.setMinRAM = function(minRAM){
|
|
|
|
config.settings.java.minRAM = minRAM
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieve the maximum amount of memory for JVM initialization. This value
|
|
|
|
* contains the units of memory. For example, '5G' = 5 GigaBytes, '1024M' =
|
|
|
|
* 1024 MegaBytes, etc.
|
|
|
|
*
|
2018-03-28 13:42:10 -07:00
|
|
|
* @param {boolean} def Optional. If true, the default value will be returned.
|
|
|
|
* @returns {string} The maximum amount of memory for JVM initialization.
|
2017-12-02 21:38:22 -08:00
|
|
|
*/
|
|
|
|
exports.getMaxRAM = function(def = false){
|
|
|
|
return !def ? config.settings.java.maxRAM : resolveMaxRAM()
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the maximum amount of memory for JVM initialization. This value should
|
|
|
|
* contain the units of memory. For example, '5G' = 5 GigaBytes, '1024M' =
|
|
|
|
* 1024 MegaBytes, etc.
|
|
|
|
*
|
2018-03-28 13:42:10 -07:00
|
|
|
* @param {string} maxRAM The new maximum amount of memory for JVM initialization.
|
2017-12-02 21:38:22 -08:00
|
|
|
*/
|
|
|
|
exports.setMaxRAM = function(maxRAM){
|
|
|
|
config.settings.java.maxRAM = maxRAM
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieve the path of the Java Executable.
|
|
|
|
*
|
|
|
|
* This is a resolved configuration value and defaults to null until externally assigned.
|
|
|
|
*
|
2018-03-28 13:42:10 -07:00
|
|
|
* @returns {string} The path of the Java Executable.
|
2017-12-02 21:38:22 -08:00
|
|
|
*/
|
|
|
|
exports.getJavaExecutable = function(){
|
|
|
|
return config.settings.java.executable
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the path of the Java Executable.
|
|
|
|
*
|
2018-03-28 13:42:10 -07:00
|
|
|
* @param {string} executable The new path of the Java Executable.
|
2017-12-02 21:38:22 -08:00
|
|
|
*/
|
|
|
|
exports.setJavaExecutable = function(executable){
|
|
|
|
config.settings.java.executable = executable
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieve the additional arguments for JVM initialization. Required arguments,
|
|
|
|
* such as memory allocation, will be dynamically resolved and will not be included
|
|
|
|
* in this value.
|
|
|
|
*
|
2018-03-28 13:42:10 -07:00
|
|
|
* @param {boolean} def Optional. If true, the default value will be returned.
|
|
|
|
* @returns {Array.<string>} An array of the additional arguments for JVM initialization.
|
2017-12-02 21:38:22 -08:00
|
|
|
*/
|
|
|
|
exports.getJVMOptions = function(def = false){
|
|
|
|
return !def ? config.settings.java.jvmOptions : DEFAULT_CONFIG.settings.java.jvmOptions
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the additional arguments for JVM initialization. Required arguments,
|
|
|
|
* such as memory allocation, will be dynamically resolved and should not be
|
|
|
|
* included in this value.
|
|
|
|
*
|
2018-03-28 13:42:10 -07:00
|
|
|
* @param {Array.<string>} jvmOptions An array of the new additional arguments for JVM
|
2017-12-02 21:38:22 -08:00
|
|
|
* initialization.
|
|
|
|
*/
|
|
|
|
exports.setJVMOptions = function(jvmOptions){
|
|
|
|
config.settings.java.jvmOptions = jvmOptions
|
|
|
|
}
|
|
|
|
|
|
|
|
// Game Settings
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieve the width of the game window.
|
|
|
|
*
|
2018-03-28 13:42:10 -07:00
|
|
|
* @param {boolean} def Optional. If true, the default value will be returned.
|
|
|
|
* @returns {number} The width of the game window.
|
2017-12-02 21:38:22 -08:00
|
|
|
*/
|
|
|
|
exports.getGameWidth = function(def = false){
|
|
|
|
return !def ? config.settings.game.resWidth : DEFAULT_CONFIG.settings.game.resWidth
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the width of the game window.
|
|
|
|
*
|
2018-03-28 13:42:10 -07:00
|
|
|
* @param {number} resWidth The new width of the game window.
|
2017-12-02 21:38:22 -08:00
|
|
|
*/
|
|
|
|
exports.setGameWidth = function(resWidth){
|
2018-06-04 13:28:17 -07:00
|
|
|
config.settings.game.resWidth = Number.parseInt(resWidth)
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Validate a potential new width value.
|
|
|
|
*
|
2018-06-04 20:08:03 -07:00
|
|
|
* @param {number} resWidth The width value to validate.
|
|
|
|
* @returns {boolean} Whether or not the value is valid.
|
2018-06-04 13:28:17 -07:00
|
|
|
*/
|
|
|
|
exports.validateGameWidth = function(resWidth){
|
|
|
|
const nVal = Number.parseInt(resWidth)
|
|
|
|
return Number.isInteger(nVal) && nVal >= 0
|
2017-12-02 21:38:22 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieve the height of the game window.
|
|
|
|
*
|
2018-03-28 13:42:10 -07:00
|
|
|
* @param {boolean} def Optional. If true, the default value will be returned.
|
|
|
|
* @returns {number} The height of the game window.
|
2017-12-02 21:38:22 -08:00
|
|
|
*/
|
|
|
|
exports.getGameHeight = function(def = false){
|
|
|
|
return !def ? config.settings.game.resHeight : DEFAULT_CONFIG.settings.game.resHeight
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the height of the game window.
|
|
|
|
*
|
2018-03-28 13:42:10 -07:00
|
|
|
* @param {number} resHeight The new height of the game window.
|
2017-12-02 21:38:22 -08:00
|
|
|
*/
|
|
|
|
exports.setGameHeight = function(resHeight){
|
2018-06-04 13:28:17 -07:00
|
|
|
config.settings.game.resHeight = Number.parseInt(resHeight)
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Validate a potential new height value.
|
|
|
|
*
|
2018-06-04 20:08:03 -07:00
|
|
|
* @param {number} resHeight The height value to validate.
|
|
|
|
* @returns {boolean} Whether or not the value is valid.
|
2018-06-04 13:28:17 -07:00
|
|
|
*/
|
|
|
|
exports.validateGameHeight = function(resHeight){
|
|
|
|
const nVal = Number.parseInt(resHeight)
|
|
|
|
return Number.isInteger(nVal) && nVal >= 0
|
2017-12-02 21:38:22 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if the game should be launched in fullscreen mode.
|
|
|
|
*
|
2018-03-28 13:42:10 -07:00
|
|
|
* @param {boolean} def Optional. If true, the default value will be returned.
|
|
|
|
* @returns {boolean} Whether or not the game is set to launch in fullscreen mode.
|
2017-12-02 21:38:22 -08:00
|
|
|
*/
|
2018-06-04 13:28:17 -07:00
|
|
|
exports.getFullscreen = function(def = false){
|
2017-12-02 21:38:22 -08:00
|
|
|
return !def ? config.settings.game.fullscreen : DEFAULT_CONFIG.settings.game.fullscreen
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Change the status of if the game should be launched in fullscreen mode.
|
|
|
|
*
|
2018-03-28 13:42:10 -07:00
|
|
|
* @param {boolean} fullscreen Whether or not the game should launch in fullscreen mode.
|
2017-12-02 21:38:22 -08:00
|
|
|
*/
|
|
|
|
exports.setFullscreen = function(fullscreen){
|
|
|
|
config.settings.game.fullscreen = fullscreen
|
|
|
|
}
|
2017-11-29 22:40:56 -08:00
|
|
|
|
2017-12-02 21:38:22 -08:00
|
|
|
/**
|
|
|
|
* Check if the game should auto connect to servers.
|
|
|
|
*
|
2018-03-28 13:42:10 -07:00
|
|
|
* @param {boolean} def Optional. If true, the default value will be returned.
|
|
|
|
* @returns {boolean} Whether or not the game should auto connect to servers.
|
2017-12-02 21:38:22 -08:00
|
|
|
*/
|
2018-06-04 13:28:17 -07:00
|
|
|
exports.getAutoConnect = function(def = false){
|
2017-12-02 21:38:22 -08:00
|
|
|
return !def ? config.settings.game.autoConnect : DEFAULT_CONFIG.settings.game.autoConnect
|
2017-11-22 02:48:40 -08:00
|
|
|
}
|
|
|
|
|
2017-12-02 21:38:22 -08:00
|
|
|
/**
|
|
|
|
* Change the status of whether or not the game should auto connect to servers.
|
|
|
|
*
|
2018-03-28 13:42:10 -07:00
|
|
|
* @param {boolean} autoConnect Whether or not the game should auto connect to servers.
|
2017-12-02 21:38:22 -08:00
|
|
|
*/
|
|
|
|
exports.setAutoConnect = function(autoConnect){
|
|
|
|
config.settings.game.autoConnect = autoConnect
|
2018-05-09 21:01:38 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if the game should launch as a detached process.
|
|
|
|
*
|
|
|
|
* @param {boolean} def Optional. If true, the default value will be returned.
|
|
|
|
* @returns {boolean} Whether or not the game will launch as a detached process.
|
|
|
|
*/
|
2018-06-04 13:28:17 -07:00
|
|
|
exports.getLaunchDetached = function(def = false){
|
2018-05-09 21:01:38 -07:00
|
|
|
return !def ? config.settings.game.launchDetached : DEFAULT_CONFIG.settings.game.launchDetached
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Change the status of whether or not the game should launch as a detached process.
|
|
|
|
*
|
|
|
|
* @param {boolean} launchDetached Whether or not the game should launch as a detached process.
|
|
|
|
*/
|
|
|
|
exports.setLaunchDetached = function(launchDetached){
|
|
|
|
config.settings.game.launchDetached = launchDetached
|
2018-06-04 16:34:47 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Launcher Settings
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if the launcher should download prerelease versions.
|
|
|
|
*
|
|
|
|
* @param {boolean} def Optional. If true, the default value will be returned.
|
|
|
|
* @returns {boolean} Whether or not the launcher should download prerelease versions.
|
|
|
|
*/
|
|
|
|
exports.getAllowPrerelease = function(def = false){
|
|
|
|
return !def ? config.settings.launcher.allowPrerelease : DEFAULT_CONFIG.settings.launcher.allowPrerelease
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Change the status of Whether or not the launcher should download prerelease versions.
|
|
|
|
*
|
|
|
|
* @param {boolean} launchDetached Whether or not the launcher should download prerelease versions.
|
|
|
|
*/
|
|
|
|
exports.setAllowPrerelease = function(allowPrerelease){
|
|
|
|
config.settings.launcher.allowPrerelease = allowPrerelease
|
2017-12-02 21:38:22 -08:00
|
|
|
}
|