feat(saves): import official game backups
This commit is contained in:
1 parent
2e3cc0aaec
commit
597df6b4f5
15 files changed
+661
-16
No files matched your search
@@ -1,12 +1,12 @@
|
||||
import { join } from 'node:path';
|
||||
import { dialog, utilityProcess, type BrowserWindow } from 'electron';
|
||||
import { compareVersions } from '@wto/patcher';
|
||||
import { isAbsolute, join } from 'node:path';
|
||||
import { app, dialog, utilityProcess, type BrowserWindow } from 'electron';
|
||||
import { compareVersions, isInSteamLibrary } from '@wto/patcher';
|
||||
import { AppError } from '@shared/errors.ts';
|
||||
import type { InstallRecord } from '@shared/schemas/install.ts';
|
||||
import type { CurrencyEdits, SaveBackup, SaveDetails, SaveList, SaveRegistration, SaveTransfer } from '@shared/schemas/saves.ts';
|
||||
import type { CurrencyEdits, OfficialImportOptions, OfficialPreview, SaveBackup, SaveDetails, SaveList, SaveRegistration, SaveTransfer } from '@shared/schemas/saves.ts';
|
||||
import type { SaveReply, SaveResult, SaveTask } from '../../workers/save-protocol.ts';
|
||||
import { maintenanceInProgress } from '../copies/copy-maintenance.ts';
|
||||
import { listCopies, updateCopyRecord } from '../install/install-record.ts';
|
||||
import { canonicalCopyPath, copyPathContains, listCopies, updateCopyRecord } from '../install/install-record.ts';
|
||||
import { gameProcessRunning, launchInProgress } from '../launch/launch-controller.ts';
|
||||
import { labStatusUrl, readInstalledLab } from '../launch/lab-handoff.ts';
|
||||
import { forwardProcessOutput } from '../launch/process-output.ts';
|
||||
@@ -152,6 +152,52 @@ export async function restoreSaveBackup(copyId: string, userId: string, name: st
|
||||
});
|
||||
}
|
||||
|
||||
export async function pickOfficialBackups(window: BrowserWindow | null): Promise<string[]> {
|
||||
const options = { properties: ['openFile' as const, 'multiSelections' as const], filters: [{ name: 'BLK', extensions: ['blk'] }] };
|
||||
const result = window ? await dialog.showOpenDialog(window, options) : await dialog.showOpenDialog(options);
|
||||
return result.canceled ? [] : result.filePaths;
|
||||
}
|
||||
|
||||
export async function previewSelectedBackups(
|
||||
copyId: string, userId: string, paths: readonly string[], includeUsedVehicles: boolean,
|
||||
): 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;
|
||||
}
|
||||
|
||||
export async function importSelectedBackups(
|
||||
copyId: string, userId: string, paths: readonly string[], options: OfficialImportOptions,
|
||||
): Promise<OfficialPreview> {
|
||||
return write(async () => {
|
||||
const copy = await requireCopy(copyId);
|
||||
await getSaveDetails(copyId, userId);
|
||||
const selected = await verifyBackupLocations(copy, paths);
|
||||
const before = await captureSave(copy, userId);
|
||||
await saveBackup(copy, userId, 'import');
|
||||
try {
|
||||
return await run({ operation: 'importOfficial', ...location(copy), userId, paths: selected, options }) as OfficialPreview;
|
||||
} catch (error) {
|
||||
await restoreDirectory(copy, userId, before);
|
||||
throw error;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
async function verifyBackupLocations(copy: InstallRecord, paths: readonly string[]): Promise<string[]> {
|
||||
const documents = await canonicalCopyPath(join(app.getPath('documents'), 'My Games', 'WarThunder'));
|
||||
const stock = copy.sourcePath && await canonicalCopyPath(copy.sourcePath);
|
||||
return Promise.all(paths.map(async (path) => {
|
||||
if (!isAbsolute(path)) throw new AppError('save_official_location');
|
||||
const selected = await canonicalCopyPath(path);
|
||||
if (isInSteamLibrary(selected) || copyPathContains(documents, selected) || (stock && copyPathContains(stock, selected))) {
|
||||
throw new AppError('save_official_location');
|
||||
}
|
||||
return selected;
|
||||
}));
|
||||
}
|
||||
|
||||
async function validateProfile(archive: SaveArchive, copy: InstallRecord): Promise<void> {
|
||||
const profile = archive.files['profile.blk'];
|
||||
if (!profile) return;
|
||||
|
||||
Reference in new issue
Block a user