/** * Files the build reads from a stock game folder and writes into the game copy, and the * checks that keep it from writing where it must not: never the folder it reads from, and a * Steam library only when the player has confirmed it. */ import { realpathSync } from 'node:fs'; import { join, resolve, sep } from 'node:path'; export const GAME_FILES = { charPack: 'char.vromfs.bin', mainPack: 'aces.vromfs.bin', guiPack: 'gui.vromfs.bin', executable: join('win64', 'aces.exe'), } as const; export interface WritableCopyOptions { /** * The player was told that installing into a Steam library changes the online client, can be * undone by Steam's file check or an update, and risks a ban when started online, and chose to * go on. Development tools never set it. */ readonly steamLibraryConfirmed?: boolean; } export function assertWritableCopy(stockFolder: string, copyFolder: string, options: WritableCopyOptions = {}): void { const stock = canonical(stockFolder); const copy = canonical(copyFolder); if (copy === stock) throw new Error('the output folder is the folder the stock files are read from'); if (isInSteamLibrary(copy) && !options.steamLibraryConfirmed) { throw new Error(`refusing to write into a Steam library without the player's confirmation: ${copy}`); } } /** Whether a folder lies inside a Steam library (a `steamapps` folder on its path). */ export function isInSteamLibrary(folder: string): boolean { return canonical(folder).toLowerCase().split(sep).includes('steamapps'); } function canonical(folder: string): string { try { return realpathSync(folder); } catch { return resolve(folder); } }