fix(patch-pack): write bundled manifest and prefer newer bundled patches

Generate manifest.json for bundled patches during installer builds and ignore previously downloaded adaptation packs that are older than or equal to the bundled patch set.
This commit is contained in:
N0VAN0M4LY committed 2026-11-30 16:50:46 +08:00
1 parent 8c19811714
commit f39d7b05c1
4 files changed
+34 -24

No files matched your search

@@ -6,12 +6,9 @@
* A pack is newer when its version is above the active set's. A bundled set without a version
* (a repository checkout) is older than every pack.
*/
import { existsSync, readFileSync } from 'node:fs';
import { join } from 'node:path';
import { app } from 'electron';
import {
comparePackVersions,
MANIFEST_FILE,
manifestIncompatibility,
parseManifest,
PatchPackError,
@@ -22,7 +19,7 @@ import {
} from '@wto/patcher';
import type { ActivePatchSet, PackApplyResult, PackCheck, PackProblem, PackRelease } from '@shared/schemas/patch-pack.ts';
import { bundledResourcePaths, usesDownloadedPacks } from '../resources/resource-paths.ts';
import { activeDownloadedPack, installPack, useBundledPatchSet } from './pack-store.ts';
import { activeDownloadedPack, bundledPatchVersion, installPack, useBundledPatchSet } from './pack-store.ts';
import { downloadReleaseFile, FeedUnreachableError, newestProjectRelease, ReleasePageLimitError, type PackReleaseFiles } from './release-feed.ts';
/** The manifest copy beside a release is a few hundred bytes. */
@@ -31,10 +28,10 @@ const MANIFEST_COPY_MAX_BYTES = 64 * 1024;
const SIGNATURE_MAX_BYTES = 1024;
export function activePatchSet(): ActivePatchSet {
const pack = usesDownloadedPacks() ? activeDownloadedPack() : null;
if (pack) return { source: 'downloaded', version: pack.manifest.version, gameVersions: [...pack.manifest.gameVersions] };
const root = bundledResourcePaths().patches;
return { source: 'bundled', version: bundledVersion(root), gameVersions: recordedGameVersions(root) };
const pack = usesDownloadedPacks() ? activeDownloadedPack(root) : null;
if (pack) return { source: 'downloaded', version: pack.manifest.version, gameVersions: [...pack.manifest.gameVersions] };
return { source: 'bundled', version: bundledPatchVersion(root), gameVersions: recordedGameVersions(root) };
}
export async function checkPackUpdate(): Promise<PackCheck> {
@@ -103,18 +100,6 @@ function isNewer(candidate: string, active: string | null): boolean {
return active === null || comparePackVersions(candidate, active) > 0;
}
/** The version of a bundled set that carries a manifest (a packaged launcher's), else null. */
function bundledVersion(root: string): string | null {
const path = join(root, MANIFEST_FILE);
if (!existsSync(path)) return null;
try {
return parseManifest(readFileSync(path, 'utf8')).version;
} catch (error) {
console.warn('[patch-pack] the bundled manifest is unreadable:', error);
return null;
}
}
function problemOf(error: unknown): PackProblem {
if (error instanceof ReleasePageLimitError) return 'page_limit';
if (error instanceof FeedUnreachableError) return 'network';