configmanager.ts 25 KB

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