feat(saves): import official game backups

This commit is contained in:
N0VAN0M4LY committed 2026-11-29 16:03:31 +08:00
1 parent 2e3cc0aaec
commit 597df6b4f5
15 files changed
+661 -16

No files matched your search

@@ -258,8 +258,27 @@
"overview": "Overview",
"battles": "Battle history",
"vehicles": "Vehicles and research",
"official": "Import official backup",
"backup": "Backup and restore"
},
"official": {
"files": "Backup files",
"fileHint": "Select copies of global.blk, machine.blk or storage.blk.",
"choose": "Choose files…",
"content": "Import contents",
"settings": "Game settings",
"unlock": "Unlock vehicles from presets",
"equipment": "Modifications",
"full": "All equipment",
"basic": "Essential equipment",
"stock": "Stock configuration",
"includeUsed": "Include other vehicles found in the backup",
"preview": "Preview",
"import": "Import",
"summary": "{{files}} file(s) · {{presets}} preset(s) · {{vehicles}} available vehicle(s)",
"omitted": "Unavailable vehicles to skip · {{names}}",
"done": "Backup imported. The previous save is available in Backup and restore."
},
"archive": {
"fromCopy": "Copy from another copy",
"import": "Import save file…",
@@ -278,7 +297,8 @@
"type": {
"manual": "Manual backup",
"launch": "Before launch",
"restore": "Before restore"
"restore": "Before restore",
"import": "Before import"
}
},
"create": "Create save",
@@ -420,6 +440,8 @@
"internal_error": "An internal launcher error occurred.",
"logs_folder_open_failed": "The launcher log folder could not be opened.",
"diagnostics_export_failed": "The diagnostics archive could not be saved.",
"save_official_invalid": "The selected files are not supported official backup files.",
"save_official_location": "Choose backup files copied outside the official game's folders.",
"save_archive_invalid": "The selected file is not a supported WTOffline save archive.",
"save_not_found": "The selected save could not be found.",
"save_read_only": "Saves are read-only while the game or local server is running.",
@@ -258,8 +258,27 @@
"overview": "概览",
"battles": "战绩",
"vehicles": "载具与研发",
"official": "导入正版备份",
"backup": "备份与还原"
},
"official": {
"files": "备份文件",
"fileHint": "请选择复制备份的 global.blk、machine.blk 或 storage.blk。",
"choose": "选择文件…",
"content": "导入内容",
"settings": "游戏设置",
"unlock": "解锁预设中的载具",
"equipment": "改装件",
"full": "完全体",
"basic": "基础生存配件",
"stock": "白板状态",
"includeUsed": "包含备份中的其他已用载具",
"preview": "预览",
"import": "导入",
"summary": "{{files}} 个文件 · {{presets}} 套预设 · {{vehicles}} 辆可用载具",
"omitted": "将跳过的不可用载具 · {{names}}",
"done": "备份已导入。原存档可在「备份与还原」中恢复。"
},
"archive": {
"fromCopy": "从其他副本复制",
"import": "导入存档文件…",
@@ -278,7 +297,8 @@
"type": {
"manual": "手动备份",
"launch": "启动前自动备份",
"restore": "还原前自动备份"
"restore": "还原前自动备份",
"import": "导入前自动备份"
}
},
"create": "新建存档",
@@ -420,6 +440,8 @@
"internal_error": "启动器内部错误。",
"logs_folder_open_failed": "无法打开启动器日志文件夹。",
"diagnostics_export_failed": "无法保存诊断信息。",
"save_official_invalid": "所选文件不是受支持的正版备份。",
"save_official_location": "请选择复制到正版目录以外的备份文件。",
"save_archive_invalid": "所选文件不是受支持的 WTOffline 存档归档。",
"save_not_found": "找不到所选存档。",
"save_read_only": "游戏或本地服务器运行期间存档为只读。",
@@ -0,0 +1,105 @@
import { useState } from 'react';
import { useTranslation } from 'react-i18next';
import type { OfficialImportOptions, OfficialPreview } from '@shared/schemas/saves.ts';
import { Row } from '../../components/Row.tsx';
import { ipcInvoke } from '../../ipc.ts';
const DEFAULTS: OfficialImportOptions = {
importSettings: true, unlockVehicles: true, includeUsedVehicles: false, equipment: 'full',
};
interface Props {
readonly copyId: string;
readonly userId: string;
readonly readOnly: boolean;
readonly onError: (error: unknown) => void;
}
export function OfficialSaveImport({ copyId, userId, readOnly, onError }: Props) {
const { t } = useTranslation();
const [paths, setPaths] = useState<string[]>([]);
const [options, setOptions] = useState(DEFAULTS);
const [preview, setPreview] = useState<OfficialPreview | null>(null);
const [busy, setBusy] = useState(false);
const [imported, setImported] = useState(false);
const request = { copyId, userId, paths };
const choose = (): void => {
ipcInvoke('saves:pickOfficialBackups').then((selection) => {
if (selection.length === 0) return;
setPaths(selection);
setPreview(null);
setImported(false);
}).catch(onError);
};
const load = (): void => {
setBusy(true);
setImported(false);
ipcInvoke('saves:previewOfficial', { ...request, includeUsedVehicles: options.includeUsedVehicles })
.then(setPreview).catch(onError).finally(() => setBusy(false));
};
const apply = (): void => {
setBusy(true);
ipcInvoke('saves:importOfficial', { ...request, options }).then((value) => {
setPreview(value);
setImported(true);
}).catch(onError).finally(() => setBusy(false));
};
return (
<>
<Row label={t('saves.official.files')} hint={t('saves.official.fileHint')}>
<button type="button" className="button" onClick={choose} disabled={busy}>{t('saves.official.choose')}</button>
{paths.length > 0 && <span className="folder-path" title={paths.join('\n')}>{paths.map((path) => path.split(/[\\/]/).at(-1)).join(', ')}</span>}
</Row>
<Row label={t('saves.official.content')}>
<label className="check check-inline">
<input type="checkbox" checked={options.importSettings} disabled={busy} onChange={(event) => {
setOptions({ ...options, importSettings: event.target.checked });
}} />
{t('saves.official.settings')}
</label>
<label className="check check-inline">
<input type="checkbox" checked={options.unlockVehicles} disabled={busy} onChange={(event) => {
setOptions({ ...options, unlockVehicles: event.target.checked });
}} />
{t('saves.official.unlock')}
</label>
</Row>
<Row label={t('saves.official.equipment')}>
<select className="select" aria-label={t('saves.official.equipment')} value={options.equipment} disabled={busy || !options.unlockVehicles}
onChange={(event) => setOptions({ ...options, equipment: event.target.value as OfficialImportOptions['equipment'] })}>
<option value="full">{t('saves.official.full')}</option>
<option value="basic">{t('saves.official.basic')}</option>
<option value="stock">{t('saves.official.stock')}</option>
</select>
<label className="check check-inline">
<input type="checkbox" checked={options.includeUsedVehicles} disabled={busy || !options.unlockVehicles} onChange={(event) => {
setOptions({ ...options, includeUsedVehicles: event.target.checked });
setPreview(null);
setImported(false);
}} />
{t('saves.official.includeUsed')}
</label>
</Row>
<div className="copy-list-actions">
<button type="button" className="button" disabled={busy || paths.length === 0} onClick={load}>{t('saves.official.preview')}</button>
<button type="button" className="button button-primary"
disabled={busy || readOnly || !preview || imported || (!options.importSettings && !options.unlockVehicles)} onClick={apply}>
{t('saves.official.import')}
</button>
</div>
{readOnly && <p className="small">{t('saves.readOnly')}</p>}
{preview && (
<div className="maintenance-confirm">
<p>{t('saves.official.summary', { files: preview.files.length, presets: preview.presets.length, vehicles: preview.vehicles.length })}</p>
{preview.presets.map((preset, index) => <p key={index}>{preset.title} · {preset.vehicles.join(', ')}</p>)}
{preview.omitted.length > 0 && <p>{t('saves.official.omitted', { names: preview.omitted.join(', ') })}</p>}
</div>
)}
{imported && <p className="small" role="status">{t('saves.official.done')}</p>}
</>
);
}
@@ -6,6 +6,7 @@ import { Row } from '../../components/Row.tsx';
import { Sheet } from '../../components/Sheet.tsx';
import { ipcInvoke } from '../../ipc.ts';
import type { SaveSection } from '../../shell/navigation.ts';
import { OfficialSaveImport } from './OfficialSaveImport.tsx';
import { SaveBackups } from './SaveBackups.tsx';
interface SavesPageProps {
@@ -236,6 +237,7 @@ export function SavesPage({ copy, copies, section, readOnly, onError }: SavesPag
</Row>
))
)}
{section === 'official' && <OfficialSaveImport key={save.userId} copyId={copy.id} userId={save.userId} readOnly={readOnly} onError={onError} />}
{section === 'backup' && <SaveBackups key={save.userId} copyId={copy.id} userId={save.userId} readOnly={readOnly} onError={onError} onRestored={updateDetails} />}
{section === 'vehicles' && (
<>
@@ -6,7 +6,7 @@
export const PAGES = ['home', 'saves', 'copies', 'settings', 'about'] as const;
export type PageId = (typeof PAGES)[number];
export const SAVE_SECTIONS = ['list', 'overview', 'battles', 'vehicles', 'backup'] as const;
export const SAVE_SECTIONS = ['list', 'overview', 'battles', 'vehicles', 'official', 'backup'] as const;
export type SaveSection = (typeof SAVE_SECTIONS)[number];
export const COPY_SECTIONS = ['list', 'summary', 'features', 'maintain'] as const;