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

+2
View File
@@ -19,6 +19,8 @@ export const APP_ERROR_CODES = [
'copy_not_found',
'save_not_found',
'save_archive_invalid',
'save_official_invalid',
'save_official_location',
'save_read_only',
'save_operation_failed',
'save_login_invalid',
+13 -1
View File
@@ -15,7 +15,7 @@ import {
} from '../schemas/install.ts';
import { LabInfoSchema, LaunchStateSchema } from '../schemas/launch.ts';
import { MaintenanceInfoSchema, MaintenanceProgressSchema, MaintenanceRequestSchema } from '../schemas/maintenance.ts';
import { CurrencyEditsSchema, SaveBackupNameSchema, SaveBackupSchema, SaveDetailsSchema, SaveKeysSchema, SaveListSchema, SaveRegistrationSchema, SaveTransferSchema } from '../schemas/saves.ts';
import { OfficialImportOptionsSchema, OfficialPreviewSchema, SaveOfficialRequestSchema, CurrencyEditsSchema, SaveBackupNameSchema, SaveBackupSchema, SaveDetailsSchema, SaveKeysSchema, SaveListSchema, SaveRegistrationSchema, SaveTransferSchema } from '../schemas/saves.ts';
import { SettingsPatchSchema, SettingsSchema } from '../schemas/settings.ts';
/**
@@ -176,6 +176,18 @@ export const ipcContract = {
input: SaveKeysSchema.extend({ name: SaveBackupNameSchema }),
output: SaveDetailsSchema,
},
'saves:pickOfficialBackups': {
input: z.void(),
output: z.array(z.string()),
},
'saves:previewOfficial': {
input: SaveOfficialRequestSchema.extend({ includeUsedVehicles: z.boolean() }),
output: OfficialPreviewSchema,
},
'saves:importOfficial': {
input: SaveOfficialRequestSchema.extend({ options: OfficialImportOptionsSchema }),
output: OfficialPreviewSchema,
},
'launch:getState': {
input: z.void(),
output: LaunchStateSchema,
+18 -2
View File
@@ -46,11 +46,27 @@ export const SaveTransferSchema = SaveRegistrationSchema.extend({
z.object({ kind: z.literal('file'), path: z.string().min(1) }),
]),
});
export const SaveBackupNameSchema = z.string().regex(/^\d{4}-\d{2}-\d{2}T\d{2}-\d{2}-\d{2}-\d{3}Z\.(manual|launch|restore)\.[0-9a-f-]{36}\.zip$/);
export const SaveBackupNameSchema = z.string().regex(/^\d{4}-\d{2}-\d{2}T\d{2}-\d{2}-\d{2}-\d{3}Z\.(manual|launch|restore|import)\.[0-9a-f-]{36}\.zip$/);
export const SaveBackupSchema = z.object({
name: SaveBackupNameSchema, createdAt: z.string(), type: z.enum(['manual', 'launch', 'restore']), size: z.number().int().nonnegative(),
name: SaveBackupNameSchema, createdAt: z.string(), type: z.enum(['manual', 'launch', 'restore', 'import']), size: z.number().int().nonnegative(),
});
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(),
equipment: z.enum(['full', 'basic', 'stock']),
});
export const OfficialPreviewSchema = z.object({
files: z.array(z.object({ name: z.string(), version: z.number().int() })),
presets: z.array(z.object({ country: z.string(), title: z.string(), vehicles: z.array(z.string()) })),
vehicles: z.array(z.string()),
omitted: z.array(z.string()),
});
export type OfficialPreview = z.output<typeof OfficialPreviewSchema>;
export type OfficialImportOptions = z.output<typeof OfficialImportOptionsSchema>;
export type SaveTransfer = z.output<typeof SaveTransferSchema>;
export type SaveBackup = z.output<typeof SaveBackupSchema>;