57 lines
2.4 KiB
TypeScript
57 lines
2.4 KiB
TypeScript
import { join, resolve } from 'node:path';
|
|
import { app } from 'electron';
|
|
import { activeDownloadedPack } from '../patch-pack/pack-store.ts';
|
|
|
|
/**
|
|
* Where the launcher finds what it ships besides its own code: the patch set (exe, GUI and native
|
|
* definitions and version records, @wto/patcher patch-set.ts) and the network hook library.
|
|
*
|
|
* The patch set is the active downloaded adaptation pack when there is a usable one
|
|
* (services/patch-pack/), otherwise the bundled one. A repository checkout uses its own patches/
|
|
* unless WTO_USE_PATCH_PACK=1 is set, so that edits to patches/ take effect while developing.
|
|
*/
|
|
export interface ResourcePaths {
|
|
/** Root of the patch set. */
|
|
readonly patches: string;
|
|
/** wto_ws.dll, built by native/wto-net/build.ps1. */
|
|
readonly networkHookLibrary: string;
|
|
/** Multi-resolution Windows icon for the window and system tray. */
|
|
readonly appIcon: string;
|
|
/** Bundled example mod templates seeded into an empty mods folder on first use. */
|
|
readonly modTemplates: string;
|
|
/** Offline HTML mod development handbook (zh-CN.html and en.html). */
|
|
readonly modDocs: string;
|
|
}
|
|
|
|
export function resourcePaths(): ResourcePaths {
|
|
const bundled = bundledResourcePaths();
|
|
const pack = usesDownloadedPacks() ? activeDownloadedPack(bundled.patches) : null;
|
|
return pack ? { ...bundled, patches: pack.root } : bundled;
|
|
}
|
|
|
|
/** The resources that ship with the launcher, ignoring downloaded packs. */
|
|
export function bundledResourcePaths(): ResourcePaths {
|
|
if (app.isPackaged) {
|
|
return {
|
|
patches: join(process.resourcesPath, 'patches'),
|
|
networkHookLibrary: join(process.resourcesPath, 'native', 'wto_ws.dll'),
|
|
appIcon: join(process.resourcesPath, 'icon.ico'),
|
|
modTemplates: join(process.resourcesPath, 'mod-templates'),
|
|
modDocs: join(process.resourcesPath, 'mod-dev-docs'),
|
|
};
|
|
}
|
|
// The app path is apps/launcher; the repository is two levels up.
|
|
const repository = resolve(app.getAppPath(), '..', '..');
|
|
return {
|
|
patches: join(repository, 'patches'),
|
|
networkHookLibrary: join(repository, 'build', 'native', 'wto_ws.dll'),
|
|
appIcon: join(repository, 'apps', 'launcher', 'resources', 'icon.ico'),
|
|
modTemplates: join(repository, 'mod-dev-docs', 'templates'),
|
|
modDocs: join(repository, 'build', 'mod-dev-docs'),
|
|
};
|
|
}
|
|
|
|
export function usesDownloadedPacks(): boolean {
|
|
return app.isPackaged || process.env['WTO_USE_PATCH_PACK'] === '1';
|
|
}
|