diff --git a/lib/core/backup_service.dart b/lib/core/backup_service.dart index ba90a0449..d65530eb5 100644 --- a/lib/core/backup_service.dart +++ b/lib/core/backup_service.dart @@ -2,6 +2,7 @@ import 'dart:convert'; import 'dart:io'; import 'dart:typed_data'; import 'package:cake_wallet/core/secure_storage.dart'; +import 'package:cake_wallet/entities/get_encryption_key.dart'; import 'package:cake_wallet/entities/transaction_description.dart'; import 'package:cake_wallet/themes/theme_list.dart'; import 'package:cw_core/root_dir.dart'; @@ -105,7 +106,15 @@ class BackupService { if (entity.path == archivePath || entity.path == tmpDir.path) { return; } - + final filename = entity.absolute; + for (var ignore in ignoreFiles) { + final filename = entity.absolute.path; + if (filename.endsWith(ignore) && !filename.contains("wallets/")) { + print("ignoring backup file: $filename"); + return; + } + } + print("restoring: $filename"); if (entity.statSync().type == FileSystemEntityType.directory) { zipEncoder.addDirectory(Directory(entity.path)); } else { @@ -148,14 +157,29 @@ class BackupService { await _importPreferencesDump(); } + // checked with .endsWith - so this should be the last part of the filename + static const ignoreFiles = [ + "flutter_assets/kernel_blob.bin", + "flutter_assets/vm_snapshot_data", + "flutter_assets/isolate_snapshot_data", + ".lock", + ]; + Future _importBackupV2(Uint8List data, String password) async { final appDir = await getAppDir(); final decryptedData = await _decryptV2(data, password); final zip = ZipDecoder().decodeBytes(decryptedData); + outer: for (var file in zip.files) { final filename = file.name; - + for (var ignore in ignoreFiles) { + if (filename.endsWith(ignore) && !filename.contains("wallets/")) { + print("ignoring backup file: $filename"); + continue outer; + } + } + print("restoring: $filename"); if (file.isFile) { final content = file.content as List; File('${appDir.path}/' + filename) @@ -206,6 +230,16 @@ class BackupService { json.decode(transactionDescriptionFile.readAsStringSync()) as Map; final descriptionsMap = jsonData.map((key, value) => MapEntry(key, TransactionDescription.fromJson(value as Map))); + + if (!_transactionDescriptionBox.isOpen) { + final transactionDescriptionsBoxKey = await getEncryptionKey(secureStorage: secureStorageShared, forKey: TransactionDescription.boxKey); + final transactionDescriptionBox = await CakeHive.openBox( + TransactionDescription.boxName, + encryptionKey: transactionDescriptionsBoxKey, + ); + await transactionDescriptionBox.putAll(descriptionsMap); + return; + } await _transactionDescriptionBox.putAll(descriptionsMap); }