(opts: LaunchAddAppOpts, child: boolean, serverOverride?: string)
| 60 | const logSource = 'Game Launcher'; |
| 61 | |
| 62 | export async function launchAdditionalApplication(opts: LaunchAddAppOpts, child: boolean, serverOverride?: string): Promise<void> { |
| 63 | await checkAndInstallPlatform(opts.parentGame.detailedPlatforms!, opts.state, opts.openDialog); |
| 64 | switch (opts.addApp.applicationPath) { |
| 65 | case ':message:': { |
| 66 | const dialogId = await opts.openDialog({ |
| 67 | largeMessage: true, |
| 68 | message: opts.addApp.launchCommand, |
| 69 | buttons: opts.addApp.waitForExit ? ['Ok', 'Cancel'] : ['Ok'], |
| 70 | }); |
| 71 | const result = (await awaitDialog(opts.state, dialogId)).buttonIdx; |
| 72 | if (result !== 0) { |
| 73 | throw 'User aborted game launch (denied message box)'; |
| 74 | } |
| 75 | return; |
| 76 | } |
| 77 | case ':extras:': { |
| 78 | const folderPath = fixSlashes(path.join(opts.fpPath, path.posix.join('Extras', opts.addApp.launchCommand))); |
| 79 | return opts.openExternal(folderPath, { activate: true }) |
| 80 | .catch(error => { |
| 81 | if (error) { |
| 82 | opts.openDialog({ |
| 83 | largeMessage: true, |
| 84 | message: `${error.toString()}\n`+ |
| 85 | `Path: ${folderPath}`, |
| 86 | buttons: ['Ok'], |
| 87 | }); |
| 88 | } |
| 89 | }); |
| 90 | } |
| 91 | default: { |
| 92 | let appPath: string = getApplicationPath(opts.addApp.applicationPath, opts.execMappings, opts.native); |
| 93 | const appPathOverride = opts.appPathOverrides.filter(a => a.enabled).find(a => a.path === appPath); |
| 94 | if (appPathOverride) { appPath = appPathOverride.override; } |
| 95 | const appArgs: string = opts.addApp.launchCommand; |
| 96 | const useWine: boolean = process.platform != 'win32' && appPath.endsWith('.exe'); |
| 97 | const gamePath: string = path.isAbsolute(appPath) ? fixSlashes(appPath) : fixSlashes(path.join(opts.fpPath, appPath)); |
| 98 | if (opts.parentGame.activeDataId && !child) { |
| 99 | // If run from a game, game would already have done this! |
| 100 | const gameData = await fpDatabase.findGameDataById(opts.parentGame.activeDataId); |
| 101 | await handleGameDataParams(opts, serverOverride, gameData || undefined); |
| 102 | } |
| 103 | const launchInfo: LaunchInfo = { |
| 104 | override: opts.override, |
| 105 | gamePath: gamePath, |
| 106 | gameArgs: appArgs, |
| 107 | useWine, |
| 108 | env: getEnvironment(opts.fpPath, opts.proxy, opts.envPATH), |
| 109 | }; |
| 110 | const managedProc = opts.runAddApp(launchInfo); |
| 111 | log.info(logSource, `Launch ${managedProc.name} (PID: ${managedProc.getPid()}) [\n`+ |
| 112 | ` applicationPath: "${opts.addApp.applicationPath}",\n`+ |
| 113 | ` launchCommand: "${opts.addApp.launchCommand}" ]`); |
| 114 | return new Promise((resolve, reject) => { |
| 115 | if (opts.addApp.waitForExit) { |
| 116 | resolve(); |
| 117 | } else { |
| 118 | if (managedProc.getState() !== ProcessState.RUNNING) { resolve(); } |
| 119 | else { |
no test coverage detected