(opts: LaunchBaseOpts, serverOverride?: string, gameData?: GameData)
| 539 | } |
| 540 | |
| 541 | async function handleGameDataParams(opts: LaunchBaseOpts, serverOverride?: string, gameData?: GameData) { |
| 542 | if (gameData) { |
| 543 | const mountParams = minimist(gameData.parameters?.split(' ') ?? []); |
| 544 | const extract = gameData.parameters?.startsWith('-extract') ?? false; |
| 545 | const extractFile = mountParams['extracted']; |
| 546 | const server = mountParams['server']; |
| 547 | // Handle -extract param |
| 548 | if (extract) { |
| 549 | let alreadyExtracted = false; |
| 550 | if (extractFile) { |
| 551 | const filePath = path.join(opts.fpPath, opts.htdocsPath, extractFile); |
| 552 | alreadyExtracted = fs.existsSync(filePath); |
| 553 | } |
| 554 | if (!alreadyExtracted) { |
| 555 | // Extract game data to htdocs folder |
| 556 | const gameDataPath = path.join(opts.fpPath, opts.dataPacksFolderPath, getGameDataFilename(gameData) || ''); |
| 557 | const tempPath = path.join(opts.fpPath, '.temp', 'extract'); |
| 558 | await fs.ensureDir(tempPath); |
| 559 | const destPath = path.join(opts.fpPath, opts.htdocsPath); |
| 560 | log.debug('Launcher', `Extracting game data from "${gameDataPath}" to "${tempPath}"`); |
| 561 | await extractFullPromise([gameDataPath, tempPath, { $bin: opts.sevenZipPath }]) |
| 562 | .catch((err) => { |
| 563 | console.log(err); |
| 564 | log.error('Launcher', `Failed to extract game data: ${err}`); |
| 565 | throw err; |
| 566 | }); |
| 567 | const contentFolder = path.join(tempPath, 'content'); |
| 568 | // Move contents of contentFolder to destPath |
| 569 | log.debug('Launcher', `Moving extracted game data from "${contentFolder}" to "${destPath}"`); |
| 570 | for (const file of await fs.readdir(contentFolder)) { |
| 571 | await fs.move(path.join(contentFolder, file), path.join(destPath, file), { overwrite: true }); |
| 572 | } |
| 573 | // Remove temp dir |
| 574 | await fs.remove(tempPath); |
| 575 | } else { |
| 576 | log.debug('Launcher', 'Game data already extracted, skipping...'); |
| 577 | } |
| 578 | } |
| 579 | // Use -server param if present |
| 580 | await opts.changeServer(server || serverOverride); |
| 581 | } else { |
| 582 | // Ignore default server switch if launching curation |
| 583 | await opts.changeServer(serverOverride); |
| 584 | } |
| 585 | } |
| 586 | |
| 587 | export async function checkAndInstallPlatform(platforms: Platform[], state: BackState, openMessageBox: ShowMessageBoxFunc) { |
| 588 | const compsToInstall: ComponentStatus[] = []; |
no test coverage detected