import { file } from "bun"; import { z } from "zod"; import { toCamelCaseKeys } from "../../utils/zod.ts"; import { getLauncherInstalledPath } from "./path.ts"; /** * Zod schema for working with the Epic Games Launcher's * `LauncherInstalled.dat` file. */ export const launcherInstalledSchema = toCamelCaseKeys( z.looseObject({ installationList: toCamelCaseKeys( z.looseObject({ installLocation: z.string(), /** @type {string | undefined} */ namespaceId: z.unknown().optional(), /** @type {string | undefined} */ itemId: z.unknown().optional(), /** @type {string | undefined} */ artifactId: z.unknown().optional(), /** @type {string | undefined} */ appVersion: z.unknown().optional(), appName: z.string(), }), ).array(), }), ); /** * Gets information about Epic Games Launcher apps installed on this * computer, parsed from its `LauncherInstalled.dat` file. */ export const getLauncherInstalled = async () => launcherInstalledSchema.parse(await file(getLauncherInstalledPath()).json()) .installationList;