fix(saves): keep imported presets intact, cap crews to preset units and drop used-unit scan
This commit is contained in:
1 parent
388dc9d9d7
commit
e6e75d92c6
10 files changed
+109
-114
No files matched your search
@@ -139,8 +139,8 @@ export function registerIpcHandlers(): void {
|
||||
handle('saves:discoverOnlineData', () => discoverOnlineData());
|
||||
handle('saves:copyOnlineData', ({ copyId, userId, accountId }) => copyOnlineData(copyId, userId, accountId));
|
||||
handle('saves:pickOfficialBackups', (_input, sender) => pickOfficialBackups(BrowserWindow.fromWebContents(sender)));
|
||||
handle('saves:previewOfficial', ({ copyId, userId, paths, includeUsedVehicles }) =>
|
||||
previewSelectedBackups(copyId, userId, paths, includeUsedVehicles));
|
||||
handle('saves:previewOfficial', ({ copyId, userId, paths }) =>
|
||||
previewSelectedBackups(copyId, userId, paths));
|
||||
handle('saves:importOfficial', ({ copyId, userId, paths, options }) =>
|
||||
importSelectedBackups(copyId, userId, paths, options));
|
||||
|
||||
|
||||
@@ -190,11 +190,16 @@ function onlineSavesRoot(): string {
|
||||
return join(app.getPath('documents'), 'My Games', 'WarThunder', 'Saves');
|
||||
}
|
||||
|
||||
async function offlineClientCacheFolder(userId: string): Promise<string | undefined> {
|
||||
if (!/^\d+$/.test(userId)) return undefined;
|
||||
async function offlineClientCacheFolders(userId: string): Promise<string[]> {
|
||||
if (!/^\d+$/.test(userId)) return [];
|
||||
const root = await canonicalCopyPath(join(app.getPath('documents'), 'My Games', 'WTOffline', 'Saves'));
|
||||
const target = await canonicalCopyPath(join(root, userId, 'production'));
|
||||
return copyPathContains(root, target) ? target : undefined;
|
||||
const candidates = [join(root, userId, 'production'), join(root, 'last', 'production')];
|
||||
const folders: string[] = [];
|
||||
for (const candidate of candidates) {
|
||||
const resolved = await canonicalCopyPath(candidate);
|
||||
if (copyPathContains(root, resolved)) folders.push(resolved);
|
||||
}
|
||||
return folders;
|
||||
}
|
||||
|
||||
/** Read-only discovery of local online client settings under Documents/My Games/WarThunder/Saves. */
|
||||
@@ -276,12 +281,12 @@ export async function pickOfficialBackups(window: BrowserWindow | null): Promise
|
||||
}
|
||||
|
||||
export async function previewSelectedBackups(
|
||||
copyId: string, userId: string, paths: readonly string[], includeUsedVehicles: boolean,
|
||||
copyId: string, userId: string, paths: readonly string[],
|
||||
): Promise<OfficialPreview> {
|
||||
const copy = await requireCopy(copyId);
|
||||
await getSaveDetails(copyId, userId);
|
||||
const selected = await verifyBackupLocations(copy, paths);
|
||||
return await run({ operation: 'previewOfficial', ...location(copy), paths: selected, includeUsedVehicles }) as OfficialPreview;
|
||||
return await run({ operation: 'previewOfficial', ...location(copy), paths: selected }) as OfficialPreview;
|
||||
}
|
||||
|
||||
export async function importSelectedBackups(
|
||||
@@ -291,7 +296,7 @@ export async function importSelectedBackups(
|
||||
const copy = await requireCopy(copyId);
|
||||
await getSaveDetails(copyId, userId);
|
||||
const selected = await verifyBackupLocations(copy, paths);
|
||||
const cacheFolder = await offlineClientCacheFolder(userId);
|
||||
const cacheFolders = await offlineClientCacheFolders(userId);
|
||||
const before = await captureSave(copy, userId);
|
||||
await saveBackup(copy, userId, 'import');
|
||||
try {
|
||||
@@ -301,7 +306,7 @@ export async function importSelectedBackups(
|
||||
userId,
|
||||
paths: selected,
|
||||
options,
|
||||
...(cacheFolder ? { offlineClientCacheFolder: cacheFolder } : {}),
|
||||
...(cacheFolders.length > 0 ? { offlineClientCacheFolders: cacheFolders } : {}),
|
||||
}) as OfficialPreview;
|
||||
} catch (error) {
|
||||
await restoreDirectory(copy, userId, before);
|
||||
|
||||
@@ -13,13 +13,13 @@ export type SaveTask = Location & (
|
||||
| { readonly operation: 'avatarPreview'; readonly avatar: string }
|
||||
| { readonly operation: 'editAccount'; readonly userId: string; readonly edits: AccountEdits }
|
||||
| { readonly operation: 'edit'; readonly userId: string; readonly values: CurrencyEdits }
|
||||
| { readonly operation: 'previewOfficial'; readonly paths: readonly string[]; readonly includeUsedVehicles: boolean }
|
||||
| { readonly operation: 'previewOfficial'; readonly paths: readonly string[] }
|
||||
| {
|
||||
readonly operation: 'importOfficial';
|
||||
readonly paths: readonly string[];
|
||||
readonly userId: string;
|
||||
readonly options: OfficialImportOptions;
|
||||
readonly offlineClientCacheFolder?: string;
|
||||
readonly offlineClientCacheFolders?: readonly string[];
|
||||
}
|
||||
| { readonly operation: 'readResearch'; readonly userId: string; readonly branch?: ResearchBranch }
|
||||
| { readonly operation: 'editResearch'; readonly userId: string; readonly branch: ResearchBranch; readonly action: ResearchOperation }
|
||||
|
||||
@@ -26,9 +26,9 @@ function execute(task: SaveTask): SaveReply {
|
||||
return editSaveCurrencies(task, task.userId, task.values)
|
||||
? { ok: true, result: null } : { ok: false, error: 'save_not_found' };
|
||||
case 'previewOfficial':
|
||||
return { ok: true, result: previewOfficialBackup(task, task.paths, task.includeUsedVehicles) };
|
||||
return { ok: true, result: previewOfficialBackup(task, task.paths) };
|
||||
case 'importOfficial':
|
||||
return { ok: true, result: importOfficialBackup(task, task.userId, task.paths, task.options, task.offlineClientCacheFolder) };
|
||||
return { ok: true, result: importOfficialBackup(task, task.userId, task.paths, task.options, task.offlineClientCacheFolders) };
|
||||
case 'readResearch': {
|
||||
const result = readSaveResearch(task, task.userId, task.branch);
|
||||
return result ? { ok: true, result } : { ok: false, error: 'save_not_found' };
|
||||
|
||||
@@ -356,7 +356,6 @@
|
||||
"full": "All equipment",
|
||||
"basic": "Essential equipment",
|
||||
"stock": "Stock configuration",
|
||||
"includeUsed": "Include additional vehicles from per-unit settings (without prerequisite lines)",
|
||||
"preview": "Preview",
|
||||
"import": "Import",
|
||||
"summary": "{{files}} file(s) · {{presets}} preset(s) · {{vehicles}} available vehicle(s)",
|
||||
|
||||
@@ -356,7 +356,6 @@
|
||||
"full": "完全体",
|
||||
"basic": "基础生存配件",
|
||||
"stock": "白板状态",
|
||||
"includeUsed": "额外包含其他单车配置中的载具(不连带解锁前置科技树)",
|
||||
"preview": "预览",
|
||||
"import": "导入",
|
||||
"summary": "{{files}} 个文件 · {{presets}} 套预设 · {{vehicles}} 辆可用载具",
|
||||
|
||||
@@ -5,7 +5,7 @@ import { Row } from '../../components/Row.tsx';
|
||||
import { ipcInvoke } from '../../ipc.ts';
|
||||
|
||||
const DEFAULTS: OfficialImportOptions = {
|
||||
importSettings: true, unlockVehicles: true, includeUsedVehicles: false, equipment: 'full',
|
||||
importSettings: true, unlockVehicles: true, equipment: 'full',
|
||||
};
|
||||
|
||||
interface Props {
|
||||
@@ -26,12 +26,12 @@ export function OfficialSaveImport({ copyId, userId, readOnly, onError, onImport
|
||||
const [busy, setBusy] = useState(false);
|
||||
const [imported, setImported] = useState(false);
|
||||
|
||||
const stageAndPreview = async (accountId: string, includeUsed: boolean): Promise<string[]> => {
|
||||
const stageAndPreview = async (accountId: string): Promise<string[]> => {
|
||||
const copied = await ipcInvoke('saves:copyOnlineData', { copyId, userId, accountId });
|
||||
setSelectedAccount(accountId);
|
||||
setPaths(copied);
|
||||
setImported(false);
|
||||
const nextPreview = await ipcInvoke('saves:previewOfficial', { copyId, userId, paths: copied, includeUsedVehicles: includeUsed });
|
||||
const nextPreview = await ipcInvoke('saves:previewOfficial', { copyId, userId, paths: copied });
|
||||
setPreview(nextPreview);
|
||||
return copied;
|
||||
};
|
||||
@@ -49,7 +49,7 @@ export function OfficialSaveImport({ copyId, userId, readOnly, onError, onImport
|
||||
return;
|
||||
}
|
||||
const first = found[0]!;
|
||||
const copied = await stageAndPreview(first.accountId, options.includeUsedVehicles);
|
||||
const copied = await stageAndPreview(first.accountId);
|
||||
if (importImmediately && found.length === 1 && !readOnly && (options.importSettings || options.unlockVehicles)) {
|
||||
const result = await ipcInvoke('saves:importOfficial', { copyId, userId, paths: copied, options });
|
||||
setPreview(result);
|
||||
@@ -65,7 +65,7 @@ export function OfficialSaveImport({ copyId, userId, readOnly, onError, onImport
|
||||
if (!accountId) return;
|
||||
setBusy(true);
|
||||
setImported(false);
|
||||
stageAndPreview(accountId, options.includeUsedVehicles)
|
||||
stageAndPreview(accountId)
|
||||
.catch(onError)
|
||||
.finally(() => setBusy(false));
|
||||
};
|
||||
@@ -80,11 +80,11 @@ export function OfficialSaveImport({ copyId, userId, readOnly, onError, onImport
|
||||
}).catch(onError);
|
||||
};
|
||||
|
||||
const load = (targetPaths = paths, includeUsed = options.includeUsedVehicles): void => {
|
||||
const load = (targetPaths = paths): void => {
|
||||
if (targetPaths.length === 0) return;
|
||||
setBusy(true);
|
||||
setImported(false);
|
||||
ipcInvoke('saves:previewOfficial', { copyId, userId, paths: targetPaths, includeUsedVehicles: includeUsed })
|
||||
ipcInvoke('saves:previewOfficial', { copyId, userId, paths: targetPaths })
|
||||
.then(setPreview)
|
||||
.catch(onError)
|
||||
.finally(() => setBusy(false));
|
||||
@@ -178,19 +178,6 @@ export function OfficialSaveImport({ copyId, userId, readOnly, onError, onImport
|
||||
<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) => {
|
||||
const nextInclude = event.target.checked;
|
||||
setOptions({ ...options, includeUsedVehicles: nextInclude });
|
||||
setImported(false);
|
||||
if (paths.length > 0 && preview) {
|
||||
load(paths, nextInclude);
|
||||
} else {
|
||||
setPreview(null);
|
||||
}
|
||||
}} />
|
||||
{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>
|
||||
|
||||
@@ -213,7 +213,7 @@ export const ipcContract = {
|
||||
output: z.array(z.string()),
|
||||
},
|
||||
'saves:previewOfficial': {
|
||||
input: SaveOfficialRequestSchema.extend({ includeUsedVehicles: z.boolean() }),
|
||||
input: SaveOfficialRequestSchema,
|
||||
output: OfficialPreviewSchema,
|
||||
},
|
||||
'saves:importOfficial': {
|
||||
|
||||
@@ -80,7 +80,7 @@ export const SaveOfficialRequestSchema = SaveKeysSchema.extend({
|
||||
paths: z.array(z.string().min(1)).min(1).max(3),
|
||||
});
|
||||
export const OfficialImportOptionsSchema = z.object({
|
||||
importSettings: z.boolean(), unlockVehicles: z.boolean(), includeUsedVehicles: z.boolean(),
|
||||
importSettings: z.boolean(), unlockVehicles: z.boolean(),
|
||||
equipment: z.enum(['full', 'basic', 'stock']),
|
||||
});
|
||||
export const OfficialPreviewSchema = z.object({
|
||||
|
||||
Reference in new issue
Block a user