Add the install wizard to the launcher window

The window now installs the offline version in five steps:

1. Game: the player picks their War Thunder folder; the launcher says
   whether it is one and whether its version is the one the patches were
   verified on (another version is pointed out, not refused).
2. Method: copy into a new folder (recommended; shows the size of the
   installation, the room on the target drive, and why a folder cannot
   be used) or install into the chosen folder itself. A Steam library
   brings up the three risks and needs a tick before going on.
3. Data: the folder for saves, caches and logs, the launcher's own data
   folder by default.
4. Check: the patch check runs each time the step is entered. Missing
   essential changes stop the installation; other missing changes are
   listed as the features they cost, translated, with the patches behind
   them folded away, and need a tick to go on.
5. Install: phase, a byte progress bar and file counts while copying,
   and a cancel button. An error goes back to the check step with its
   translated message.

The first screen shows either the invitation to install or what is
installed (copy, data folder, version, method, missing features) with a
button to install again. Feature tags of the patch definitions have
names in both languages; a tag without one is shown as it is.

The app's productName gives its user data folder a readable name.

Checked with the launcher typecheck and build, and a start on a scratch
user data folder: the first screen and the wizard's first step render
in Chinese and English with no console errors.
This commit is contained in:
N0VAN0M4LY committed 2026-11-29 06:29:53 +08:00
1 parent 54a783b80e
commit 303dbf24e6
19 files changed
+1028 -15

No files matched your search

