feat(launcher): prompt for stock source when adding patched client without backup

This commit is contained in:
N0VAN0M4LY committed 2026-11-30 20:59:38 +08:00
1 parent 39228c6e75
commit bfedc3d27e
13 files changed
+195 -41

No files matched your search

+2 -1
View File
@@ -78,7 +78,8 @@ export function registerIpcHandlers(): void {
}
});
handle('install:checkPatches', ({ gamePath, dataPath }) => checkGameFolder(gamePath, dataPath));
handle('install:checkPatches', ({ gamePath, dataPath, stockSourcePath }) =>
checkGameFolder(gamePath, dataPath, stockSourcePath));
handle('install:start', async (request) => {
if (maintenanceInProgress()) throw new AppError('maintenance_busy');
const record = await installGame(request, (progress) => broadcast('event:install-progress', progress));
@@ -1,14 +1,18 @@
import { access, readFile, realpath, stat } from 'node:fs/promises';
import { join } from 'node:path';
import { dirname, join } from 'node:path';
import { executableVersion, GAME_FILES, isInSteamLibrary, recordedGameVersions } from '@wto/patcher';
import { AppError } from '@shared/errors.ts';
import type { GameFolderInspection } from '@shared/schemas/install.ts';
import { STOCK_BACKUP_FOLDER } from '../install/stock-backup.ts';
import { resourcePaths } from '../resources/resource-paths.ts';
const PATCH_MARKER_FILES = ['wto_ws.dll', 'wto_ws.cfg'] as const;
const PATCHED_EXE_MARKER = Buffer.from('wto_ws.dll', 'ascii');
/**
* Look at a folder the player chose as their War Thunder installation: is it one, which version,
* whether it already has an offline stock backup, and whether it is inside a Steam library. Only reads.
* whether it already has an offline stock backup, whether it is already patched without one,
* and whether it is inside a Steam library. Only reads.
*/
export async function inspectGameFolder(path: string): Promise<GameFolderInspection> {
await requireFolder(path);
@@ -30,20 +34,42 @@ export async function inspectGameFolder(path: string): Promise<GameFolderInspect
const executablePath = hasOfflineBackup
? join(stockRoot, GAME_FILES.executable)
: join(resolved, GAME_FILES.executable);
const executableBytes = (!hasOfflineBackup && missingFiles.includes(GAME_FILES.executable))
? null
: await readBytes(executablePath);
const version = executableBytes ? readVersionFromBytes(executableBytes) : null;
let needsStockSource = false;
if (!hasOfflineBackup && missingFiles.length === 0) {
const exeDir = join(resolved, dirname(GAME_FILES.executable));
const hasMarkerFile = (await Promise.all(
PATCH_MARKER_FILES.map((file) => exists(join(exeDir, file))),
)).some(Boolean);
needsStockSource = hasMarkerFile || (executableBytes !== null && executableBytes.includes(PATCHED_EXE_MARKER));
}
return {
path,
resolvedPath: resolved,
missingFiles,
version: !hasOfflineBackup && missingFiles.includes(GAME_FILES.executable) ? null : await readVersion(executablePath),
version,
verifiedVersions: recordedGameVersions(resources.patches),
inSteamLibrary: isInSteamLibrary(path) || isInSteamLibrary(resolved),
hasOfflineBackup,
needsStockSource,
};
}
async function readVersion(executablePath: string): Promise<string | null> {
async function readBytes(filePath: string): Promise<Buffer | null> {
try {
return executableVersion(await readFile(executablePath));
return await readFile(filePath);
} catch (error) {
console.warn('[game-folder] reading the executable failed:', error);
return null;
}
}
function readVersionFromBytes(bytes: Buffer): string | null {
try {
return executableVersion(bytes);
} catch (error) {
// Not a PE file, or unreadable: the folder is then not a usable installation, which the
// missing version already says.
@@ -12,7 +12,7 @@ import { discardDecalCache, importDecalCache } from './decals.ts';
import { hardlinkResource, hasHardlinkEvidence, verifyHardlinkResource } from './hardlink-files.ts';
import { canonicalCopyPath, copyPathContains, requireAvailableCopy, writeInstallRecord } from './install-record.ts';
import { checkPatches } from './patch-check.ts';
import { backUpStockFiles, installStockSource, refreshStockBackup, requireStockBackupLocation, stockBackupPath } from './stock-backup.ts';
import { backUpStockFiles, backUpStockFilesFrom, installStockSource, refreshStockBackup, requireStockBackupLocation, stockBackupPath } from './stock-backup.ts';
/**
* Install the offline version: check the patches against the player's game,
@@ -57,19 +57,25 @@ export function cancelInstall(): boolean {
}
/** Which patches fit the game in `gameFolder`, for the window to show before installing. */
export async function checkGameFolder(gameFolder: string, dataPath: string): Promise<PatchCheck> {
const { resolvedPath, version } = await requireGameFolder(gameFolder);
const stock = await installStockSource(resolvedPath, version);
export async function checkGameFolder(gameFolder: string, dataPath: string, stockSourcePath?: string): Promise<PatchCheck> {
const game = await requireGameFolder(gameFolder);
const stock = stockSourcePath
? await resolveExternalStockSource(stockSourcePath, game.version)
: game.needsStockSource
? (() => { throw new AppError('stock_source_invalid'); })()
: await installStockSource(game.resolvedPath, game.version);
const data = await canonicalCopyPath(dataPath);
await requireUnredirectedData(data);
return checkPatches(stock.path, data);
}
async function install(request: InstallRequest, signal: AbortSignal, report: (progress: InstallProgress) => void): Promise<InstallRecord> {
const { version, requestedCopyPath, copyPath, dataPath, sourcePath, target, useHardLinks, copyInSteam, dataInSteam } =
const { version, requestedCopyPath, copyPath, dataPath, sourcePath, externalStockPath, target, useHardLinks, copyInSteam, dataInSteam } =
await inspectInstallation(request);
report({ phase: 'checking', doneBytes: 0, totalBytes: 0, doneFiles: 0, totalFiles: 0 });
const stock = await installStockSource(sourcePath, version);
const stock = externalStockPath
? { path: externalStockPath, refresh: false }
: await installStockSource(sourcePath, version);
await mkdir(dataPath, { recursive: true });
const check = await checkPatches(stock.path, dataPath);
const essential = check.unavailable.filter((patch) => patch.essential);
@@ -88,9 +94,11 @@ async function install(request: InstallRequest, signal: AbortSignal, report: (pr
: undefined;
report({ phase: 'backing-up', doneBytes: 0, totalBytes: 0, doneFiles: 0, totalFiles: 0 });
const stockBackup = (request.method === 'in-place' || request.method === 'existing') && stock.refresh
? await refreshStockBackup(copyPath)
: await backUpStockFiles(copyPath);
const stockBackup = externalStockPath
? await backUpStockFilesFrom(copyPath, externalStockPath)
: (request.method === 'in-place' || request.method === 'existing') && stock.refresh
? await refreshStockBackup(copyPath)
: await backUpStockFiles(copyPath);
report({ phase: 'recording', doneBytes: 0, totalBytes: 0, doneFiles: 0, totalFiles: 0 });
const record: InstallRecord = {
@@ -120,13 +128,22 @@ async function install(request: InstallRequest, signal: AbortSignal, report: (pr
async function inspectInstallation(request: InstallRequest) {
const gameFolder = request.method === 'copy' ? request.sourcePath : request.gamePath;
const game = await requireGameFolder(gameFolder);
let externalStockPath: string | null = null;
if (request.method === 'copy') {
if (game.needsStockSource) throw new AppError('stock_source_invalid');
} else if (request.stockSourcePath) {
externalStockPath = (await resolveExternalStockSource(request.stockSourcePath, game.version)).path;
} else if (game.needsStockSource) {
throw new AppError('stock_source_invalid');
}
const requestedCopyPath = request.method === 'copy' ? request.copyPath : request.gamePath;
const [copyPath, dataPath, sourcePath] = await Promise.all([
canonicalCopyPath(requestedCopyPath), canonicalCopyPath(request.dataPath), canonicalCopyPath(gameFolder),
]);
await requireAvailableCopy(request.id, copyPath, dataPath);
if (!isAbsolute(request.dataPath) || copyPathContains(stockBackupPath(copyPath), dataPath) ||
(request.method === 'copy' && copyPathContains(sourcePath, dataPath))) {
(request.method === 'copy' && copyPathContains(sourcePath, dataPath)) ||
(externalStockPath && copyPathContains(externalStockPath, dataPath))) {
throw new AppError('target_not_usable', { problem: 'overlaps_stock' });
}
@@ -145,7 +162,16 @@ async function inspectInstallation(request: InstallRequest) {
throw new AppError('steam_library_not_confirmed');
}
await Promise.all([requireStockBackupLocation(copyPath), requireUnredirectedData(dataPath)]);
return { version: game.version, requestedCopyPath, copyPath, dataPath, sourcePath, target, useHardLinks, copyInSteam, dataInSteam };
return { version: game.version, requestedCopyPath, copyPath, dataPath, sourcePath, externalStockPath, target, useHardLinks, copyInSteam, dataInSteam };
}
async function resolveExternalStockSource(stockSourcePath: string, expectedVersion: string | null) {
const stockGame = await requireGameFolder(stockSourcePath);
if (stockGame.needsStockSource) throw new AppError('stock_source_invalid');
if (expectedVersion !== null && stockGame.version !== null && expectedVersion !== stockGame.version) {
throw new AppError('stock_source_version_mismatch', { expected: expectedVersion, actual: stockGame.version });
}
return installStockSource(stockGame.resolvedPath, stockGame.version);
}
async function copyGame(
@@ -32,12 +32,20 @@ export async function requireStockBackupLocation(copyFolder: string): Promise<st
* a backed-up file is never replaced, because the copy's own file may be a patched one by then.
*/
export async function backUpStockFiles(copyFolder: string): Promise<string> {
return backUpStockFilesFrom(copyFolder, copyFolder);
}
/**
* Copies the four stock files from `sourceFolder` (read-only) into `<copyFolder>/wtoffline/stock`,
* keeping any file that is already backed up.
*/
export async function backUpStockFilesFrom(copyFolder: string, sourceFolder: string): Promise<string> {
const backup = await requireStockBackupLocation(copyFolder);
for (const file of Object.values(GAME_FILES)) {
const kept = join(backup, file);
if (await exists(kept)) continue;
await mkdir(dirname(kept), { recursive: true });
await copyFile(join(copyFolder, file), kept, constants.COPYFILE_EXCL);
await copyFile(join(sourceFolder, file), kept, constants.COPYFILE_EXCL);
}
return backup;
}
@@ -132,6 +132,11 @@
"existingBody": "Select an existing offline client folder.",
"existingDialogTitle": "Select an existing offline client folder",
"offlineBackupDetected": "An existing offline original-file backup (wtoffline\\stock) was detected. This client can be added directly without copying.",
"patchedNeedsStock": "This folder already has offline patches applied but is missing the 4 original core files (wtoffline\\stock). Select an unpatched game folder of the same version; the launcher will read-only copy only those 4 files (~150 MB) without recopying the game.",
"stockSourceTitle": "Select an unpatched War Thunder folder of the same version",
"stockSourcePatched": "The selected folder is also patched and missing an original backup. Choose an unpatched game folder.",
"stockSourceVersionMismatch": "The selected original game version ({{actual}}) does not match this client ({{expected}}).",
"stockSourceReady": "Original core file source ready (version {{version}}). Only the 4 core files will be copied into wtoffline\\stock.",
"notAGame": "The selected folder is not a War Thunder installation. Missing: {{files}}",
"versionVerified": "Game version {{version}} (verified)",
"versionUnverified": "Game version {{version}} has no check record yet. Installing still tries every patch; the patch check shows which features are available.",
@@ -153,6 +158,7 @@
"existing": "Add existing client",
"existingBody": "Registers the selected existing game folder directly without copying files. If no original backup exists yet, one will be created in wtoffline\\stock.",
"existingBodyWithBackup": "Registers the existing offline client directly, preserving its wtoffline\\stock original-file backup without copying game files.",
"existingBodyWithStockSource": "Registers the existing offline client directly and copies only the 4 original core files from the selected stock folder into wtoffline\\stock.",
"room": "Free space on target drive: {{free}}",
"noRoom": "Not enough free space: {{needed}} required, {{free}} available on the target drive.",
"problem": {
@@ -692,6 +698,8 @@
"settings_write_failed": "The settings could not be saved.",
"folder_unreadable": "The folder cannot be read: {{path}}",
"not_a_game_folder": "The selected folder is not a War Thunder installation: {{path}}",
"stock_source_invalid": "This client is already patched and lacks an original backup. Select an unpatched game folder of the same version.",
"stock_source_version_mismatch": "The selected original game version ({{actual}}) does not match the client version ({{expected}}).",
"target_not_usable": "The selected folder cannot be used for installation.",
"steam_library_not_confirmed": "The client or data folder is in a Steam library. Confirm the risk notice first.",
"not_enough_space": "Not enough disk space: {{neededGb}} GB required, {{freeGb}} GB available.",
@@ -132,6 +132,11 @@
"existingBody": "选择已准备好的离线客户端文件夹。",
"existingDialogTitle": "选择已有离线客户端文件夹",
"offlineBackupDetected": "已检测到离线客户端的原版文件备份(wtoffline\\stock),可直接添加,无需重新复制。",
"patchedNeedsStock": "所选文件夹已包含离线补丁,但缺少 4 个原版核心文件(wtoffline\\stock)。请选择同版本的原版游戏目录,启动器将只读复制这 4 个文件(约 150 MB),无需重新复制整包游戏。",
"stockSourceTitle": "选择同版本的原版战争雷霆目录",
"stockSourcePatched": "所选目录同样已打过离线补丁且缺少原版文件备份,请选择未打补丁的原版游戏目录。",
"stockSourceVersionMismatch": "所选原版目录版本({{actual}})与当前客户端版本({{expected}})不一致。",
"stockSourceReady": "原版核心文件来源就绪(版本 {{version}}),添加时将仅复制 4 个核心文件至 wtoffline\\stock。",
"notAGame": "所选文件夹不是战争雷霆的安装文件夹,缺少:{{files}}",
"versionVerified": "游戏版本 {{version}}(已核对)",
"versionUnverified": "游戏版本 {{version}} 还没有核对记录。安装时仍会逐个尝试全部补丁,可用功能以补丁检查结果为准。",
@@ -153,6 +158,7 @@
"existing": "添加已有客户端",
"existingBody": "直接登记所选的已有游戏文件夹,不复制游戏文件;如尚未建立原版备份将自动备份至 wtoffline\\stock。",
"existingBodyWithBackup": "直接登记已存在的离线客户端,保留现有的 wtoffline\\stock 原版文件备份,不复制游戏文件。",
"existingBodyWithStockSource": "直接登记已存在的离线客户端,仅从所选原版目录补齐 4 个核心文件至 wtoffline\\stock,不重新复制游戏。",
"room": "目标磁盘可用空间:{{free}}",
"noRoom": "可用空间不足:需要 {{needed}},目标磁盘仅剩 {{free}}。",
"problem": {
@@ -692,6 +698,8 @@
"settings_write_failed": "无法保存设置。",
"folder_unreadable": "无法读取文件夹:{{path}}",
"not_a_game_folder": "所选文件夹不是战争雷霆的安装文件夹:{{path}}",
"stock_source_invalid": "所选客户端已打过离线补丁且缺少原版文件备份,请指定一份未打补丁的同版本原版游戏目录。",
"stock_source_version_mismatch": "所选原版游戏目录版本({{actual}})与当前客户端版本({{expected}})不一致。",
"target_not_usable": "所选文件夹不能用于安装。",
"steam_library_not_confirmed": "客户端或数据目录位于 Steam 游戏库中,请先确认风险提示。",
"not_enough_space": "磁盘空间不足:需要 {{neededGb}} GB,仅剩 {{freeGb}} GB。",
@@ -47,12 +47,19 @@ export function MethodStep({ source, sourceSize, choice, onChoice, onError }: Me
{steamWarning}
</>
);
const savingAvailable = (sourceSize?.linkableBytes ?? 0) > 0;
const savingAvailable = !source.needsStockSource && (sourceSize?.linkableBytes ?? 0) > 0;
const preferExisting = source.hasOfflineBackup || source.needsStockSource;
const existingChoice = (
<Choice
selected={choice.method === 'existing'}
title={t('method.existing')}
body={t(source.hasOfflineBackup ? 'method.existingBodyWithBackup' : 'method.existingBody')}
body={t(
source.needsStockSource
? 'method.existingBodyWithStockSource'
: source.hasOfflineBackup
? 'method.existingBodyWithBackup'
: 'method.existingBody',
)}
onSelect={() => choose('existing')}
>
{steamWarning}
@@ -60,9 +67,10 @@ export function MethodStep({ source, sourceSize, choice, onChoice, onError }: Me
);
return (
<>
{source.hasOfflineBackup && existingChoice}
{preferExisting && existingChoice}
<Choice
selected={choice.method === 'copy'}
disabled={source.needsStockSource}
title={t('method.copy')}
body={sourceSize ? t('method.copyBody', { size: formatBytes(sourceSize.bytes) }) : t('method.copyBodyPending')}
onSelect={() => choose('copy')}
@@ -90,7 +98,7 @@ export function MethodStep({ source, sourceSize, choice, onChoice, onError }: Me
>
{steamWarning}
</Choice>
{!source.hasOfflineBackup && existingChoice}
{!preferExisting && existingChoice}
</>
);
}
@@ -11,20 +11,26 @@ import type { WizardMode } from './useInstallWizard.ts';
interface SourceStepProps {
readonly mode: WizardMode;
readonly source: GameFolderInspection | null;
readonly stockSource: GameFolderInspection | null;
/** Null while the folder is measured. */
readonly sourceSize: FolderSize | null;
readonly supportedVersions: readonly string[];
readonly onSource: (source: GameFolderInspection | null) => void;
readonly onStockSource: (source: GameFolderInspection | null) => void;
readonly onError: (error: unknown) => void;
}
/** Step 1: the player's War Thunder installation, its version and the adaptation used for it. */
export function SourceStep({ mode, source, sourceSize, supportedVersions, onSource, onError }: SourceStepProps) {
export function SourceStep({ mode, source, stockSource, sourceSize, supportedVersions, onSource, onStockSource, onError }: SourceStepProps) {
const { t } = useTranslation();
const inspect = (path: string): void => {
onSource(null);
ipcInvoke('install:inspectGameFolder', { path }).then(onSource).catch(onError);
};
const inspectStock = (path: string): void => {
onStockSource(null);
ipcInvoke('install:inspectGameFolder', { path }).then(onStockSource).catch(onError);
};
return (
<>
<p className="lead">{t(mode === 'existing' ? 'source.existingBody' : 'source.body')}</p>
@@ -35,6 +41,18 @@ export function SourceStep({ mode, source, sourceSize, supportedVersions, onSour
onError={onError}
/>
{source && <SourceVerdict source={source} sourceSize={sourceSize} supportedVersions={supportedVersions} />}
{source?.needsStockSource && (
<div className="maintenance-confirm">
<p className="lead">{t('source.patchedNeedsStock')}</p>
<FolderField
path={stockSource?.path ?? null}
dialogTitle={t('source.stockSourceTitle')}
onChosen={inspectStock}
onError={onError}
/>
{stockSource && <StockSourceVerdict source={source} stockSource={stockSource} />}
</div>
)}
</>
);
}
@@ -66,7 +84,27 @@ function SourceVerdict({ source, sourceSize, supportedVersions }: { readonly sou
);
}
function StockSourceVerdict({ source, stockSource }: { readonly source: GameFolderInspection; readonly stockSource: GameFolderInspection }) {
const { t } = useTranslation();
if (stockSource.missingFiles.length) {
return <Notice tone="error">{t('source.notAGame', { files: stockSource.missingFiles.join(', ') })}</Notice>;
}
if (stockSource.needsStockSource) {
return <Notice tone="error">{t('source.stockSourcePatched')}</Notice>;
}
if (source.version !== null && stockSource.version !== null && source.version !== stockSource.version) {
return <Notice tone="error">{t('source.stockSourceVersionMismatch', { expected: source.version, actual: stockSource.version })}</Notice>;
}
return <Notice tone="info">{t('source.stockSourceReady', { version: stockSource.version ?? t('source.versionUnknown') })}</Notice>;
}
/** Whether the wizard may go past step 1. */
export function sourceUsable(source: GameFolderInspection | null): source is GameFolderInspection {
return source !== null && source.missingFiles.length === 0;
export function sourceUsable(
source: GameFolderInspection | null,
stockSource: GameFolderInspection | null = null,
): source is GameFolderInspection {
if (source === null || source.missingFiles.length > 0) return false;
if (!source.needsStockSource) return true;
if (stockSource === null || stockSource.missingFiles.length > 0 || stockSource.needsStockSource) return false;
return source.version === null || stockSource.version === null || source.version === stockSource.version;
}
@@ -15,9 +15,18 @@ export function WizardMain({ wizard, supportedVersions }: { readonly wizard: Ins
return (
<Sheet title={t(`wizard.steps.${step}`)} aside={t('wizard.stepOf', { index: wizard.index + 1, total: WIZARD_STEPS.length })}>
{step === 'source' && (
<SourceStep mode={wizard.mode} source={source} sourceSize={wizard.sourceSize} supportedVersions={supportedVersions} onSource={wizard.chooseSource} onError={wizard.report} />
<SourceStep
mode={wizard.mode}
source={source}
stockSource={wizard.stockSource}
sourceSize={wizard.sourceSize}
supportedVersions={supportedVersions}
onSource={wizard.chooseSource}
onStockSource={wizard.setStockSource}
onError={wizard.report}
/>
)}
{step === 'method' && sourceUsable(source) && (
{step === 'method' && sourceUsable(source, wizard.stockSource) && (
<>
<Row label={t('copies.summary.name')}>
<input className="input" aria-label={t('copies.summary.name')} value={wizard.name} onChange={(event) => wizard.setName(event.target.value)} />
@@ -27,6 +27,7 @@ export function useInstallWizard({ onInstalled }: WizardOptions) {
const [mode, setMode] = useState<WizardMode>('new');
const [step, setStep] = useState<WizardStep>('source');
const [source, setSource] = useState<GameFolderInspection | null>(null);
const [stockSource, setStockSource] = useState<GameFolderInspection | null>(null);
const [sourceSize, setSourceSize] = useState<FolderSize | null>(null);
const [choice, setChoice] = useState<MethodChoice>(NO_CHOICE);
const [draftId, setDraftId] = useState<string | null>(null);
@@ -42,7 +43,7 @@ export function useInstallWizard({ onInstalled }: WizardOptions) {
// The size of the installation decides whether a target drive has room; measure it once per source.
useEffect(() => {
setSourceSize(null);
if (!sourceUsable(source)) return;
if (!source || source.missingFiles.length > 0) return;
let current = true;
ipcInvoke('install:measureFolder', { path: source.path, version: source.version })
.then((size) => current && setSourceSize(size))
@@ -74,11 +75,15 @@ export function useInstallWizard({ onInstalled }: WizardOptions) {
// The check runs every time the step is entered: the choices before it may have changed.
useEffect(() => {
if (!active || step !== 'check' || !sourceUsable(source)) return;
if (!active || step !== 'check' || !sourceUsable(source, stockSource)) return;
let current = true;
setCheck(null);
setMissingAccepted(false);
ipcInvoke('install:checkPatches', { gamePath: source.path, dataPath })
ipcInvoke('install:checkPatches', {
gamePath: source.path,
dataPath,
...(source.needsStockSource && stockSource ? { stockSourcePath: stockSource.path } : {}),
})
.then((result) => current && setCheck(result))
.catch((error: unknown) => {
if (!current) return;
@@ -88,7 +93,7 @@ export function useInstallWizard({ onInstalled }: WizardOptions) {
return () => {
current = false;
};
}, [active, step, source, dataPath, report]);
}, [active, step, source, stockSource, dataPath, report]);
useEffect(() => ipcOn('event:install-progress', setProgress), []);
@@ -97,6 +102,7 @@ export function useInstallWizard({ onInstalled }: WizardOptions) {
setMode(nextMode);
setStep('source');
setSource(null);
setStockSource(null);
setChoice(nextMode === 'existing' ? { method: 'existing', target: null, steamConfirmed: false } : NO_CHOICE);
setName('');
setDraftId(null);
@@ -112,15 +118,17 @@ export function useInstallWizard({ onInstalled }: WizardOptions) {
const chooseSource = (found: GameFolderInspection | null): void => {
setSource(found);
const defaultMethod = mode === 'existing' || found?.hasOfflineBackup ? 'existing' : 'copy';
setStockSource(null);
const defaultMethod = mode === 'existing' || found?.hasOfflineBackup || found?.needsStockSource ? 'existing' : 'copy';
setChoice({ method: defaultMethod, target: null, steamConfirmed: false });
setName(found?.path.split(/[\\/]/).filter(Boolean).at(-1) ?? '');
};
const install = (): void => {
if (!sourceUsable(source) || !draftId || !dataReady) return;
if (!sourceUsable(source, stockSource) || !draftId || !dataReady) return;
const directFolder = choice.method === 'in-place' || choice.method === 'existing';
const copyFolder = directFolder ? source : choice.target;
const stockExtra = source.needsStockSource && stockSource ? { stockSourcePath: stockSource.path } : {};
const choices = {
id: draftId, name, dataPath,
...(choice.steamConfirmed && copyFolder ? { confirmedSteamCopyPath: copyFolder.resolvedPath } : {}),
@@ -129,9 +137,9 @@ export function useInstallWizard({ onInstalled }: WizardOptions) {
...(decalSource ? { decalSourcePath: decalSource } : {}),
};
const request: InstallRequest = choice.method === 'in-place'
? { method: 'in-place', gamePath: source.path, ...choices }
? { method: 'in-place', gamePath: source.path, ...stockExtra, ...choices }
: choice.method === 'existing'
? { method: 'existing', gamePath: source.path, ...choices }
? { method: 'existing', gamePath: source.path, ...stockExtra, ...choices }
: { method: 'copy', useHardLinks: choice.method === 'hardlink', sourcePath: source.path, copyPath: choice.target!.path, ...choices };
clear();
setProgress(null);
@@ -150,8 +158,8 @@ export function useInstallWizard({ onInstalled }: WizardOptions) {
const canGoOn = ((): boolean => {
switch (step) {
case 'source': return draftId !== null && sourceUsable(source);
case 'method': return name.trim().length > 0 && sourceUsable(source) && methodUsable(source, sourceSize, choice);
case 'source': return draftId !== null && sourceUsable(source, stockSource);
case 'method': return name.trim().length > 0 && sourceUsable(source, stockSource) && methodUsable(source, sourceSize, choice);
case 'data': return dataReady;
case 'check': return dataReady && checkUsable(check, missingAccepted);
case 'installing': return false;
@@ -179,9 +187,9 @@ export function useInstallWizard({ onInstalled }: WizardOptions) {
};
return {
active, mode, step, index, source, sourceSize, choice, name, dataPath, decalSource, check, missingAccepted, progress, cancelling, message, canGoOn,
active, mode, step, index, source, stockSource, sourceSize, choice, name, dataPath, decalSource, check, missingAccepted, progress, cancelling, message, canGoOn,
steamDataPath: dataChecked?.inSteam ? dataChecked.path : null, steamDataConfirmed: dataChecked?.confirmed ?? false,
start, back, next, cancel, report, chooseSource, setChoice, setName, setDataPath, setSteamDataConfirmed, setDecalSource, setMissingAccepted,
start, back, next, cancel, report, chooseSource, setStockSource, setChoice, setName, setDataPath, setSteamDataConfirmed, setDecalSource, setMissingAccepted,
};
}
+4
View File
@@ -69,6 +69,10 @@ export const APP_ERROR_CODES = [
'folder_unreadable',
/** The chosen folder lacks the files of a War Thunder installation (params: path). */
'not_a_game_folder',
/** A patched client lacking wtoffline/stock needs an unpatched original game folder. */
'stock_source_invalid',
/** The chosen original game folder has a different version than the patched client. */
'stock_source_version_mismatch',
/** The folder chosen for the copy cannot take it (params: problem, one of TARGET_PROBLEMS). */
'target_not_usable',
/** A copy or data folder is inside a Steam library and the player has not confirmed the warning. */
+6 -2
View File
@@ -89,8 +89,12 @@ export const ipcContract = {
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) }),
/** The game folder to install from, optional stock source folder, and the data folder whose store tuning the build uses. */
input: z.object({
gamePath: z.string().min(1),
dataPath: z.string().min(1),
stockSourcePath: z.string().min(1).optional(),
}),
output: PatchCheckSchema,
},
'install:start': {
@@ -14,6 +14,8 @@ export const GameFolderInspectionSchema = z.object({
inSteamLibrary: z.boolean(),
/** True when the folder already holds a complete wtoffline/stock backup from an offline setup. */
hasOfflineBackup: z.boolean(),
/** True when the folder is already patched for offline use but lacks a wtoffline/stock backup. */
needsStockSource: z.boolean(),
});
export type GameFolderInspection = z.output<typeof GameFolderInspectionSchema>;
@@ -111,11 +113,15 @@ export const InstallRequestSchema = z.discriminatedUnion('method', [
method: z.literal('in-place'),
/** The player's prepared game folder, used as the game copy. */
gamePath: z.string().min(1),
/** Optional unpatched game folder to supply the 4 stock files when the folder is already patched. */
stockSourcePath: z.string().min(1).optional(),
}),
InstallChoicesSchema.extend({
method: z.literal('existing'),
/** An already prepared offline client folder registered directly without copying. */
gamePath: z.string().min(1),
/** Optional unpatched game folder to supply the 4 stock files when wtoffline/stock is missing. */
stockSourcePath: z.string().min(1).optional(),
}),
]);
export type InstallRequest = z.output<typeof InstallRequestSchema>;