Bind confirmation to the selected copy and data paths throughout installation, launch, and maintenance. Validate redirected runtime data paths and recheck original files before refreshing an in-place backup. Verified by type checking and build. The acceptance checklist covers directory links and Steam confirmation.
46 lines
1.7 KiB
TypeScript
46 lines
1.7 KiB
TypeScript
/**
|
|
* 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(copyFolder) && !options.steamLibraryConfirmed) {
|
|
throw new Error(`refusing to write into a Steam library without the player's confirmation: ${copy}`);
|
|
}
|
|
}
|
|
|
|
/** A Steam-managed path can use a junction to store its files outside the library. */
|
|
export function isInSteamLibrary(folder: string): boolean {
|
|
return [resolve(folder), canonical(folder)].some((path) => path.toLowerCase().split(sep).includes('steamapps'));
|
|
}
|
|
|
|
function canonical(folder: string): string {
|
|
try {
|
|
return realpathSync(folder);
|
|
} catch {
|
|
return resolve(folder);
|
|
}
|
|
}
|