Files
WT-Offline/packages/patcher/src/patch-pack/patch-pack-tuning.ts
T
N0VAN0M4LY 3e2acc5a17 Release adaptation packs and let the launcher install them
An adaptation pack is the patch set (exe, GUI, native definitions and
version records) released on its own, so a new game build can be adapted
without a new offline version. It is a zip with a manifest, signed with
Ed25519, published as a GitHub release tagged patches-<YYYY.MM.DD[.N]>.

- packages/patcher/src/patch-pack: manifest and version numbers, zip
  writing and reading with path and size checks, signatures, a check that
  a patch set reads as a whole; tuning/patch-pack.jsonc holds the
  repository and the limits.
- scripts/generate-patch-signing-key.ts writes the public key for the
  repository and the private key outside it; scripts/build-patch-pack.ts
  packs only committed files and signs with PATCH_SIGNING_KEY.
- .github/workflows/patch-pack.yml packs, signs and publishes on a
  patches-* tag or a manual run.
- Launcher main process: find the newest pack release, download, verify,
  unpack into user data and make it active; resource paths use the
  active pack when it is usable (a repository checkout only with
  WTO_USE_PATCH_PACK=1). The pages that show and start this come later.
2026-11-29 16:08:37 +08:00

49 lines
1.8 KiB
TypeScript

/**
* The adaptation pack settings in packages/patcher/tuning/patch-pack.jsonc.
*/
import { readFileSync } from 'node:fs';
import { parseJsonc } from '@wto/jsonc';
import { PatchPackError } from './patch-pack-error.ts';
export interface PatchPackTuning {
/** `owner/repo` on GitHub. */
readonly repository: string;
readonly releasesPerCheck: number;
readonly maxPackBytes: number;
readonly maxUnpackedBytes: number;
readonly requestTimeoutMs: number;
}
const TUNING_FILE = new URL('../../tuning/patch-pack.jsonc', import.meta.url);
let cached: PatchPackTuning | null = null;
export function patchPackTuning(): PatchPackTuning {
if (cached) return cached;
const value = parseJsonc(readFileSync(TUNING_FILE, 'utf8'));
if (typeof value !== 'object' || value === null || Array.isArray(value)) throw tuningError('the file is not an object');
const fields = value as Record<string, unknown>;
const repository = fields['repository'];
if (typeof repository !== 'string' || !/^[A-Za-z0-9._-]+\/[A-Za-z0-9._-]+$/.test(repository)) {
throw tuningError('"repository" must be "owner/repo"');
}
cached = {
repository,
releasesPerCheck: positiveInteger(fields, 'releases_per_check'),
maxPackBytes: positiveInteger(fields, 'max_pack_bytes'),
maxUnpackedBytes: positiveInteger(fields, 'max_unpacked_bytes'),
requestTimeoutMs: positiveInteger(fields, 'request_timeout_ms'),
};
return cached;
}
function positiveInteger(fields: Record<string, unknown>, key: string): number {
const value = fields[key];
if (typeof value !== 'number' || !Number.isInteger(value) || value <= 0) throw tuningError(`"${key}" must be a positive integer`);
return value;
}
function tuningError(detail: string): PatchPackError {
return new PatchPackError('tuning', `tuning/patch-pack.jsonc: ${detail}`);
}