(message: any)
| 279 | } |
| 280 | |
| 281 | async function prepForInit(message: any): Promise<void> { |
| 282 | console.log(`--- Build Version: ${VERSION} ---`); |
| 283 | console.log('Back - Initializing...'); |
| 284 | |
| 285 | const content: BackInitArgs = JSON.parse(message); |
| 286 | state.isDev = content.isDev; |
| 287 | state.verbose = content.verbose; |
| 288 | state.configFolder = content.configFolder; |
| 289 | state.localeCode = content.localeCode; |
| 290 | state.exePath = content.exePath; |
| 291 | state.version = content.version; |
| 292 | console.log(`Version: ${state.version}`); |
| 293 | state.versionStr = `${content.version} ${content.isDev ? 'DEV' : ''}`; |
| 294 | state.acceptRemote = content.acceptRemote; |
| 295 | state.logFile = new LogFile( |
| 296 | state.isDev ? |
| 297 | path.join(process.cwd(), 'launcher.log') |
| 298 | : path.join(process.platform == 'darwin' ? state.configFolder : path.dirname(content.exePath), 'launcher.log')); |
| 299 | |
| 300 | const addLog = (entry: ILogEntry): number => { return state.log.push(entry) - 1; }; |
| 301 | global.log = { |
| 302 | trace: logFactory(LogLevel.TRACE, state.socketServer, addLog, state.logFile, state.verbose, state.apiEmitters.onLog), |
| 303 | debug: logFactory(LogLevel.DEBUG, state.socketServer, addLog, state.logFile, state.verbose, state.apiEmitters.onLog), |
| 304 | info: logFactory(LogLevel.INFO, state.socketServer, addLog, state.logFile, state.verbose, state.apiEmitters.onLog), |
| 305 | warn: logFactory(LogLevel.WARN, state.socketServer, addLog, state.logFile, state.verbose, state.apiEmitters.onLog), |
| 306 | error: logFactory(LogLevel.ERROR, state.socketServer, addLog, state.logFile, state.verbose, state.apiEmitters.onLog) |
| 307 | }; |
| 308 | |
| 309 | log.info('Launcher', `Build Version: ${VERSION}`); |
| 310 | log.info('Launcher', `FPA Version: ${FPA_VERSION}`); |
| 311 | |
| 312 | state.socketServer.secret = content.secret; |
| 313 | |
| 314 | log.info('Launcher', `Starting Flashpoint Launcher ${state.versionStr}`); |
| 315 | |
| 316 | // Set SevenZip binary path |
| 317 | { |
| 318 | const basePath = state.isDev ? process.cwd() : path.dirname(state.exePath); |
| 319 | switch (process.platform) { |
| 320 | case 'darwin': state.sevenZipPath = path.join(basePath, 'extern/7zip-bin/mac', '7za'); break; |
| 321 | case 'win32': state.sevenZipPath = path.join(basePath, 'extern/7zip-bin/win', process.arch, '7za'); break; |
| 322 | case 'linux': state.sevenZipPath = path.join(basePath, 'extern/7zip-bin/linux', process.arch, '7za'); break; |
| 323 | default: state.sevenZipPath = '7za'; break; |
| 324 | } |
| 325 | } |
| 326 | |
| 327 | // Read configs & preferences |
| 328 | // readOrCreateFile can throw errors, let's wrap it in try-catch each time. |
| 329 | try { |
| 330 | state.config = await ConfigFile.readOrCreateFile(path.join(state.configFolder, CONFIG_FILENAME)); |
| 331 | } catch (e) { |
| 332 | console.log(e); |
| 333 | // Fatal, quit. |
| 334 | send({ quit: true, errorMessage: 'Invalid config.json!' }); |
| 335 | return; |
| 336 | } |
| 337 | |
| 338 | console.log('Back - Loaded Config'); |
nothing calls this directly
no test coverage detected