feat(launcher): install offline copies and back up stock files

The launcher's main process can now install the game copy, driven over
IPC by the install wizard to come:

- install:checkPatches builds the copy in memory in a utility process
  (workers/patch-check-worker.ts, a second main entry) and reports the
  patches that do not fit, each marked essential or not. Nothing is
  written.
- install:start checks first, on the stock files the copy would get, so
  a game whose essential patches do not fit is refused before tens of
  gigabytes are copied; other missing patches need the player's
  acceptance. Then, for the copy method, it measures, checks the target
  drive's free space (plus 1 GB) and copies; it keeps the four stock
  files in <copy>/wtoffline/stock, never replacing a file already there;
  and it writes <user data>/install.json. Patched files are written by
  the build at every launch with that launch's port, not here.
- The copy leaves out the top-level folders that hold what the game
  produced while played online (.game_logs, cache, Replays, Screenshots,
  UserMissions). It copies in chunks through streams, so progress moves
  within a large data pack and install:cancel stops at once; it never
  overwrites a file, and after a failure or a cancel it removes what it
  copied, which is safe because the target was new or empty. One failing
  parallel copy stops the others before the cleanup starts.
- Progress goes to the window as event:install-progress, at most every
  250 ms. install:getRecord returns the record and the default data
  folder (<user data>/data).
- New error codes, translated in both languages: not_a_game_folder,
  target_not_usable, steam_library_not_confirmed, not_enough_space,
  essential_patches_unavailable, missing_features_not_accepted,
  patch_check_failed, copy_failed, install_cancelled, install_busy.

Checked with the launcher typecheck and build, and the calls made from a
running launcher window on a 2 GB test game folder holding the real
stock files: the check (12 exe and 35 GUI patches ready), a copy
install (player data folders left out, stock files backed up, record
written, 51 progress events), a second install into the same folder
(not_empty), a cancel 36 MB into a copy (install_cancelled, the copy
removed), an in-place install of the copy (its backup used) and a
folder that is not a game.
This commit is contained in:
N0VAN0M4LY committed 2026-11-29 05:03:40 +08:00
1 parent ab0d3b1f30
commit 3dcf7bb062
14 files changed
+629 -3

No files matched your search

