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' };
|
||||
|
||||
Reference in new issue
Block a user