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

@@ -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,
};
}