feat(launcher): add map adaptation pack updates

This commit is contained in:
N0VAN0M4LY committed 2026-12-06 19:53:45 +08:00
1 parent 9ba92f289d
commit 036a479aab
24 files changed
+770 -86

No files matched your search

+23
View File
@@ -3,7 +3,9 @@ import { cp, lstat, mkdir, mkdtemp, readdir, readFile, realpath, rm, writeFile }
import { tmpdir } from 'node:os';
import { dirname, join, relative, resolve, sep } from 'node:path';
import { Arch, build, Platform } from 'electron-builder';
import { installerDigest } from '../apps/launcher/src/main/services/app-update/installer-integrity.ts';
import { launcherReleaseFiles, portableLauncherReleaseFiles } from '../apps/launcher/src/shared/schemas/app-update.ts';
import { MapNavManifestSchema } from '../apps/launcher/src/shared/schemas/map-nav-pack.ts';
import { formatManifest, MANIFEST_FILE, PATCH_PACK_FORMAT, recordedGameVersions } from '../packages/patcher/src/index.ts';
const repository = resolve(import.meta.dirname, '..');
@@ -72,6 +74,7 @@ async function stageInstaller(stage: string, manifest: LauncherManifest): Promis
await cp(join(native, 'wto_ws.dll'), join(resources, 'native', 'wto_ws.dll'));
await cp(join(repository, 'mod-dev-docs', 'templates'), join(resources, 'mod-templates'), { recursive: true });
await cp(join(repository, 'game-ai', 'ground'), join(resources, 'game-ai', 'ground'), { recursive: true });
await stageMapNavBundle(resources);
for (const folder of ['exe', 'gui', 'native', 'versions']) {
await cp(join(repository, 'patches', folder), join(resources, 'patches', folder), { recursive: true });
}
@@ -91,6 +94,26 @@ async function stageInstaller(stage: string, manifest: LauncherManifest): Promis
}
}
async function stageMapNavBundle(resources: string): Promise<void> {
const source = join(buildFolder, 'map-nav');
const text = await readFile(join(source, 'manifest.json'), 'utf8').catch((error: NodeJS.ErrnoException) => {
if (error.code === 'ENOENT') return null;
throw error;
});
if (!text) return;
const manifest = MapNavManifestSchema.parse(JSON.parse(text));
const destination = join(resources, 'map-nav');
await mkdir(join(destination, 'maps'), { recursive: true });
for (const { level, size, sha256 } of manifest.maps) {
const filename = level + '.wtonav';
const target = join(destination, 'maps', filename);
await cp(join(source, 'maps', filename), target, { dereference: true });
const digest = await installerDigest(target, size);
if (digest.size !== size || digest.sha256 !== sha256) throw new Error('The bundled map file does not match its manifest: ' + filename);
}
await writeFile(join(destination, 'manifest.json'), text, 'utf8');
}
async function cleanInstallerOutput(version: string): Promise<void> {
await mkdir(buildFolder, { recursive: true });
if (relative(buildFolder, await realpath(buildFolder)) !== '') throw new Error('The build directory is redirected.');
+51
View File
@@ -9,6 +9,7 @@
* Options:
* --add-launcher <dir> Stage signed installer (and optional portable zip) from a build folder
* --add-pack <path> Stage signed adaptation pack(s) from a folder or a specific .zip file
* --add-map-nav <zip> Stage a signed map navigation archive
* --notes <file> Release notes Markdown for --add-launcher (defaults to .github/release-notes/v<ver>.md)
* --remove-tag <tag> Remove a tag from the release feed
* --out <dir> Local staging directory (default: build/r2-dist)
@@ -50,6 +51,9 @@ import {
portableLauncherReleaseFiles,
PortableReleaseManifest,
} from '../apps/launcher/src/shared/schemas/app-update.ts';
import {
MAP_NAV_TAG_PREFIX, MapNavVersionSchema, MapNavReleaseManifestSchema, mapNavReleaseFiles, mapNavSignaturePayload,
} from '../apps/launcher/src/shared/schemas/map-nav-pack.ts';
import { renderDownloadPage, type ReleaseAssetEntry, type ReleaseEntry } from './r2/download-page.ts';
import { R2Client, sha256 } from './r2/sigv4.ts';
@@ -68,6 +72,7 @@ async function main(): Promise<void> {
options: {
'add-launcher': { type: 'string', multiple: true },
'add-pack': { type: 'string', multiple: true },
'add-map-nav': { type: 'string', multiple: true },
notes: { type: 'string' },
'remove-tag': { type: 'string', multiple: true },
out: { type: 'string', default: DEFAULT_OUT },
@@ -127,6 +132,12 @@ async function main(): Promise<void> {
}
}
for (const target of values['add-map-nav'] ?? []) {
const entry = await stageMapNavRelease(resolve(target), filesRoot, publicUrl, publicKey);
byTag.set(entry.tag_name, entry);
console.info('Staged map pack ' + entry.tag_name);
}
for (const tag of values['remove-tag'] ?? []) {
if (byTag.delete(tag)) console.info(`Removed ${tag} from release list.`);
}
@@ -292,6 +303,45 @@ async function stageAdaptationPacks(
return staged;
}
async function stageMapNavRelease(
zipPath: string, filesRoot: string, publicUrl: string, publicKey: string,
): Promise<ReleaseEntry> {
const version = MapNavVersionSchema.parse(/^wtoffline-map-nav-(.+)\.zip$/.exec(basename(zipPath))?.[1]);
const files = mapNavReleaseFiles(version);
const directory = dirname(zipPath);
const signature = join(directory, files.signature);
const manifestFile = join(directory, files.manifest);
const [bytes, signatureText] = await Promise.all([readFile(manifestFile), readFile(signature, 'utf8')]);
if (!verifyEd25519(mapNavSignaturePayload(bytes), signatureText, publicKey)) {
throw new Error('Signature verification failed for ' + files.zip);
}
const manifest = MapNavReleaseManifestSchema.parse(JSON.parse(bytes.toString('utf8')));
if (manifest.version !== version) throw new Error('The map pack manifest version does not match its file name.');
const digest = await installerDigest(zipPath, manifest.archive.size);
if (digest.size !== manifest.archive.size || digest.sha256 !== manifest.archive.sha256) {
throw new Error('The map archive does not match the signed manifest.');
}
const tag = MAP_NAV_TAG_PREFIX + version;
const destination = join(filesRoot, tag);
await mkdir(destination, { recursive: true });
const assets = [
await copyAsset(zipPath, destination, tag, publicUrl, digest.sha256),
await copyAsset(signature, destination, tag, publicUrl),
await copyAsset(manifestFile, destination, tag, publicUrl),
];
return {
tag_name: tag,
name: 'Map Adaptation Pack ' + version,
draft: false,
prerelease: true,
published_at: manifest.createdAt,
body: 'Maps: ' + manifest.maps.length + '\nGame versions: ' + manifest.gameVersions.join(', ') + '\n',
game_versions: manifest.gameVersions,
min_app_version: manifest.minAppVersion,
assets,
};
}
async function copyAsset(
sourcePath: string,
targetDir: string,
@@ -455,6 +505,7 @@ function printUsage(): void {
'',
' --add-launcher <dir> Stage signed installer/portable release from a build folder',
' --add-pack <path> Stage signed adaptation pack(s) from a folder or .zip file',
' --add-map-nav <zip> Stage a signed map navigation archive',
' --notes <file> Release notes Markdown file for --add-launcher',
' --remove-tag <tag> Remove a tag from the release feed',
' --out <dir> Local staging directory (default: build/r2-dist)',