+1
View File
@@ -1,5 +1,6 @@
{
"name": "@wto/launcher",
"productName": "WTOffline Launcher",
"version": "0.1.0",
"private": true,
"description": "Installer and launcher of the War Thunder offline project.",
+16 -2
View File
@@ -1,19 +1,25 @@
import { useEffect, useState } from 'react';
import { useTranslation } from 'react-i18next';
import type { InstallRecord } from '@shared/schemas/install.ts';
import type { Settings } from '@shared/schemas/settings.ts';
import { LanguageMenu } from './components/LanguageMenu.tsx';
import { applyLanguage, resolveLanguage } from './i18n/index.ts';
import { ipcOn } from './ipc.ts';
import { InstallWizard } from './pages/install/InstallWizard.tsx';
import { WelcomePage } from './pages/WelcomePage.tsx';
interface AppProps {
readonly initialSettings: Settings;
readonly systemLocale: string;
readonly initialRecord: InstallRecord | null;
readonly defaultDataPath: string;
}
export function App({ initialSettings, systemLocale }: AppProps) {
export function App({ initialSettings, systemLocale, initialRecord, defaultDataPath }: AppProps) {
const { t } = useTranslation();
const [settings, setSettings] = useState(initialSettings);
const [record, setRecord] = useState(initialRecord);
const [installing, setInstalling] = useState(false);
useEffect(() => ipcOn('event:settings-changed', setSettings), []);
useEffect(() => applyLanguage(resolveLanguage(settings.language, systemLocale)), [settings.language, systemLocale]);
@@ -25,7 +31,15 @@ export function App({ initialSettings, systemLocale }: AppProps) {
<LanguageMenu value={settings.language} />
</header>
<main className="app-main">
<WelcomePage />
{installing ? (
<InstallWizard
defaultDataPath={record?.dataPath ?? defaultDataPath}
onInstalled={(installed) => { setRecord(installed); setInstalling(false); }}
onClose={() => setInstalling(false)}
/>
) : (
<WelcomePage record={record} onInstall={() => setInstalling(true)} />
)}
</main>
</div>
);
@@ -0,0 +1,31 @@
import { useTranslation } from 'react-i18next';
import { ipcInvoke } from '../ipc.ts';
interface FolderFieldProps {
readonly path: string | null;
/** Title of the folder dialog. */
readonly dialogTitle: string;
readonly disabled?: boolean;
readonly onChosen: (path: string) => void;
readonly onError: (error: unknown) => void;
}
/** A chosen folder and the button that opens the folder dialog. */
export function FolderField({ path, dialogTitle, disabled = false, onChosen, onError }: FolderFieldProps) {
const { t } = useTranslation();
const choose = (): void => {
ipcInvoke('dialog:pickFolder', { title: dialogTitle })
.then(({ path: chosen }) => {
if (chosen) onChosen(chosen);
})
.catch(onError);
};
return (
<div className="folder-field">
<span className={path ? 'folder-path' : 'folder-path folder-path-empty'}>{path ?? t('folder.none')}</span>
<button type="button" className="button" onClick={choose} disabled={disabled}>
{path ? t('folder.change') : t('folder.choose')}
</button>
</div>
);
}
@@ -0,0 +1,6 @@
import type { ReactNode } from 'react';
/** A boxed message: information, a warning the player can go past, or a problem that stops them. */
export function Notice({ tone, children }: { readonly tone: 'info' | 'warning' | 'error'; readonly children: ReactNode }) {
return <div className={`notice notice-${tone}`}>{children}</div>;
}
@@ -0,0 +1,9 @@
/** A bar filled to `value` of `max`; without a max it shows that work is going on. */
export function ProgressBar({ value, max }: { readonly value: number; readonly max: number | null }) {
const fraction = max ? Math.min(1, value / max) : null;
return (
<div className="progress" role="progressbar" aria-valuemin={0} aria-valuemax={100} aria-valuenow={fraction === null ? undefined : Math.round(fraction * 100)}>
<div className={fraction === null ? 'progress-fill progress-busy' : 'progress-fill'} style={fraction === null ? undefined : { width: `${fraction * 100}%` }} />
</div>
);
}
@@ -0,0 +1,10 @@
import type { TFunction } from 'i18next';
/**
* The player-facing name of a feature tag from a patch definition (a feature inventory row such
* as "K-侦察"). Tags without a translation are shown as they are.
*/
export function featureName(t: TFunction, tag: string): string {
// Tags hold spaces and slashes but never the key separator, so they work as keys as they are.
return t(`features.${tag}`, { defaultValue: tag });
}
+6
View File
@@ -0,0 +1,6 @@
/** Sizes as the player reads them: gigabytes with one decimal, megabytes below one gigabyte. */
export function formatBytes(bytes: number): string {
const gigabytes = bytes / 1024 ** 3;
if (gigabytes >= 1) return `${gigabytes.toFixed(1)} GB`;
return `${Math.max(0, Math.round(bytes / 1024 ** 2))} MB`;
}
@@ -10,7 +10,134 @@
},
"welcome": {
"title": "Not installed yet",
"body": "Install the offline version from your own copy of War Thunder. Your original game is only read, never changed."
"body": "Install the offline version from your own War Thunder. By default it works on a copy; your original game is only read, never changed.",
"install": "Install"
},
"installed": {
"title": "The offline version is installed",
"launchLater": "Starting the game comes in the next version.",
"reinstall": "Install again"
},
"summary": {
"copy": "Game copy",
"data": "Data folder",
"version": "Game version",
"method": "Installed",
"methods": {
"copy": "as a copy in a new folder",
"in-place": "in the original folder"
},
"missing": "These features do not work with your game version:"
},
"folder": {
"none": "Not chosen",
"choose": "Choose folder",
"change": "Change"
},
"wizard": {
"steps": {
"source": "Game",
"method": "Method",
"data": "Data",
"check": "Check",
"installing": "Install"
},
"back": "Back",
"next": "Next",
"cancel": "Cancel",
"install": "Install"
},
"source": {
"title": "Choose your War Thunder folder",
"body": "The one holding aces.vromfs.bin and the win64 folder, such as the War Thunder folder in Steam.",
"notAGame": "This is not a War Thunder folder. Missing: {{files}}",
"versionVerified": "Game version {{version}}. The offline version is made for it.",
"versionUnverified": "Game version {{version}}. The offline version is made for {{verified}}, so some features may not work. The next steps check which.",
"versionUnknown": "unknown"
},
"method": {
"title": "How to install",
"copy": "Copy into a new folder (recommended)",
"copyBody": "The whole game is copied and the offline version goes into the copy. Your original stays as it is. Needs about {{size}}.",
"measuring": "(measuring)",
"targetTitle": "Choose a folder for the game copy",
"inPlace": "Install into this folder",
"inPlaceBody": "For a copy of the game you prepared yourself. Four files in {{path}} are replaced; the originals are kept in its wtoffline\\stock folder.",
"room": "{{free}} free on this drive.",
"noRoom": "Not enough room: {{needed}} needed, {{free}} free on this drive.",
"problem": {
"not_empty": "This folder already holds files. Choose an empty or a new folder.",
"overlaps_stock": "Choose a folder other than the original game folder, outside it and not containing it.",
"not_a_folder": "This is not a folder."
}
},
"steam": {
"title": "This folder is in a Steam library. Installing here:",
"risk1": "changes your online game client directly;",
"risk2": "can be undone when Steam verifies or updates the game;",
"risk3": "risks a ban if the online game is started with the changed files.",
"advice": "Copying into a new folder is the safer choice.",
"confirm": "I understand these risks and want to install here"
},
"data": {
"title": "Choose the data folder",
"body": "Saves, caches and logs of the offline version go here. Take this folder along to take your saves."
},
"check": {
"title": "Checking your game",
"running": "Checking that the offline version's changes fit your game. This takes a few seconds…",
"allFit": "All {{count}} changes fit your game.",
"essentialMissing": "Your game version lacks changes the offline version cannot run without, so it cannot be installed. Affected:",
"someMissing": "Some changes do not fit your game version. These features will not work:",
"details": "Which changes",
"accept": "Install without these features"
},
"progress": {
"title": "Installing",
"phase": {
"checking": "Checking the game files…",
"measuring": "Counting the files to copy…",
"copying": "Copying the game…",
"backing-up": "Keeping the original files…",
"recording": "Finishing…"
},
"copied": "{{done}} of {{total}} copied ({{doneFiles}} of {{totalFiles}} files)",
"cancel": "Cancel installation",
"cancelling": "Cancelling…"
},
"features": {
"A-离线启动": "Starting offline",
"A-与正版隔离": "Kept apart from the online game",
"A-不连 Gaijin": "No connection to Gaijin",
"A-新手流程": "Tutorials",
"B-机库与载具": "Hangar and vehicles",
"G-礼包商店": "Pack store",
"G-兑换码": "Redeem codes",
"G-市场": "Marketplace",
"G-Marketplace": "Marketplace",
"G-货币": "Currency purchases",
"G-高级账户": "Premium account",
"G-Premium Account": "Premium account",
"G-Store": "Store",
"G-加成道具": "Boosters",
"H-合同 / 赌注": "Battle contracts",
"H-补给箱": "Supply chests",
"H-物品回收与合成": "Recycling and crafting",
"H-兑换券": "Coupons",
"H-External inventory": "External inventory items",
"J-对局模式": "Battle modes",
"J-陆战 街机 / 历史": "Ground battles (arcade, realistic)",
"J-空战 街机 / 历史": "Air battles (arcade, realistic)",
"J-海战 街机 / 历史": "Naval battles (arcade, realistic)",
"J-附加子模式": "Extra modes (such as night battles)",
"K-AI 对手与队友": "AI opponents and teammates",
"K-出生点数 / 重生": "Spawn points and respawning",
"K-侦察": "Scouting and drones",
"K-击杀、助攻、占点计分": "Kill, assist and capture scoring",
"K-补充载具": "Extra vehicles",
"K-计分板": "Scoreboard",
"L-结算页": "Battle results",
"L-战斗奖章": "Battle awards"
},
"errors": {
"internal_error": "Something went wrong inside the launcher.",
@@ -10,7 +10,134 @@
},
"welcome": {
"title": "尚未安装",
"body": "从你自己的战争雷霆游戏安装离线版。原版游戏只读取,不会被修改。"
"body": "用你自己的战争雷霆安装离线版。默认会复制一份游戏,原版只读取、不修改。",
"install": "开始安装"
},
"installed": {
"title": "离线版已安装",
"launchLater": "启动游戏的功能将在下一版加入。",
"reinstall": "重新安装"
},
"summary": {
"copy": "游戏副本",
"data": "数据目录",
"version": "游戏版本",
"method": "安装方式",
"methods": {
"copy": "复制到新文件夹",
"in-place": "直接在原文件夹里安装"
},
"missing": "你的游戏版本用不上以下功能:"
},
"folder": {
"none": "尚未选择",
"choose": "选择文件夹",
"change": "更改"
},
"wizard": {
"steps": {
"source": "游戏位置",
"method": "安装方式",
"data": "数据目录",
"check": "检查",
"installing": "安装"
},
"back": "上一步",
"next": "下一步",
"cancel": "取消",
"install": "开始安装"
},
"source": {
"title": "选择你的战争雷霆游戏文件夹",
"body": "就是装有 aces.vromfs.bin 和 win64 文件夹的那个,例如 Steam 里的 War Thunder 文件夹。",
"notAGame": "这不是战争雷霆的游戏文件夹,缺少:{{files}}",
"versionVerified": "游戏版本 {{version}},离线版已适配这个版本。",
"versionUnverified": "游戏版本 {{version}}。离线版适配的是 {{verified}},其他版本可能有部分功能用不了。下一步会检查具体哪些。",
"versionUnknown": "未知"
},
"method": {
"title": "怎么安装",
"copy": "复制到新文件夹(推荐)",
"copyBody": "把游戏完整复制一份,离线版装在副本里,原版不受影响。需要约 {{size}} 空间。",
"measuring": "(正在计算大小)",
"targetTitle": "选择存放游戏副本的文件夹",
"inPlace": "直接在这个文件夹里安装",
"inPlaceBody": "适合你已经自己准备好一份游戏副本的情况。会替换 {{path}} 里的 4 个文件,原文件备份在其中的 wtoffline\\stock 文件夹。",
"room": "这个盘还有 {{free}} 空间。",
"noRoom": "空间不够:需要 {{needed}},这个盘只剩 {{free}}。",
"problem": {
"not_empty": "这个文件夹里已经有文件了,请选一个空文件夹或新文件夹。",
"overlaps_stock": "不能选原版游戏文件夹本身,也不能选它里面或包含它的文件夹。",
"not_a_folder": "这不是一个文件夹。"
}
},
"steam": {
"title": "这个文件夹在 Steam 游戏库里。在这里安装:",
"risk1": "等于直接改动你的正版客户端;",
"risk2": "Steam 校验文件或更新时,改动可能被覆盖;",
"risk3": "带着改过的文件联网启动正版,有被封号的风险。",
"advice": "建议改用“复制到新文件夹”。",
"confirm": "我了解这些风险,仍要在这里安装"
},
"data": {
"title": "选择数据目录",
"body": "离线版的存档、缓存和日志都放在这里。拷走这个文件夹就能带走存档。"
},
"check": {
"title": "检查你的游戏",
"running": "正在核对离线版的改动是否都适用于你的游戏,需要几秒钟……",
"allFit": "全部 {{count}} 项改动都适用于你的游戏。",
"essentialMissing": "你的游戏版本缺少离线版运行所必需的改动,无法安装。受影响的是:",
"someMissing": "有些改动不适用于你的游戏版本,下面这些功能会用不了:",
"details": "具体是哪些改动",
"accept": "缺少这些功能也继续安装"
},
"progress": {
"title": "正在安装",
"phase": {
"checking": "正在检查游戏文件……",
"measuring": "正在统计要复制的文件……",
"copying": "正在复制游戏……",
"backing-up": "正在备份原版文件……",
"recording": "正在完成安装……"
},
"copied": "已复制 {{done}} / {{total}}({{doneFiles}} / {{totalFiles}} 个文件)",
"cancel": "取消安装",
"cancelling": "正在取消……"
},
"features": {
"A-离线启动": "离线启动",
"A-与正版隔离": "与正版游戏隔离",
"A-不连 Gaijin": "不连接 Gaijin",
"A-新手流程": "新手教程",
"B-机库与载具": "机库与载具",
"G-礼包商店": "礼包商店",
"G-兑换码": "兑换码",
"G-市场": "交易所",
"G-Marketplace": "交易所",
"G-货币": "货币购买",
"G-高级账户": "高级账户",
"G-Premium Account": "高级账户",
"G-Store": "商店",
"G-加成道具": "加成道具",
"H-合同 / 赌注": "作战合约",
"H-补给箱": "补给箱",
"H-物品回收与合成": "物品回收与合成",
"H-兑换券": "兑换券",
"H-External inventory": "外部库存物品",
"J-对局模式": "对局模式",
"J-陆战 街机 / 历史": "陆战(街机、历史)",
"J-空战 街机 / 历史": "空战(街机、历史)",
"J-海战 街机 / 历史": "海战(街机、历史)",
"J-附加子模式": "附加模式(如夜战)",
"K-AI 对手与队友": "AI 对手与队友",
"K-出生点数 / 重生": "出生点数与重生",
"K-侦察": "侦察与无人机",
"K-击杀、助攻、占点计分": "击杀、助攻和占点计分",
"K-补充载具": "补充载具",
"K-计分板": "计分板",
"L-结算页": "战后结算",
"L-战斗奖章": "战斗嘉奖"
},
"errors": {
"internal_error": "启动器内部出错了。",
+2 -2
View File
@@ -6,7 +6,7 @@ import { ipcInvoke } from './ipc.ts';
import './styles/app.css';
async function start(): Promise<void> {
const [settings, info] = await Promise.all([ipcInvoke('settings:get'), ipcInvoke('app:getInfo')]);
const [settings, info, install] = await Promise.all([ipcInvoke('settings:get'), ipcInvoke('app:getInfo'), ipcInvoke('install:getRecord')]);
const language = resolveLanguage(settings.language, info.systemLocale);
await initI18n(language);
document.documentElement.lang = language;
@@ -14,7 +14,7 @@ async function start(): Promise<void> {
if (!root) throw new Error('#root is missing from index.html');
createRoot(root).render(
<StrictMode>
<App initialSettings={settings} systemLocale={info.systemLocale} />
<App initialSettings={settings} systemLocale={info.systemLocale} initialRecord={install.record} defaultDataPath={install.defaultDataPath} />
</StrictMode>,
);
}
@@ -0,0 +1,31 @@
import { useTranslation } from 'react-i18next';
import type { InstallRecord } from '@shared/schemas/install.ts';
import { featureName } from '../features.ts';
/** What is installed where, and which features are missing. */
export function InstallSummary({ record }: { readonly record: InstallRecord }) {
const { t } = useTranslation();
const missing = [...new Set(record.unavailablePatches.flatMap((patch) => patch.features))];
return (
<>
<dl className="summary">
<dt>{t('summary.copy')}</dt>
<dd>{record.copyPath}</dd>
<dt>{t('summary.data')}</dt>
<dd>{record.dataPath}</dd>
<dt>{t('summary.version')}</dt>
<dd>{record.gameVersion ?? t('source.versionUnknown')}</dd>
<dt>{t('summary.method')}</dt>
<dd>{t(`summary.methods.${record.method}`)}</dd>
</dl>
{missing.length > 0 && (
<div className="muted">
<p>{t('summary.missing')}</p>
<ul>
{missing.map((feature) => <li key={feature}>{featureName(t, feature)}</li>)}
</ul>
</div>
)}
</>
);
}
@@ -1,12 +1,31 @@
import { useTranslation } from 'react-i18next';
import type { InstallRecord } from '@shared/schemas/install.ts';
import { InstallSummary } from './InstallSummary.tsx';
/** What the launcher shows before anything is installed. The install wizard starts from here. */
export function WelcomePage() {
interface WelcomePageProps {
/** The installed copy, or null before the first installation. */
readonly record: InstallRecord | null;
readonly onInstall: () => void;
}
/** The first screen: an invitation to install, or what is installed. */
export function WelcomePage({ record, onInstall }: WelcomePageProps) {
const { t } = useTranslation();
if (!record) {
return (
<section className="welcome">
<h2>{t('welcome.title')}</h2>
<p>{t('welcome.body')}</p>
<button type="button" className="button button-primary" onClick={onInstall}>{t('welcome.install')}</button>
</section>
);
}
return (
<section className="welcome">
<h2>{t('welcome.title')}</h2>
<p>{t('welcome.body')}</p>
<h2>{t('installed.title')}</h2>
<InstallSummary record={record} />
<p className="muted">{t('installed.launchLater')}</p>
<button type="button" className="button" onClick={onInstall}>{t('installed.reinstall')}</button>
</section>
);
}
@@ -0,0 +1,74 @@
import { useTranslation } from 'react-i18next';
import type { PatchCheck, UnavailablePatch } from '@shared/schemas/install.ts';
import { Notice } from '../../components/Notice.tsx';
import { ProgressBar } from '../../components/ProgressBar.tsx';
import { featureName } from '../../features.ts';
interface CheckStepProps {
/** Null while the check runs. */
readonly check: PatchCheck | null;
readonly missingAccepted: boolean;
readonly onMissingAccepted: (accepted: boolean) => void;
}
/** Step 4: which of the offline version's changes fit the player's game build. */
export function CheckStep({ check, missingAccepted, onMissingAccepted }: CheckStepProps) {
const { t } = useTranslation();
if (!check) {
return (
<section className="step">
<h2>{t('check.title')}</h2>
<p className="muted">{t('check.running')}</p>
<ProgressBar value={0} max={null} />
</section>
);
}
const essential = check.unavailable.filter((patch) => patch.essential);
return (
<section className="step">
<h2>{t('check.title')}</h2>
{check.unavailable.length === 0 && <Notice tone="info">{t('check.allFit', { count: check.exePatchesReady + check.guiPatchesReady })}</Notice>}
{essential.length > 0 && (
<Notice tone="error">
<p>{t('check.essentialMissing')}</p>
<PatchList patches={essential} />
</Notice>
)}
{essential.length === 0 && check.unavailable.length > 0 && (
<Notice tone="warning">
<p>{t('check.someMissing')}</p>
<PatchList patches={check.unavailable} />
<label className="check">
<input type="checkbox" checked={missingAccepted} onChange={(event) => onMissingAccepted(event.target.checked)} />
{t('check.accept')}
</label>
</Notice>
)}
</section>
);
}
/** The features the unavailable patches cover, each once, with the patches behind them. */
function PatchList({ patches }: { readonly patches: readonly UnavailablePatch[] }) {
const { t } = useTranslation();
const features = [...new Set(patches.flatMap((patch) => patch.features))];
return (
<>
<ul>
{features.map((feature) => <li key={feature}>{featureName(t, feature)}</li>)}
</ul>
<details>
<summary>{t('check.details')}</summary>
<ul className="patch-details">
{patches.map((patch) => <li key={patch.patchId}><code>{patch.patchId}</code>: {patch.reason}</li>)}
</ul>
</details>
</>
);
}
/** Whether the wizard may start the installation. */
export function checkUsable(check: PatchCheck | null, missingAccepted: boolean): boolean {
if (!check || check.unavailable.some((patch) => patch.essential)) return false;
return check.unavailable.length === 0 || missingAccepted;
}
@@ -0,0 +1,20 @@
import { useTranslation } from 'react-i18next';
import { FolderField } from '../../components/FolderField.tsx';
interface DataStepProps {
readonly dataPath: string;
readonly onDataPath: (path: string) => void;
readonly onError: (error: unknown) => void;
}
/** Step 3: where saves, caches and logs of the offline version are kept. */
export function DataStep({ dataPath, onDataPath, onError }: DataStepProps) {
const { t } = useTranslation();
return (
<section className="step">
<h2>{t('data.title')}</h2>
<p className="muted">{t('data.body')}</p>
<FolderField path={dataPath} dialogTitle={t('data.title')} onChosen={onDataPath} onError={onError} />
</section>
);
}
@@ -0,0 +1,133 @@
import { useEffect, useState } from 'react';
import { useTranslation } from 'react-i18next';
import type { FolderSize, GameFolderInspection, InstallProgress, InstallRecord, InstallRequest, PatchCheck } from '@shared/schemas/install.ts';
import { ipcInvoke, ipcOn } from '../../ipc.ts';
import { useErrorMessage } from '../../useErrorMessage.ts';
import { CheckStep, checkUsable } from './CheckStep.tsx';
import { DataStep } from './DataStep.tsx';
import { MethodStep, methodUsable, type MethodChoice } from './MethodStep.tsx';
import { ProgressStep } from './ProgressStep.tsx';
import { SourceStep, sourceUsable } from './SourceStep.tsx';
const STEPS = ['source', 'method', 'data', 'check', 'installing'] as const;
type Step = (typeof STEPS)[number];
interface InstallWizardProps {
readonly defaultDataPath: string;
readonly onInstalled: (record: InstallRecord) => void;
readonly onClose: () => void;
}
/** The install wizard: one screen per step, the work done by the main process over IPC. */
export function InstallWizard({ defaultDataPath, onInstalled, onClose }: InstallWizardProps) {
const { t } = useTranslation();
const { message, report, clear } = useErrorMessage();
const [step, setStep] = useState<Step>('source');
const [source, setSource] = useState<GameFolderInspection | null>(null);
const [sourceSize, setSourceSize] = useState<FolderSize | null>(null);
const [choice, setChoice] = useState<MethodChoice>({ method: 'copy', target: null, steamConfirmed: false });
const [dataPath, setDataPath] = useState(defaultDataPath);
const [check, setCheck] = useState<PatchCheck | null>(null);
const [missingAccepted, setMissingAccepted] = useState(false);
const [progress, setProgress] = useState<InstallProgress | null>(null);
const [cancelling, setCancelling] = useState(false);
// The size of the installation decides whether a target drive has room; measure it once per source.
useEffect(() => {
setSourceSize(null);
if (!sourceUsable(source)) return;
let current = true;
ipcInvoke('install:measureFolder', { path: source.path })
.then((size) => current && setSourceSize(size))
.catch((error: unknown) => current && report(error));
return () => { current = false; };
}, [source, report]);
// The check runs every time the step is entered: the choices before it may have changed.
useEffect(() => {
if (step !== 'check' || !sourceUsable(source)) return;
let current = true;
setCheck(null);
setMissingAccepted(false);
ipcInvoke('install:checkPatches', { gamePath: source.path, dataPath })
.then((result) => current && setCheck(result))
.catch((error: unknown) => {
if (!current) return;
report(error);
setStep('data');
});
return () => { current = false; };
}, [step, source, dataPath, report]);
useEffect(() => ipcOn('event:install-progress', setProgress), []);
const install = (): void => {
if (!sourceUsable(source)) return;
const choices = { dataPath, steamLibraryConfirmed: choice.steamConfirmed, missingFeaturesAccepted: missingAccepted };
const request: InstallRequest = choice.method === 'copy'
? { method: 'copy', sourcePath: source.path, copyPath: choice.target!.path, ...choices }
: { method: 'in-place', gamePath: source.path, ...choices };
clear();
setProgress(null);
setCancelling(false);
setStep('installing');
ipcInvoke('install:start', request)
.then(onInstalled)
.catch((error: unknown) => {
report(error);
setStep('check');
});
};
const cancel = (): void => {
setCancelling(true);
ipcInvoke('install:cancel').catch(report);
};
const canGoOn = (() => {
switch (step) {
case 'source': return sourceUsable(source);
case 'method': return sourceUsable(source) && methodUsable(source, sourceSize, choice);
case 'data': return dataPath.length > 0;
case 'check': return checkUsable(check, missingAccepted);
case 'installing': return false;
}
})();
const index = STEPS.indexOf(step);
const back = (): void => {
clear();
if (index === 0) onClose();
else setStep(STEPS[index - 1]!);
};
const next = (): void => {
clear();
if (step === 'check') install();
else setStep(STEPS[index + 1]!);
};
return (
<div className="wizard">
<ol className="wizard-steps">
{STEPS.map((name, position) => (
<li key={name} className={position === index ? 'current' : position < index ? 'done' : ''}>{t(`wizard.steps.${name}`)}</li>
))}
</ol>
<div className="wizard-body">
{step === 'source' && <SourceStep source={source} onSource={(found) => { setSource(found); setChoice({ method: 'copy', target: null, steamConfirmed: false }); }} onError={report} />}
{step === 'method' && sourceUsable(source) && <MethodStep source={source} sourceSize={sourceSize} choice={choice} onChoice={setChoice} onError={report} />}
{step === 'data' && <DataStep dataPath={dataPath} onDataPath={setDataPath} onError={report} />}
{step === 'check' && <CheckStep check={check} missingAccepted={missingAccepted} onMissingAccepted={setMissingAccepted} />}
{step === 'installing' && <ProgressStep progress={progress} cancelling={cancelling} onCancel={cancel} />}
{message && <p className="error-text">{message}</p>}
</div>
{step !== 'installing' && (
<div className="wizard-actions">
<button type="button" className="button" onClick={back}>{index === 0 ? t('wizard.cancel') : t('wizard.back')}</button>
<button type="button" className="button button-primary" onClick={next} disabled={!canGoOn}>
{step === 'check' ? t('wizard.install') : t('wizard.next')}
</button>
</div>
)}
</div>
);
}
@@ -0,0 +1,107 @@
import { useTranslation } from 'react-i18next';
import type { FolderSize, GameFolderInspection, InstallMethod, TargetFolderInspection } from '@shared/schemas/install.ts';
import { FolderField } from '../../components/FolderField.tsx';
import { Notice } from '../../components/Notice.tsx';
import { formatBytes } from '../../format.ts';
import { ipcInvoke } from '../../ipc.ts';
/** Room the copy needs beyond the game itself; the main process checks the same margin. */
const SPARE_BYTES = 1024 ** 3;
export interface MethodChoice {
readonly method: InstallMethod;
readonly target: TargetFolderInspection | null;
readonly steamConfirmed: boolean;
}
interface MethodStepProps {
readonly source: GameFolderInspection;
/** Size of the installation; null while it is being measured. */
readonly sourceSize: FolderSize | null;
readonly choice: MethodChoice;
readonly onChoice: (choice: MethodChoice) => void;
readonly onError: (error: unknown) => void;
}
/** Step 2: copy the game into a new folder, or install into the chosen folder itself. */
export function MethodStep({ source, sourceSize, choice, onChoice, onError }: MethodStepProps) {
const { t } = useTranslation();
const choose = (method: InstallMethod): void => onChoice({ method, target: choice.target, steamConfirmed: false });
const inspectTarget = (path: string): void => {
onChoice({ ...choice, target: null, steamConfirmed: false });
ipcInvoke('install:inspectTargetFolder', { path, stockPath: source.path })
.then((target) => onChoice({ method: 'copy', target, steamConfirmed: false }))
.catch(onError);
};
return (
<section className="step">
<h2>{t('method.title')}</h2>
<label className="choice">
<input type="radio" name="method" checked={choice.method === 'copy'} onChange={() => choose('copy')} />
<span>
<strong>{t('method.copy')}</strong>
<span className="muted">
{t('method.copyBody', { size: sourceSize ? formatBytes(sourceSize.bytes) : t('method.measuring') })}
</span>
</span>
</label>
{choice.method === 'copy' && (
<div className="choice-detail">
<FolderField path={choice.target?.path ?? null} dialogTitle={t('method.targetTitle')} onChosen={inspectTarget} onError={onError} />
{choice.target && <TargetVerdict target={choice.target} sourceSize={sourceSize} />}
</div>
)}
<label className="choice">
<input type="radio" name="method" checked={choice.method === 'in-place'} onChange={() => choose('in-place')} />
<span>
<strong>{t('method.inPlace')}</strong>
<span className="muted">{t('method.inPlaceBody', { path: source.path })}</span>
</span>
</label>
{steamLibraryInvolved(source, choice) && (
<SteamWarning confirmed={choice.steamConfirmed} onConfirmed={(steamConfirmed) => onChoice({ ...choice, steamConfirmed })} />
)}
</section>
);
}
function TargetVerdict({ target, sourceSize }: { readonly target: TargetFolderInspection; readonly sourceSize: FolderSize | null }) {
const { t } = useTranslation();
if (target.problem) return <Notice tone="error">{t(`method.problem.${target.problem}`)}</Notice>;
if (target.freeBytes !== null && sourceSize && target.freeBytes < sourceSize.bytes + SPARE_BYTES) {
return <Notice tone="error">{t('method.noRoom', { needed: formatBytes(sourceSize.bytes + SPARE_BYTES), free: formatBytes(target.freeBytes) })}</Notice>;
}
return target.freeBytes === null ? null : <Notice tone="info">{t('method.room', { free: formatBytes(target.freeBytes) })}</Notice>;
}
function SteamWarning({ confirmed, onConfirmed }: { readonly confirmed: boolean; readonly onConfirmed: (confirmed: boolean) => void }) {
const { t } = useTranslation();
return (
<Notice tone="warning">
<p>{t('steam.title')}</p>
<ul>
<li>{t('steam.risk1')}</li>
<li>{t('steam.risk2')}</li>
<li>{t('steam.risk3')}</li>
</ul>
<p>{t('steam.advice')}</p>
<label className="check">
<input type="checkbox" checked={confirmed} onChange={(event) => onConfirmed(event.target.checked)} />
{t('steam.confirm')}
</label>
</Notice>
);
}
function steamLibraryInvolved(source: GameFolderInspection, choice: MethodChoice): boolean {
return choice.method === 'in-place' ? source.inSteamLibrary : (choice.target?.inSteamLibrary ?? false);
}
/** Whether the wizard may go past step 2. */
export function methodUsable(source: GameFolderInspection, sourceSize: FolderSize | null, choice: MethodChoice): boolean {
if (steamLibraryInvolved(source, choice) && !choice.steamConfirmed) return false;
if (choice.method === 'in-place') return true;
const target = choice.target;
if (!target || target.problem || !sourceSize) return false;
return target.freeBytes === null || target.freeBytes >= sourceSize.bytes + SPARE_BYTES;
}
@@ -0,0 +1,39 @@
import { useTranslation } from 'react-i18next';
import type { InstallProgress } from '@shared/schemas/install.ts';
import { ProgressBar } from '../../components/ProgressBar.tsx';
import { formatBytes } from '../../format.ts';
interface ProgressStepProps {
readonly progress: InstallProgress | null;
readonly cancelling: boolean;
readonly onCancel: () => void;
}
/** Step 5: the installation running. Only the copy can be stopped; the other phases take seconds. */
export function ProgressStep({ progress, cancelling, onCancel }: ProgressStepProps) {
const { t } = useTranslation();
const phase = progress?.phase ?? 'checking';
const copying = phase === 'copying' && progress !== null;
return (
<section className="step">
<h2>{t('progress.title')}</h2>
<p>{t(`progress.phase.${phase}`)}</p>
<ProgressBar value={copying ? progress.doneBytes : 0} max={copying ? progress.totalBytes : null} />
{copying && (
<p className="muted">
{t('progress.copied', {
done: formatBytes(progress.doneBytes),
total: formatBytes(progress.totalBytes),
doneFiles: progress.doneFiles,
totalFiles: progress.totalFiles,
})}
</p>
)}
{copying && (
<button type="button" className="button" onClick={onCancel} disabled={cancelling}>
{cancelling ? t('progress.cancelling') : t('progress.cancel')}
</button>
)}
</section>
);
}
@@ -0,0 +1,48 @@
import { useTranslation } from 'react-i18next';
import type { GameFolderInspection } from '@shared/schemas/install.ts';
import { FolderField } from '../../components/FolderField.tsx';
import { Notice } from '../../components/Notice.tsx';
import { ipcInvoke } from '../../ipc.ts';
interface SourceStepProps {
readonly source: GameFolderInspection | null;
readonly onSource: (source: GameFolderInspection | null) => void;
readonly onError: (error: unknown) => void;
}
/** Step 1: the player's War Thunder installation. */
export function SourceStep({ source, onSource, onError }: SourceStepProps) {
const { t } = useTranslation();
const inspect = (path: string): void => {
onSource(null);
ipcInvoke('install:inspectGameFolder', { path }).then(onSource).catch(onError);
};
return (
<section className="step">
<h2>{t('source.title')}</h2>
<p className="muted">{t('source.body')}</p>
<FolderField path={source?.path ?? null} dialogTitle={t('source.title')} onChosen={inspect} onError={onError} />
{source && <SourceVerdict source={source} />}
</section>
);
}
function SourceVerdict({ source }: { readonly source: GameFolderInspection }) {
const { t } = useTranslation();
if (source.missingFiles.length) {
return <Notice tone="error">{t('source.notAGame', { files: source.missingFiles.join(', ') })}</Notice>;
}
const verified = source.version !== null && source.verifiedVersions.includes(source.version);
return verified ? (
<Notice tone="info">{t('source.versionVerified', { version: source.version })}</Notice>
) : (
<Notice tone="warning">
{t('source.versionUnverified', { version: source.version ?? t('source.versionUnknown'), verified: source.verifiedVersions.join(', ') })}
</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;
}
+216 -5
View File
@@ -77,20 +77,231 @@ body {
}
.welcome {
max-width: 560px;
max-width: 640px;
display: flex;
flex-direction: column;
align-items: flex-start;
gap: 12px;
}
.welcome h2 {
margin: 0 0 8px;
.welcome h2,
.step h2 {
margin: 0;
font-size: 20px;
}
.welcome p {
.welcome p,
.step p {
margin: 0;
color: var(--text-muted);
line-height: 1.6;
}
.muted {
color: var(--text-muted);
}
.error-text {
color: var(--danger);
margin: 0;
}
/* Buttons */
.button {
font: inherit;
color: var(--text);
background: var(--surface);
border: 1px solid var(--border);
border-radius: var(--radius);
padding: 6px 16px;
cursor: pointer;
}
.button:hover:not(:disabled) {
border-color: var(--accent);
}
.button:disabled {
opacity: 0.5;
cursor: default;
}
.button-primary {
background: var(--accent);
border-color: var(--accent);
color: #ffffff;
}
/* Install wizard */
.wizard {
display: flex;
flex-direction: column;
gap: 20px;
max-width: 720px;
}
.wizard-steps {
display: flex;
gap: 8px;
margin: 0;
padding: 0;
list-style: none;
counter-reset: step;
}
.wizard-steps li {
counter-increment: step;
color: var(--text-muted);
padding: 4px 10px;
border-radius: var(--radius);
}
.wizard-steps li::before {
content: counter(step) '. ';
}
.wizard-steps li.current {
color: var(--text);
background: var(--surface);
border: 1px solid var(--border);
font-weight: 600;
}
.wizard-steps li.done {
color: var(--text);
}
.wizard-body,
.step {
display: flex;
flex-direction: column;
gap: 12px;
}
.wizard-actions {
display: flex;
justify-content: space-between;
}
.folder-field {
display: flex;
align-items: center;
gap: 12px;
padding: 8px 12px;
background: var(--surface);
border: 1px solid var(--border);
border-radius: var(--radius);
}
.folder-path {
flex: 1;
overflow-wrap: anywhere;
}
.folder-path-empty {
color: var(--text-muted);
}
.choice {
display: flex;
align-items: flex-start;
gap: 10px;
cursor: pointer;
}
.choice > span {
display: flex;
flex-direction: column;
gap: 2px;
line-height: 1.5;
}
.choice-detail {
display: flex;
flex-direction: column;
gap: 8px;
margin-left: 26px;
}
.check {
display: flex;
align-items: center;
gap: 8px;
cursor: pointer;
}
.notice {
display: flex;
flex-direction: column;
gap: 6px;
padding: 10px 14px;
border-radius: var(--radius);
border: 1px solid var(--border);
line-height: 1.5;
}
.notice ul {
margin: 0;
padding-left: 20px;
}
.notice-info {
background: var(--surface);
}
.notice-warning {
border-color: var(--accent);
}
.notice-error {
border-color: var(--danger);
color: var(--danger);
}
.patch-details {
font-size: 12px;
color: var(--text-muted);
overflow-wrap: anywhere;
}
.progress {
height: 8px;
border-radius: 4px;
background: var(--border);
overflow: hidden;
}
.progress-fill {
height: 100%;
background: var(--accent);
transition: width 0.2s;
}
.progress-busy {
width: 30%;
animation: progress-busy 1.2s ease-in-out infinite;
}
@keyframes progress-busy {
from {
transform: translateX(-100%);
}
to {
transform: translateX(340%);
}
}
.summary {
display: grid;
grid-template-columns: max-content 1fr;
gap: 6px 16px;
margin: 0;
}
.summary dt {
color: var(--text-muted);
}
.summary dd {
margin: 0;
overflow-wrap: anywhere;
}