<commit_before>
import mklog, {Logger} from "../../util/log";
const log = mklog("windows-prereqs");

import {each, find} from "underscore";
import spawn from "../../util/spawn";
import pathmaker from "../../util/pathmaker";

import * as ospath from "path";

import {IManifest, IMarket, ICaveRecord} from "../../types";

interface IWindowsPrereqsOpts {
  manifest: IManifest;
  globalMarket: IMarket;
  caveId: string;
  logger: Logger;
}

export default async function handleWindowsPrereqs (opts: IWindowsPrereqsOpts) {
  const {globalMarket, caveId} = opts;
  const cave = globalMarket.getEntity("caves", caveId);

  if (!cave.installedUE4Prereq) {
    await handleUE4Prereq(cave, opts);
  }

  await handleManifest(opts);
}

async function handleUE4Prereq (cave: ICaveRecord, opts: IWindowsPrereqsOpts) {
  const {globalMarket} = opts;

  try {
    const executables = cave.executables;
    const prereqRelativePath = find(executables, (x: string) => /UE4PrereqSetup(_x64)?.exe/i.test(x));
    if (!prereqRelativePath) {
      // no UE4 prereqs
      return;
    }

    const appPath = pathmaker.appPath(cave);
    const prereqFullPath = ospath.join(appPath, prereqRelativePath);

    log(opts, `launching UE4 prereq setup ${prereqFullPath}`);
    const code = await spawn({
      command: ospath.join(appPath, prereqFullPath),
      args: [<commit_msg>Fix UE4 prereq path bug<commit_after>
import mklog, {Logger} from "../../util/log";
const log = mklog("windows-prereqs");

import {each, find} from "underscore";
import spawn from "../../util/spawn";
import pathmaker from "../../util/pathmaker";

import * as ospath from "path";

import {IManifest, IMarket, ICaveRecord} from "../../types";

interface IWindowsPrereqsOpts {
  manifest: IManifest;
  globalMarket: IMarket;
  caveId: string;
  logger: Logger;
}

export default async function handleWindowsPrereqs (opts: IWindowsPrereqsOpts) {
  const {globalMarket, caveId} = opts;
  const cave = globalMarket.getEntity("caves", caveId);

  if (!cave.installedUE4Prereq) {
    await handleUE4Prereq(cave, opts);
  }

  await handleManifest(opts);
}

async function handleUE4Prereq (cave: ICaveRecord, opts: IWindowsPrereqsOpts) {
  const {globalMarket} = opts;

  try {
    const executables = cave.executables;
    const prereqRelativePath = find(executables, (x: string) => /UE4PrereqSetup(_x64)?.exe/i.test(x));
    if (!prereqRelativePath) {
      // no UE4 prereqs
      return;
    }

    const appPath = pathmaker.appPath(cave);
    const prereqFullPath = ospath.join(appPath, prereqRelativePath);

    log(opts, `launching UE4 prereq setup ${prereqFullPath}`);
    const code = await spawn({
      command: prereqFullPath,
      args: [
{'fraction_non_alphanumeric': 0.13120830244625648, 'fraction_numerical': 0.006300963676797628, 'mean_word_length': 4.026070763500931, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3816649', 'n_tokens_mistral': 927, 'n_tokens_neox': 906, 'n_words': 227}