configmanager.ts 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700
  1. import { join } from 'path'
  2. import { pathExistsSync, writeFileSync, ensureDirSync, readFileSync } from 'fs-extra'
  3. import { totalmem } from 'os'
  4. import { SavedAccount } from './model/SavedAccount'
  5. import { LauncherConfig } from './model/LauncherConfig'
  6. import { ModConfig } from './model/ModConfig'
  7. import { NewsCache } from './model/NewsCache'
  8. import { LoggerUtil } from '../logging/loggerutil'
  9. // TODO final review upon usage in implementation.
  10. export class ConfigManager {
  11. private static readonly logger = LoggerUtil.getLogger('ConfigManager')
  12. private static readonly sysRoot = process.env.APPDATA || (process.platform == 'darwin' ? process.env.HOME + '/Library/Application Support' : process.env.HOME)
  13. private static readonly dataPath = join(ConfigManager.sysRoot as string, '.helioslauncher')
  14. // Forked processes do not have access to electron, so we have this workaround.
  15. private static readonly launcherDir = process.env.CONFIG_DIRECT_PATH || require('electron').remote.app.getPath('userData')
  16. /**
  17. * Retrieve the absolute path of the launcher directory.
  18. *
  19. * @returns {string} The absolute path of the launcher directory.
  20. */
  21. public static getLauncherDirectory(): string {
  22. return ConfigManager.launcherDir
  23. }
  24. /**
  25. * Get the launcher's data directory. This is where all files related
  26. * to game launch are installed (common, instances, java, etc).
  27. *
  28. * @returns {string} The absolute path of the launcher's data directory.
  29. */
  30. public static getDataDirectory(def = false): string {
  31. return !def ? ConfigManager.config.settings.launcher.dataDirectory : ConfigManager.DEFAULT_CONFIG.settings.launcher.dataDirectory
  32. }
  33. /**
  34. * Set the new data directory.
  35. *
  36. * @param {string} dataDirectory The new data directory.
  37. */
  38. public static setDataDirectory(dataDirectory: string): void {
  39. ConfigManager.config.settings.launcher.dataDirectory = dataDirectory
  40. }
  41. private static readonly configPath = join(ConfigManager.getLauncherDirectory(), 'config.json')
  42. private static readonly firstLaunch = !pathExistsSync(ConfigManager.configPath)
  43. /**
  44. * Three types of values:
  45. * Static = Explicitly declared.
  46. * Dynamic = Calculated by a private function.
  47. * Resolved = Resolved externally, defaults to null.
  48. */
  49. private static readonly DEFAULT_CONFIG: LauncherConfig = {
  50. settings: {
  51. java: {
  52. minRAM: ConfigManager.resolveMinRAM(),
  53. maxRAM: ConfigManager.resolveMaxRAM(), // Dynamic
  54. executable: null,
  55. jvmOptions: [
  56. '-XX:+UseConcMarkSweepGC',
  57. '-XX:+CMSIncrementalMode',
  58. '-XX:-UseAdaptiveSizePolicy',
  59. '-Xmn128M'
  60. ]
  61. },
  62. game: {
  63. resWidth: 1280,
  64. resHeight: 720,
  65. fullscreen: false,
  66. autoConnect: true,
  67. launchDetached: true
  68. },
  69. launcher: {
  70. allowPrerelease: false,
  71. dataDirectory: ConfigManager.dataPath
  72. }
  73. },
  74. newsCache: {
  75. date: null,
  76. content: null,
  77. dismissed: false
  78. },
  79. clientToken: null,
  80. selectedServer: null, // Resolved
  81. selectedAccount: null,
  82. authenticationDatabase: {},
  83. modConfigurations: []
  84. }
  85. private static config: LauncherConfig = null as unknown as LauncherConfig
  86. public static getAbsoluteMinRAM(): number {
  87. const mem = totalmem()
  88. return mem >= 6000000000 ? 3 : 2
  89. }
  90. public static getAbsoluteMaxRAM(): number {
  91. const mem = totalmem()
  92. const gT16 = mem-16000000000
  93. return Math.floor((mem-1000000000-(gT16 > 0 ? (Number.parseInt(gT16/8 as unknown as string) + 16000000000/4) : mem/4))/1000000000)
  94. }
  95. private static resolveMaxRAM(){
  96. const mem = totalmem()
  97. return mem >= 8000000000 ? '4G' : (mem >= 6000000000 ? '3G' : '2G')
  98. }
  99. private static resolveMinRAM(){
  100. return ConfigManager.resolveMaxRAM()
  101. }
  102. // Persistance Utility Functions
  103. /**
  104. * Save the current configuration to a file.
  105. */
  106. public static save(): void {
  107. writeFileSync(ConfigManager.configPath, JSON.stringify(ConfigManager.config, null, 4), 'UTF-8')
  108. }
  109. /**
  110. * Load the configuration into memory. If a configuration file exists,
  111. * that will be read and saved. Otherwise, a default configuration will
  112. * be generated. Note that "resolved" values default to null and will
  113. * need to be externally assigned.
  114. */
  115. public static load(): void {
  116. let doLoad = true
  117. if(!pathExistsSync(ConfigManager.configPath)){
  118. // Create all parent directories.
  119. ensureDirSync(join(ConfigManager.configPath, '..'))
  120. doLoad = false
  121. ConfigManager.config = ConfigManager.DEFAULT_CONFIG
  122. ConfigManager.save()
  123. }
  124. if(doLoad){
  125. let doValidate = false
  126. try {
  127. ConfigManager.config = JSON.parse(readFileSync(ConfigManager.configPath, 'UTF-8'))
  128. doValidate = true
  129. } catch (err){
  130. ConfigManager.logger.error(err)
  131. ConfigManager.logger.info('Configuration file contains malformed JSON or is corrupt.')
  132. ConfigManager.logger.info('Generating a new configuration file.')
  133. ensureDirSync(join(ConfigManager.configPath, '..'))
  134. ConfigManager.config = ConfigManager.DEFAULT_CONFIG
  135. ConfigManager.save()
  136. }
  137. if(doValidate){
  138. ConfigManager.config = ConfigManager.validateKeySet(ConfigManager.DEFAULT_CONFIG, ConfigManager.config)
  139. ConfigManager.save()
  140. }
  141. }
  142. ConfigManager.logger.info('Successfully Loaded')
  143. }
  144. /**
  145. * @returns {boolean} Whether or not the manager has been loaded.
  146. */
  147. public static isLoaded(): boolean {
  148. return ConfigManager.config != null
  149. }
  150. /**
  151. * Validate that the destination object has at least every field
  152. * present in the source object. Assign a default value otherwise.
  153. *
  154. * @param {Object} srcObj The source object to reference against.
  155. * @param {Object} destObj The destination object.
  156. * @returns {Object} A validated destination object.
  157. */
  158. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  159. private static validateKeySet(srcObj: any, destObj: any){
  160. if(srcObj == null){
  161. srcObj = {}
  162. }
  163. const validationBlacklist = ['authenticationDatabase']
  164. const keys = Object.keys(srcObj)
  165. for(let i=0; i<keys.length; i++){
  166. if(typeof destObj[keys[i]] === 'undefined'){
  167. destObj[keys[i]] = srcObj[keys[i]]
  168. } else if(typeof srcObj[keys[i]] === 'object' && srcObj[keys[i]] != null && !(srcObj[keys[i]] instanceof Array) && validationBlacklist.indexOf(keys[i]) === -1){
  169. destObj[keys[i]] = ConfigManager.validateKeySet(srcObj[keys[i]], destObj[keys[i]])
  170. }
  171. }
  172. return destObj
  173. }
  174. /**
  175. * Check to see if this is the first time the user has launched the
  176. * application. This is determined by the existance of the data path.
  177. *
  178. * @returns {boolean} True if this is the first launch, otherwise false.
  179. */
  180. public static isFirstLaunch(): boolean {
  181. return ConfigManager.firstLaunch
  182. }
  183. /**
  184. * Returns the name of the folder in the OS temp directory which we
  185. * will use to extract and store native dependencies for game launch.
  186. *
  187. * @returns {string} The name of the folder.
  188. */
  189. public static getTempNativeFolder(): string {
  190. return 'HeliosLauncherNatives'
  191. }
  192. // System Settings (Unconfigurable on UI)
  193. /**
  194. * Retrieve the news cache to determine
  195. * whether or not there is newer news.
  196. *
  197. * @returns {NewsCache} The news cache object.
  198. */
  199. public static getNewsCache(): NewsCache {
  200. return ConfigManager.config.newsCache
  201. }
  202. /**
  203. * Set the new news cache object.
  204. *
  205. * @param {Object} newsCache The new news cache object.
  206. */
  207. public static setNewsCache(newsCache: NewsCache): void {
  208. ConfigManager.config.newsCache = newsCache
  209. }
  210. /**
  211. * Set whether or not the news has been dismissed (checked)
  212. *
  213. * @param {boolean} dismissed Whether or not the news has been dismissed (checked).
  214. */
  215. public static setNewsCacheDismissed(dismissed: boolean): void {
  216. ConfigManager.config.newsCache.dismissed = dismissed
  217. }
  218. /**
  219. * Retrieve the common directory for shared
  220. * game files (assets, libraries, etc).
  221. *
  222. * @returns {string} The launcher's common directory.
  223. */
  224. public static getCommonDirectory(): string {
  225. return join(ConfigManager.getDataDirectory(), 'common')
  226. }
  227. /**
  228. * Retrieve the instance directory for the per
  229. * server game directories.
  230. *
  231. * @returns {string} The launcher's instance directory.
  232. */
  233. public static getInstanceDirectory(): string {
  234. return join(ConfigManager.getDataDirectory(), 'instances')
  235. }
  236. /**
  237. * Retrieve the launcher's Client Token.
  238. * There is no default client token.
  239. *
  240. * @returns {string | null} The launcher's Client Token.
  241. */
  242. public static getClientToken(): string | null {
  243. return ConfigManager.config.clientToken
  244. }
  245. /**
  246. * Set the launcher's Client Token.
  247. *
  248. * @param {string} clientToken The launcher's new Client Token.
  249. */
  250. public static setClientToken(clientToken: string): void {
  251. ConfigManager.config.clientToken = clientToken
  252. }
  253. /**
  254. * Retrieve the ID of the selected serverpack.
  255. *
  256. * @param {boolean} def Optional. If true, the default value will be returned.
  257. * @returns {string | null} The ID of the selected serverpack.
  258. */
  259. public static getSelectedServer(def = false): string | null {
  260. return !def ? ConfigManager.config.selectedServer : ConfigManager.DEFAULT_CONFIG.selectedServer
  261. }
  262. /**
  263. * Set the ID of the selected serverpack.
  264. *
  265. * @param {string} serverID The ID of the new selected serverpack.
  266. */
  267. public static setSelectedServer(serverID: string): void {
  268. ConfigManager.config.selectedServer = serverID
  269. }
  270. /**
  271. * Get an array of each account currently authenticated by the launcher.
  272. *
  273. * @returns {Array.<SavedAccount>} An array of each stored authenticated account.
  274. */
  275. public static getAuthAccounts(): {[uuid: string]: SavedAccount} {
  276. return ConfigManager.config.authenticationDatabase
  277. }
  278. /**
  279. * Returns the authenticated account with the given uuid. Value may
  280. * be null.
  281. *
  282. * @param {string} uuid The uuid of the authenticated account.
  283. * @returns {SavedAccount} The authenticated account with the given uuid.
  284. */
  285. public static getAuthAccount(uuid: string): SavedAccount {
  286. return ConfigManager.config.authenticationDatabase[uuid]
  287. }
  288. /**
  289. * Update the access token of an authenticated account.
  290. *
  291. * @param {string} uuid The uuid of the authenticated account.
  292. * @param {string} accessToken The new Access Token.
  293. *
  294. * @returns {SavedAccount} The authenticated account object created by this action.
  295. */
  296. public static updateAuthAccount(uuid: string, accessToken: string): SavedAccount {
  297. ConfigManager.config.authenticationDatabase[uuid].accessToken = accessToken
  298. return ConfigManager.config.authenticationDatabase[uuid]
  299. }
  300. /**
  301. * Adds an authenticated account to the database to be stored.
  302. *
  303. * @param {string} uuid The uuid of the authenticated account.
  304. * @param {string} accessToken The accessToken of the authenticated account.
  305. * @param {string} username The username (usually email) of the authenticated account.
  306. * @param {string} displayName The in game name of the authenticated account.
  307. *
  308. * @returns {SavedAccount} The authenticated account object created by this action.
  309. */
  310. public static addAuthAccount(
  311. uuid: string,
  312. accessToken: string,
  313. username: string,
  314. displayName: string
  315. ): SavedAccount {
  316. ConfigManager.config.selectedAccount = uuid
  317. ConfigManager.config.authenticationDatabase[uuid] = {
  318. accessToken,
  319. username: username.trim(),
  320. uuid: uuid.trim(),
  321. displayName: displayName.trim()
  322. }
  323. return ConfigManager.config.authenticationDatabase[uuid]
  324. }
  325. /**
  326. * Remove an authenticated account from the database. If the account
  327. * was also the selected account, a new one will be selected. If there
  328. * are no accounts, the selected account will be null.
  329. *
  330. * @param {string} uuid The uuid of the authenticated account.
  331. *
  332. * @returns {boolean} True if the account was removed, false if it never existed.
  333. */
  334. public static removeAuthAccount(uuid: string): boolean {
  335. if(ConfigManager.config.authenticationDatabase[uuid] != null){
  336. delete ConfigManager.config.authenticationDatabase[uuid]
  337. if(ConfigManager.config.selectedAccount === uuid){
  338. const keys = Object.keys(ConfigManager.config.authenticationDatabase)
  339. if(keys.length > 0){
  340. ConfigManager.config.selectedAccount = keys[0]
  341. } else {
  342. ConfigManager.config.selectedAccount = null
  343. ConfigManager.config.clientToken = null
  344. }
  345. }
  346. return true
  347. }
  348. return false
  349. }
  350. /**
  351. * Get the currently selected authenticated account.
  352. *
  353. * @returns {SavedAccount | null} The selected authenticated account.
  354. */
  355. public static getSelectedAccount(): SavedAccount | null {
  356. return ConfigManager.config.selectedAccount == null ?
  357. null :
  358. ConfigManager.config.authenticationDatabase[ConfigManager.config.selectedAccount]
  359. }
  360. /**
  361. * Set the selected authenticated account.
  362. *
  363. * @param {string} uuid The UUID of the account which is to be set
  364. * as the selected account.
  365. *
  366. * @returns {SavedAccount} The selected authenticated account.
  367. */
  368. public static setSelectedAccount(uuid: string): SavedAccount {
  369. const authAcc = ConfigManager.config.authenticationDatabase[uuid]
  370. if(authAcc != null) {
  371. ConfigManager.config.selectedAccount = uuid
  372. }
  373. return authAcc
  374. }
  375. /**
  376. * Get an array of each mod configuration currently stored.
  377. *
  378. * @returns {Array.<ModConfig>} An array of each stored mod configuration.
  379. */
  380. public static getModConfigurations(): ModConfig[] {
  381. return ConfigManager.config.modConfigurations
  382. }
  383. /**
  384. * Set the array of stored mod configurations.
  385. *
  386. * @param {Array.<ModConfig>} configurations An array of mod configurations.
  387. */
  388. public static setModConfigurations(configurations: ModConfig[]): void {
  389. ConfigManager.config.modConfigurations = configurations
  390. }
  391. /**
  392. * Get the mod configuration for a specific server.
  393. *
  394. * @param {string} serverid The id of the server.
  395. * @returns {ModConfig | null} The mod configuration for the given server.
  396. */
  397. public static getModConfiguration(serverid: string): ModConfig | null {
  398. const cfgs = ConfigManager.config.modConfigurations
  399. for(let i=0; i<cfgs.length; i++){
  400. if(cfgs[i].id === serverid){
  401. return cfgs[i]
  402. }
  403. }
  404. return null
  405. }
  406. /**
  407. * Set the mod configuration for a specific server. This overrides any existing value.
  408. *
  409. * @param {string} serverid The id of the server for the given mod configuration.
  410. * @param {ModConfig} configuration The mod configuration for the given server.
  411. */
  412. public static setModConfiguration(serverid: string, configuration: ModConfig): void {
  413. const cfgs = ConfigManager.config.modConfigurations
  414. for(let i=0; i<cfgs.length; i++){
  415. if(cfgs[i].id === serverid){
  416. cfgs[i] = configuration
  417. return
  418. }
  419. }
  420. cfgs.push(configuration)
  421. }
  422. // User Configurable Settings
  423. // Java Settings
  424. /**
  425. * Retrieve the minimum amount of memory for JVM initialization. This value
  426. * contains the units of memory. For example, '5G' = 5 GigaBytes, '1024M' =
  427. * 1024 MegaBytes, etc.
  428. *
  429. * @param {boolean} def Optional. If true, the default value will be returned.
  430. * @returns {string} The minimum amount of memory for JVM initialization.
  431. */
  432. public static getMinRAM(def = false): string {
  433. return !def ? ConfigManager.config.settings.java.minRAM : ConfigManager.DEFAULT_CONFIG.settings.java.minRAM
  434. }
  435. /**
  436. * Set the minimum amount of memory for JVM initialization. This value should
  437. * contain the units of memory. For example, '5G' = 5 GigaBytes, '1024M' =
  438. * 1024 MegaBytes, etc.
  439. *
  440. * @param {string} minRAM The new minimum amount of memory for JVM initialization.
  441. */
  442. public static setMinRAM(minRAM: string): void {
  443. ConfigManager.config.settings.java.minRAM = minRAM
  444. }
  445. /**
  446. * Retrieve the maximum amount of memory for JVM initialization. This value
  447. * contains the units of memory. For example, '5G' = 5 GigaBytes, '1024M' =
  448. * 1024 MegaBytes, etc.
  449. *
  450. * @param {boolean} def Optional. If true, the default value will be returned.
  451. * @returns {string} The maximum amount of memory for JVM initialization.
  452. */
  453. public static getMaxRAM(def = false): string {
  454. return !def ? ConfigManager.config.settings.java.maxRAM : ConfigManager.resolveMaxRAM()
  455. }
  456. /**
  457. * Set the maximum amount of memory for JVM initialization. This value should
  458. * contain the units of memory. For example, '5G' = 5 GigaBytes, '1024M' =
  459. * 1024 MegaBytes, etc.
  460. *
  461. * @param {string} maxRAM The new maximum amount of memory for JVM initialization.
  462. */
  463. public static setMaxRAM(maxRAM: string): void {
  464. ConfigManager.config.settings.java.maxRAM = maxRAM
  465. }
  466. /**
  467. * Retrieve the path of the Java Executable.
  468. *
  469. * This is a resolved configuration value and defaults to null until externally assigned.
  470. *
  471. * @returns {string | null} The path of the Java Executable.
  472. */
  473. public static getJavaExecutable(): string | null {
  474. return ConfigManager.config.settings.java.executable
  475. }
  476. /**
  477. * Set the path of the Java Executable.
  478. *
  479. * @param {string} executable The new path of the Java Executable.
  480. */
  481. public static setJavaExecutable(executable: string): void {
  482. ConfigManager.config.settings.java.executable = executable
  483. }
  484. /**
  485. * Retrieve the additional arguments for JVM initialization. Required arguments,
  486. * such as memory allocation, will be dynamically resolved and will not be included
  487. * in this value.
  488. *
  489. * @param {boolean} def Optional. If true, the default value will be returned.
  490. * @returns {Array.<string>} An array of the additional arguments for JVM initialization.
  491. */
  492. public static getJVMOptions(def = false): string[] {
  493. return !def ? ConfigManager.config.settings.java.jvmOptions : ConfigManager.DEFAULT_CONFIG.settings.java.jvmOptions
  494. }
  495. /**
  496. * Set the additional arguments for JVM initialization. Required arguments,
  497. * such as memory allocation, will be dynamically resolved and should not be
  498. * included in this value.
  499. *
  500. * @param {Array.<string>} jvmOptions An array of the new additional arguments for JVM
  501. * initialization.
  502. */
  503. public static setJVMOptions(jvmOptions: string[]): void {
  504. ConfigManager.config.settings.java.jvmOptions = jvmOptions
  505. }
  506. // Game Settings
  507. /**
  508. * Retrieve the width of the game window.
  509. *
  510. * @param {boolean} def Optional. If true, the default value will be returned.
  511. * @returns {number} The width of the game window.
  512. */
  513. public static getGameWidth(def = false): number {
  514. return !def ? ConfigManager.config.settings.game.resWidth : ConfigManager.DEFAULT_CONFIG.settings.game.resWidth
  515. }
  516. /**
  517. * Set the width of the game window.
  518. *
  519. * @param {number} resWidth The new width of the game window.
  520. */
  521. public static setGameWidth(resWidth: number): void {
  522. ConfigManager.config.settings.game.resWidth = Number.parseInt(resWidth as unknown as string)
  523. }
  524. /**
  525. * Validate a potential new width value.
  526. *
  527. * @param {number} resWidth The width value to validate.
  528. * @returns {boolean} Whether or not the value is valid.
  529. */
  530. public static validateGameWidth(resWidth: number): boolean {
  531. const nVal = Number.parseInt(resWidth as unknown as string)
  532. return Number.isInteger(nVal) && nVal >= 0
  533. }
  534. /**
  535. * Retrieve the height of the game window.
  536. *
  537. * @param {boolean} def Optional. If true, the default value will be returned.
  538. * @returns {number} The height of the game window.
  539. */
  540. public static getGameHeight(def = false): number {
  541. return !def ? ConfigManager.config.settings.game.resHeight : ConfigManager.DEFAULT_CONFIG.settings.game.resHeight
  542. }
  543. /**
  544. * Set the height of the game window.
  545. *
  546. * @param {number} resHeight The new height of the game window.
  547. */
  548. public static setGameHeight(resHeight: number): void {
  549. ConfigManager.config.settings.game.resHeight = Number.parseInt(resHeight as unknown as string)
  550. }
  551. /**
  552. * Validate a potential new height value.
  553. *
  554. * @param {number} resHeight The height value to validate.
  555. * @returns {boolean} Whether or not the value is valid.
  556. */
  557. public static validateGameHeight(resHeight: number): boolean {
  558. const nVal = Number.parseInt(resHeight as unknown as string)
  559. return Number.isInteger(nVal) && nVal >= 0
  560. }
  561. /**
  562. * Check if the game should be launched in fullscreen mode.
  563. *
  564. * @param {boolean} def Optional. If true, the default value will be returned.
  565. * @returns {boolean} Whether or not the game is set to launch in fullscreen mode.
  566. */
  567. public static getFullscreen(def = false): boolean {
  568. return !def ? ConfigManager.config.settings.game.fullscreen : ConfigManager.DEFAULT_CONFIG.settings.game.fullscreen
  569. }
  570. /**
  571. * Change the status of if the game should be launched in fullscreen mode.
  572. *
  573. * @param {boolean} fullscreen Whether or not the game should launch in fullscreen mode.
  574. */
  575. public static setFullscreen(fullscreen: boolean): void {
  576. ConfigManager.config.settings.game.fullscreen = fullscreen
  577. }
  578. /**
  579. * Check if the game should auto connect to servers.
  580. *
  581. * @param {boolean} def Optional. If true, the default value will be returned.
  582. * @returns {boolean} Whether or not the game should auto connect to servers.
  583. */
  584. public static getAutoConnect(def = false): boolean {
  585. return !def ? ConfigManager.config.settings.game.autoConnect : ConfigManager.DEFAULT_CONFIG.settings.game.autoConnect
  586. }
  587. /**
  588. * Change the status of whether or not the game should auto connect to servers.
  589. *
  590. * @param {boolean} autoConnect Whether or not the game should auto connect to servers.
  591. */
  592. public static setAutoConnect(autoConnect: boolean): void {
  593. ConfigManager.config.settings.game.autoConnect = autoConnect
  594. }
  595. /**
  596. * Check if the game should launch as a detached process.
  597. *
  598. * @param {boolean} def Optional. If true, the default value will be returned.
  599. * @returns {boolean} Whether or not the game will launch as a detached process.
  600. */
  601. public static getLaunchDetached(def = false): boolean {
  602. return !def ? ConfigManager.config.settings.game.launchDetached : ConfigManager.DEFAULT_CONFIG.settings.game.launchDetached
  603. }
  604. /**
  605. * Change the status of whether or not the game should launch as a detached process.
  606. *
  607. * @param {boolean} launchDetached Whether or not the game should launch as a detached process.
  608. */
  609. public static setLaunchDetached(launchDetached: boolean): void {
  610. ConfigManager.config.settings.game.launchDetached = launchDetached
  611. }
  612. // Launcher Settings
  613. /**
  614. * Check if the launcher should download prerelease versions.
  615. *
  616. * @param {boolean} def Optional. If true, the default value will be returned.
  617. * @returns {boolean} Whether or not the launcher should download prerelease versions.
  618. */
  619. public static getAllowPrerelease(def = false): boolean {
  620. return !def ? ConfigManager.config.settings.launcher.allowPrerelease : ConfigManager.DEFAULT_CONFIG.settings.launcher.allowPrerelease
  621. }
  622. /**
  623. * Change the status of Whether or not the launcher should download prerelease versions.
  624. *
  625. * @param {boolean} launchDetached Whether or not the launcher should download prerelease versions.
  626. */
  627. public static setAllowPrerelease(allowPrerelease: boolean): void {
  628. ConfigManager.config.settings.launcher.allowPrerelease = allowPrerelease
  629. }
  630. }