feat(launcher)!: manage multiple game copies

BREAKING CHANGE: The launcher stores copy registrations in copies.json. Installations recorded only in install.json must be registered again.
This commit is contained in:
N0VAN0M4LY committed 2026-11-29 15:14:41 +08:00
1 parent e41b73aaa3
commit 7d68dc0548
24 files changed
+408 -97

No files matched your search

+3
View File
@@ -16,6 +16,9 @@ export const APP_ERROR_CODES = [
'settings_write_failed',
'logs_folder_open_failed',
'diagnostics_export_failed',
'copy_not_found',
'copies_write_failed',
'copy_location_in_use',
'launch_no_copy',
'launch_busy',
'launch_lab_required',
+2
View File
@@ -12,6 +12,8 @@ export const IPC_CHANNEL_PREFIXES = [
'dialog:',
/** Installing the offline version: looking at the chosen folders, copying, patching. */
'install:',
/** Listing and managing installed copies. */
'copies:',
/** Starting and stopping the active copy. */
'launch:',
/** The launcher's own settings. */
+21 -1
View File
@@ -1,6 +1,9 @@
import { z } from 'zod';
import { BackgroundPictureSchema } from '../schemas/background.ts';
import {
CopiesSchema,
CopyIdSchema,
CopyNameSchema,
FolderSizeSchema,
GameFolderInspectionSchema,
InstallProgressSchema,
@@ -59,6 +62,10 @@ export const ipcContract = {
/** The chosen folder, or null when the player cancelled. */
output: z.object({ path: z.string().nullable() }),
},
'install:prepareCopy': {
input: z.void(),
output: z.object({ id: CopyIdSchema, dataPath: z.string() }),
},
'install:inspectGameFolder': {
input: z.object({ path: z.string().min(1) }),
output: GameFolderInspectionSchema,
@@ -88,13 +95,25 @@ export const ipcContract = {
},
'install:getRecord': {
input: z.void(),
output: z.object({ record: InstallRecordSchema.nullable(), defaultDataPath: z.string() }),
output: z.object({ record: InstallRecordSchema.nullable() }),
},
'install:listFeatures': {
/** Every feature the patches cover; which of them a copy lacks is in its install record. */
input: z.void(),
output: z.array(PatchFeatureSchema),
},
'copies:list': {
input: z.void(),
output: CopiesSchema,
},
'copies:setCurrent': {
input: z.object({ id: CopyIdSchema }),
output: CopiesSchema,
},
'copies:rename': {
input: z.object({ id: CopyIdSchema, name: CopyNameSchema }),
output: CopiesSchema,
},
'launch:getState': {
input: z.void(),
output: LaunchStateSchema,
@@ -137,6 +156,7 @@ export const ipcEvents = {
'event:settings-changed': SettingsSchema,
'event:install-progress': InstallProgressSchema,
'event:launch-state': LaunchStateSchema,
'event:copies-changed': CopiesSchema,
} as const;
export type IpcChannel = keyof typeof ipcContract;
@@ -77,7 +77,12 @@ export type PatchCheck = z.output<typeof PatchCheckSchema>;
export const INSTALL_METHODS = ['copy', 'in-place'] as const;
export type InstallMethod = (typeof INSTALL_METHODS)[number];
export const CopyIdSchema = z.uuid();
export const CopyNameSchema = z.string().trim().min(1);
const InstallChoicesSchema = z.object({
id: CopyIdSchema,
name: CopyNameSchema,
/** Where the local server keeps saves, caches and logs. */
dataPath: z.string().min(1),
/** The player confirmed installing into a Steam library after the warning. */
@@ -115,6 +120,10 @@ export type InstallProgress = z.output<typeof InstallProgressSchema>;
/** What the launcher knows about the installed game copy. */
export const InstallRecordSchema = z.object({
id: CopyIdSchema,
name: CopyNameSchema,
/** Recorded only for a separate source copied during installation. */
sourcePath: z.string().min(1).nullable(),
method: z.enum(INSTALL_METHODS),
copyPath: z.string(),
dataPath: z.string(),
@@ -126,3 +135,14 @@ export const InstallRecordSchema = z.object({
installedAt: z.string(),
});
export type InstallRecord = z.output<typeof InstallRecordSchema>;
export const CopiesSchema = z.object({
formatVersion: z.literal(1),
current: CopyIdSchema.nullable(),
copies: z.array(InstallRecordSchema),
}).refine(({ current, copies }) => {
const ids = new Set(copies.map((copy) => copy.id));
return ids.size === copies.length && (copies.length === 0 ? current === null : current !== null && ids.has(current));
});
export type Copies = z.output<typeof CopiesSchema>;
@@ -6,6 +6,7 @@ export const LaunchStateSchema = z.object({
'ready', 'checking', 'building', 'starting-server', 'starting-game', 'running',
'stopping', 'port-busy', 'version-changed', 'server-exited', 'failed',
]),
copyId: z.uuid().optional(),
port: z.number().int().min(1).max(65535).optional(),
filesWritten: z.number().int().nonnegative().optional(),
filesTotal: z.number().int().nonnegative().optional(),