174 lines
7.0 KiB
TypeScript
174 lines
7.0 KiB
TypeScript
import { z } from 'zod';
|
|
|
|
/** What the launcher found in a folder the player chose as their War Thunder installation. */
|
|
export const GameFolderInspectionSchema = z.object({
|
|
path: z.string(),
|
|
resolvedPath: z.string(),
|
|
/** Files a game folder must have that this one lacks; empty for a game folder. */
|
|
missingFiles: z.array(z.string()),
|
|
/** The file version of win64/aces.exe, or null when it has none or is missing. */
|
|
version: z.string().nullable(),
|
|
/** The versions every patch was verified on; a different version is pointed out, not refused. */
|
|
verifiedVersions: z.array(z.string()),
|
|
/** The folder lies in a Steam library: installing into it needs the player's confirmation. */
|
|
inSteamLibrary: z.boolean(),
|
|
/** True when the folder already holds a complete wtoffline/stock backup from an offline setup. */
|
|
hasOfflineBackup: z.boolean(),
|
|
});
|
|
export type GameFolderInspection = z.output<typeof GameFolderInspectionSchema>;
|
|
|
|
/** Why a folder cannot hold the game copy. */
|
|
export const TARGET_PROBLEMS = [
|
|
/** The folder holds files already (a copy needs an empty or a new folder). */
|
|
'not_empty',
|
|
/** The folder is the stock installation, lies inside it, or contains it. */
|
|
'overlaps_stock',
|
|
/** The path names a file, not a folder. */
|
|
'not_a_folder',
|
|
] as const;
|
|
|
|
export const TargetFolderInspectionSchema = z.object({
|
|
path: z.string(),
|
|
resolvedPath: z.string(),
|
|
problem: z.enum(TARGET_PROBLEMS).nullable(),
|
|
inSteamLibrary: z.boolean(),
|
|
/** Bytes free on the drive the folder is on; null when the drive cannot be read. */
|
|
freeBytes: z.number().nullable(),
|
|
/** Whether the folder is on the same drive as the stock installation. */
|
|
sameDriveAsStock: z.boolean(),
|
|
});
|
|
export type TargetFolderInspection = z.output<typeof TargetFolderInspectionSchema>;
|
|
|
|
export const FolderSizeSchema = z.object({
|
|
bytes: z.number(),
|
|
files: z.number(),
|
|
linkableBytes: z.number().nonnegative().optional(),
|
|
});
|
|
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>;
|
|
|
|
/** A feature inventory row the patches cover, with the patches behind it. */
|
|
export const PatchFeatureSchema = z.object({
|
|
/** Feature tag with a prefix identifying its feature group. */
|
|
tag: z.string(),
|
|
/** A copy cannot run, or cannot stay apart from the online game, without it. */
|
|
essential: z.boolean(),
|
|
patchIds: z.array(z.string()),
|
|
});
|
|
export type PatchFeature = z.output<typeof PatchFeatureSchema>;
|
|
|
|
/** 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 directly; its stock files are backed up inside it.
|
|
* existing: an already prepared offline client folder is registered directly without copying.
|
|
*/
|
|
export const INSTALL_METHODS = ['copy', 'in-place', 'existing'] 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),
|
|
decalSourcePath: z.string().min(1).optional(),
|
|
/** Resolved Steam locations shown in the risk prompts the player confirmed. */
|
|
confirmedSteamCopyPath: z.string().min(1).optional(),
|
|
confirmedSteamDataPath: z.string().min(1).optional(),
|
|
/** 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'),
|
|
useHardLinks: z.boolean().optional(),
|
|
/** 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),
|
|
}),
|
|
InstallChoicesSchema.extend({
|
|
method: z.literal('existing'),
|
|
/** An already prepared offline client folder registered directly without copying. */
|
|
gamePath: z.string().min(1),
|
|
}),
|
|
]);
|
|
export type InstallRequest = z.output<typeof InstallRequestSchema>;
|
|
|
|
export const INSTALL_PHASES = ['checking', 'importing-decals', 'measuring', 'verifying', '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({
|
|
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(),
|
|
/** The stock files every build starts from, inside the copy. */
|
|
stockBackupPath: z.string(),
|
|
/** Confirmation applies only to these resolved copy and data paths. */
|
|
steamLibraryConfirmation: z.object({
|
|
copyPath: z.string(),
|
|
dataPath: z.string(),
|
|
}).optional(),
|
|
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(),
|
|
lastCheckedAt: z.string().optional(),
|
|
currentSaveId: z.string().regex(/^\d+$/).optional(),
|
|
decalCacheId: z.uuid().optional(),
|
|
/** Relative paths read from the installation source during the last copy or update. */
|
|
sourceFiles: z.array(z.string().min(1)).optional(),
|
|
/** Relative resource paths linked to the source and detached on a version update. */
|
|
hardlinkedFiles: z.array(z.string().min(1)).optional(),
|
|
});
|
|
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>;
|