import path from "node:path"; export interface RuntimeResourcePathOptions { isPackaged: boolean; resourcesPath: string; currentWorkingDirectory: string; appPath: string; overridePath?: string; } function uniqueCandidates(candidates: Array) { return candidates.filter((candidate, index, all): candidate is string => ( Boolean(candidate) && all.indexOf(candidate) === index )); } export function inputHelperPathCandidates({ isPackaged, resourcesPath, currentWorkingDirectory, appPath, overridePath, }: RuntimeResourcePathOptions) { const packagedPath = path.join(resourcesPath, "input-helper", "InputHelper.exe"); const developmentPaths = [ path.join(currentWorkingDirectory, "native", "input-helper", "bin", "publish", "InputHelper.exe"), path.join(appPath, "native", "input-helper", "bin", "publish", "InputHelper.exe"), ]; return uniqueCandidates([ overridePath, ...(isPackaged ? [packagedPath] : [...developmentPaths, packagedPath]), ]); } export function ikInventoryListsPathCandidates({ isPackaged, resourcesPath, currentWorkingDirectory, appPath, overridePath, }: RuntimeResourcePathOptions) { const packagedPath = path.join(resourcesPath, "ik-inventorylists"); const developmentPaths = [ path.join(currentWorkingDirectory, "data", "ik-inventorylists"), path.join(appPath, "data", "ik-inventorylists"), ]; return uniqueCandidates([ overridePath, ...(isPackaged ? [packagedPath] : [...developmentPaths, packagedPath]), ]); }