From 303dbf24e6408aea7b2670bbefc2d0533cc13d6c Mon Sep 17 00:00:00 2001 From: N0VAN0M4LY <224130499+N0VAN0M4LY@users.noreply.github.com> Date: Sun, 29 Nov 2026 06:29:53 +0800 Subject: [PATCH] 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. --- apps/launcher/package.json | 1 + apps/launcher/src/renderer/src/App.tsx | 18 +- .../renderer/src/components/FolderField.tsx | 31 +++ .../src/renderer/src/components/Notice.tsx | 6 + .../renderer/src/components/ProgressBar.tsx | 9 + apps/launcher/src/renderer/src/features.ts | 10 + apps/launcher/src/renderer/src/format.ts | 6 + .../src/renderer/src/i18n/locales/en.json | 129 +++++++++- .../src/renderer/src/i18n/locales/zh-CN.json | 129 +++++++++- apps/launcher/src/renderer/src/main.tsx | 4 +- .../src/renderer/src/pages/InstallSummary.tsx | 31 +++ .../src/renderer/src/pages/WelcomePage.tsx | 27 ++- .../renderer/src/pages/install/CheckStep.tsx | 74 ++++++ .../renderer/src/pages/install/DataStep.tsx | 20 ++ .../src/pages/install/InstallWizard.tsx | 133 +++++++++++ .../renderer/src/pages/install/MethodStep.tsx | 107 +++++++++ .../src/pages/install/ProgressStep.tsx | 39 ++++ .../renderer/src/pages/install/SourceStep.tsx | 48 ++++ apps/launcher/src/renderer/src/styles/app.css | 221 +++++++++++++++++- 19 files changed, 1028 insertions(+), 15 deletions(-) create mode 100644 apps/launcher/src/renderer/src/components/FolderField.tsx create mode 100644 apps/launcher/src/renderer/src/components/Notice.tsx create mode 100644 apps/launcher/src/renderer/src/components/ProgressBar.tsx create mode 100644 apps/launcher/src/renderer/src/features.ts create mode 100644 apps/launcher/src/renderer/src/format.ts create mode 100644 apps/launcher/src/renderer/src/pages/InstallSummary.tsx create mode 100644 apps/launcher/src/renderer/src/pages/install/CheckStep.tsx create mode 100644 apps/launcher/src/renderer/src/pages/install/DataStep.tsx create mode 100644 apps/launcher/src/renderer/src/pages/install/InstallWizard.tsx create mode 100644 apps/launcher/src/renderer/src/pages/install/MethodStep.tsx create mode 100644 apps/launcher/src/renderer/src/pages/install/ProgressStep.tsx create mode 100644 apps/launcher/src/renderer/src/pages/install/SourceStep.tsx diff --git a/apps/launcher/package.json b/apps/launcher/package.json index 0e9a8dc..6c72090 100644 --- a/apps/launcher/package.json +++ b/apps/launcher/package.json @@ -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.", diff --git a/apps/launcher/src/renderer/src/App.tsx b/apps/launcher/src/renderer/src/App.tsx index 492524f..3cec809 100644 --- a/apps/launcher/src/renderer/src/App.tsx +++ b/apps/launcher/src/renderer/src/App.tsx @@ -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) {
- + {installing ? ( + { setRecord(installed); setInstalling(false); }} + onClose={() => setInstalling(false)} + /> + ) : ( + setInstalling(true)} /> + )}
); diff --git a/apps/launcher/src/renderer/src/components/FolderField.tsx b/apps/launcher/src/renderer/src/components/FolderField.tsx new file mode 100644 index 0000000..fa85583 --- /dev/null +++ b/apps/launcher/src/renderer/src/components/FolderField.tsx @@ -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 ( +
+ {path ?? t('folder.none')} + +
+ ); +} diff --git a/apps/launcher/src/renderer/src/components/Notice.tsx b/apps/launcher/src/renderer/src/components/Notice.tsx new file mode 100644 index 0000000..f2049e2 --- /dev/null +++ b/apps/launcher/src/renderer/src/components/Notice.tsx @@ -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
{children}
; +} diff --git a/apps/launcher/src/renderer/src/components/ProgressBar.tsx b/apps/launcher/src/renderer/src/components/ProgressBar.tsx new file mode 100644 index 0000000..43a5bda --- /dev/null +++ b/apps/launcher/src/renderer/src/components/ProgressBar.tsx @@ -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 ( +
+
+
+ ); +} diff --git a/apps/launcher/src/renderer/src/features.ts b/apps/launcher/src/renderer/src/features.ts new file mode 100644 index 0000000..bb41523 --- /dev/null +++ b/apps/launcher/src/renderer/src/features.ts @@ -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 }); +} diff --git a/apps/launcher/src/renderer/src/format.ts b/apps/launcher/src/renderer/src/format.ts new file mode 100644 index 0000000..32e1c4f --- /dev/null +++ b/apps/launcher/src/renderer/src/format.ts @@ -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`; +} diff --git a/apps/launcher/src/renderer/src/i18n/locales/en.json b/apps/launcher/src/renderer/src/i18n/locales/en.json index ab7d35b..f93893f 100644 --- a/apps/launcher/src/renderer/src/i18n/locales/en.json +++ b/apps/launcher/src/renderer/src/i18n/locales/en.json @@ -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.", 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 4f72f53..1377293 100644 --- a/apps/launcher/src/renderer/src/i18n/locales/zh-CN.json +++ b/apps/launcher/src/renderer/src/i18n/locales/zh-CN.json @@ -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": "启动器内部出错了。", diff --git a/apps/launcher/src/renderer/src/main.tsx b/apps/launcher/src/renderer/src/main.tsx index 2455386..a118ca4 100644 --- a/apps/launcher/src/renderer/src/main.tsx +++ b/apps/launcher/src/renderer/src/main.tsx @@ -6,7 +6,7 @@ import { ipcInvoke } from './ipc.ts'; import './styles/app.css'; async function start(): Promise { - 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 { if (!root) throw new Error('#root is missing from index.html'); createRoot(root).render( - + , ); } diff --git a/apps/launcher/src/renderer/src/pages/InstallSummary.tsx b/apps/launcher/src/renderer/src/pages/InstallSummary.tsx new file mode 100644 index 0000000..260eed8 --- /dev/null +++ b/apps/launcher/src/renderer/src/pages/InstallSummary.tsx @@ -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 ( + <> +
+
{t('summary.copy')}
+
{record.copyPath}
+
{t('summary.data')}
+
{record.dataPath}
+
{t('summary.version')}
+
{record.gameVersion ?? t('source.versionUnknown')}
+
{t('summary.method')}
+
{t(`summary.methods.${record.method}`)}
+
+ {missing.length > 0 && ( +
+

{t('summary.missing')}

+
    + {missing.map((feature) =>
  • {featureName(t, feature)}
  • )} +
+
+ )} + + ); +} diff --git a/apps/launcher/src/renderer/src/pages/WelcomePage.tsx b/apps/launcher/src/renderer/src/pages/WelcomePage.tsx index 2ccb508..14e9855 100644 --- a/apps/launcher/src/renderer/src/pages/WelcomePage.tsx +++ b/apps/launcher/src/renderer/src/pages/WelcomePage.tsx @@ -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 ( +
+

{t('welcome.title')}

+

{t('welcome.body')}

+ +
+ ); + } return (
-

{t('welcome.title')}

-

{t('welcome.body')}

+

{t('installed.title')}

+ +

{t('installed.launchLater')}

+
); } diff --git a/apps/launcher/src/renderer/src/pages/install/CheckStep.tsx b/apps/launcher/src/renderer/src/pages/install/CheckStep.tsx new file mode 100644 index 0000000..a18f529 --- /dev/null +++ b/apps/launcher/src/renderer/src/pages/install/CheckStep.tsx @@ -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 ( +
+

{t('check.title')}

+

{t('check.running')}

+ +
+ ); + } + const essential = check.unavailable.filter((patch) => patch.essential); + return ( +
+

{t('check.title')}

+ {check.unavailable.length === 0 && {t('check.allFit', { count: check.exePatchesReady + check.guiPatchesReady })}} + {essential.length > 0 && ( + +

{t('check.essentialMissing')}

+ +
+ )} + {essential.length === 0 && check.unavailable.length > 0 && ( + +

{t('check.someMissing')}

+ + +
+ )} +
+ ); +} + +/** 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 ( + <> +
    + {features.map((feature) =>
  • {featureName(t, feature)}
  • )} +
+
+ {t('check.details')} +
    + {patches.map((patch) =>
  • {patch.patchId}: {patch.reason}
  • )} +
+
+ + ); +} + +/** 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; +} diff --git a/apps/launcher/src/renderer/src/pages/install/DataStep.tsx b/apps/launcher/src/renderer/src/pages/install/DataStep.tsx new file mode 100644 index 0000000..4f26a05 --- /dev/null +++ b/apps/launcher/src/renderer/src/pages/install/DataStep.tsx @@ -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 ( +
+

{t('data.title')}

+

{t('data.body')}

+ +
+ ); +} diff --git a/apps/launcher/src/renderer/src/pages/install/InstallWizard.tsx b/apps/launcher/src/renderer/src/pages/install/InstallWizard.tsx new file mode 100644 index 0000000..5040a5c --- /dev/null +++ b/apps/launcher/src/renderer/src/pages/install/InstallWizard.tsx @@ -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('source'); + const [source, setSource] = useState(null); + const [sourceSize, setSourceSize] = useState(null); + const [choice, setChoice] = useState({ method: 'copy', target: null, steamConfirmed: false }); + const [dataPath, setDataPath] = useState(defaultDataPath); + const [check, setCheck] = useState(null); + const [missingAccepted, setMissingAccepted] = useState(false); + const [progress, setProgress] = useState(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 ( +
+
    + {STEPS.map((name, position) => ( +
  1. {t(`wizard.steps.${name}`)}
  2. + ))} +
+
+ {step === 'source' && { setSource(found); setChoice({ method: 'copy', target: null, steamConfirmed: false }); }} onError={report} />} + {step === 'method' && sourceUsable(source) && } + {step === 'data' && } + {step === 'check' && } + {step === 'installing' && } + {message &&

{message}

} +
+ {step !== 'installing' && ( +
+ + +
+ )} +
+ ); +} diff --git a/apps/launcher/src/renderer/src/pages/install/MethodStep.tsx b/apps/launcher/src/renderer/src/pages/install/MethodStep.tsx new file mode 100644 index 0000000..c20dce5 --- /dev/null +++ b/apps/launcher/src/renderer/src/pages/install/MethodStep.tsx @@ -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 ( +
+

{t('method.title')}

+ + {choice.method === 'copy' && ( +
+ + {choice.target && } +
+ )} + + {steamLibraryInvolved(source, choice) && ( + onChoice({ ...choice, steamConfirmed })} /> + )} +
+ ); +} + +function TargetVerdict({ target, sourceSize }: { readonly target: TargetFolderInspection; readonly sourceSize: FolderSize | null }) { + const { t } = useTranslation(); + if (target.problem) return {t(`method.problem.${target.problem}`)}; + if (target.freeBytes !== null && sourceSize && target.freeBytes < sourceSize.bytes + SPARE_BYTES) { + return {t('method.noRoom', { needed: formatBytes(sourceSize.bytes + SPARE_BYTES), free: formatBytes(target.freeBytes) })}; + } + return target.freeBytes === null ? null : {t('method.room', { free: formatBytes(target.freeBytes) })}; +} + +function SteamWarning({ confirmed, onConfirmed }: { readonly confirmed: boolean; readonly onConfirmed: (confirmed: boolean) => void }) { + const { t } = useTranslation(); + return ( + +

{t('steam.title')}

+
    +
  • {t('steam.risk1')}
  • +
  • {t('steam.risk2')}
  • +
  • {t('steam.risk3')}
  • +
+

{t('steam.advice')}

+ +
+ ); +} + +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; +} diff --git a/apps/launcher/src/renderer/src/pages/install/ProgressStep.tsx b/apps/launcher/src/renderer/src/pages/install/ProgressStep.tsx new file mode 100644 index 0000000..e0976ff --- /dev/null +++ b/apps/launcher/src/renderer/src/pages/install/ProgressStep.tsx @@ -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 ( +
+

{t('progress.title')}

+

{t(`progress.phase.${phase}`)}

+ + {copying && ( +

+ {t('progress.copied', { + done: formatBytes(progress.doneBytes), + total: formatBytes(progress.totalBytes), + doneFiles: progress.doneFiles, + totalFiles: progress.totalFiles, + })} +

+ )} + {copying && ( + + )} +
+ ); +} diff --git a/apps/launcher/src/renderer/src/pages/install/SourceStep.tsx b/apps/launcher/src/renderer/src/pages/install/SourceStep.tsx new file mode 100644 index 0000000..9a341f3 --- /dev/null +++ b/apps/launcher/src/renderer/src/pages/install/SourceStep.tsx @@ -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 ( +
+

{t('source.title')}

+

{t('source.body')}

+ + {source && } +
+ ); +} + +function SourceVerdict({ source }: { readonly source: GameFolderInspection }) { + const { t } = useTranslation(); + if (source.missingFiles.length) { + return {t('source.notAGame', { files: source.missingFiles.join(', ') })}; + } + const verified = source.version !== null && source.verifiedVersions.includes(source.version); + return verified ? ( + {t('source.versionVerified', { version: source.version })} + ) : ( + + {t('source.versionUnverified', { version: source.version ?? t('source.versionUnknown'), verified: source.verifiedVersions.join(', ') })} + + ); +} + +/** Whether the wizard may go past step 1. */ +export function sourceUsable(source: GameFolderInspection | null): source is GameFolderInspection { + return source !== null && source.missingFiles.length === 0; +} diff --git a/apps/launcher/src/renderer/src/styles/app.css b/apps/launcher/src/renderer/src/styles/app.css index 9b6c1ee..dd80245 100644 --- a/apps/launcher/src/renderer/src/styles/app.css +++ b/apps/launcher/src/renderer/src/styles/app.css @@ -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; }