()
| 672 | } |
| 673 | |
| 674 | async function initialize() { |
| 675 | await whenReady(); |
| 676 | |
| 677 | if (process.platform === 'darwin') { |
| 678 | state.pathVar = await getMacPATH(); |
| 679 | console.log('Back - Started Mac PATH-reading'); |
| 680 | } |
| 681 | |
| 682 | try { |
| 683 | const [extConf] = await (Promise.all([ |
| 684 | ExtConfigFile.readOrCreateFile(path.join(state.config.flashpointPath, EXT_CONFIG_FILENAME)) |
| 685 | ])); |
| 686 | state.extConfig = extConf; |
| 687 | } catch (e) { |
| 688 | console.log(e); |
| 689 | // Non-fatal, don't quit. |
| 690 | } |
| 691 | |
| 692 | console.log('Back - Loaded Extension Config'); |
| 693 | |
| 694 | // Register middleware |
| 695 | |
| 696 | state.socketServer.registerMiddlewareBackRes((ctx, next) => { |
| 697 | // Fire events for adding / removal of curations |
| 698 | if (ctx.type === BackOut.CURATE_LIST_CHANGE) { |
| 699 | const args = ctx.args as BackResParams<typeof ctx.type>; |
| 700 | state.apiEmitters.curations.onDidCurationListChange.fire( { |
| 701 | added: args[0], |
| 702 | removed: args[1] |
| 703 | }); |
| 704 | } |
| 705 | return next(); |
| 706 | }); |
| 707 | |
| 708 | // Create Game Data Directory and clean up temp files |
| 709 | const fullDataPacksFolderPath = path.join(state.config.flashpointPath, state.preferences.dataPacksFolderPath); |
| 710 | try { |
| 711 | fs.promises.readdir(fullDataPacksFolderPath) |
| 712 | .then((files) => { |
| 713 | for (const f of files) { |
| 714 | if (f.endsWith('.temp')) { |
| 715 | fs.promises.unlink(path.join(fullDataPacksFolderPath, f)); |
| 716 | } |
| 717 | } |
| 718 | }); |
| 719 | } catch (error) { |
| 720 | console.log('Failed to create default Data Packs folder!'); |
| 721 | // Non-fatal, don't quit. |
| 722 | } |
| 723 | |
| 724 | if (state.preferences.enableVerboseLogging) { |
| 725 | loggerSusbcribe((err, line) => { |
| 726 | if (err) { |
| 727 | log.error('Rust Library', 'Logging error - ' + err); |
| 728 | } else { |
| 729 | try { |
| 730 | const output = line.toString().trim(); |
| 731 | if (output) { |
nothing calls this directly
no test coverage detected