(opts: LaunchGameOpts, onWillEvent: ApiEmitterFirable<GameLaunchInfo>, curation: boolean, serverOverride?: string)
| 134 | * @param serverOverride Change active server for this game launch only |
| 135 | */ |
| 136 | export async function launchGame(opts: LaunchGameOpts, onWillEvent: ApiEmitterFirable<GameLaunchInfo>, curation: boolean, serverOverride?: string): Promise<void> { |
| 137 | await checkAndInstallPlatform(opts.game.detailedPlatforms!, opts.state, opts.openDialog); |
| 138 | // Handle any special game data actions |
| 139 | const gameData = !curation ? (opts.game.activeDataId ? await fpDatabase.findGameDataById(opts.game.activeDataId) : null) : null; |
| 140 | // Run all provided additional applications with "AutoRunBefore" enabled |
| 141 | if (opts.game.addApps) { |
| 142 | const addAppOpts: Omit<LaunchAddAppOpts, 'addApp' | 'parentGame'> = { |
| 143 | changeServer: opts.changeServer, |
| 144 | fpPath: opts.fpPath, |
| 145 | htdocsPath: opts.htdocsPath, |
| 146 | dataPacksFolderPath: opts.dataPacksFolderPath, |
| 147 | sevenZipPath: opts.sevenZipPath, |
| 148 | native: opts.native, |
| 149 | execMappings: opts.execMappings, |
| 150 | lang: opts.lang, |
| 151 | isDev: opts.isDev, |
| 152 | exePath: opts.exePath, |
| 153 | appPathOverrides: opts.appPathOverrides, |
| 154 | providers: opts.providers, |
| 155 | proxy: opts.proxy, |
| 156 | openDialog: opts.openDialog, |
| 157 | openExternal: opts.openExternal, |
| 158 | runGame: opts.runGame, |
| 159 | runAddApp: opts.runAddApp, |
| 160 | envPATH: opts.envPATH, |
| 161 | state: opts.state, |
| 162 | activeConfig: opts.activeConfig, |
| 163 | autoClearWininetCache: opts.autoClearWininetCache, |
| 164 | override: opts.override, |
| 165 | }; |
| 166 | for (const addApp of opts.game.addApps) { |
| 167 | if (addApp.autoRunBefore) { |
| 168 | await launchAdditionalApplication({ ...addAppOpts, addApp, parentGame: opts.game }, curation); |
| 169 | } |
| 170 | } |
| 171 | } |
| 172 | // Launch game callback |
| 173 | const launchCb = async (launchInfo: GameLaunchInfo): Promise<void> => { |
| 174 | /** |
| 175 | * Order |
| 176 | * - API listeners |
| 177 | * - Middleware |
| 178 | * - Handle game data params |
| 179 | */ |
| 180 | await onWillEvent.fire(launchInfo) |
| 181 | .then(async () => { |
| 182 | // Handle middleware |
| 183 | if (launchInfo.activeConfig) { |
| 184 | log.info(logSource, `Using Game Configuration: ${launchInfo.activeConfig.name}`); |
| 185 | for (const middlewareConfig of launchInfo.activeConfig.middleware) { |
| 186 | // Find middleware in registry |
| 187 | const middleware = opts.state.registry.middlewares.get(middlewareConfig.middlewareId); |
| 188 | if (!middleware) { |
| 189 | throw `Middleware not found (${middlewareConfig.middlewareId})`; |
| 190 | } |
| 191 | try { |
| 192 | launchInfo = await Promise.resolve(middleware.execute(launchInfo, middlewareConfig)); |
| 193 | } catch (err) { |
nothing calls this directly
no test coverage detected