+20
View File
@@ -16,6 +16,26 @@ export const APP_ERROR_CODES = [
'settings_write_failed',
/** A folder the player chose does not exist or cannot be read (params: path). */
'folder_unreadable',
/** The chosen folder lacks the files of a War Thunder installation (params: path). */
'not_a_game_folder',
/** The folder chosen for the copy cannot take it (params: problem, one of TARGET_PROBLEMS). */
'target_not_usable',
/** The game copy would go into a Steam library and the player has not confirmed the warning. */
'steam_library_not_confirmed',
/** The target drive has too little room (params: neededGb, freeGb). */
'not_enough_space',
/** Patches the copy cannot run safely without do not fit this game build (params: patches). */
'essential_patches_unavailable',
/** Some patches do not fit and the player has not chosen to go on without their features. */
'missing_features_not_accepted',
/** Working out which patches fit failed; the details are in the log. */
'patch_check_failed',
/** Copying the game failed; what was copied has been removed. */
'copy_failed',
/** The player stopped the installation; what was copied has been removed. */
'install_cancelled',
/** An installation is already running. */
'install_busy',
] as const;
export type AppErrorCode = (typeof APP_ERROR_CODES)[number];
+29 -1
View File
@@ -1,5 +1,13 @@
import { z } from 'zod';
import { FolderSizeSchema, GameFolderInspectionSchema, TargetFolderInspectionSchema } from '../schemas/install.ts';
import {
FolderSizeSchema,
GameFolderInspectionSchema,
InstallProgressSchema,
InstallRecordSchema,
InstallRequestSchema,
PatchCheckSchema,
TargetFolderInspectionSchema,
} from '../schemas/install.ts';
import { SettingsPatchSchema, SettingsSchema } from '../schemas/settings.ts';
/**
@@ -38,6 +46,25 @@ export const ipcContract = {
input: z.object({ path: z.string().min(1) }),
output: FolderSizeSchema,
},
'install:checkPatches': {
/** The game folder to install from, and the data folder whose store tuning the build uses. */
input: z.object({ gamePath: z.string().min(1), dataPath: z.string().min(1) }),
output: PatchCheckSchema,
},
'install:start': {
/** Runs until the installation is done; progress arrives as event:install-progress. */
input: InstallRequestSchema,
output: InstallRecordSchema,
},
'install:cancel': {
input: z.void(),
/** Whether an installation was running. */
output: z.object({ cancelled: z.boolean() }),
},
'install:getRecord': {
input: z.void(),
output: z.object({ record: InstallRecordSchema.nullable(), defaultDataPath: z.string() }),
},
'settings:get': {
input: z.void(),
output: SettingsSchema,
@@ -50,6 +77,7 @@ export const ipcContract = {
export const ipcEvents = {
'event:settings-changed': SettingsSchema,
'event:install-progress': InstallProgressSchema,
} as const;
export type IpcChannel = keyof typeof ipcContract;
@@ -40,3 +40,79 @@ export const FolderSizeSchema = z.object({
files: z.number(),
});
export type FolderSize = z.output<typeof FolderSizeSchema>;
/** A patch that does not fit the game build, with the feature inventory rows it covers. */
export const UnavailablePatchSchema = z.object({
patchId: z.string(),
features: z.array(z.string()),
reason: z.string(),
/** Without it the copy must not be installed (it would not start, or not stay apart from the online game). */
essential: z.boolean(),
});
export type UnavailablePatch = z.output<typeof UnavailablePatchSchema>;
/** Which patches fit the game build; nothing is written by the check. */
export const PatchCheckSchema = z.object({
exePatchesReady: z.number(),
guiPatchesReady: z.number(),
unavailable: z.array(UnavailablePatchSchema),
});
export type PatchCheck = z.output<typeof PatchCheckSchema>;
/**
* copy: the stock installation is copied to a new folder and only read.
* in-place: the player's own prepared folder is used as the copy; its stock files are kept in
* the backup folder inside it.
*/
export const INSTALL_METHODS = ['copy', 'in-place'] as const;
export type InstallMethod = (typeof INSTALL_METHODS)[number];
const InstallChoicesSchema = z.object({
/** 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. */
steamLibraryConfirmed: z.boolean(),
/** The player chose to go on without the features of the unavailable patches. */
missingFeaturesAccepted: z.boolean(),
});
export const InstallRequestSchema = z.discriminatedUnion('method', [
InstallChoicesSchema.extend({
method: z.literal('copy'),
/** The War Thunder installation to copy; only read. */
sourcePath: z.string().min(1),
/** A new or empty folder for the game copy. */
copyPath: z.string().min(1),
}),
InstallChoicesSchema.extend({
method: z.literal('in-place'),
/** The player's prepared game folder, used as the game copy. */
gamePath: z.string().min(1),
}),
]);
export type InstallRequest = z.output<typeof InstallRequestSchema>;
export const INSTALL_PHASES = ['checking', 'measuring', 'copying', 'backing-up', 'recording'] as const;
export const InstallProgressSchema = z.object({
phase: z.enum(INSTALL_PHASES),
doneBytes: z.number(),
totalBytes: z.number(),
doneFiles: z.number(),
totalFiles: z.number(),
});
export type InstallProgress = z.output<typeof InstallProgressSchema>;
/** What the launcher knows about the installed game copy. */
export const InstallRecordSchema = z.object({
method: z.enum(INSTALL_METHODS),
copyPath: z.string(),
dataPath: z.string(),
/** The stock files every build starts from, inside the copy. */
stockBackupPath: z.string(),
gameVersion: z.string().nullable(),
/** Patches that did not fit when the copy was installed; their features are missing. */
unavailablePatches: z.array(UnavailablePatchSchema),
installedAt: z.string(),
});
export type InstallRecord = z.output<typeof InstallRecordSchema>;