From bfedc3d27eb68d03fcea11d1b38245add0bdb963 Mon Sep 17 00:00:00 2001 From: N0VAN0M4LY <224130499+N0VAN0M4LY@users.noreply.github.com> Date: Mon, 30 Nov 2026 20:59:38 +0800 Subject: [PATCH] feat(launcher): prompt for stock source when adding patched client without backup --- apps/launcher/src/main/ipc/handlers.ts | 3 +- .../game-folder/inspect-game-folder.ts | 36 ++++++++++++-- .../src/main/services/install/install-game.ts | 48 ++++++++++++++----- .../src/main/services/install/stock-backup.ts | 10 +++- .../src/renderer/src/i18n/locales/en.json | 8 ++++ .../src/renderer/src/i18n/locales/zh-CN.json | 8 ++++ .../renderer/src/pages/install/MethodStep.tsx | 16 +++++-- .../renderer/src/pages/install/SourceStep.tsx | 44 +++++++++++++++-- .../renderer/src/pages/install/WizardMain.tsx | 13 ++++- .../src/pages/install/useInstallWizard.ts | 32 ++++++++----- apps/launcher/src/shared/errors.ts | 4 ++ apps/launcher/src/shared/ipc/contract.ts | 8 +++- apps/launcher/src/shared/schemas/install.ts | 6 +++ 13 files changed, 195 insertions(+), 41 deletions(-) diff --git a/apps/launcher/src/main/ipc/handlers.ts b/apps/launcher/src/main/ipc/handlers.ts index 7ba44a9..dae1802 100644 --- a/apps/launcher/src/main/ipc/handlers.ts +++ b/apps/launcher/src/main/ipc/handlers.ts @@ -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)); diff --git a/apps/launcher/src/main/services/game-folder/inspect-game-folder.ts b/apps/launcher/src/main/services/game-folder/inspect-game-folder.ts index d126e64..92001b0 100644 --- a/apps/launcher/src/main/services/game-folder/inspect-game-folder.ts +++ b/apps/launcher/src/main/services/game-folder/inspect-game-folder.ts @@ -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 { await requireFolder(path); @@ -30,20 +34,42 @@ export async function inspectGameFolder(path: string): Promise 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 { +async function readBytes(filePath: string): Promise { 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. diff --git a/apps/launcher/src/main/services/install/install-game.ts b/apps/launcher/src/main/services/install/install-game.ts index 6602468..acb3f3f 100644 --- a/apps/launcher/src/main/services/install/install-game.ts +++ b/apps/launcher/src/main/services/install/install-game.ts @@ -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 { - const { resolvedPath, version } = await requireGameFolder(gameFolder); - const stock = await installStockSource(resolvedPath, version); +export async function checkGameFolder(gameFolder: string, dataPath: string, stockSourcePath?: string): Promise { + 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 { - 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( diff --git a/apps/launcher/src/main/services/install/stock-backup.ts b/apps/launcher/src/main/services/install/stock-backup.ts index 234447a..9130682 100644 --- a/apps/launcher/src/main/services/install/stock-backup.ts +++ b/apps/launcher/src/main/services/install/stock-backup.ts @@ -32,12 +32,20 @@ export async function requireStockBackupLocation(copyFolder: string): Promise { + return backUpStockFilesFrom(copyFolder, copyFolder); +} + +/** + * Copies the four stock files from `sourceFolder` (read-only) into `/wtoffline/stock`, + * keeping any file that is already backed up. + */ +export async function backUpStockFilesFrom(copyFolder: string, sourceFolder: string): Promise { 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; } diff --git a/apps/launcher/src/renderer/src/i18n/locales/en.json b/apps/launcher/src/renderer/src/i18n/locales/en.json index 1ee9788..6e6527a 100644 --- a/apps/launcher/src/renderer/src/i18n/locales/en.json +++ b/apps/launcher/src/renderer/src/i18n/locales/en.json @@ -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.", diff --git a/apps/launcher/src/renderer/src/i18n/locales/zh-CN.json b/apps/launcher/src/renderer/src/i18n/locales/zh-CN.json index dc7d188..bd54538 100644 --- a/apps/launcher/src/renderer/src/i18n/locales/zh-CN.json +++ b/apps/launcher/src/renderer/src/i18n/locales/zh-CN.json @@ -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。", diff --git a/apps/launcher/src/renderer/src/pages/install/MethodStep.tsx b/apps/launcher/src/renderer/src/pages/install/MethodStep.tsx index 7b933a7..aec1699 100644 --- a/apps/launcher/src/renderer/src/pages/install/MethodStep.tsx +++ b/apps/launcher/src/renderer/src/pages/install/MethodStep.tsx @@ -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 = ( choose('existing')} > {steamWarning} @@ -60,9 +67,10 @@ export function MethodStep({ source, sourceSize, choice, onChoice, onError }: Me ); return ( <> - {source.hasOfflineBackup && existingChoice} + {preferExisting && existingChoice} choose('copy')} @@ -90,7 +98,7 @@ export function MethodStep({ source, sourceSize, choice, onChoice, onError }: Me > {steamWarning} - {!source.hasOfflineBackup && existingChoice} + {!preferExisting && existingChoice} ); } diff --git a/apps/launcher/src/renderer/src/pages/install/SourceStep.tsx b/apps/launcher/src/renderer/src/pages/install/SourceStep.tsx index 5f06b9f..15b4f24 100644 --- a/apps/launcher/src/renderer/src/pages/install/SourceStep.tsx +++ b/apps/launcher/src/renderer/src/pages/install/SourceStep.tsx @@ -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 ( <>

{t(mode === 'existing' ? 'source.existingBody' : 'source.body')}

@@ -35,6 +41,18 @@ export function SourceStep({ mode, source, sourceSize, supportedVersions, onSour onError={onError} /> {source && } + {source?.needsStockSource && ( +
+

{t('source.patchedNeedsStock')}

+ + {stockSource && } +
+ )} ); } @@ -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 {t('source.notAGame', { files: stockSource.missingFiles.join(', ') })}; + } + if (stockSource.needsStockSource) { + return {t('source.stockSourcePatched')}; + } + if (source.version !== null && stockSource.version !== null && source.version !== stockSource.version) { + return {t('source.stockSourceVersionMismatch', { expected: source.version, actual: stockSource.version })}; + } + return {t('source.stockSourceReady', { version: stockSource.version ?? t('source.versionUnknown') })}; +} + /** 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; } diff --git a/apps/launcher/src/renderer/src/pages/install/WizardMain.tsx b/apps/launcher/src/renderer/src/pages/install/WizardMain.tsx index de47247..bf81aaa 100644 --- a/apps/launcher/src/renderer/src/pages/install/WizardMain.tsx +++ b/apps/launcher/src/renderer/src/pages/install/WizardMain.tsx @@ -15,9 +15,18 @@ export function WizardMain({ wizard, supportedVersions }: { readonly wizard: Ins return ( {step === 'source' && ( - + )} - {step === 'method' && sourceUsable(source) && ( + {step === 'method' && sourceUsable(source, wizard.stockSource) && ( <> wizard.setName(event.target.value)} /> diff --git a/apps/launcher/src/renderer/src/pages/install/useInstallWizard.ts b/apps/launcher/src/renderer/src/pages/install/useInstallWizard.ts index c62f298..568cf8f 100644 --- a/apps/launcher/src/renderer/src/pages/install/useInstallWizard.ts +++ b/apps/launcher/src/renderer/src/pages/install/useInstallWizard.ts @@ -27,6 +27,7 @@ export function useInstallWizard({ onInstalled }: WizardOptions) { const [mode, setMode] = useState('new'); const [step, setStep] = useState('source'); const [source, setSource] = useState(null); + const [stockSource, setStockSource] = useState(null); const [sourceSize, setSourceSize] = useState(null); const [choice, setChoice] = useState(NO_CHOICE); const [draftId, setDraftId] = useState(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, }; } diff --git a/apps/launcher/src/shared/errors.ts b/apps/launcher/src/shared/errors.ts index 534b705..917f5da 100644 --- a/apps/launcher/src/shared/errors.ts +++ b/apps/launcher/src/shared/errors.ts @@ -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. */ diff --git a/apps/launcher/src/shared/ipc/contract.ts b/apps/launcher/src/shared/ipc/contract.ts index c7ba69a..7b272b9 100644 --- a/apps/launcher/src/shared/ipc/contract.ts +++ b/apps/launcher/src/shared/ipc/contract.ts @@ -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': { diff --git a/apps/launcher/src/shared/schemas/install.ts b/apps/launcher/src/shared/schemas/install.ts index 12af778..b1ad893 100644 --- a/apps/launcher/src/shared/schemas/install.ts +++ b/apps/launcher/src/shared/schemas/install.ts @@ -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; @@ -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;